libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
baseplotwidget.cpp
Go to the documentation of this file.
1/* This code comes right from the msXpertSuite software project.
2 *
3 * msXpertSuite - mass spectrometry software suite
4 * -----------------------------------------------
5 * Copyright(C) 2009,...,2018 Filippo Rusconi
6 *
7 * http://www.msxpertsuite.org
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 * END software license
23 */
24
25
26/////////////////////// StdLib includes
27#include <vector>
28
29
30/////////////////////// Qt includes
31#include <QVector>
32
33
34/////////////////////// Local includes
35#include "../../types.h"
36#include "../../utils.h"
37#include "baseplotwidget.h"
38#include "../../pappsoexception.h"
39#include "../../exception/exceptionnotpossible.h"
40
41
43 qRegisterMetaType<pappso::BasePlotContext>("pappso::BasePlotContext");
45 qRegisterMetaType<pappso::BasePlotContext *>("pappso::BasePlotContext *");
46
47
48namespace pappso
49{
50BasePlotWidget::BasePlotWidget(QWidget *parent) : QCustomPlot(parent)
51{
52 if(parent == nullptr)
53 qFatal("Programming error.");
54
55 // Default settings for the pen used to graph the data.
56 m_pen.setStyle(Qt::SolidLine);
57 m_pen.setBrush(Qt::black);
58 m_pen.setWidth(1);
59
60 // qDebug() << "Created new BasePlotWidget with" << layerCount()
61 //<< "layers before setting up widget.";
62 // qDebug().noquote() << "All layer names:\n" << allLayerNamesToString();
63
64 // As of today 20210313, the QCustomPlot is created with the following 6
65 // layers:
66 //
67 // All layers' name:
68 //
69 // Layer index 0 name: background
70 // Layer index 1 name: grid
71 // Layer index 2 name: main
72 // Layer index 3 name: axes
73 // Layer index 4 name: legend
74 // Layer index 5 name: overlay
75
76 if(!setupWidget())
77 qFatal("Programming error.");
78
79 // Do not call createAllAncillaryItems() in this base class because all the
80 // items will have been created *before* the addition of plots and then the
81 // rendering order will hide them to the viewer, since the rendering order is
82 // according to the order in which the items have been created.
83 //
84 // The fact that the ancillary items are created before trace plots is not a
85 // problem because the trace plots are sparse and do not effectively hide the
86 // data.
87 //
88 // But, in the color map plot widgets, we cannot afford to create the
89 // ancillary items *before* the plot itself because then, the rendering of the
90 // plot (created after) would screen off the ancillary items (created before).
91 //
92 // So, the createAllAncillaryItems() function needs to be called in the
93 // derived classes at the most appropriate moment in the setting up of the
94 // widget.
95 //
96 // All this is only a workaround of a bug in QCustomPlot. See
97 // https://www.qcustomplot.com/index.php/support/forum/2283.
98 //
99 // I initially wanted to have a plots layer on top of the default background
100 // layer and a items layer on top of it. But that setting prevented the
101 // selection of graphs.
102
103 // qDebug() << "Created new BasePlotWidget with" << layerCount()
104 //<< "layers after setting up widget.";
105 // qDebug().noquote() << "All layer names:\n" << allLayerNamesToString();
106
107 show();
108}
109
110
112 const QString &x_axis_label,
113 const QString &y_axis_label)
114 : QCustomPlot(parent), m_axisLabelX(x_axis_label), m_axisLabelY(y_axis_label)
115{
116 // qDebug();
117
118 if(parent == nullptr)
119 qFatal("Programming error.");
120
121 // Default settings for the pen used to graph the data.
122 m_pen.setStyle(Qt::SolidLine);
123 m_pen.setBrush(Qt::black);
124 m_pen.setWidth(1);
125
126 xAxis->setLabel(x_axis_label);
127 yAxis->setLabel(y_axis_label);
128
129 // qDebug() << "Created new BasePlotWidget with" << layerCount()
130 //<< "layers before setting up widget.";
131 // qDebug().noquote() << "All layer names:\n" << allLayerNamesToString();
132
133 // As of today 20210313, the QCustomPlot is created with the following 6
134 // layers:
135 //
136 // All layers' name:
137 //
138 // Layer index 0 name: background
139 // Layer index 1 name: grid
140 // Layer index 2 name: main
141 // Layer index 3 name: axes
142 // Layer index 4 name: legend
143 // Layer index 5 name: overlay
144
145 if(!setupWidget())
146 qFatal("Programming error.");
147
148 // qDebug() << "Created new BasePlotWidget with" << layerCount()
149 //<< "layers after setting up widget.";
150 // qDebug().noquote() << "All layer names:\n" << allLayerNamesToString();
151
152 show();
153}
154
155
156//! Destruct \c this BasePlotWidget instance.
157/*!
158
159 The destruction involves clearing the history, deleting all the axis range
160 history items for x and y axes.
161
162*/
164{
165 // qDebug() << "In the destructor of plot widget:" << this;
166
167 m_xAxisRangeHistory.clear();
168 m_yAxisRangeHistory.clear();
169
170 // Note that the QCustomPlot xxxItem objects are allocated with (this) which
171 // means their destruction is automatically handled upon *this' destruction.
172}
173
174
175QString
177{
178
179 QString text;
180
181 for(int iter = 0; iter < layerCount(); ++iter)
182 {
183 text +=
184 QString("Layer index %1: %2\n").arg(iter).arg(layer(iter)->name());
185 }
186
187 return text;
188}
189
190
191QString
192BasePlotWidget::layerableLayerName(QCPLayerable *layerable_p) const
193{
194 if(layerable_p == nullptr)
195 qFatal("Programming error.");
196
197 QCPLayer *layer_p = layerable_p->layer();
198
199 return layer_p->name();
200}
201
202
203int
204BasePlotWidget::layerableLayerIndex(QCPLayerable *layerable_p) const
205{
206 if(layerable_p == nullptr)
207 qFatal("Programming error.");
208
209 QCPLayer *layer_p = layerable_p->layer();
210
211 for(int iter = 0; iter < layerCount(); ++iter)
212 {
213 if(layer(iter) == layer_p)
214 return iter;
215 }
216
217 return -1;
218}
219
220void
222{
223 // Make a copy of the pen to just change its color and set that color to
224 // the tracer line.
225 QPen pen = m_pen;
226
227 // Create the lines that will act as tracers for position and selection of
228 // regions.
229 //
230 // We have the cross hair that serves as the cursor. That crosshair cursor is
231 // made of a vertical line (green, because when click-dragging the mouse it
232 // becomes the tracer that is being anchored at the region start. The second
233 // line i horizontal and is always black.
234
235 pen.setColor(QColor("steelblue"));
236
237 // The set of tracers (horizontal and vertical) that track the position of the
238 // mouse cursor.
239
240 mp_vPosTracerItem = new QCPItemLine(this);
241 mp_vPosTracerItem->setLayer("plotsLayer");
242 mp_vPosTracerItem->setPen(pen);
243 mp_vPosTracerItem->start->setType(QCPItemPosition::ptPlotCoords);
244 mp_vPosTracerItem->end->setType(QCPItemPosition::ptPlotCoords);
245 mp_vPosTracerItem->start->setCoords(0, 0);
246 mp_vPosTracerItem->end->setCoords(0, 0);
247
248 mp_hPosTracerItem = new QCPItemLine(this);
249 mp_hPosTracerItem->setLayer("plotsLayer");
250 mp_hPosTracerItem->setPen(pen);
251 mp_hPosTracerItem->start->setType(QCPItemPosition::ptPlotCoords);
252 mp_hPosTracerItem->end->setType(QCPItemPosition::ptPlotCoords);
253 mp_hPosTracerItem->start->setCoords(0, 0);
254 mp_hPosTracerItem->end->setCoords(0, 0);
255
256 // The set of tracers (horizontal only) that track the region
257 // spanning/selection regions.
258 //
259 // The start vertical tracer is colored in greeen.
260 pen.setColor(QColor("green"));
261
262 mp_vStartTracerItem = new QCPItemLine(this);
263 mp_vStartTracerItem->setLayer("plotsLayer");
264 mp_vStartTracerItem->setPen(pen);
265 mp_vStartTracerItem->start->setType(QCPItemPosition::ptPlotCoords);
266 mp_vStartTracerItem->end->setType(QCPItemPosition::ptPlotCoords);
267 mp_vStartTracerItem->start->setCoords(0, 0);
268 mp_vStartTracerItem->end->setCoords(0, 0);
269
270 // The end vertical tracer is colored in red.
271 pen.setColor(QColor("red"));
272
273 mp_vEndTracerItem = new QCPItemLine(this);
274 mp_vEndTracerItem->setLayer("plotsLayer");
275 mp_vEndTracerItem->setPen(pen);
276 mp_vEndTracerItem->start->setType(QCPItemPosition::ptPlotCoords);
277 mp_vEndTracerItem->end->setType(QCPItemPosition::ptPlotCoords);
278 mp_vEndTracerItem->start->setCoords(0, 0);
279 mp_vEndTracerItem->end->setCoords(0, 0);
280
281 // When the user click-drags the mouse, the X distance between the drag start
282 // point and the drag end point (current point) is the xDelta.
283 mp_xDeltaTextItem = new QCPItemText(this);
284 mp_xDeltaTextItem->setLayer("plotsLayer");
285 mp_xDeltaTextItem->setColor(QColor("steelblue"));
286 mp_xDeltaTextItem->setPositionAlignment(Qt::AlignBottom | Qt::AlignCenter);
287 mp_xDeltaTextItem->position->setType(QCPItemPosition::ptPlotCoords);
288 mp_xDeltaTextItem->setVisible(false);
289
290 // Same for the y delta
291 mp_yDeltaTextItem = new QCPItemText(this);
292 mp_yDeltaTextItem->setLayer("plotsLayer");
293 mp_yDeltaTextItem->setColor(QColor("steelblue"));
294 mp_yDeltaTextItem->setPositionAlignment(Qt::AlignBottom | Qt::AlignCenter);
295 mp_yDeltaTextItem->position->setType(QCPItemPosition::ptPlotCoords);
296 mp_yDeltaTextItem->setVisible(false);
297
298 // Make sure we prepare the four lines that will be needed to
299 // draw the selection rectangle.
300 pen = m_pen;
301
302 pen.setColor("steelblue");
303
304 mp_selectionRectangeLine1 = new QCPItemLine(this);
305 mp_selectionRectangeLine1->setLayer("plotsLayer");
306 mp_selectionRectangeLine1->setPen(pen);
307 mp_selectionRectangeLine1->start->setType(QCPItemPosition::ptPlotCoords);
308 mp_selectionRectangeLine1->end->setType(QCPItemPosition::ptPlotCoords);
309 mp_selectionRectangeLine1->start->setCoords(0, 0);
310 mp_selectionRectangeLine1->end->setCoords(0, 0);
311 mp_selectionRectangeLine1->setVisible(false);
312
313 mp_selectionRectangeLine2 = new QCPItemLine(this);
314 mp_selectionRectangeLine2->setLayer("plotsLayer");
315 mp_selectionRectangeLine2->setPen(pen);
316 mp_selectionRectangeLine2->start->setType(QCPItemPosition::ptPlotCoords);
317 mp_selectionRectangeLine2->end->setType(QCPItemPosition::ptPlotCoords);
318 mp_selectionRectangeLine2->start->setCoords(0, 0);
319 mp_selectionRectangeLine2->end->setCoords(0, 0);
320 mp_selectionRectangeLine2->setVisible(false);
321
322 mp_selectionRectangeLine3 = new QCPItemLine(this);
323 mp_selectionRectangeLine3->setLayer("plotsLayer");
324 mp_selectionRectangeLine3->setPen(pen);
325 mp_selectionRectangeLine3->start->setType(QCPItemPosition::ptPlotCoords);
326 mp_selectionRectangeLine3->end->setType(QCPItemPosition::ptPlotCoords);
327 mp_selectionRectangeLine3->start->setCoords(0, 0);
328 mp_selectionRectangeLine3->end->setCoords(0, 0);
329 mp_selectionRectangeLine3->setVisible(false);
330
331 mp_selectionRectangeLine4 = new QCPItemLine(this);
332 mp_selectionRectangeLine4->setLayer("plotsLayer");
333 mp_selectionRectangeLine4->setPen(pen);
334 mp_selectionRectangeLine4->start->setType(QCPItemPosition::ptPlotCoords);
335 mp_selectionRectangeLine4->end->setType(QCPItemPosition::ptPlotCoords);
336 mp_selectionRectangeLine4->start->setCoords(0, 0);
337 mp_selectionRectangeLine4->end->setCoords(0, 0);
338 mp_selectionRectangeLine4->setVisible(false);
339}
340
341
342bool
344{
345 // qDebug();
346
347 // By default the widget comes with a graph. Remove it.
348
349 if(graphCount())
350 {
351 // QCPLayer *layer_p = graph(0)->layer();
352 // qDebug() << "The graph was on layer:" << layer_p->name();
353
354 // As of today 20210313, the graph is created on the currentLayer(), that
355 // is "main".
356
357 removeGraph(0);
358 }
359
360 // The general idea is that we do want custom layers for the trace|colormap
361 // plots.
362
363 // qDebug().noquote() << "Right before creating the new layer, layers:\n"
364 //<< allLayerNamesToString();
365
366 // Add the layer that will store all the plots and all the ancillary items.
367 addLayer(
368 "plotsLayer", layer("background"), QCustomPlot::LayerInsertMode::limAbove);
369 // qDebug().noquote() << "Added new plotsLayer, layers:\n"
370 //<< allLayerNamesToString();
371
372 // This is required so that we get the keyboard events.
373 setFocusPolicy(Qt::StrongFocus);
374 setInteractions(QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iMultiSelect);
375
376 // We want to capture the signals emitted by the QCustomPlot base class.
377 connect(
378 this, &QCustomPlot::mouseMove, this, &BasePlotWidget::mouseMoveHandler);
379
380 connect(
381 this, &QCustomPlot::mousePress, this, &BasePlotWidget::mousePressHandler);
382
383 connect(this,
384 &QCustomPlot::mouseRelease,
385 this,
387
388 connect(
389 this, &QCustomPlot::mouseWheel, this, &BasePlotWidget::mouseWheelHandler);
390
391 connect(this,
392 &QCustomPlot::axisDoubleClick,
393 this,
395
396 return true;
397}
398
399
400void
402{
403 m_pen = pen;
404}
405
406
407const QPen &
409{
410 return m_pen;
411}
412
413
414void
415BasePlotWidget::setPlottingColor(QCPAbstractPlottable *plottable_p,
416 const QColor &new_color)
417{
418 if(plottable_p == nullptr)
419 qFatal("Pointer cannot be nullptr.");
420
421 // First this single-graph widget
422 QPen pen;
423
424 pen = plottable_p->pen();
425 pen.setColor(new_color);
426 plottable_p->setPen(pen);
427
428 replot();
429}
430
431
432void
433BasePlotWidget::setPlottingColor(int index, const QColor &new_color)
434{
435 if(!new_color.isValid())
436 return;
437
438 QCPGraph *graph_p = graph(index);
439
440 if(graph_p == nullptr)
441 qFatal("Programming error.");
442
443 return setPlottingColor(graph_p, new_color);
444}
445
446
447QColor
448BasePlotWidget::getPlottingColor(QCPAbstractPlottable *plottable_p) const
449{
450 if(plottable_p == nullptr)
451 qFatal("Programming error.");
452
453 return plottable_p->pen().color();
454}
455
456
457QColor
459{
460 QCPGraph *graph_p = graph(index);
461
462 if(graph_p == nullptr)
463 qFatal("Programming error.");
464
465 return getPlottingColor(graph_p);
466}
467
468
469void
470BasePlotWidget::setAxisLabelX(const QString &label)
471{
472 xAxis->setLabel(label);
473}
474
475
476void
477BasePlotWidget::setAxisLabelY(const QString &label)
478{
479 yAxis->setLabel(label);
480}
481
482
483// AXES RANGE HISTORY-related functions
484void
486{
487 m_xAxisRangeHistory.clear();
488 m_yAxisRangeHistory.clear();
489
490 m_xAxisRangeHistory.push_back(new QCPRange(xAxis->range()));
491 m_yAxisRangeHistory.push_back(new QCPRange(yAxis->range()));
492
493 // qDebug() << "size of history:" << m_xAxisRangeHistory.size()
494 //<< "setting index to 0";
495
496 // qDebug() << "resetting axes history to values:" << xAxis->range().lower
497 //<< "--" << xAxis->range().upper << "and" << yAxis->range().lower
498 //<< "--" << yAxis->range().upper;
499
501}
502
503
504//! Create new axis range history items and append them to the history.
505/*!
506
507 The plot widget is queried to get the current x/y-axis ranges and the
508 current ranges are appended to the history for x-axis and for y-axis.
509
510*/
511void
513{
514 m_xAxisRangeHistory.push_back(new QCPRange(xAxis->range()));
515 m_yAxisRangeHistory.push_back(new QCPRange(yAxis->range()));
516
518
519 // qDebug() << "axes history size:" << m_xAxisRangeHistory.size()
520 //<< "current index:" << m_lastAxisRangeHistoryIndex
521 //<< xAxis->range().lower << "--" << xAxis->range().upper << "and"
522 //<< yAxis->range().lower << "--" << yAxis->range().upper;
523}
524
525
526//! Go up one history element in the axis history.
527/*!
528
529 If possible, back up one history item in the axis histories and update the
530 plot's x/y-axis ranges to match that history item.
531
532*/
533void
535{
536 // qDebug() << "axes history size:" << m_xAxisRangeHistory.size()
537 //<< "current index:" << m_lastAxisRangeHistoryIndex;
538
540 {
541 // qDebug() << "current index is 0 returning doing nothing";
542
543 return;
544 }
545
546 // qDebug() << "Setting index to:" << m_lastAxisRangeHistoryIndex - 1
547 //<< "and restoring axes history to that index";
548
550}
551
552
553//! Get the axis histories at index \p index and update the plot ranges.
554/*!
555
556 \param index index at which to select the axis history item.
557
558 \sa updateAxesRangeHistory().
559
560*/
561void
563{
564 // qDebug() << "Axes history size:" << m_xAxisRangeHistory.size()
565 //<< "current index:" << m_lastAxisRangeHistoryIndex
566 //<< "asking to restore index:" << index;
567
568 if(index >= m_xAxisRangeHistory.size())
569 {
570 // qDebug() << "index >= history size. Returning.";
571 return;
572 }
573
574 // We want to go back to the range history item at index, which means we want
575 // to pop back all the items between index+1 and size-1.
576
577 while(m_xAxisRangeHistory.size() > index + 1)
578 m_xAxisRangeHistory.pop_back();
579
580 if(m_xAxisRangeHistory.size() - 1 != index)
581 qFatal("Programming error.");
582
583 xAxis->setRange(*(m_xAxisRangeHistory.at(index)));
584 yAxis->setRange(*(m_yAxisRangeHistory.at(index)));
585
587
588 mp_vPosTracerItem->setVisible(false);
589 mp_hPosTracerItem->setVisible(false);
590
591 mp_vStartTracerItem->setVisible(false);
592 mp_vEndTracerItem->setVisible(false);
593
594
595 // The start tracer will keep beeing represented at the last position and last
596 // size even if we call this function repetitively. So actually do not show,
597 // it will reappare as soon as the mouse is moved.
598 // if(m_shouldTracersBeVisible)
599 //{
600 // mp_vStartTracerItem->setVisible(true);
601 //}
602
603 replot();
604
606
607 // qDebug() << "restored axes history to index:" << index
608 //<< "with values:" << xAxis->range().lower << "--"
609 //<< xAxis->range().upper << "and" << yAxis->range().lower << "--"
610 //<< yAxis->range().upper;
611
613}
614// AXES RANGE HISTORY-related functions
615
616
617/// KEYBOARD-related EVENTS
618void
620{
621 // qDebug() << "ENTER";
622
623 // We need this because some keys modify our behaviour.
624 m_context.m_pressedKeyCode = event->key();
625 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
626
627 if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
628 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
629 {
630 return directionKeyPressEvent(event);
631 }
632 else if(event->key() == m_leftMousePseudoButtonKey ||
633 event->key() == m_rightMousePseudoButtonKey)
634 {
635 return mousePseudoButtonKeyPressEvent(event);
636 }
637
638 // Do not do anything here, because this function is used by derived classes
639 // that will emit the signal below. Otherwise there are going to be multiple
640 // signals sent.
641 // qDebug() << "Going to emit keyPressEventSignal(m_context);";
642 // emit keyPressEventSignal(m_context);
643}
644
645
646//! Handle specific key codes and trigger respective actions.
647void
649{
650 m_context.m_releasedKeyCode = event->key();
651
652 // The keyboard key is being released, set the key code to 0.
654
655 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
656
657 // Now test if the key that was released is one of the housekeeping keys.
658 if(event->key() == Qt::Key_Backspace)
659 {
660 // qDebug();
661
662 // The user wants to iterate back in the x/y axis range history.
664
665 event->accept();
666 }
667 else if(event->key() == Qt::Key_Space)
668 {
669 return spaceKeyReleaseEvent(event);
670 }
671 else if(event->key() == Qt::Key_Delete)
672 {
673 // The user wants to delete a graph. What graph is to be determined
674 // programmatically:
675
676 // If there is a single graph, then that is the graph to be removed.
677 // If there are more than one graph, then only the ones that are selected
678 // are to be removed.
679
680 // Note that the user of this widget might want to provide the user with
681 // the ability to specify if all the children graph needs to be removed
682 // also. This can be coded in key modifiers. So provide the context.
683
684 int graph_count = plottableCount();
685
686 if(!graph_count)
687 {
688 // qDebug() << "Not a single graph in the plot widget. Doing
689 // nothing.";
690
691 event->accept();
692 return;
693 }
694
695 if(graph_count == 1)
696 {
697 // qDebug() << "A single graph is in the plot widget. Emitting a graph
698 // " "destruction requested signal for it:"
699 //<< graph();
700
702 }
703 else
704 {
705 // At this point we know there are more than one graph in the plot
706 // widget. We need to get the selected one (if any).
707 QList<QCPGraph *> selected_graph_list;
708
709 selected_graph_list = selectedGraphs();
710
711 if(!selected_graph_list.size())
712 {
713 event->accept();
714 return;
715 }
716
717 // qDebug() << "Number of selected graphs to be destrobyed:"
718 //<< selected_graph_list.size();
719
720 for(int iter = 0; iter < selected_graph_list.size(); ++iter)
721 {
722 // qDebug()
723 //<< "Emitting a graph destruction requested signal for graph:"
724 //<< selected_graph_list.at(iter);
725
727 this, selected_graph_list.at(iter), m_context);
728
729 // We do not do this, because we want the slot called by the
730 // signal above to handle that removal. Remember that it is not
731 // possible to delete graphs manually.
732 //
733 // removeGraph(selected_graph_list.at(iter));
734 }
735 event->accept();
736 }
737 }
738 // End of
739 // else if(event->key() == Qt::Key_Delete)
740 else if(event->key() == Qt::Key_T)
741 {
742 // The user wants to toggle the visibiity of the tracers.
744
746 hideTracers();
747 else
748 showTracers();
749
750 event->accept();
751 }
752 else if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
753 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
754 {
755 return directionKeyReleaseEvent(event);
756 }
757 else if(event->key() == m_leftMousePseudoButtonKey ||
758 event->key() == m_rightMousePseudoButtonKey)
759 {
761 }
762 else if(event->key() == Qt::Key_S)
763 {
764 // The user is defining the size of the rhomboid fixed side. That could be
765 // either a vertical side (less intuitive) or a horizontal size (more
766 // intuitive, first exclusive implementation). But, in order to be able to
767 // perform identical integrations starting from non-transposed color maps
768 // and transposed color maps, the ability to define a vertical fixed size
769 // side of the rhomboid integration scope has become necessary.
770
771 // Check if the vertical displacement is significant (>= 10% of the color
772 // map height.
773
775 {
776 // The user is dragging the cursor vertically in a sufficient delta to
777 // consider that they are willing to define a vertical fixed size
778 // of the rhomboid integration scope.
779
783
784 // qDebug() << "Set m_context.m_integrationScopePolyHeight to"
785 // << m_context.m_integrationScopeRhombHeight
786 // << "upon release of S key";
787 }
788 else
789 {
790 // The user is dragging the cursor horiontally to define a horizontal
791 // fixed size of the rhomboid integration scope.
792
796
797 // qDebug() << "Set m_context.m_integrationScopePolyWidth to"
798 // << m_context.m_integrationScopeRhombWidth
799 // << "upon release of S key";
800 }
801 }
802 // At this point emit the signal, since we did not treat it. Maybe the
803 // consumer widget wants to know that the keyboard key was released.
804
806}
807
808
809void
810BasePlotWidget::spaceKeyReleaseEvent([[maybe_unused]] QKeyEvent *event)
811{
812 // qDebug();
813}
814
815
816void
818{
819 // qDebug() << "event key:" << event->key();
820
821 // The user is trying to move the positional cursor/markers. There are
822 // multiple way they can do that:
823 //
824 // 1.a. Hitting the arrow left/right keys alone will search for next pixel.
825 // 1.b. Hitting the arrow left/right keys with Alt modifier will search for
826 // a multiple of pixels that might be equivalent to one 20th of the pixel
827 // width of the plot widget. 1.c Hitting the left/right keys with Alt and
828 // Shift modifiers will search for a multiple of pixels that might be the
829 // equivalent to half of the pixel width.
830 //
831 // 2. Hitting the Control modifier will move the cursor to the next data
832 // point of the graph.
833
834 int pixel_increment = 0;
835
836 if(m_context.m_keyboardModifiers == Qt::NoModifier)
837 pixel_increment = 1;
838 else if(m_context.m_keyboardModifiers == Qt::AltModifier)
839 pixel_increment = 50;
840
841 // The user is moving the positional markers. This is equivalent to a
842 // non-dragging cursor movement to the next pixel. Note that the origin is
843 // located at the top left, so key down increments and key up decrements.
844
845 if(event->key() == Qt::Key_Left)
846 horizontalMoveMouseCursorCountPixels(-pixel_increment);
847 else if(event->key() == Qt::Key_Right)
849 else if(event->key() == Qt::Key_Up)
850 verticalMoveMouseCursorCountPixels(-pixel_increment);
851 else if(event->key() == Qt::Key_Down)
852 verticalMoveMouseCursorCountPixels(pixel_increment);
853
854 event->accept();
855}
856
857
858void
860{
861 // qDebug() << "event key:" << event->key();
862 event->accept();
863}
864
865
866void
868 [[maybe_unused]] QKeyEvent *event)
869{
870 // qDebug();
871}
872
873
874void
876{
877
878 QPointF pixel_coordinates(
879 xAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.x()),
880 yAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.y()));
881
882 Qt::MouseButton button = Qt::NoButton;
883 QEvent::Type q_event_type = QEvent::MouseButtonPress;
884
885 if(event->key() == m_leftMousePseudoButtonKey)
886 {
887 // Toggles the left mouse button on/off
888
889 button = Qt::LeftButton;
890
893
895 q_event_type = QEvent::MouseButtonPress;
896 else
897 q_event_type = QEvent::MouseButtonRelease;
898 }
899 else if(event->key() == m_rightMousePseudoButtonKey)
900 {
901 // Toggles the right mouse button.
902
903 button = Qt::RightButton;
904
907
909 q_event_type = QEvent::MouseButtonPress;
910 else
911 q_event_type = QEvent::MouseButtonRelease;
912 }
913
914 // qDebug() << "pressed/released pseudo button:" << button
915 //<< "q_event_type:" << q_event_type;
916
917 // Synthesize a QMouseEvent and use it.
918
919 QMouseEvent *mouse_event_p =
920 new QMouseEvent(q_event_type,
921 pixel_coordinates,
922 mapToGlobal(pixel_coordinates.toPoint()),
923 mapToGlobal(pixel_coordinates.toPoint()),
924 button,
925 button,
927 Qt::MouseEventSynthesizedByApplication);
928
929 if(q_event_type == QEvent::MouseButtonPress)
930 mousePressHandler(mouse_event_p);
931 else
932 mouseReleaseHandler(mouse_event_p);
933
934 // event->accept();
935}
936/// KEYBOARD-related EVENTS
937
938
939/// MOUSE-related EVENTS
940
941void
943{
944
945 // If we have no focus, then get it. See setFocus() to understand why asking
946 // for focus is cosly and thus why we want to make this decision first.
947 if(!hasFocus())
948 setFocus();
949
950 // qDebug() << (graph() != nullptr);
951 // if(graph(0) != nullptr)
952 // { // check if the widget contains some graphs
953
954 // The event->button() must be by Qt instructions considered to be 0.
955
956 // Whatever happens, we want to store the plot coordinates of the current
957 // mouse cursor position (will be useful later for countless needs).
958
959 // Fix from Qt5 to Qt6
960#if QT_VERSION < 0x060000
961 QPointF mousePoint = event->localPos();
962#else
963 QPointF mousePoint = event->position();
964#endif
965 // qDebug() << "local mousePoint position in pixels:" << mousePoint;
966
967 m_context.m_lastCursorHoveredPoint.setX(xAxis->pixelToCoord(mousePoint.x()));
968 m_context.m_lastCursorHoveredPoint.setY(yAxis->pixelToCoord(mousePoint.y()));
969
970 // qDebug() << "lastCursorHoveredPoint coord:"
971 //<< m_context.m_lastCursorHoveredPoint;
972
973 // Now, depending on the button(s) (if any) that are pressed or not, we
974 // have a different processing.
975
976 // qDebug();
977
978 if(m_context.m_pressedMouseButtons & Qt::LeftButton ||
979 m_context.m_pressedMouseButtons & Qt::RightButton)
981 else
983 // }
984 // qDebug();
985 event->accept();
986}
987
988
989void
991{
992
993 // qDebug();
995
996 // qDebug();
997 // We are not dragging the mouse (no button pressed), simply let this
998 // widget's consumer know the position of the cursor and update the markers.
999 // The consumer of this widget will update mouse cursor position at
1000 // m_context.m_lastCursorHoveredPoint if so needed.
1001
1003
1004 // qDebug();
1005
1006 // We are not dragging, so we do not show the region end tracer we only
1007 // show the anchoring start trace that might be of use if the user starts
1008 // using the arrow keys to move the cursor.
1009 if(mp_vEndTracerItem != nullptr)
1010 mp_vEndTracerItem->setVisible(false);
1011
1012 // qDebug();
1013 // Only bother with the tracers if the user wants them to be visible.
1014 // Their crossing point must be exactly at the last cursor-hovered point.
1015
1017 {
1018 // We are not dragging, so only show the position markers (v and h);
1019
1020 // qDebug();
1021 if(mp_hPosTracerItem != nullptr)
1022 {
1023 // Horizontal position tracer.
1024 mp_hPosTracerItem->setVisible(true);
1025 mp_hPosTracerItem->start->setCoords(
1026 xAxis->range().lower, m_context.m_lastCursorHoveredPoint.y());
1027 mp_hPosTracerItem->end->setCoords(
1028 xAxis->range().upper, m_context.m_lastCursorHoveredPoint.y());
1029 }
1030
1031 // qDebug();
1032 // Vertical position tracer.
1033 if(mp_vPosTracerItem != nullptr)
1034 {
1035 mp_vPosTracerItem->setVisible(true);
1036
1037 mp_vPosTracerItem->setVisible(true);
1038 mp_vPosTracerItem->start->setCoords(
1039 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().upper);
1040 mp_vPosTracerItem->end->setCoords(
1041 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().lower);
1042 }
1043
1044 // qDebug();
1045 replot();
1046 }
1047
1048
1049 return;
1050}
1051
1052
1053void
1055{
1056 // qDebug();
1058
1059 // Now store the mouse position data into the the current drag point
1060 // member datum, that will be used in countless occasions later.
1062 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
1063
1064 // When we drag (either keyboard or mouse), we hide the position markers
1065 // (black) and we show the start and end vertical markers for the region.
1066 // Then, we draw the horizontal region range marker that delimits
1067 // horizontally the dragged-over region.
1068
1069 if(mp_hPosTracerItem != nullptr)
1070 mp_hPosTracerItem->setVisible(false);
1071 if(mp_vPosTracerItem != nullptr)
1072 mp_vPosTracerItem->setVisible(false);
1073
1074 // Only bother with the tracers if the user wants them to be visible.
1076 {
1077
1078 // The vertical end tracer position must be refreshed.
1079 mp_vEndTracerItem->start->setCoords(m_context.m_currentDragPoint.x(),
1080 yAxis->range().upper);
1081
1083 yAxis->range().lower);
1084
1085 mp_vEndTracerItem->setVisible(true);
1086 }
1087
1088 // Whatever the button, when we are dealing with the axes, we do not
1089 // want to show any of the tracers.
1090
1092 {
1093 if(mp_hPosTracerItem != nullptr)
1094 mp_hPosTracerItem->setVisible(false);
1095 if(mp_vPosTracerItem != nullptr)
1096 mp_vPosTracerItem->setVisible(false);
1097
1098 if(mp_vStartTracerItem != nullptr)
1099 mp_vStartTracerItem->setVisible(false);
1100 if(mp_vEndTracerItem != nullptr)
1101 mp_vEndTracerItem->setVisible(false);
1102 }
1103 else
1104 {
1105 // Since we are not dragging the mouse cursor over the axes, make sure
1106 // we store the drag directions in the context, as this might be
1107 // useful for later operations.
1108
1110
1111 // qDebug() << m_context.toString();
1112 }
1113
1114 // Because when we drag the mouse button (whatever the button) we need to
1115 // know what is the drag delta (distance between start point and current
1116 // point of the drag operation) on both axes, ask that these x|y deltas be
1117 // computed.
1119
1120 // Now deal with the BUTTON-SPECIFIC CODE.
1121
1122 if(m_context.m_mouseButtonsAtMousePress & Qt::LeftButton)
1123 {
1125 }
1126 else if(m_context.m_mouseButtonsAtMousePress & Qt::RightButton)
1127 {
1129 }
1130}
1131
1132
1133void
1135{
1136 // qDebug() << "The left button is dragging.";
1137
1138 // Set the context.m_isMeasuringDistance to false, which later might be set
1139 // to true if effectively we are measuring a distance. This is required
1140 // because the derived widget classes might want to know if they have to
1141 // perform some action on the basis that context is measuring a distance,
1142 // for example the mass spectrum-specific widget might want to compute
1143 // deconvolutions.
1144
1146
1147 // Let's first check if the mouse drag operation originated on either
1148 // axis. In that case, the user is performing axis reframing or rescaling.
1149
1151 {
1152 // qDebug() << "Click was on one of the axes.";
1153
1154 if(m_context.m_keyboardModifiers & Qt::ControlModifier)
1155 {
1156 // The user is asking a rescale of the plot.
1157
1158 // We know that we do not want the tracers when we perform axis
1159 // rescaling operations.
1160
1161 if(mp_hPosTracerItem != nullptr)
1162 mp_hPosTracerItem->setVisible(false);
1163 if(mp_vPosTracerItem != nullptr)
1164 mp_vPosTracerItem->setVisible(false);
1165
1166 if(mp_vStartTracerItem != nullptr)
1167 mp_vStartTracerItem->setVisible(false);
1168 if(mp_vEndTracerItem != nullptr)
1169 mp_vEndTracerItem->setVisible(false);
1170
1171 // This operation is particularly intensive, thus we want to
1172 // reduce the number of calculations by skipping this calculation
1173 // a number of times. The user can ask for this feature by
1174 // clicking the 'Q' letter.
1175
1176 if(m_context.m_pressedKeyCode == Qt::Key_Q)
1177 {
1179 {
1181 return;
1182 }
1183 else
1184 {
1186 }
1187 }
1188
1189 // qDebug() << "Asking that the axes be rescaled.";
1190
1191 axisRescale();
1192 }
1193 else
1194 {
1195 // The user was simply dragging the axis. Just pan, that is slide
1196 // the plot in the same direction as the mouse movement and with the
1197 // same amplitude.
1198
1199 // qDebug() << "Asking that the axes be panned.";
1200
1201 axisPan();
1202 }
1203
1204 return;
1205 }
1206
1207 // At this point we understand that the user was not performing any
1208 // panning/rescaling operation by clicking on any one of the axes.. Go on
1209 // with other possibilities.
1210
1211 // Let's check if the user is actually drawing a rectangle (covering a
1212 // real area) or is drawing a line.
1213
1214 // qDebug() << "The mouse dragging did not originate on an axis.";
1215
1217 {
1218 // qDebug() << "Apparently the selection is two-dimensional.";
1219
1220 // When we draw a two-dimensional integration scope, the tracers are of no
1221 // use.
1222
1223 if(mp_hPosTracerItem != nullptr)
1224 mp_hPosTracerItem->setVisible(false);
1225 if(mp_vPosTracerItem != nullptr)
1226 mp_vPosTracerItem->setVisible(false);
1227
1228 if(mp_vStartTracerItem != nullptr)
1229 mp_vStartTracerItem->setVisible(false);
1230 if(mp_vEndTracerItem != nullptr)
1231 mp_vEndTracerItem->setVisible(false);
1232
1233 // Draw the rectangle, false, not as line segment and
1234 // false, not for integration
1236
1237 // Draw the selection width/height text
1240 }
1241 else
1242 {
1243 // qDebug() << "Apparently we are measuring a delta.";
1244
1245 // Draw the rectangle, true, as line segment and
1246 // false, not for integration
1248
1249 // The pure position tracers should be hidden.
1250 if(mp_hPosTracerItem != nullptr)
1251 mp_hPosTracerItem->setVisible(true);
1252 if(mp_vPosTracerItem != nullptr)
1253 mp_vPosTracerItem->setVisible(true);
1254
1255 // Then, make sure the region range vertical tracers are visible.
1256 if(mp_vStartTracerItem != nullptr)
1257 mp_vStartTracerItem->setVisible(true);
1258 if(mp_vEndTracerItem != nullptr)
1259 mp_vEndTracerItem->setVisible(true);
1260
1261 // Draw the selection width text
1263 }
1264}
1265
1266
1267void
1269{
1270 // qDebug() << "The right button is dragging.";
1271
1272 // Set the context.m_isMeasuringDistance to false, which later might be set
1273 // to true if effectively we are measuring a distance. This is required
1274 // because the derived widgets might want to know if they have to perform
1275 // some action on the basis that context is measuring a distance, for
1276 // example the mass spectrum-specific widget might want to compute
1277 // deconvolutions.
1278
1280
1282 {
1283 // qDebug() << "Apparently the selection has height.";
1284
1285 // When we draw a rectangle the tracers are of no use.
1286
1287 if(mp_hPosTracerItem != nullptr)
1288 mp_hPosTracerItem->setVisible(false);
1289 if(mp_vPosTracerItem != nullptr)
1290 mp_vPosTracerItem->setVisible(false);
1291
1292 if(mp_vStartTracerItem != nullptr)
1293 mp_vStartTracerItem->setVisible(false);
1294 if(mp_vEndTracerItem != nullptr)
1295 mp_vEndTracerItem->setVisible(false);
1296
1297 // Draw the rectangle, false for as_line_segment and true for
1298 // integration.
1300
1301 // Draw the selection width/height text
1304 }
1305 else
1306 {
1307 // qDebug() << "Apparently the selection is a not a rectangle.";
1308
1309 // Draw the rectangle, true as line segment and
1310 // true for integration
1312
1313 // Draw the selection width text
1315 }
1316}
1317
1318
1319void
1321{
1322 // When the user clicks this widget it has to take focus.
1323 setFocus();
1324
1325 // Fix from Qt5 to Qt6
1326 // QPointF mousePoint = event->localPos();
1327
1328#if QT_VERSION < 0x060000
1329 QPointF mousePoint = event->localPos();
1330#else
1331 QPointF mousePoint = event->position();
1332#endif
1333
1334 m_context.m_lastPressedMouseButton = event->button();
1335 m_context.m_mouseButtonsAtMousePress = event->buttons();
1336
1337 // The pressedMouseButtons must continually inform on the status of
1338 // pressed buttons so add the pressed button.
1339 m_context.m_pressedMouseButtons |= event->button();
1340
1341 // qDebug().noquote() << m_context.toString();
1342
1343 // In all the processing of the events, we need to know if the user is
1344 // clicking somewhere with the intent to change the plot ranges (reframing
1345 // or rescaling the plot).
1346 //
1347 // Reframing the plot means that the new x and y axes ranges are modified
1348 // so that they match the region that the user has encompassed by left
1349 // clicking the mouse and dragging it over the plot. That is we reframe
1350 // the plot so that it contains only the "selected" region.
1351 //
1352 // Rescaling the plot means the the new x|y axis range is modified such
1353 // that the lower axis range is constant and the upper axis range is moved
1354 // either left or right by the same amont as the x|y delta encompassed by
1355 // the user moving the mouse. The axis is thus either compressed (mouse
1356 // movement is leftwards) or un-compressed (mouse movement is rightwards).
1357
1358 // There are two ways to perform axis range modifications:
1359 //
1360 // 1. By clicking on any of the axes
1361 // 2. By clicking on the plot region but using keyboard key modifiers,
1362 // like Alt and Ctrl.
1363 //
1364 // We need to know both cases separately which is why we need to perform a
1365 // number of tests below.
1366
1367 // Let's check if the click is on the axes, either X or Y, because that
1368 // will allow us to take proper actions.
1369
1370 if(isClickOntoXAxis(mousePoint))
1371 {
1372 // The X axis was clicked upon, we need to document that:
1373 // qDebug() << __FILE__ << __LINE__
1374 //<< "Layout element is axisRect and actually on an X axis part.";
1375
1377
1378 // int currentInteractions = interactions();
1379 // currentInteractions |= QCP::iRangeDrag;
1380 // setInteractions((QCP::Interaction)currentInteractions);
1381 // axisRect()->setRangeDrag(xAxis->orientation());
1382 }
1383 else
1385
1386 if(isClickOntoYAxis(mousePoint))
1387 {
1388 // The Y axis was clicked upon, we need to document that:
1389 // qDebug() << __FILE__ << __LINE__
1390 //<< "Layout element is axisRect and actually on an Y axis part.";
1391
1393
1394 // int currentInteractions = interactions();
1395 // currentInteractions |= QCP::iRangeDrag;
1396 // setInteractions((QCP::Interaction)currentInteractions);
1397 // axisRect()->setRangeDrag(yAxis->orientation());
1398 }
1399 else
1401
1402 // At this point, let's see if we need to remove the QCP::iRangeDrag bit:
1403
1405 {
1406 // qDebug() << __FILE__ << __LINE__
1407 // << "Click outside of axes.";
1408
1409 // int currentInteractions = interactions();
1410 // currentInteractions = currentInteractions & ~QCP::iRangeDrag;
1411 // setInteractions((QCP::Interaction)currentInteractions);
1412 }
1413
1414 m_context.m_startDragPoint.setX(xAxis->pixelToCoord(mousePoint.x()));
1415 m_context.m_startDragPoint.setY(yAxis->pixelToCoord(mousePoint.y()));
1416
1417 // Now install the vertical start tracer at the last cursor hovered
1418 // position.
1419 if((m_shouldTracersBeVisible) && (mp_vStartTracerItem != nullptr))
1420 mp_vStartTracerItem->setVisible(true);
1421
1422 if(mp_vStartTracerItem != nullptr)
1423 {
1424 mp_vStartTracerItem->start->setCoords(
1425 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().upper);
1426 mp_vStartTracerItem->end->setCoords(
1427 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().lower);
1428 }
1429
1430 replot();
1431}
1432
1433
1434void
1436{
1437 // qDebug();
1438
1439 // Now the real code of this function.
1440
1441 m_context.m_lastReleasedMouseButton = event->button();
1442
1443 // The event->buttons() is the description of the buttons that are pressed
1444 // at the moment the handler is invoked, that is now. If left and right were
1445 // pressed, and left was released, event->buttons() would be right.
1446 m_context.m_mouseButtonsAtMouseRelease = event->buttons();
1447
1448 // The pressedMouseButtons must continually inform on the status of pressed
1449 // buttons so remove the released button.
1450 m_context.m_pressedMouseButtons ^= event->button();
1451
1452 // qDebug().noquote() << m_context.toString();
1453
1454 // We'll need to know if modifiers were pressed a the moment the user
1455 // released the mouse button.
1456 m_context.m_keyboardModifiers = QGuiApplication::keyboardModifiers();
1457
1459 {
1460 // Let the user know that the mouse was *not* being dragged.
1462
1463 event->accept();
1464
1465 return;
1466 }
1467
1468 // Let the user know that the mouse was being dragged.
1470
1471 // We cannot hide all items in one go because we rely on their visibility
1472 // to know what kind of dragging operation we need to perform (line-only
1473 // X-based zoom or rectangle-based X- and Y-based zoom, for example). The
1474 // only thing we know is that we can make the text invisible.
1475
1476 // Same for the x delta text item
1477 mp_xDeltaTextItem->setVisible(false);
1478 mp_yDeltaTextItem->setVisible(false);
1479
1480 // We do not show the end vertical region range marker.
1481 mp_vEndTracerItem->setVisible(false);
1482
1483 // Horizontal position tracer.
1484 mp_hPosTracerItem->setVisible(true);
1485 mp_hPosTracerItem->start->setCoords(xAxis->range().lower,
1487 mp_hPosTracerItem->end->setCoords(xAxis->range().upper,
1489
1490 // Vertical position tracer.
1491 mp_vPosTracerItem->setVisible(true);
1492
1493 mp_vPosTracerItem->setVisible(true);
1495 yAxis->range().upper);
1497 yAxis->range().lower);
1498
1499 // Force replot now because later that call might not be performed.
1500 replot();
1501
1502 // If we were using the "quantum" display for the rescale of the axes
1503 // using the Ctrl-modified left button click drag in the axes, then reset
1504 // the count to 0.
1506
1507 // By definition we are stopping the drag operation by releasing the mouse
1508 // button. Whatever that mouse button was pressed before and if there was
1509 // one pressed before. We cannot set that boolean value to false before
1510 // this place, because we call a number of routines above that need to know
1511 // that dragging was occurring. Like mouseReleaseHandledEvent(event) for
1512 // example.
1513
1515
1516 // Before returning, emit the signal for the user of
1517 // this class consumption.
1518 // qDebug() << "Emitting mouseReleaseEventSignal.";
1520
1521 // Now that we have computed the useful ranges, we need to check what to do
1522 // depending on the button that was pressed.
1523
1524 if(m_context.m_lastReleasedMouseButton == Qt::LeftButton)
1525 {
1527 }
1528 else if(m_context.m_lastReleasedMouseButton == Qt::RightButton)
1529 {
1531 }
1532
1533 event->accept();
1534
1535 return;
1536}
1537
1538
1539void
1541{
1542
1544 {
1545
1546 // When the mouse move handler pans the plot, we cannot store each axes
1547 // range history element that would mean store a huge amount of such
1548 // elements, as many element as there are mouse move event handled by
1549 // the Qt event queue. But we can store an axis range history element
1550 // for the last situation of the mouse move: when the button is
1551 // released:
1552
1554
1556
1557 replot();
1558
1559 // Nothing else to do.
1560 return;
1561 }
1562
1563 // There are two possibilities:
1564 //
1565 // 1. The full integration scope (four lines) were currently drawn, which
1566 // means the user was willing to perform a zoom operation.
1567 //
1568 // 2. Only the first top line was drawn, which means the user was dragging
1569 // the cursor horizontally. That might have two ends, as shown below.
1570
1571 // So, first check what is drawn of the selection polygon.
1572
1573 SelectionDrawingLines selection_drawing_lines =
1575
1576 // Now that we know what was currently drawn of the selection polygon, we
1577 // can remove it. true to reset the values to 0.
1579
1580 // Force replot now because later that call might not be performed.
1581 replot();
1582
1583 if(selection_drawing_lines == SelectionDrawingLines::FULL_POLYGON)
1584 {
1585 // qDebug() << "Yes, the full polygon was visible";
1586
1587 // If we were dragging with the left button pressed and could draw a
1588 // rectangle, then we were preparing a zoom operation. Let's bring that
1589 // operation to its accomplishment.
1590
1591 axisZoom();
1592
1593 return;
1594 }
1595 else if(selection_drawing_lines == SelectionDrawingLines::TOP_LINE)
1596 {
1597 // qDebug() << "No, only the top line of the full polygon was visible";
1598
1599 // The user was dragging the left mouse cursor and that may mean they
1600 // were measuring a distance or willing to perform a special zoom
1601 // operation if the Ctrl key was down.
1602
1603 // If the user started by clicking in the plot region, dragged the mouse
1604 // cursor with the left button and pressed the Ctrl modifier, then that
1605 // means that they wanted to do a rescale over the x-axis in the form of
1606 // a reframing.
1607
1608 if(m_context.m_keyboardModifiers & Qt::ControlModifier)
1609 {
1610 return axisReframe();
1611 }
1612 }
1613 // else
1614 // qDebug() << "Another possibility.";
1615}
1616
1617
1618void
1620{
1621 // qDebug();
1622 // The right button is used for the integrations. Not for axis range
1623 // operations. So all we have to do is remove the various graphics items and
1624 // send a signal with the context that contains all the data required by the
1625 // user to perform the integrations over the right plot regions.
1626
1627 // Whatever we were doing we need to make the selection line invisible:
1628
1629 if(mp_xDeltaTextItem->visible())
1630 mp_xDeltaTextItem->setVisible(false);
1631 if(mp_yDeltaTextItem->visible())
1632 mp_yDeltaTextItem->setVisible(false);
1633
1634 // Also make the vertical end tracer invisible.
1635 mp_vEndTracerItem->setVisible(false);
1636
1637 // Once the integration is asked for, then the selection rectangle if of no
1638 // more use.
1640
1641 // Force replot now because later that call might not be performed.
1642 replot();
1643
1644 // Note that we only request an integration if the x-axis delta is enough.
1645
1646 double x_delta_pixel =
1647 fabs(xAxis->coordToPixel(m_context.m_currentDragPoint.x()) -
1648 xAxis->coordToPixel(m_context.m_startDragPoint.x()));
1649
1650 if(x_delta_pixel > 3)
1652 // else
1653 // qDebug() << "Not asking for integration.";
1654}
1655
1656
1657void
1658BasePlotWidget::mouseWheelHandler([[maybe_unused]] QWheelEvent *event)
1659{
1660 // We should record the new range values each time the wheel is used to
1661 // zoom/unzoom.
1662
1663 m_context.m_xRange = QCPRange(xAxis->range());
1664 m_context.m_yRange = QCPRange(yAxis->range());
1665
1666 // qDebug() << "New x range: " << m_context.m_xRange;
1667 // qDebug() << "New y range: " << m_context.m_yRange;
1668
1670
1673
1674 event->accept();
1675}
1676
1677
1678void
1680 QCPAxis *axis,
1681 [[maybe_unused]] QCPAxis::SelectablePart part,
1682 QMouseEvent *event)
1683{
1684 // qDebug();
1685
1686 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
1687
1688 if(m_context.m_keyboardModifiers & Qt::ControlModifier)
1689 {
1690 // qDebug();
1691
1692 // If the Ctrl modifiers is active, then both axes are to be reset. Also
1693 // the histories are reset also.
1694
1695 rescaleAxes();
1697 }
1698 else
1699 {
1700 // qDebug();
1701
1702 // Only the axis passed as parameter is to be rescaled.
1703 // Reset the range of that axis to the max view possible.
1704
1705 axis->rescale();
1706
1708
1709 event->accept();
1710 }
1711
1712 // The double-click event does not cancel the mouse press event. That is, if
1713 // left-double-clicking, at the end of the operation the button still
1714 // "pressed". We need to remove manually the button from the pressed buttons
1715 // context member.
1716
1717 m_context.m_pressedMouseButtons ^= event->button();
1718
1720
1722
1723 replot();
1724}
1725
1726
1727bool
1728BasePlotWidget::isClickOntoXAxis(const QPointF &mousePoint)
1729{
1730 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1731
1732 if(layoutElement &&
1733 layoutElement == dynamic_cast<QCPLayoutElement *>(axisRect()))
1734 {
1735 // The graph is *inside* the axisRect that is the outermost envelope of
1736 // the graph. Thus, if we want to know if the click was indeed on an
1737 // axis, we need to check what selectable part of the the axisRect we
1738 // were clicking:
1739 QCPAxis::SelectablePart selectablePart;
1740
1741 selectablePart = xAxis->getPartAt(mousePoint);
1742
1743 if(selectablePart == QCPAxis::spAxisLabel ||
1744 selectablePart == QCPAxis::spAxis ||
1745 selectablePart == QCPAxis::spTickLabels)
1746 return true;
1747 }
1748
1749 return false;
1750}
1751
1752
1753bool
1754BasePlotWidget::isClickOntoYAxis(const QPointF &mousePoint)
1755{
1756 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1757
1758 if(layoutElement &&
1759 layoutElement == dynamic_cast<QCPLayoutElement *>(axisRect()))
1760 {
1761 // The graph is *inside* the axisRect that is the outermost envelope of
1762 // the graph. Thus, if we want to know if the click was indeed on an
1763 // axis, we need to check what selectable part of the the axisRect we
1764 // were clicking:
1765 QCPAxis::SelectablePart selectablePart;
1766
1767 selectablePart = yAxis->getPartAt(mousePoint);
1768
1769 if(selectablePart == QCPAxis::spAxisLabel ||
1770 selectablePart == QCPAxis::spAxis ||
1771 selectablePart == QCPAxis::spTickLabels)
1772 return true;
1773 }
1774
1775 return false;
1776}
1777
1778/// MOUSE-related EVENTS
1779
1780
1781/// MOUSE MOVEMENTS mouse/keyboard-triggered
1782
1783int
1785{
1786 // The user is dragging the mouse, probably to rescale the axes, but we need
1787 // to sort out in which direction the drag is happening.
1788
1789 // This function should be called after calculateDragDeltas, so that
1790 // m_context has the proper x/y delta values that we'll compare.
1791
1792 // Note that we cannot compare simply x or y deltas because the y axis might
1793 // have a different scale that the x axis. So we first need to convert the
1794 // positions to pixels.
1795
1796 double x_delta_pixel =
1797 fabs(xAxis->coordToPixel(m_context.m_currentDragPoint.x()) -
1798 xAxis->coordToPixel(m_context.m_startDragPoint.x()));
1799
1800 double y_delta_pixel =
1801 fabs(yAxis->coordToPixel(m_context.m_currentDragPoint.y()) -
1802 yAxis->coordToPixel(m_context.m_startDragPoint.y()));
1803
1804 if(x_delta_pixel > y_delta_pixel)
1805 return Qt::Horizontal;
1806
1807 return Qt::Vertical;
1808}
1809
1810
1811void
1813{
1814 // First convert the graph coordinates to pixel coordinates.
1815
1816 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1817 yAxis->coordToPixel(graph_coordinates.y()));
1818
1819 moveMouseCursorPixelCoordToGlobal(pixels_coordinates.toPoint());
1820}
1821
1822
1823void
1825{
1826 // qDebug() << "Calling set pos with new cursor position.";
1827 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1828}
1829
1830
1831void
1833{
1834 QPointF graph_coord = horizontalGetGraphCoordNewPointCountPixels(pixel_count);
1835
1836 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1837 yAxis->coordToPixel(graph_coord.y()));
1838
1839 // Now we need ton convert the new coordinates to the global position system
1840 // and to move the cursor to that new position. That will create an event to
1841 // move the mouse cursor.
1842
1843 moveMouseCursorPixelCoordToGlobal(pixel_coord.toPoint());
1844}
1845
1846
1847QPointF
1849{
1850 QPointF pixel_coordinates(
1851 xAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.x()) + pixel_count,
1852 yAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.y()));
1853
1854 // Now convert back to local coordinates.
1855
1856 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1857 yAxis->pixelToCoord(pixel_coordinates.y()));
1858
1859 return graph_coordinates;
1860}
1861
1862
1863void
1865{
1866
1867 QPointF graph_coord = verticalGetGraphCoordNewPointCountPixels(pixel_count);
1868
1869 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1870 yAxis->coordToPixel(graph_coord.y()));
1871
1872 // Now we need ton convert the new coordinates to the global position system
1873 // and to move the cursor to that new position. That will create an event to
1874 // move the mouse cursor.
1875
1876 moveMouseCursorPixelCoordToGlobal(pixel_coord.toPoint());
1877}
1878
1879
1880QPointF
1882{
1883 QPointF pixel_coordinates(
1884 xAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.x()),
1885 yAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.y()) + pixel_count);
1886
1887 // Now convert back to local coordinates.
1888
1889 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1890 yAxis->pixelToCoord(pixel_coordinates.y()));
1891
1892 return graph_coordinates;
1893}
1894
1895/// MOUSE MOVEMENTS mouse/keyboard-triggered
1896
1897
1898/// RANGE-related functions
1899
1900QCPRange
1901BasePlotWidget::getRangeX(bool &found_range, int index) const
1902{
1903 QCPGraph *graph_p = graph(index);
1904
1905 if(graph_p == nullptr)
1906 qFatal("Programming error.");
1907
1908 return graph_p->getKeyRange(found_range);
1909}
1910
1911
1912QCPRange
1913BasePlotWidget::getRangeY(bool &found_range, int index) const
1914{
1915 QCPGraph *graph_p = graph(index);
1916
1917 if(graph_p == nullptr)
1918 qFatal("Programming error.");
1919
1920 return graph_p->getValueRange(found_range);
1921}
1922
1923
1924QCPRange
1926 RangeType range_type,
1927 bool &found_range) const
1928{
1929
1930 // Iterate in all the graphs in this widget and return a QCPRange that has
1931 // its lower member as the greatest lower value of all
1932 // its upper member as the smallest upper value of all
1933
1934 if(!graphCount())
1935 {
1936 found_range = false;
1937
1938 return QCPRange(0, 1);
1939 }
1940
1941 if(graphCount() == 1)
1942 return graph()->getKeyRange(found_range);
1943
1944 bool found_at_least_one_range = false;
1945
1946 // Create an invalid range.
1947 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1948
1949 for(int iter = 0; iter < graphCount(); ++iter)
1950 {
1951 QCPRange temp_range;
1952
1953 bool found_range_for_iter = false;
1954
1955 QCPGraph *graph_p = graph(iter);
1956
1957 // Depending on the axis param, select the key or value range.
1958
1959 if(axis == Axis::x)
1960 temp_range = graph_p->getKeyRange(found_range_for_iter);
1961 else if(axis == Axis::y)
1962 temp_range = graph_p->getValueRange(found_range_for_iter);
1963 else
1964 qFatal("Cannot reach this point. Programming error.");
1965
1966 // Was a range found for the iterated graph ? If not skip this
1967 // iteration.
1968
1969 if(!found_range_for_iter)
1970 continue;
1971
1972 // While the innermost_range is invalid, we need to seed it with a good
1973 // one. So check this.
1974
1975 if(!QCPRange::validRange(result_range))
1976 qFatal("The obtained range is invalid !");
1977
1978 // At this point we know the obtained range is OK.
1979 result_range = temp_range;
1980
1981 // We found at least one valid range!
1982 found_at_least_one_range = true;
1983
1984 // At this point we have two valid ranges to compare. Depending on
1985 // range_type, we need to perform distinct comparisons.
1986
1987 if(range_type == RangeType::innermost)
1988 {
1989 if(temp_range.lower > result_range.lower)
1990 result_range.lower = temp_range.lower;
1991 if(temp_range.upper < result_range.upper)
1992 result_range.upper = temp_range.upper;
1993 }
1994 else if(range_type == RangeType::outermost)
1995 {
1996 if(temp_range.lower < result_range.lower)
1997 result_range.lower = temp_range.lower;
1998 if(temp_range.upper > result_range.upper)
1999 result_range.upper = temp_range.upper;
2000 }
2001 else
2002 qFatal("Cannot reach this point. Programming error.");
2003
2004 // Continue to next graph, if any.
2005 }
2006 // End of
2007 // for(int iter = 0; iter < graphCount(); ++iter)
2008
2009 // Let the caller know if we found at least one range.
2010 found_range = found_at_least_one_range;
2011
2012 return result_range;
2013}
2014
2015
2016QCPRange
2018{
2019
2020 return getRange(Axis::x, RangeType::innermost, found_range);
2021}
2022
2023
2024QCPRange
2026{
2027 return getRange(Axis::x, RangeType::outermost, found_range);
2028}
2029
2030
2031QCPRange
2033{
2034
2035 return getRange(Axis::y, RangeType::innermost, found_range);
2036}
2037
2038
2039QCPRange
2041{
2042 return getRange(Axis::y, RangeType::outermost, found_range);
2043}
2044
2045
2046/// RANGE-related functions
2047
2048
2049/// PLOTTING / REPLOTTING functions
2050
2051void
2053{
2054 // Get the current x lower/upper range, that is, leftmost/rightmost x
2055 // coordinate.
2056 double xLower = xAxis->range().lower;
2057 double xUpper = xAxis->range().upper;
2058
2059 // Get the current y lower/upper range, that is, bottommost/topmost y
2060 // coordinate.
2061 double yLower = yAxis->range().lower;
2062 double yUpper = yAxis->range().upper;
2063
2064 // This function is called only when the user has clicked on the x/y axis or
2065 // when the user has dragged the left mouse button with the Ctrl key
2066 // modifier. The m_context.m_wasClickOnXAxis is then simulated in the mouse
2067 // move handler. So we need to test which axis was clicked-on.
2068
2070 {
2071 // We are changing the range of the X axis.
2072
2073 // If xDelta is < 0, then we were dragging from right to left, we are
2074 // compressing the view on the x axis, by adding new data to the right
2075 // hand size of the graph. So we add xDelta to the upper bound of the
2076 // range. Otherwise we are uncompressing the view on the x axis and
2077 // remove the xDelta from the upper bound of the range. This is why we
2078 // have the
2079 // '-'
2080 // and not '+' below;
2081
2082 xAxis->setRange(xLower, xUpper - m_context.m_xDelta);
2083 }
2084 // End of
2085 // if(m_context.m_wasClickOnXAxis)
2086 else // that is, if(m_context.m_wasClickOnYAxis)
2087 {
2088 // We are changing the range of the Y axis.
2089
2090 // See above for an explanation of the computation (the - sign below).
2091
2092 yAxis->setRange(yLower, yUpper - m_context.m_yDelta);
2093 }
2094 // End of
2095 // else // that is, if(m_context.m_wasClickOnYAxis)
2096
2097 // Update the context with the current axes ranges
2098
2100
2102
2103 replot();
2104}
2105
2106
2107void
2109{
2110
2111 // double sorted_start_drag_point_x =
2112 // std::min(m_context.m_startDragPoint.x(),
2113 // m_context.m_currentDragPoint.x());
2114
2115 // xAxis->setRange(sorted_start_drag_point_x,
2116 // sorted_start_drag_point_x + fabs(m_context.m_xDelta));
2117
2118 xAxis->setRange(
2120
2121 // Note that the y axis should be rescaled from current lower value to new
2122 // upper value matching the y-axis position of the cursor when the mouse
2123 // button was released.
2124
2125 yAxis->setRange(xAxis->range().lower,
2126 std::max<double>(m_context.m_yRegionRangeStart,
2128
2129 // qDebug() << "xaxis:" << xAxis->range().lower << "-" <<
2130 // xAxis->range().upper
2131 //<< "yaxis:" << yAxis->range().lower << "-" << yAxis->range().upper;
2132
2134
2137
2138 replot();
2139}
2140
2141
2142void
2144{
2145
2146 // Use the m_context.m_xRegionRangeStart/End values, but we need to sort the
2147 // values before using them, because now we want to really have the lower x
2148 // value. Simply craft a QCPRange that will swap the values if lower is not
2149 // < than upper QCustomPlot calls this normalization).
2150
2151 xAxis->setRange(
2153
2154 yAxis->setRange(
2156
2158
2161
2162 replot();
2163}
2164
2165
2166void
2168{
2169 // Sanity check
2171 qFatal(
2172 "This function can only be called if the mouse click was on one of the "
2173 "axes");
2174
2176 {
2177 xAxis->setRange(m_context.m_xRange.lower - m_context.m_xDelta,
2179 }
2180
2182 {
2183 yAxis->setRange(m_context.m_yRange.lower - m_context.m_yDelta,
2185 }
2186
2188
2189 // qDebug() << "The updated context:" << m_context.toString();
2190
2191 // We cannot store the new ranges in the history, because the pan operation
2192 // involved a huge quantity of micro-movements elicited upon each mouse move
2193 // cursor event so we would have a huge history.
2194 // updateAxesRangeHistory();
2195
2196 // Now that the context has the right range values, we can emit the
2197 // signal that will be used by this plot widget users, typically to
2198 // abide by the x/y range lock required by the user.
2199
2201
2202 replot();
2203}
2204
2205
2206void
2208 QCPRange yAxisRange,
2209 Axis axis)
2210{
2211 // qDebug() << "With axis:" << (int)axis;
2212
2213 if(static_cast<int>(axis) & static_cast<int>(Axis::x))
2214 {
2215 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2216 }
2217
2218 if(static_cast<int>(axis) & static_cast<int>(Axis::y))
2219 {
2220 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2221 }
2222
2223 // We do not want to update the history, because there would be way too
2224 // much history items, since this function is called upon mouse moving
2225 // handling and not only during mouse release events.
2226 // updateAxesRangeHistory();
2227
2228 replot();
2229}
2230
2231
2232void
2233BasePlotWidget::replotWithAxisRangeX(double lower, double upper)
2234{
2235 // qDebug();
2236
2237 xAxis->setRange(lower, upper);
2238
2239 replot();
2240}
2241
2242
2243void
2244BasePlotWidget::replotWithAxisRangeY(double lower, double upper)
2245{
2246 // qDebug();
2247
2248 yAxis->setRange(lower, upper);
2249
2250 replot();
2251}
2252
2253/// PLOTTING / REPLOTTING functions
2254
2255
2256/// PLOT ITEMS : TRACER TEXT ITEMS...
2257
2258//! Hide the selection line, the xDelta text and the zoom rectangle items.
2259void
2261{
2262 mp_xDeltaTextItem->setVisible(false);
2263 mp_yDeltaTextItem->setVisible(false);
2264
2265 // mp_zoomRectItem->setVisible(false);
2267
2268 // Force a replot to make sure the action is immediately visible by the
2269 // user, even without moving the mouse.
2270 replot();
2271}
2272
2273
2274//! Show the traces (vertical and horizontal).
2275void
2277{
2279
2280 mp_vPosTracerItem->setVisible(true);
2281 mp_hPosTracerItem->setVisible(true);
2282
2283 mp_vStartTracerItem->setVisible(true);
2284 mp_vEndTracerItem->setVisible(true);
2285
2286 // Force a replot to make sure the action is immediately visible by the
2287 // user, even without moving the mouse.
2288 replot();
2289}
2290
2291
2292//! Hide the traces (vertical and horizontal).
2293void
2295{
2297 mp_hPosTracerItem->setVisible(false);
2298 mp_vPosTracerItem->setVisible(false);
2299
2300 mp_vStartTracerItem->setVisible(false);
2301 mp_vEndTracerItem->setVisible(false);
2302
2303 // Force a replot to make sure the action is immediately visible by the
2304 // user, even without moving the mouse.
2305 replot();
2306}
2307
2308
2309void
2311 bool for_integration)
2312{
2313 // The user has dragged the mouse left button on the graph, which means he
2314 // is willing to draw a selection rectangle, either for zooming-in or for
2315 // integration.
2316
2317 if(mp_xDeltaTextItem != nullptr)
2318 mp_xDeltaTextItem->setVisible(false);
2319 if(mp_yDeltaTextItem != nullptr)
2320 mp_yDeltaTextItem->setVisible(false);
2321
2322 // Ensure the right selection rectangle is drawn.
2323
2324 updateIntegrationScopeDrawing(as_line_segment, for_integration);
2325
2326 // Note that if we draw a zoom rectangle, then we are certainly not
2327 // measuring anything. So set the boolean value to false so that the user of
2328 // this widget or derived classes know that there is nothing to perform upon
2329 // (like deconvolution, for example).
2330
2332
2333 // Also remove the delta value from the pipeline by sending a simple
2334 // distance without measurement signal.
2335
2336 emit xAxisMeasurementSignal(m_context, false);
2337
2338 replot();
2339}
2340
2341
2342void
2344{
2345 // Depending on the kind of integration scope, we will have to display
2346 // differently calculated values. We want to provide the user with
2347 // the horizontal span of the integration scope. There are different
2348 // situations.
2349
2350 // 1. The scope is mono-dimensional across the x axis: the span
2351 // is thus simply the width.
2352
2353 // 2. The scope is bi-dimensional and is a rectangle: the span is
2354 // thus simply the width.
2355
2356 // 3. The socpe is bi-dimensional and is a rhomboid: the span is
2357 // the width.
2358
2359 // In the first and second cases above, the width is equal to the
2360 // m_context.m_xDelta.
2361
2362 // In the case of the rhomboid, the span is not m_context.m_xDelta,
2363 // it is more than that if the rhomboid is horizontal because it is
2364 // the m_context.m_xDelta plus the rhomboid's horizontal size.
2365
2366 // FIXME: is this still true?
2367 //
2368 // We do not want to show the position markers because the only horiontal
2369 // line to be visible must be contained between the start and end vertical
2370 // tracer items.
2371 mp_hPosTracerItem->setVisible(false);
2372 mp_vPosTracerItem->setVisible(false);
2373
2374 // We want to draw the text in the middle position of the leftmost-rightmost
2375 // point, even with rhomboid scopes.
2376
2377 QPointF leftmost_point;
2378 if(!m_context.msp_integrationScope->getLeftMostPoint(leftmost_point))
2379 qFatal("Could not get the left-most point.");
2380
2381 double width;
2382 if(!m_context.msp_integrationScope->getWidth(width))
2383 qFatal("Could not get width.");
2384 // qDebug() << "width:" << width;
2385
2386 double x_axis_center_position = leftmost_point.x() + width / 2;
2387
2388 // We want the text to print inside the rectangle, always at the current
2389 // drag point so the eye can follow the delta value while looking where to
2390 // drag the mouse. To position the text inside the rectangle, we need to
2391 // know what is the drag direction.
2392
2393 // What is the distance between the rectangle line at current drag point and
2394 // the text itself. Think of this as a margin distance between the
2395 // point of interest and the actual position of the text.
2396 int pixels_away_from_line = 15;
2397
2398 QPointF reference_point_for_y_axis_label_position;
2399
2400 // ATTENTION: the pixel coordinates for the vertical direction go in reverse
2401 // order with respect to the y axis values !!! That is, pixel(0,0) is top
2402 // left of the graph.
2403 if(static_cast<int>(m_context.m_dragDirections) &
2404 static_cast<int>(DragDirections::BOTTOM_TO_TOP))
2405 {
2406 // We need to print outside the rectangle, that is pixels_away_from_line
2407 // pixels to the top, so with pixel y value decremented of that
2408 // pixels_above_line value (one would have expected to increment that
2409 // value, along the y axis, but the coordinates in pixel go in reverse
2410 // order).
2411
2412 pixels_away_from_line *= -1;
2413
2414 if(!m_context.msp_integrationScope->getTopMostPoint(
2415 reference_point_for_y_axis_label_position))
2416 qFatal("Failed to get top most point.");
2417 }
2418 else
2419 {
2420 if(!m_context.msp_integrationScope->getBottomMostPoint(
2421 reference_point_for_y_axis_label_position))
2422 qFatal("Failed to get bottom most point.");
2423 }
2424
2425 // double y_axis_pixel_coordinate =
2426 // yAxis->coordToPixel(m_context.m_currentDragPoint.y());
2427 double y_axis_pixel_coordinate =
2428 yAxis->coordToPixel(reference_point_for_y_axis_label_position.y());
2429
2430 // Now that we have the coordinate in pixel units, we can correct
2431 // it by the value of the margin we want to give.
2432 double y_axis_modified_pixel_coordinate =
2433 y_axis_pixel_coordinate + pixels_away_from_line;
2434
2435 // Set aside a point instance to store the pixel coordinates of the text.
2436 QPointF pixel_coordinates;
2437
2438 pixel_coordinates.setX(x_axis_center_position);
2439 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2440
2441 // Now convert back to graph coordinates.
2442 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2443 yAxis->pixelToCoord(pixel_coordinates.y()));
2444
2445 // qDebug() << "Should print the label at point:" << graph_coordinates;
2446
2447 if(mp_xDeltaTextItem != nullptr)
2448 {
2449 mp_xDeltaTextItem->position->setCoords(x_axis_center_position,
2450 graph_coordinates.y());
2451
2452 // Dynamically set the number of decimals to ensure we can read
2453 // a meaning full delta value even if it is very very very small.
2454 // That is, allow one to read 0.00333, 0.000333, 1.333 and so on.
2455
2456 // The computation below only works properly when the passed
2457 // value is fabs() (not negative !!!).
2458
2459 int decimals = Utils::zeroDecimalsInValue(width) + 3;
2460
2461 QString label_text = QString("full x span %1 -- x drag delta %2")
2462 .arg(width, 0, 'f', decimals)
2463 .arg(fabs(m_context.m_xDelta), 0, 'f', decimals);
2464
2465 mp_xDeltaTextItem->setText(label_text);
2466
2467 mp_xDeltaTextItem->setFont(QFont(font().family(), 9));
2468 mp_xDeltaTextItem->setVisible(true);
2469 }
2470
2471 // Set the boolean to true so that derived widgets know that something is
2472 // being measured, and they can act accordingly, for example by computing
2473 // deconvolutions in a mass spectrum.
2475
2476 replot();
2477
2478 // Let the caller know that we were measuring something.
2480
2481 return;
2482}
2483
2484void
2486{
2487 // See drawXScopeSpanFeatures() for explanations.
2488
2489 // Check right away if there is height!
2490 double height;
2491 if(!m_context.msp_integrationScope->getHeight(height))
2492 qFatal("Could not get height.");
2493
2494 // If there is no height, we have nothing to do here.
2495 if(!height)
2496 return;
2497 // qDebug() << "height:" << height;
2498
2499 // FIXME: is this still true?
2500 //
2501 // We do not want to show the position markers because the only horiontal
2502 // line to be visible must be contained between the start and end vertical
2503 // tracer items.
2504 mp_hPosTracerItem->setVisible(false);
2505 mp_vPosTracerItem->setVisible(false);
2506
2507 // First the easy part: the vertical position: centered on the
2508 // scope Y span.
2509 QPointF bottom_most_point;
2510 if(!m_context.msp_integrationScope->getBottomMostPoint(bottom_most_point))
2511 qFatal("Could not get the bottom-most bottom point.");
2512
2513 double y_axis_center_position = bottom_most_point.y() + height / 2;
2514
2515 // We want to draw the text outside the rectangle (if normal rectangle)
2516 // at a small distance from the vertical limit of the scope at the
2517 // position of the current drag point. We need to check the horizontal
2518 // drag direction to put the text at the right place (left of
2519 // current drag point if dragging right to left, for example).
2520
2521 // What is the distance between the rectangle line at current drag point and
2522 // the text itself.
2523 int pixels_away_from_line = 15;
2524 double x_axis_coordinate;
2525 double x_axis_pixel_coordinate;
2526
2527 if(static_cast<int>(m_context.m_dragDirections) &
2528 static_cast<int>(DragDirections::RIGHT_TO_LEFT))
2529 {
2530 QPointF left_most_point;
2531
2532 if(!m_context.msp_integrationScope->getLeftMostPoint(left_most_point))
2533 qFatal("Failed to get left most point.");
2534
2535 x_axis_coordinate = left_most_point.x();
2536
2537 pixels_away_from_line *= -1;
2538 }
2539 else
2540 {
2541 QPointF right_most_point;
2542
2543 if(!m_context.msp_integrationScope->getRightMostPoint(right_most_point))
2544 qFatal("Failed to get right most point.");
2545
2546 x_axis_coordinate = right_most_point.x();
2547 }
2548 x_axis_pixel_coordinate = xAxis->coordToPixel(x_axis_coordinate);
2549
2550 double x_axis_modified_pixel_coordinate =
2551 x_axis_pixel_coordinate + pixels_away_from_line;
2552
2553 // Set aside a point instance to store the pixel coordinates of the text.
2554 QPointF pixel_coordinates;
2555
2556 pixel_coordinates.setX(x_axis_modified_pixel_coordinate);
2557 pixel_coordinates.setY(y_axis_center_position);
2558
2559 // Now convert back to graph coordinates.
2560
2561 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2562 yAxis->pixelToCoord(pixel_coordinates.y()));
2563
2564 mp_yDeltaTextItem->position->setCoords(graph_coordinates.x(),
2565 y_axis_center_position);
2566
2567 int decimals = Utils::zeroDecimalsInValue(height) + 3;
2568
2569 QString label_text = QString("full y span %1 -- y drag delta %2")
2570 .arg(height, 0, 'f', decimals)
2571 .arg(fabs(m_context.m_yDelta), 0, 'f', decimals);
2572
2573 mp_yDeltaTextItem->setText(label_text);
2574 mp_yDeltaTextItem->setFont(QFont(font().family(), 9));
2575 mp_yDeltaTextItem->setVisible(true);
2576 mp_yDeltaTextItem->setRotation(90);
2577
2578 // Set the boolean to true so that derived widgets know that something is
2579 // being measured, and they can act accordingly, for example by computing
2580 // deconvolutions in a mass spectrum.
2582
2583 replot();
2584
2585 // Let the caller know that we were measuring something.
2587}
2588
2589
2590void
2592{
2593
2594 // We compute signed differentials. If the user does not want the sign,
2595 // fabs(double) is their friend.
2596
2597 // Compute the xAxis differential:
2598
2601
2602 // Same with the Y-axis range:
2603
2606
2607 return;
2608}
2609
2610
2611bool
2613{
2614 // First get the height of the plot.
2615 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2616
2617 double heightDiff =
2619
2620 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2621
2622 if(heightDiffRatio > 10)
2623 {
2624 return true;
2625 }
2626
2627 return false;
2628}
2629
2630
2631void
2633{
2634
2635 // if(for_integration)
2636 // qDebug() << "for_integration:" << for_integration;
2637
2638 // By essence, the one-dimension IntegrationScope is characterized
2639 // by the left-most point and the width. Using these two data bits
2640 // it is possible to compute the x value of the right-most point.
2641
2642 double x_range_start =
2644 double x_range_end =
2646
2647 double y_position = m_context.m_startDragPoint.y();
2648
2650
2651 // Top line
2652 mp_selectionRectangeLine1->start->setCoords(
2653 QPointF(x_range_start, y_position));
2654 mp_selectionRectangeLine1->end->setCoords(QPointF(x_range_end, y_position));
2655
2656 // Only if we are drawing a selection rectangle for integration, do we set
2657 // arrow heads to the line.
2658 if(for_integration)
2659 {
2660 mp_selectionRectangeLine1->setHead(QCPLineEnding::esSpikeArrow);
2661 mp_selectionRectangeLine1->setTail(QCPLineEnding::esSpikeArrow);
2662 }
2663 else
2664 {
2665 mp_selectionRectangeLine1->setHead(QCPLineEnding::esNone);
2666 mp_selectionRectangeLine1->setTail(QCPLineEnding::esNone);
2667 }
2668 mp_selectionRectangeLine1->setVisible(true);
2669
2670 // Right line: does not exist, start and end are the same end point of the
2671 // top line.
2672 mp_selectionRectangeLine2->start->setCoords(QPointF(x_range_end, y_position));
2673 mp_selectionRectangeLine2->end->setCoords(QPointF(x_range_end, y_position));
2674 mp_selectionRectangeLine2->setVisible(false);
2675
2676 // Bottom line: identical to the top line, but invisible
2677 mp_selectionRectangeLine3->start->setCoords(
2678 QPointF(x_range_start, y_position));
2679 mp_selectionRectangeLine3->end->setCoords(QPointF(x_range_end, y_position));
2680 mp_selectionRectangeLine3->setVisible(false);
2681
2682 // Left line: does not exist: start and end are the same end point of the
2683 // top line.
2684 mp_selectionRectangeLine4->start->setCoords(QPointF(x_range_end, y_position));
2685 mp_selectionRectangeLine4->end->setCoords(QPointF(x_range_end, y_position));
2686 mp_selectionRectangeLine4->setVisible(false);
2687}
2688
2689
2690void
2692{
2693 // qDebug();
2694
2695 // if(for_integration)
2696 // qDebug() << "for_integration:" << for_integration;
2697
2698 // We are handling a conventional rectangle. Just create four points
2699 // from top left to bottom right. But we want the top left point to be
2700 // effectively the top left point and the bottom point to be the bottom
2701 // point. So we need to try all four direction combinations, left to right
2702 // or converse versus top to bottom or converse.
2703
2705
2706 // Now that the integration scope has been updated as a rectangle,
2707 // use these newly set data to actually draw the integration
2708 // scope lines.
2709
2710 QPointF bottom_left_point;
2711 if(!m_context.msp_integrationScope->getPoint(bottom_left_point))
2712 qFatal("Failed to get point.");
2713 // qDebug() << "Starting point is left bottom point:" << bottom_left_point;
2714
2715 double width;
2716 if(!m_context.msp_integrationScope->getWidth(width))
2717 qFatal("Failed to get width.");
2718 // qDebug() << "Width:" << width;
2719
2720 double height;
2721 if(!m_context.msp_integrationScope->getHeight(height))
2722 qFatal("Failed to get height.");
2723 // qDebug() << "Height:" << height;
2724
2725 QPointF bottom_right_point(bottom_left_point.x() + width,
2726 bottom_left_point.y());
2727 // qDebug() << "bottom_right_point:" << bottom_right_point;
2728
2729 QPointF top_right_point(bottom_left_point.x() + width,
2730 bottom_left_point.y() + height);
2731 // qDebug() << "top_right_point:" << top_right_point;
2732
2733 QPointF top_left_point(bottom_left_point.x(), bottom_left_point.y() + height);
2734
2735 // qDebug() << "top_left_point:" << top_left_point;
2736
2737 // Start by drawing the bottom line because the IntegrationScopeRect has the
2738 // left bottom point and the width and the height to fully characterize it.
2739
2740 // Bottom line (left to right)
2741 mp_selectionRectangeLine3->start->setCoords(bottom_left_point);
2742 mp_selectionRectangeLine3->end->setCoords(bottom_right_point);
2743 mp_selectionRectangeLine3->setVisible(true);
2744
2745 // Right line (bottom to top)
2746 mp_selectionRectangeLine2->start->setCoords(bottom_right_point);
2747 mp_selectionRectangeLine2->end->setCoords(top_right_point);
2748 mp_selectionRectangeLine2->setVisible(true);
2749
2750 // Top line (right to left)
2751 mp_selectionRectangeLine1->start->setCoords(top_right_point);
2752 mp_selectionRectangeLine1->end->setCoords(top_left_point);
2753 mp_selectionRectangeLine1->setVisible(true);
2754
2755 // Left line (top to bottom)
2756 mp_selectionRectangeLine4->start->setCoords(top_left_point);
2757 mp_selectionRectangeLine4->end->setCoords(bottom_left_point);
2758 mp_selectionRectangeLine4->setVisible(true);
2759
2760 // Only if we are drawing a selection rectangle for integration, do we
2761 // set arrow heads to the line.
2762 if(for_integration)
2763 {
2764 mp_selectionRectangeLine1->setHead(QCPLineEnding::esSpikeArrow);
2765 mp_selectionRectangeLine1->setTail(QCPLineEnding::esSpikeArrow);
2766 }
2767 else
2768 {
2769 mp_selectionRectangeLine1->setHead(QCPLineEnding::esNone);
2770 mp_selectionRectangeLine1->setTail(QCPLineEnding::esNone);
2771 }
2772}
2773
2774
2775void
2777{
2778 // We are handling a rhomboid scope, that is, a rectangle that
2779 // is tilted either to the left or to the right.
2780
2781 // There are two kinds of rhomboid integration scopes: horizontal and
2782 // vertical.
2783
2784 /*
2785 * +----------+
2786 * | |
2787 * | |
2788 * | |
2789 * | |
2790 * | |
2791 * | |
2792 * | |
2793 * +----------+
2794 * ----width---
2795 */
2796
2797 // As visible here, the fixed size of the rhomboid (using the S key in the
2798 // plot widget) is the *horizontal* side (this is the plot context's
2799 // m_integrationScopeRhombWidth).
2800
2801 IntegrationScopeFeatures scope_features;
2802
2803 // Top horizontal line
2804 QPointF point_1;
2805 scope_features = m_context.msp_integrationScope->getLeftMostTopPoint(point_1);
2806
2807 // When the user rotates the horizontal rhomboid, at some point, if the
2808 // current drag point has the same y axis value as the start drag point, then
2809 // we say that the rhomboid is flattened on the x axis. In this case, we do
2810 // not draw anything as this is a purely unusable situation.
2811
2812 if(scope_features & IntegrationScopeFeatures::FLAT_ON_X_AXIS)
2813 {
2814 // qDebug() << "The horizontal rhomboid is flattened on the x axis.";
2815
2816 mp_selectionRectangeLine1->setVisible(false);
2817 mp_selectionRectangeLine2->setVisible(false);
2818 mp_selectionRectangeLine3->setVisible(false);
2819 mp_selectionRectangeLine4->setVisible(false);
2820
2821 return;
2822 }
2823
2825 qFatal("The rhomboid should be horizontal!");
2826
2827 // At this point we can draw the rhomboid fine.
2828
2829 if(!m_context.msp_integrationScope->getLeftMostTopPoint(point_1))
2830 qFatal("Failed to getLeftMostTopPoint.");
2831 QPointF point_2;
2832 if(!m_context.msp_integrationScope->getRightMostTopPoint(point_2))
2833 qFatal("Failed to getRightMostTopPoint.");
2834
2835 // qDebug() << "For top line, two points:" << point_1 << "--" << point_2;
2836
2837 mp_selectionRectangeLine1->start->setCoords(point_1);
2838 mp_selectionRectangeLine1->end->setCoords(point_2);
2839
2840 // Only if we are drawing a selection rectangle for integration, do we set
2841 // arrow heads to the line.
2842 if(for_integration)
2843 {
2844 mp_selectionRectangeLine1->setHead(QCPLineEnding::esSpikeArrow);
2845 mp_selectionRectangeLine1->setTail(QCPLineEnding::esSpikeArrow);
2846 }
2847 else
2848 {
2849 mp_selectionRectangeLine1->setHead(QCPLineEnding::esNone);
2850 mp_selectionRectangeLine1->setTail(QCPLineEnding::esNone);
2851 }
2852
2853 mp_selectionRectangeLine1->setVisible(true);
2854
2855 // Right line
2856 if(!m_context.msp_integrationScope->getRightMostBottomPoint(point_1))
2857 qFatal("Failed to getRightMostBottomPoint.");
2858 mp_selectionRectangeLine2->start->setCoords(point_2);
2859 mp_selectionRectangeLine2->end->setCoords(point_1);
2860 mp_selectionRectangeLine2->setVisible(true);
2861
2862 // qDebug() << "For right line, two points:" << point_2 << "--" << point_1;
2863
2864 // Bottom horizontal line
2865 if(!m_context.msp_integrationScope->getLeftMostBottomPoint(point_2))
2866 qFatal("Failed to getLeftMostBottomPoint.");
2867 mp_selectionRectangeLine3->start->setCoords(point_1);
2868 mp_selectionRectangeLine3->end->setCoords(point_2);
2869 mp_selectionRectangeLine3->setVisible(true);
2870
2871 // qDebug() << "For bottom line, two points:" << point_1 << "--" << point_2;
2872
2873 // Left line
2874 if(!m_context.msp_integrationScope->getLeftMostTopPoint(point_1))
2875 qFatal("Failed to getLeftMostTopPoint.");
2876 mp_selectionRectangeLine4->end->setCoords(point_2);
2877 mp_selectionRectangeLine4->start->setCoords(point_1);
2878 mp_selectionRectangeLine4->setVisible(true);
2879
2880 // qDebug() << "For left line, two points:" << point_2 << "--" << point_1;
2881}
2882
2883
2884void
2886{
2887 // We are handling a rhomboid scope, that is, a rectangle that
2888 // is tilted either to the left or to the right.
2889
2890 // There are two kinds of rhomboid integration scopes: horizontal and
2891 // vertical.
2892
2893 /*
2894 * +3
2895 * . |
2896 * . |
2897 * . |
2898 * . +2
2899 * . .
2900 * . .
2901 * . .
2902 * 4+ .
2903 * | | .
2904 * height | | .
2905 * | | .
2906 * 1+
2907 *
2908 */
2909
2910 // As visible here, the fixed size of the rhomboid (using the S key in the
2911 // plot widget) is the *vertical* side (this is the plot context's
2912 // m_integrationScopeRhombHeight).
2913
2914 IntegrationScopeFeatures scope_features;
2915
2916 // Left vertical line
2917 QPointF point_1;
2918 scope_features = m_context.msp_integrationScope->getLeftMostTopPoint(point_1);
2919
2920 // When the user rotates the vertical rhomboid, at some point, if the current
2921 // drag point is on the same x axis value as the start drag point, then we say
2922 // that the rhomboid is flattened on the y axis. In this case, we do not draw
2923 // anything as this is a purely unusable situation.
2924
2925 if(scope_features & IntegrationScopeFeatures::FLAT_ON_Y_AXIS)
2926 {
2927 // qDebug() << "The vertical rhomboid is flattened on the y axis.";
2928
2929 mp_selectionRectangeLine1->setVisible(false);
2930 mp_selectionRectangeLine2->setVisible(false);
2931 mp_selectionRectangeLine3->setVisible(false);
2932 mp_selectionRectangeLine4->setVisible(false);
2933
2934 return;
2935 }
2936
2938 qFatal("The rhomboid should be vertical!");
2939
2940 // At this point we can draw the rhomboid fine.
2941
2942 QPointF point_2;
2943 if(!m_context.msp_integrationScope->getLeftMostBottomPoint(point_2))
2944 qFatal("Failed to getLeftMostBottomPoint.");
2945
2946 // qDebug() << "For left vertical line, two points:" << point_1 << "--"
2947 // << point_2;
2948
2949 mp_selectionRectangeLine1->start->setCoords(point_1);
2950 mp_selectionRectangeLine1->end->setCoords(point_2);
2951
2952 // Only if we are drawing a selection rectangle for integration, do we set
2953 // arrow heads to the line.
2954 if(for_integration)
2955 {
2956 mp_selectionRectangeLine1->setHead(QCPLineEnding::esSpikeArrow);
2957 mp_selectionRectangeLine1->setTail(QCPLineEnding::esSpikeArrow);
2958 }
2959 else
2960 {
2961 mp_selectionRectangeLine1->setHead(QCPLineEnding::esNone);
2962 mp_selectionRectangeLine1->setTail(QCPLineEnding::esNone);
2963 }
2964
2965 mp_selectionRectangeLine1->setVisible(true);
2966
2967 // Lower oblique line
2968 if(!m_context.msp_integrationScope->getRightMostBottomPoint(point_1))
2969 qFatal("Failed to getRightMostBottomPoint.");
2970 mp_selectionRectangeLine2->start->setCoords(point_2);
2971 mp_selectionRectangeLine2->end->setCoords(point_1);
2972 mp_selectionRectangeLine2->setVisible(true);
2973
2974 // qDebug() << "For lower oblique line, two points:" << point_2 << "--"
2975 // << point_1;
2976
2977 // Right vertical line
2978 if(!m_context.msp_integrationScope->getRightMostTopPoint(point_2))
2979 qFatal("Failed to getRightMostTopPoint.");
2980 mp_selectionRectangeLine3->start->setCoords(point_1);
2981 mp_selectionRectangeLine3->end->setCoords(point_2);
2982 mp_selectionRectangeLine3->setVisible(true);
2983
2984 // qDebug() << "For right vertical line, two points:" << point_1 << "--"
2985 // << point_2;
2986
2987 // Upper oblique line
2988 if(!m_context.msp_integrationScope->getLeftMostTopPoint(point_1))
2989 qFatal("Failed to get the LeftMostTopPoint.");
2990 mp_selectionRectangeLine4->end->setCoords(point_2);
2991 mp_selectionRectangeLine4->start->setCoords(point_1);
2992 mp_selectionRectangeLine4->setVisible(true);
2993
2994 // qDebug() << "For upper oblique line, two points:" << point_2 << "--"
2995 // << point_1;
2996}
2997
2998
2999void
3001{
3002 // qDebug();
3003
3004 // if(for_integration)
3005 // qDebug() << "for_integration:" << for_integration;
3006
3007 // We are handling a skewed rectangle (rhomboid), that is a rectangle that
3008 // is tilted either to the left or to the right.
3009
3010 // There are two kinds of rhomboid integration scopes:
3011
3012 /*
3013 4+----------+3
3014 | |
3015 | |
3016 | |
3017 | |
3018 | |
3019 | |
3020 | |
3021 1+----------+2
3022 ----width---
3023 */
3024
3025 // As visible here, the fixed size of the rhomboid (using the S key in the
3026 // plot widget) is the *horizontal* side (this is the plot context's
3027 // m_integrationScopeRhombWidth).
3028
3029 // and
3030
3031
3032 /*
3033 * +3
3034 * . |
3035 * . |
3036 * . |
3037 * . +2
3038 * . .
3039 * . .
3040 * . .
3041 * 4+ .
3042 * | | .
3043 * height | | .
3044 * | | .
3045 * 1+
3046 *
3047 */
3048
3049 // As visible here, the fixed size of the rhomboid (using the S key in the
3050 // plot widget) is the *vertical* side (this is the plot context's
3051 // m_integrationScopeRhombHeight).
3052
3053 // qDebug() << "Before calling updateIntegrationScopeRhomb(), "
3054 // "m_integrationScopeRhombWidth:"
3055 // << m_context.m_integrationScopeRhombWidth
3056 // << "and m_integrationScopeRhombHeight:"
3057 // << m_context.m_integrationScopeRhombHeight;
3058
3060
3061 // qDebug() << "After, m_integrationScopeRhombWidth:"
3062 // << m_context.m_integrationScopeRhombWidth
3063 // << "and m_integrationScopeRhombHeight:"
3064 // << m_context.m_integrationScopeRhombHeight;
3065
3066 // Now that the integration scope has been updated as a rhomboid,
3067 // use these newly set data to actually draw the integration
3068 // scope lines.
3069
3070 // We thus need to first establish if we have a horiontal or a vertical
3071 // rhomboid scope. This information is located in
3072 // m_context.m_integrationScopeRhombWidth and
3073 // m_context.m_integrationScopeRhombHeight. If width > 0, height *has to be
3074 // 0*, which indicates a horizontal rhomb.Conversely, if height is > 0, then
3075 // the rhomb is vertical.
3076
3078 // We are dealing with a horizontal scope.
3081 // We are dealing with a vertical scope.
3082 updateIntegrationScopeVerticalRhomb(for_integration);
3083 else
3084 qFatal("Cannot be both the width or height of rhomboid scope be 0.");
3085}
3086
3087void
3089 bool for_integration)
3090{
3091 // qDebug() << "as_line_segment:" << as_line_segment;
3092 // qDebug() << "for_integration:" << for_integration;
3093
3094 // We now need to construct the selection rectangle, either for zoom or for
3095 // integration.
3096
3097 // There are two situations :
3098 //
3099 // 1. if the rectangle should look like a line segment
3100 //
3101 // 2. if the rectangle should actually look like a rectangle. In this case,
3102 // there are two sub-situations:
3103 //
3104 // a. if the Alt modifier key is down, then the rectangle is rhomboid.
3105 //
3106 // b. otherwise the rectangle is conventional.
3107
3108 if(as_line_segment)
3109 {
3110 // qDebug() << "Updating the integration scope to an IntegrationScope.";
3111 updateIntegrationScope(for_integration);
3112 }
3113 else
3114 {
3115 if(!(m_context.m_keyboardModifiers & Qt::AltModifier))
3116 {
3117 // qDebug()
3118 // << "Updating the integration scope to an IntegrationScopeRect.";
3119 updateIntegrationScopeRect(for_integration);
3120 }
3121 else if(m_context.m_keyboardModifiers & Qt::AltModifier)
3122 {
3123 // qDebug()
3124 // << "Updating the integration scope to an IntegrationScopeRhomb.";
3125 updateIntegrationScopeRhomb(for_integration);
3126 }
3127 }
3128
3129 // Depending on the kind of IntegrationScope, (normal, rect or rhomb)
3130 // we have to measure things in different ways. We now set in the context
3131 // a number of parameters that will be used by its user.
3132
3133 QPointF point;
3134 double height;
3135 std::vector<QPointF> points;
3136
3137 if(m_context.msp_integrationScope->getPoints(points))
3138 {
3139 // We have defined a IntegrationScopeRhomb.
3140
3141 if(!m_context.msp_integrationScope->getLeftMostPoint(point))
3142 qFatal("Failed to get LeftMost point.");
3143 m_context.m_xRegionRangeStart = point.x();
3144
3145 if(!m_context.msp_integrationScope->getRightMostPoint(point))
3146 qFatal("Failed to get RightMost point.");
3147 m_context.m_xRegionRangeEnd = point.x();
3148 }
3149 else if(m_context.msp_integrationScope->getHeight(height))
3150 {
3151 // We have defined a IntegrationScopeRect.
3152
3153 if(!m_context.msp_integrationScope->getPoint(point))
3154 qFatal("Failed to get point.");
3155 m_context.m_xRegionRangeStart = point.x();
3156
3157 double width;
3158
3159 if(!m_context.msp_integrationScope->getWidth(width))
3160 qFatal("Failed to get width.");
3161
3163
3164 m_context.m_yRegionRangeStart = point.y();
3165
3166 m_context.m_yRegionRangeEnd = point.y() + height;
3167 }
3168 else
3169 {
3170 // We have defined a IntegrationScope.
3171
3172 if(!m_context.msp_integrationScope->getPoint(point))
3173 qFatal("Failed to get point.");
3174 m_context.m_xRegionRangeStart = point.x();
3175
3176 double width;
3177
3178 if(!m_context.msp_integrationScope->getWidth(width))
3179 qFatal("Failed to get width.");
3181 }
3182
3183 // At this point, draw the text describing the widths.
3184
3185 // We want the x-delta on the bottom of the rectangle, inside it
3186 // and the y-delta on the vertical side of the rectangle, inside it.
3187
3188 // Draw the selection width text
3190}
3191
3192void
3194{
3195 mp_selectionRectangeLine1->setVisible(false);
3196 mp_selectionRectangeLine2->setVisible(false);
3197 mp_selectionRectangeLine3->setVisible(false);
3198 mp_selectionRectangeLine4->setVisible(false);
3199
3200 if(reset_values)
3201 {
3203 }
3204}
3205
3206
3207void
3209{
3210 std::const_pointer_cast<IntegrationScopeBase>(m_context.msp_integrationScope)
3211 ->reset();
3212}
3213
3216{
3217 // There are four lines that make the selection polygon. We want to know
3218 // which lines are visible.
3219
3220 int current_selection_polygon =
3221 static_cast<int>(SelectionDrawingLines::NOT_SET);
3222
3223 if(mp_selectionRectangeLine1->visible())
3224 {
3225 current_selection_polygon |=
3226 static_cast<int>(SelectionDrawingLines::TOP_LINE);
3227 // qDebug() << "current_selection_polygon:" <<
3228 // current_selection_polygon;
3229 }
3230 if(mp_selectionRectangeLine2->visible())
3231 {
3232 current_selection_polygon |=
3233 static_cast<int>(SelectionDrawingLines::RIGHT_LINE);
3234 // qDebug() << "current_selection_polygon:" <<
3235 // current_selection_polygon;
3236 }
3237 if(mp_selectionRectangeLine3->visible())
3238 {
3239 current_selection_polygon |=
3240 static_cast<int>(SelectionDrawingLines::BOTTOM_LINE);
3241 // qDebug() << "current_selection_polygon:" <<
3242 // current_selection_polygon;
3243 }
3244 if(mp_selectionRectangeLine4->visible())
3245 {
3246 current_selection_polygon |=
3247 static_cast<int>(SelectionDrawingLines::LEFT_LINE);
3248 // qDebug() << "current_selection_polygon:" <<
3249 // current_selection_polygon;
3250 }
3251
3252 // qDebug() << "returning visibility:" << current_selection_polygon;
3253
3254 return static_cast<SelectionDrawingLines>(current_selection_polygon);
3255}
3256
3257
3258bool
3260{
3261 // Sanity check
3262 int check = 0;
3263
3264 check += mp_selectionRectangeLine1->visible();
3265 check += mp_selectionRectangeLine2->visible();
3266 check += mp_selectionRectangeLine3->visible();
3267 check += mp_selectionRectangeLine4->visible();
3268
3269 if(check > 0)
3270 return true;
3271
3272 return false;
3273}
3274
3275
3276void
3278{
3279 // qDebug() << "Setting focus to the QCustomPlot:" << this;
3280
3281 QCustomPlot::setFocus();
3282
3283 // qDebug() << "Emitting setFocusSignal().";
3284
3285 emit setFocusSignal();
3286}
3287
3288
3289//! Redraw the background of the \p focusedPlotWidget plot widget.
3290void
3291BasePlotWidget::redrawPlotBackground(QWidget *focusedPlotWidget)
3292{
3293 if(focusedPlotWidget == nullptr)
3295 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3296 "-- "
3297 "ERROR focusedPlotWidget cannot be nullptr.");
3298
3299 if(dynamic_cast<QWidget *>(this) != focusedPlotWidget)
3300 {
3301 // The focused widget is not *this widget. We should make sure that
3302 // we were not the one that had the focus, because in this case we
3303 // need to redraw an unfocused background.
3304
3305 axisRect()->setBackground(m_unfocusedBrush);
3306 }
3307 else
3308 {
3309 axisRect()->setBackground(m_focusedBrush);
3310 }
3311
3312 replot();
3313}
3314
3315
3316void
3318{
3319 m_context.m_xRange = QCPRange(xAxis->range().lower, xAxis->range().upper);
3320 m_context.m_yRange = QCPRange(yAxis->range().lower, yAxis->range().upper);
3321
3322 // qDebug() << "The new updated context: " << m_context.toString();
3323}
3324
3325
3326const BasePlotContext &
3328{
3329 return m_context;
3330}
3331
3332
3333} // namespace pappso
int basePlotContextPtrMetaTypeId
int basePlotContextMetaTypeId
Qt::MouseButtons m_mouseButtonsAtMousePress
IntegrationScopeBaseCstSPtr msp_integrationScope
DragDirections recordDragDirections()
Qt::KeyboardModifiers m_keyboardModifiers
Qt::MouseButtons m_lastPressedMouseButton
DragDirections m_dragDirections
Qt::MouseButtons m_pressedMouseButtons
Qt::MouseButtons m_mouseButtonsAtMouseRelease
Qt::MouseButtons m_lastReleasedMouseButton
virtual void updateIntegrationScopeRect(bool for_integration=false)
int m_mouseMoveHandlerSkipAmount
How many mouse move events must be skipped *‍/.
std::size_t m_lastAxisRangeHistoryIndex
Index of the last axis range history item.
virtual void updateAxesRangeHistory()
Create new axis range history items and append them to the history.
virtual void mouseWheelHandler(QWheelEvent *event)
bool m_shouldTracersBeVisible
Tells if the tracers should be visible.
virtual void hideSelectionRectangle(bool reset_values=false)
virtual void mouseMoveHandlerDraggingCursor()
virtual void updateIntegrationScopeDrawing(bool as_line_segment=false, bool for_integration=false)
virtual void directionKeyReleaseEvent(QKeyEvent *event)
QCPItemText * mp_yDeltaTextItem
QCPItemLine * mp_selectionRectangeLine1
Rectangle defining the borders of zoomed-in/out data.
virtual QCPRange getOutermostRangeX(bool &found_range) const
void lastCursorHoveredPointSignal(const QPointF &pointf)
void plottableDestructionRequestedSignal(BasePlotWidget *base_plot_widget_p, QCPAbstractPlottable *plottable_p, const BasePlotContext &context)
virtual const BasePlotContext & getContext() const
virtual void drawSelectionRectangleAndPrepareZoom(bool as_line_segment=false, bool for_integration=false)
virtual QCPRange getRangeY(bool &found_range, int index) const
virtual void keyPressEvent(QKeyEvent *event)
KEYBOARD-related EVENTS.
virtual ~BasePlotWidget()
Destruct this BasePlotWidget instance.
virtual void updateIntegrationScope(bool for_integration=false)
QCPItemLine * mp_selectionRectangeLine2
QCPItemText * mp_xDeltaTextItem
Text describing the x-axis delta value during a drag operation.
virtual void setAxisLabelX(const QString &label)
virtual void mouseMoveHandlerLeftButtonDraggingCursor()
int m_mouseMoveHandlerSkipCount
Counter to handle the "fat data" mouse move event handling.
virtual QCPRange getOutermostRangeY(bool &found_range) const
int dragDirection()
MOUSE-related EVENTS.
bool isClickOntoYAxis(const QPointF &mousePoint)
virtual void moveMouseCursorPixelCoordToGlobal(QPointF local_coordinates)
QCPItemLine * mp_hPosTracerItem
Horizontal position tracer.
QCPItemLine * mp_vPosTracerItem
Vertical position tracer.
virtual void replotWithAxesRanges(QCPRange xAxisRange, QCPRange yAxisRange, Axis axis)
virtual void setPen(const QPen &pen)
virtual void mouseReleaseHandlerRightButton()
virtual QCPRange getInnermostRangeX(bool &found_range) const
virtual void mouseMoveHandlerNotDraggingCursor()
virtual void redrawPlotBackground(QWidget *focusedPlotWidget)
Redraw the background of the focusedPlotWidget plot widget.
bool isClickOntoXAxis(const QPointF &mousePoint)
virtual void setAxisLabelY(const QString &label)
virtual void restoreAxesRangeHistory(std::size_t index)
Get the axis histories at index index and update the plot ranges.
virtual void drawXScopeSpanFeatures()
virtual void spaceKeyReleaseEvent(QKeyEvent *event)
virtual void replotWithAxisRangeX(double lower, double upper)
virtual void createAllAncillaryItems()
virtual QColor getPlottingColor(QCPAbstractPlottable *plottable_p) const
virtual void mouseReleaseHandlerLeftButton()
QBrush m_focusedBrush
Color used for the background of focused plot.
QPen m_pen
Pen used to draw the graph and textual elements in the plot widget.
virtual bool isSelectionRectangleVisible()
virtual bool isVerticalDisplacementAboveThreshold()
virtual void mousePressHandler(QMouseEvent *event)
KEYBOARD-related EVENTS.
virtual void verticalMoveMouseCursorCountPixels(int pixel_count)
virtual void updateIntegrationScopeRhomb(bool for_integration=false)
void mouseWheelEventSignal(const BasePlotContext &context)
virtual void resetAxesRangeHistory()
virtual SelectionDrawingLines whatIsVisibleOfTheSelectionRectangle()
virtual void showTracers()
Show the traces (vertical and horizontal).
virtual QPointF horizontalGetGraphCoordNewPointCountPixels(int pixel_count)
QCPItemLine * mp_selectionRectangeLine4
virtual void horizontalMoveMouseCursorCountPixels(int pixel_count)
BasePlotWidget(QWidget *parent)
std::vector< QCPRange * > m_yAxisRangeHistory
List of y axis ranges occurring during the panning zooming actions.
virtual QCPRange getInnermostRangeY(bool &found_range) const
void mouseReleaseEventSignal(const BasePlotContext &context)
virtual void setFocus()
PLOT ITEMS : TRACER TEXT ITEMS...
virtual void drawYScopeSpanFeatures()
void keyReleaseEventSignal(const BasePlotContext &context)
virtual const QPen & getPen() const
virtual void updateContextXandYAxisRanges()
virtual void updateIntegrationScopeHorizontalRhomb(bool for_integration=false)
virtual void mousePseudoButtonKeyPressEvent(QKeyEvent *event)
virtual void setPlottingColor(QCPAbstractPlottable *plottable_p, const QColor &new_color)
virtual void calculateDragDeltas()
virtual QPointF verticalGetGraphCoordNewPointCountPixels(int pixel_count)
void plotRangesChangedSignal(const BasePlotContext &context)
QCPItemLine * mp_vStartTracerItem
Vertical selection start tracer (typically in green).
virtual void mouseReleaseHandler(QMouseEvent *event)
QBrush m_unfocusedBrush
Color used for the background of unfocused plot.
virtual void axisRescale()
RANGE-related functions.
virtual void moveMouseCursorGraphCoordToGlobal(QPointF plot_coordinates)
virtual QString allLayerNamesToString() const
QCPItemLine * mp_selectionRectangeLine3
virtual void axisDoubleClickHandler(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event)
virtual void mouseMoveHandlerRightButtonDraggingCursor()
QCPItemLine * mp_vEndTracerItem
Vertical selection end tracer (typically in red).
virtual void mouseMoveHandler(QMouseEvent *event)
KEYBOARD-related EVENTS.
virtual void directionKeyPressEvent(QKeyEvent *event)
virtual QString layerableLayerName(QCPLayerable *layerable_p) const
virtual void keyReleaseEvent(QKeyEvent *event)
Handle specific key codes and trigger respective actions.
virtual void resetSelectionRectangle()
virtual void restorePreviousAxesRangeHistory()
Go up one history element in the axis history.
virtual int layerableLayerIndex(QCPLayerable *layerable_p) const
void integrationRequestedSignal(const BasePlotContext &context)
void xAxisMeasurementSignal(const BasePlotContext &context, bool with_delta)
QCPRange getRange(Axis axis, RangeType range_type, bool &found_range) const
virtual void replotWithAxisRangeY(double lower, double upper)
virtual void hideTracers()
Hide the traces (vertical and horizontal).
virtual void updateIntegrationScopeVerticalRhomb(bool for_integration=false)
virtual void mousePseudoButtonKeyReleaseEvent(QKeyEvent *event)
virtual void hideAllPlotItems()
PLOTTING / REPLOTTING functions.
virtual QCPRange getRangeX(bool &found_range, int index) const
MOUSE MOVEMENTS mouse/keyboard-triggered.
std::vector< QCPRange * > m_xAxisRangeHistory
List of x axis ranges occurring during the panning zooming actions.
BasePlotContext m_context
static int zeroDecimalsInValue(pappso_double value)
0.11 would return 0 (no empty decimal) 2.001 would return 2 1000.0001254 would return 3
Definition utils.cpp:104
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
SelectionDrawingLines