libpappsomspp
Library for mass spectrometry
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 "baseplotwidget.h"
37#include "../../pappsoexception.h"
38#include "../../exception/exceptionnotpossible.h"
39
40
42 qRegisterMetaType<pappso::BasePlotContext>("pappso::BasePlotContext");
44 qRegisterMetaType<pappso::BasePlotContext *>("pappso::BasePlotContext *");
45
46
47namespace pappso
48{
49BasePlotWidget::BasePlotWidget(QWidget *parent) : QCustomPlot(parent)
50{
51 if(parent == nullptr)
52 qFatal("Programming error.");
53
54 // Default settings for the pen used to graph the data.
55 m_pen.setStyle(Qt::SolidLine);
56 m_pen.setBrush(Qt::black);
57 m_pen.setWidth(1);
58
59 // qDebug() << "Created new BasePlotWidget with" << layerCount()
60 //<< "layers before setting up widget.";
61 // qDebug().noquote() << "All layer names:\n" << allLayerNamesToString();
62
63 // As of today 20210313, the QCustomPlot is created with the following 6
64 // layers:
65 //
66 // All layers' name:
67 //
68 // Layer index 0 name: background
69 // Layer index 1 name: grid
70 // Layer index 2 name: main
71 // Layer index 3 name: axes
72 // Layer index 4 name: legend
73 // Layer index 5 name: overlay
74
75 if(!setupWidget())
76 qFatal("Programming error.");
77
78 // Do not call createAllAncillaryItems() in this base class because all the
79 // items will have been created *before* the addition of plots and then the
80 // rendering order will hide them to the viewer, since the rendering order is
81 // according to the order in which the items have been created.
82 //
83 // The fact that the ancillary items are created before trace plots is not a
84 // problem because the trace plots are sparse and do not effectively hide the
85 // data.
86 //
87 // But, in the color map plot widgets, we cannot afford to create the
88 // ancillary items *before* the plot itself because then, the rendering of the
89 // plot (created after) would screen off the ancillary items (created before).
90 //
91 // So, the createAllAncillaryItems() function needs to be called in the
92 // derived classes at the most appropriate moment in the setting up of the
93 // widget.
94 //
95 // All this is only a workaround of a bug in QCustomPlot. See
96 // https://www.qcustomplot.com/index.php/support/forum/2283.
97 //
98 // I initially wanted to have a plots layer on top of the default background
99 // layer and a items layer on top of it. But that setting prevented the
100 // selection of graphs.
101
102 // qDebug() << "Created new BasePlotWidget with" << layerCount()
103 //<< "layers after setting up widget.";
104 // qDebug().noquote() << "All layer names:\n" << allLayerNamesToString();
105
106 show();
107}
108
109
111 const QString &x_axis_label,
112 const QString &y_axis_label)
113 : QCustomPlot(parent), m_axisLabelX(x_axis_label), m_axisLabelY(y_axis_label)
114{
115 // qDebug();
116
117 if(parent == nullptr)
118 qFatal("Programming error.");
119
120 // Default settings for the pen used to graph the data.
121 m_pen.setStyle(Qt::SolidLine);
122 m_pen.setBrush(Qt::black);
123 m_pen.setWidth(1);
124
125 xAxis->setLabel(x_axis_label);
126 yAxis->setLabel(y_axis_label);
127
128 // qDebug() << "Created new BasePlotWidget with" << layerCount()
129 //<< "layers before setting up widget.";
130 // qDebug().noquote() << "All layer names:\n" << allLayerNamesToString();
131
132 // As of today 20210313, the QCustomPlot is created with the following 6
133 // layers:
134 //
135 // All layers' name:
136 //
137 // Layer index 0 name: background
138 // Layer index 1 name: grid
139 // Layer index 2 name: main
140 // Layer index 3 name: axes
141 // Layer index 4 name: legend
142 // Layer index 5 name: overlay
143
144 if(!setupWidget())
145 qFatal("Programming error.");
146
147 // qDebug() << "Created new BasePlotWidget with" << layerCount()
148 //<< "layers after setting up widget.";
149 // qDebug().noquote() << "All layer names:\n" << allLayerNamesToString();
150
151 show();
152}
153
154
155//! Destruct \c this BasePlotWidget instance.
156/*!
157
158 The destruction involves clearing the history, deleting all the axis range
159 history items for x and y axes.
160
161*/
163{
164 // qDebug() << "In the destructor of plot widget:" << this;
165
166 m_xAxisRangeHistory.clear();
167 m_yAxisRangeHistory.clear();
168
169 // Note that the QCustomPlot xxxItem objects are allocated with (this) which
170 // means their destruction is automatically handled upon *this' destruction.
171}
172
173
174QString
176{
177
178 QString text;
179
180 for(int iter = 0; iter < layerCount(); ++iter)
181 {
182 text +=
183 QString("Layer index %1: %2\n").arg(iter).arg(layer(iter)->name());
184 }
185
186 return text;
187}
188
189
190QString
191BasePlotWidget::layerableLayerName(QCPLayerable *layerable_p) const
192{
193 if(layerable_p == nullptr)
194 qFatal("Programming error.");
195
196 QCPLayer *layer_p = layerable_p->layer();
197
198 return layer_p->name();
199}
200
201
202int
203BasePlotWidget::layerableLayerIndex(QCPLayerable *layerable_p) const
204{
205 if(layerable_p == nullptr)
206 qFatal("Programming error.");
207
208 QCPLayer *layer_p = layerable_p->layer();
209
210 for(int iter = 0; iter < layerCount(); ++iter)
211 {
212 if(layer(iter) == layer_p)
213 return iter;
214 }
215
216 return -1;
217}
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 has asked to measure the horizontal size of the rectangle and
765 // to start making a skewed selection rectangle.
766
769
770 // qDebug() << "Set m_context.selectRectangleWidth to"
771 //<< m_context.m_selectRectangleWidth << "upon release of S key";
772 }
773 // At this point emit the signal, since we did not treat it. Maybe the
774 // consumer widget wants to know that the keyboard key was released.
775
777}
778
779
780void
781BasePlotWidget::spaceKeyReleaseEvent([[maybe_unused]] QKeyEvent *event)
782{
783 // qDebug();
784}
785
786
787void
789{
790 // qDebug() << "event key:" << event->key();
791
792 // The user is trying to move the positional cursor/markers. There are
793 // multiple way they can do that:
794 //
795 // 1.a. Hitting the arrow left/right keys alone will search for next pixel.
796 // 1.b. Hitting the arrow left/right keys with Alt modifier will search for a
797 // multiple of pixels that might be equivalent to one 20th of the pixel width
798 // of the plot widget.
799 // 1.c Hitting the left/right keys with Alt and Shift modifiers will search
800 // for a multiple of pixels that might be the equivalent to half of the pixel
801 // width.
802 //
803 // 2. Hitting the Control modifier will move the cursor to the next data point
804 // of the graph.
805
806 int pixel_increment = 0;
807
808 if(m_context.m_keyboardModifiers == Qt::NoModifier)
809 pixel_increment = 1;
810 else if(m_context.m_keyboardModifiers == Qt::AltModifier)
811 pixel_increment = 50;
812
813 // The user is moving the positional markers. This is equivalent to a
814 // non-dragging cursor movement to the next pixel. Note that the origin is
815 // located at the top left, so key down increments and key up decrements.
816
817 if(event->key() == Qt::Key_Left)
818 horizontalMoveMouseCursorCountPixels(-pixel_increment);
819 else if(event->key() == Qt::Key_Right)
821 else if(event->key() == Qt::Key_Up)
822 verticalMoveMouseCursorCountPixels(-pixel_increment);
823 else if(event->key() == Qt::Key_Down)
824 verticalMoveMouseCursorCountPixels(pixel_increment);
825
826 event->accept();
827}
828
829
830void
832{
833 // qDebug() << "event key:" << event->key();
834 event->accept();
835}
836
837
838void
840 [maybe_unused]] QKeyEvent *event)
841{
842 // qDebug();
843}
844
845
846void
848{
849
850 QPointF pixel_coordinates(
851 xAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.x()),
852 yAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.y()));
853
854 Qt::MouseButton button = Qt::NoButton;
855 QEvent::Type q_event_type = QEvent::MouseButtonPress;
856
857 if(event->key() == m_leftMousePseudoButtonKey)
858 {
859 // Toggles the left mouse button on/off
860
861 button = Qt::LeftButton;
862
865
867 q_event_type = QEvent::MouseButtonPress;
868 else
869 q_event_type = QEvent::MouseButtonRelease;
870 }
871 else if(event->key() == m_rightMousePseudoButtonKey)
872 {
873 // Toggles the right mouse button.
874
875 button = Qt::RightButton;
876
879
881 q_event_type = QEvent::MouseButtonPress;
882 else
883 q_event_type = QEvent::MouseButtonRelease;
884 }
885
886 // qDebug() << "pressed/released pseudo button:" << button
887 //<< "q_event_type:" << q_event_type;
888
889 // Synthesize a QMouseEvent and use it.
890
891 QMouseEvent *mouse_event_p =
892 new QMouseEvent(q_event_type,
893 pixel_coordinates,
894 mapToGlobal(pixel_coordinates.toPoint()),
895 mapToGlobal(pixel_coordinates.toPoint()),
896 button,
897 button,
899 Qt::MouseEventSynthesizedByApplication);
900
901 if(q_event_type == QEvent::MouseButtonPress)
902 mousePressHandler(mouse_event_p);
903 else
904 mouseReleaseHandler(mouse_event_p);
905
906 // event->accept();
907}
908/// KEYBOARD-related EVENTS
909
910
911/// MOUSE-related EVENTS
912
913void
915{
916
917 // If we have no focus, then get it. See setFocus() to understand why asking
918 // for focus is cosly and thus why we want to make this decision first.
919 if(!hasFocus())
920 setFocus();
921
922 qDebug() << (graph() != nullptr);
923 // if(graph(0) != nullptr)
924 // { // check if the widget contains some graphs
925
926 // The event->button() must be by Qt instructions considered to be 0.
927
928 // Whatever happens, we want to store the plot coordinates of the current
929 // mouse cursor position (will be useful later for countless needs).
930
931 // Fix from Qt5 to Qt6
932 // QPointF mousePoint = event->localPos();
933 QPointF mousePoint = event->position();
934 qDebug();
935 qDebug() << "local mousePoint position in pixels:" << mousePoint;
936
937 m_context.m_lastCursorHoveredPoint.setX(xAxis->pixelToCoord(mousePoint.x()));
938 qDebug();
939 m_context.m_lastCursorHoveredPoint.setY(yAxis->pixelToCoord(mousePoint.y()));
940 qDebug();
941
942 // qDebug() << "lastCursorHoveredPoint coord:"
943 //<< m_context.lastCursorHoveredPoint;
944
945 // Now, depending on the button(s) (if any) that are pressed or not, we
946 // have a different processing.
947
948 qDebug();
949 if(m_context.m_pressedMouseButtons & Qt::LeftButton ||
950 m_context.m_pressedMouseButtons & Qt::RightButton)
952 else
954 // }
955 qDebug();
956 event->accept();
957}
958
959
960void
962{
963
964 qDebug();
966
967 qDebug();
968 // We are not dragging the mouse (no button pressed), simply let this
969 // widget's consumer know the position of the cursor and update the markers.
970 // The consumer of this widget will update mouse cursor position at
971 // m_context.m_lastCursorHoveredPoint if so needed.
972
974
975 qDebug();
976
977 // We are not dragging, so we do not show the region end tracer we only
978 // show the anchoring start trace that might be of use if the user starts
979 // using the arrow keys to move the cursor.
980 if(mp_vEndTracerItem != nullptr)
981 mp_vEndTracerItem->setVisible(false);
982
983 qDebug();
984 // Only bother with the tracers if the user wants them to be visible.
985 // Their crossing point must be exactly at the last cursor-hovered point.
986
988 {
989 // We are not dragging, so only show the position markers (v and h);
990
991 qDebug();
992 if(mp_hPosTracerItem != nullptr)
993 {
994 // Horizontal position tracer.
995 mp_hPosTracerItem->setVisible(true);
996 mp_hPosTracerItem->start->setCoords(
997 xAxis->range().lower, m_context.m_lastCursorHoveredPoint.y());
998 mp_hPosTracerItem->end->setCoords(
999 xAxis->range().upper, m_context.m_lastCursorHoveredPoint.y());
1000 }
1001
1002 qDebug();
1003 // Vertical position tracer.
1004 if(mp_vPosTracerItem != nullptr)
1005 {
1006 mp_vPosTracerItem->setVisible(true);
1007
1008 mp_vPosTracerItem->setVisible(true);
1009 mp_vPosTracerItem->start->setCoords(
1010 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().upper);
1011 mp_vPosTracerItem->end->setCoords(
1012 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().lower);
1013 }
1014
1015 qDebug();
1016 replot();
1017 }
1018
1019
1020 return;
1021}
1022
1023
1024void
1026{
1027 qDebug();
1029
1030 // Now store the mouse position data into the the current drag point
1031 // member datum, that will be used in countless occasions later.
1033 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
1034
1035 // When we drag (either keyboard or mouse), we hide the position markers
1036 // (black) and we show the start and end vertical markers for the region.
1037 // Then, we draw the horizontal region range marker that delimits
1038 // horizontally the dragged-over region.
1039
1040 if(mp_hPosTracerItem != nullptr)
1041 mp_hPosTracerItem->setVisible(false);
1042 if(mp_vPosTracerItem != nullptr)
1043 mp_vPosTracerItem->setVisible(false);
1044
1045 // Only bother with the tracers if the user wants them to be visible.
1047 {
1048
1049 // The vertical end tracer position must be refreshed.
1050 mp_vEndTracerItem->start->setCoords(m_context.m_currentDragPoint.x(),
1051 yAxis->range().upper);
1052
1054 yAxis->range().lower);
1055
1056 mp_vEndTracerItem->setVisible(true);
1057 }
1058
1059 // Whatever the button, when we are dealing with the axes, we do not
1060 // want to show any of the tracers.
1061
1063 {
1064 qDebug();
1065 if(mp_hPosTracerItem != nullptr)
1066 mp_hPosTracerItem->setVisible(false);
1067 if(mp_vPosTracerItem != nullptr)
1068 mp_vPosTracerItem->setVisible(false);
1069
1070 if(mp_vStartTracerItem != nullptr)
1071 mp_vStartTracerItem->setVisible(false);
1072 if(mp_vEndTracerItem != nullptr)
1073 mp_vEndTracerItem->setVisible(false);
1074 }
1075 else
1076 {
1077 qDebug();
1078 // Since we are not dragging the mouse cursor over the axes, make sure
1079 // we store the drag directions in the context, as this might be
1080 // useful for later operations.
1081
1083
1084 // qDebug() << m_context.toString();
1085 }
1086
1087 // Because when we drag the mouse button (whatever the button) we need to
1088 // know what is the drag delta (distance between start point and current
1089 // point of the drag operation) on both axes, ask that these x|y deltas be
1090 // computed.
1091 qDebug();
1093
1094 // Now deal with the BUTTON-SPECIFIC CODE.
1095
1096 if(m_context.m_mouseButtonsAtMousePress & Qt::LeftButton)
1097 {
1098 qDebug();
1100 }
1101 else if(m_context.m_mouseButtonsAtMousePress & Qt::RightButton)
1102 {
1103 qDebug();
1105 }
1106
1107 qDebug();
1108}
1109
1110
1111void
1113{
1114 qDebug() << "the left button is dragging.";
1115
1116 // Set the context.m_isMeasuringDistance to false, which later might be set to
1117 // true if effectively we are measuring a distance. This is required because
1118 // the derived widget classes might want to know if they have to perform
1119 // some action on the basis that context is measuring a distance, for
1120 // example the mass spectrum-specific widget might want to compute
1121 // deconvolutions.
1122
1124
1125 // Let's first check if the mouse drag operation originated on either
1126 // axis. In that case, the user is performing axis reframing or rescaling.
1127
1129 {
1130 qDebug() << "Click was on one of the axes.";
1131
1132 if(m_context.m_keyboardModifiers & Qt::ControlModifier)
1133 {
1134 // The user is asking a rescale of the plot.
1135
1136 // We know that we do not want the tracers when we perform axis
1137 // rescaling operations.
1138
1139 if(mp_hPosTracerItem != nullptr)
1140 mp_hPosTracerItem->setVisible(false);
1141 if(mp_vPosTracerItem != nullptr)
1142 mp_vPosTracerItem->setVisible(false);
1143
1144 if(mp_vStartTracerItem != nullptr)
1145 mp_vStartTracerItem->setVisible(false);
1146 if(mp_vEndTracerItem != nullptr)
1147 mp_vEndTracerItem->setVisible(false);
1148
1149 // This operation is particularly intensive, thus we want to
1150 // reduce the number of calculations by skipping this calculation
1151 // a number of times. The user can ask for this feature by
1152 // clicking the 'Q' letter.
1153
1154 if(m_context.m_pressedKeyCode == Qt::Key_Q)
1155 {
1157 {
1159 return;
1160 }
1161 else
1162 {
1164 }
1165 }
1166
1167 qDebug() << "Asking that the axes be rescaled.";
1168
1169 axisRescale();
1170 }
1171 else
1172 {
1173 // The user was simply dragging the axis. Just pan, that is slide
1174 // the plot in the same direction as the mouse movement and with the
1175 // same amplitude.
1176
1177 qDebug() << "Asking that the axes be panned.";
1178
1179 axisPan();
1180 }
1181
1182 return;
1183 }
1184
1185 // At this point we understand that the user was not performing any
1186 // panning/rescaling operation by clicking on any one of the axes.. Go on
1187 // with other possibilities.
1188
1189 // Let's check if the user is actually drawing a rectangle (covering a
1190 // real area) or is drawing a line.
1191
1192 // qDebug() << "The mouse dragging did not originate on an axis.";
1193
1195 {
1196 qDebug() << "Apparently the selection is a real rectangle.";
1197
1198 // When we draw a rectangle the tracers are of no use.
1199
1200 if(mp_hPosTracerItem != nullptr)
1201 mp_hPosTracerItem->setVisible(false);
1202 if(mp_vPosTracerItem != nullptr)
1203 mp_vPosTracerItem->setVisible(false);
1204
1205 if(mp_vStartTracerItem != nullptr)
1206 mp_vStartTracerItem->setVisible(false);
1207 if(mp_vEndTracerItem != nullptr)
1208 mp_vEndTracerItem->setVisible(false);
1209
1210 // Draw the rectangle, false, not as line segment and
1211 // false, not for integration
1213
1214 // Draw the selection width/height text
1217
1218 // qDebug() << "The selection polygon:"
1219 //<< m_context.m_selectionPolygon.toString();
1220 }
1221 else
1222 {
1223 qDebug() << "Apparently we are measuring a delta.";
1224
1225 // Draw the rectangle, true, as line segment and
1226 // false, not for integration
1228
1229 // qDebug() << "The selection polygon:"
1230 //<< m_context.m_selectionPolygon.toString();
1231
1232 // The pure position tracers should be hidden.
1233 if(mp_hPosTracerItem != nullptr)
1234 mp_hPosTracerItem->setVisible(true);
1235 if(mp_vPosTracerItem != nullptr)
1236 mp_vPosTracerItem->setVisible(true);
1237
1238 // Then, make sure the region range vertical tracers are visible.
1239 if(mp_vStartTracerItem != nullptr)
1240 mp_vStartTracerItem->setVisible(true);
1241 if(mp_vEndTracerItem != nullptr)
1242 mp_vEndTracerItem->setVisible(true);
1243
1244 // Draw the selection width text
1246 }
1247 qDebug();
1248}
1249
1250
1251void
1253{
1254 qDebug() << "the right button is dragging.";
1255
1256 // Set the context.m_isMeasuringDistance to false, which later might be set to
1257 // true if effectively we are measuring a distance. This is required because
1258 // the derived widgets might want to know if they have to perform some
1259 // action on the basis that context is measuring a distance, for example the
1260 // mass spectrum-specific widget might want to compute deconvolutions.
1261
1263
1265 {
1266 // qDebug() << "Apparently the selection is a real rectangle.";
1267
1268 // When we draw a rectangle the tracers are of no use.
1269
1270 if(mp_hPosTracerItem != nullptr)
1271 mp_hPosTracerItem->setVisible(false);
1272 if(mp_vPosTracerItem != nullptr)
1273 mp_vPosTracerItem->setVisible(false);
1274
1275 if(mp_vStartTracerItem != nullptr)
1276 mp_vStartTracerItem->setVisible(false);
1277 if(mp_vEndTracerItem != nullptr)
1278 mp_vEndTracerItem->setVisible(false);
1279
1280 // Draw the rectangle, false for as_line_segment and true, for
1281 // integration.
1283
1284 // Draw the selection width/height text
1287 }
1288 else
1289 {
1290 // qDebug() << "Apparently the selection is a not a rectangle.";
1291
1292 // Draw the rectangle, true, as line segment and
1293 // false, true for integration
1295
1296 // Draw the selection width text
1298 }
1299
1300 // Draw the selection width text
1302}
1303
1304
1305void
1307{
1308 // When the user clicks this widget it has to take focus.
1309 setFocus();
1310
1311 // Fix from Qt5 to Qt6
1312 //QPointF mousePoint = event->localPos();
1313 QPointF mousePoint = event->position();
1314
1315
1316 m_context.m_lastPressedMouseButton = event->button();
1317 m_context.m_mouseButtonsAtMousePress = event->buttons();
1318
1319 // The pressedMouseButtons must continually inform on the status of
1320 // pressed buttons so add the pressed button.
1321 m_context.m_pressedMouseButtons |= event->button();
1322
1323 qDebug().noquote() << m_context.toString();
1324
1325 // In all the processing of the events, we need to know if the user is
1326 // clicking somewhere with the intent to change the plot ranges (reframing
1327 // or rescaling the plot).
1328 //
1329 // Reframing the plot means that the new x and y axes ranges are modified
1330 // so that they match the region that the user has encompassed by left
1331 // clicking the mouse and dragging it over the plot. That is we reframe
1332 // the plot so that it contains only the "selected" region.
1333 //
1334 // Rescaling the plot means the the new x|y axis range is modified such
1335 // that the lower axis range is constant and the upper axis range is moved
1336 // either left or right by the same amont as the x|y delta encompassed by
1337 // the user moving the mouse. The axis is thus either compressed (mouse
1338 // movement is leftwards) or un-compressed (mouse movement is rightwards).
1339
1340 // There are two ways to perform axis range modifications:
1341 //
1342 // 1. By clicking on any of the axes
1343 // 2. By clicking on the plot region but using keyboard key modifiers,
1344 // like Alt and Ctrl.
1345 //
1346 // We need to know both cases separately which is why we need to perform a
1347 // number of tests below.
1348
1349 // Let's check if the click is on the axes, either X or Y, because that
1350 // will allow us to take proper actions.
1351
1352 if(isClickOntoXAxis(mousePoint))
1353 {
1354 // The X axis was clicked upon, we need to document that:
1355 // qDebug() << __FILE__ << __LINE__
1356 //<< "Layout element is axisRect and actually on an X axis part.";
1357
1359
1360 // int currentInteractions = interactions();
1361 // currentInteractions |= QCP::iRangeDrag;
1362 // setInteractions((QCP::Interaction)currentInteractions);
1363 // axisRect()->setRangeDrag(xAxis->orientation());
1364 }
1365 else
1367
1368 if(isClickOntoYAxis(mousePoint))
1369 {
1370 // The Y axis was clicked upon, we need to document that:
1371 // qDebug() << __FILE__ << __LINE__
1372 //<< "Layout element is axisRect and actually on an Y axis part.";
1373
1375
1376 // int currentInteractions = interactions();
1377 // currentInteractions |= QCP::iRangeDrag;
1378 // setInteractions((QCP::Interaction)currentInteractions);
1379 // axisRect()->setRangeDrag(yAxis->orientation());
1380 }
1381 else
1383
1384 // At this point, let's see if we need to remove the QCP::iRangeDrag bit:
1385
1387 {
1388 // qDebug() << __FILE__ << __LINE__
1389 // << "Click outside of axes.";
1390
1391 // int currentInteractions = interactions();
1392 // currentInteractions = currentInteractions & ~QCP::iRangeDrag;
1393 // setInteractions((QCP::Interaction)currentInteractions);
1394 }
1395
1396 m_context.m_startDragPoint.setX(xAxis->pixelToCoord(mousePoint.x()));
1397 m_context.m_startDragPoint.setY(yAxis->pixelToCoord(mousePoint.y()));
1398
1399 // Now install the vertical start tracer at the last cursor hovered
1400 // position.
1401 if((m_shouldTracersBeVisible) && (mp_vStartTracerItem != nullptr))
1402 mp_vStartTracerItem->setVisible(true);
1403
1404 if(mp_vStartTracerItem != nullptr)
1405 {
1406 mp_vStartTracerItem->start->setCoords(
1407 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().upper);
1408 mp_vStartTracerItem->end->setCoords(
1409 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().lower);
1410 }
1411
1412 replot();
1413}
1414
1415
1416void
1418{
1419 // Now the real code of this function.
1420
1421 m_context.m_lastReleasedMouseButton = event->button();
1422
1423 // The event->buttons() is the description of the buttons that are pressed at
1424 // the moment the handler is invoked, that is now. If left and right were
1425 // pressed, and left was released, event->buttons() would be right.
1426 m_context.m_mouseButtonsAtMouseRelease = event->buttons();
1427
1428 // The pressedMouseButtons must continually inform on the status of pressed
1429 // buttons so remove the released button.
1430 m_context.m_pressedMouseButtons ^= event->button();
1431
1432 // qDebug().noquote() << m_context.toString();
1433
1434 // We'll need to know if modifiers were pressed a the moment the user
1435 // released the mouse button.
1436 m_context.m_keyboardModifiers = QGuiApplication::keyboardModifiers();
1437
1439 {
1440 // Let the user know that the mouse was *not* being dragged.
1442
1443 event->accept();
1444
1445 return;
1446 }
1447
1448 // Let the user know that the mouse was being dragged.
1450
1451 // We cannot hide all items in one go because we rely on their visibility
1452 // to know what kind of dragging operation we need to perform (line-only
1453 // X-based zoom or rectangle-based X- and Y-based zoom, for example). The
1454 // only thing we know is that we can make the text invisible.
1455
1456 // Same for the x delta text item
1457 mp_xDeltaTextItem->setVisible(false);
1458 mp_yDeltaTextItem->setVisible(false);
1459
1460 // We do not show the end vertical region range marker.
1461 mp_vEndTracerItem->setVisible(false);
1462
1463 // Horizontal position tracer.
1464 mp_hPosTracerItem->setVisible(true);
1465 mp_hPosTracerItem->start->setCoords(xAxis->range().lower,
1467 mp_hPosTracerItem->end->setCoords(xAxis->range().upper,
1469
1470 // Vertical position tracer.
1471 mp_vPosTracerItem->setVisible(true);
1472
1473 mp_vPosTracerItem->setVisible(true);
1475 yAxis->range().upper);
1477 yAxis->range().lower);
1478
1479 // Force replot now because later that call might not be performed.
1480 replot();
1481
1482 // If we were using the "quantum" display for the rescale of the axes
1483 // using the Ctrl-modified left button click drag in the axes, then reset
1484 // the count to 0.
1486
1487 // Now that we have computed the useful ranges, we need to check what to do
1488 // depending on the button that was pressed.
1489
1490 if(m_context.m_lastReleasedMouseButton == Qt::LeftButton)
1491 {
1493 }
1494 else if(m_context.m_lastReleasedMouseButton == Qt::RightButton)
1495 {
1497 }
1498
1499 // By definition we are stopping the drag operation by releasing the mouse
1500 // button. Whatever that mouse button was pressed before and if there was
1501 // one pressed before. We cannot set that boolean value to false before
1502 // this place, because we call a number of routines above that need to know
1503 // that dragging was occurring. Like mouseReleaseHandledEvent(event) for
1504 // example.
1505
1507
1508 event->accept();
1509
1510 return;
1511}
1512
1513
1514void
1516{
1517
1519 {
1520
1521 // When the mouse move handler pans the plot, we cannot store each axes
1522 // range history element that would mean store a huge amount of such
1523 // elements, as many element as there are mouse move event handled by
1524 // the Qt event queue. But we can store an axis range history element
1525 // for the last situation of the mouse move: when the button is
1526 // released:
1527
1529
1531
1532 replot();
1533
1534 // Nothing else to do.
1535 return;
1536 }
1537
1538 // There are two possibilities:
1539 //
1540 // 1. The full selection polygon (four lines) were currently drawn, which
1541 // means the user was willing to perform a zoom operation
1542 //
1543 // 2. Only the first top line was drawn, which means the user was dragging
1544 // the cursor horizontally. That might have two ends, as shown below.
1545
1546 // So, first check what is drawn of the selection polygon.
1547
1548 PolygonType current_selection_polygon_type =
1550
1551 // Now that we know what was currently drawn of the selection polygon, we can
1552 // remove it. true to reset the values to 0.
1554
1555 // Force replot now because later that call might not be performed.
1556 replot();
1557
1558 if(current_selection_polygon_type == PolygonType::FULL_POLYGON)
1559 {
1560 // qDebug() << "Yes, the full polygon was visible";
1561
1562 // If we were dragging with the left button pressed and could draw a
1563 // rectangle, then we were preparing a zoom operation. Let's bring that
1564 // operation to its accomplishment.
1565
1566 axisZoom();
1567
1568 // qDebug() << "The selection polygon:"
1569 //<< m_context.m_selectionPolygon.toString();
1570
1571 return;
1572 }
1573 else if(current_selection_polygon_type == PolygonType::TOP_LINE)
1574 {
1575 // qDebug() << "No, only the top line of the full polygon was visible";
1576
1577 // The user was dragging the left mouse cursor and that may mean they were
1578 // measuring a distance or willing to perform a special zoom operation if
1579 // the Ctrl key was down.
1580
1581 // If the user started by clicking in the plot region, dragged the mouse
1582 // cursor with the left button and pressed the Ctrl modifier, then that
1583 // means that they wanted to do a rescale over the x-axis in the form of a
1584 // reframing.
1585
1586 if(m_context.m_keyboardModifiers & Qt::ControlModifier)
1587 {
1588 return axisReframe();
1589
1590 // qDebug() << "The selection polygon:"
1591 //<< m_context.m_selectionPolygon.toString();
1592 }
1593 }
1594 // else
1595 // qDebug() << "Another possibility.";
1596}
1597
1598
1599void
1601{
1602 qDebug();
1603 // The right button is used for the integrations. Not for axis range
1604 // operations. So all we have to do is remove the various graphics items and
1605 // send a signal with the context that contains all the data required by the
1606 // user to perform the integrations over the right plot regions.
1607
1608 // Whatever we were doing we need to make the selection line invisible:
1609
1610 if(mp_xDeltaTextItem->visible())
1611 mp_xDeltaTextItem->setVisible(false);
1612 if(mp_yDeltaTextItem->visible())
1613 mp_yDeltaTextItem->setVisible(false);
1614
1615 // Also make the vertical end tracer invisible.
1616 mp_vEndTracerItem->setVisible(false);
1617
1618 // Once the integration is asked for, then the selection rectangle if of no
1619 // more use.
1621
1622 // Force replot now because later that call might not be performed.
1623 replot();
1624
1625 // Note that we only request an integration if the x-axis delta is enough.
1626
1627 double x_delta_pixel =
1628 fabs(xAxis->coordToPixel(m_context.m_currentDragPoint.x()) -
1629 xAxis->coordToPixel(m_context.m_startDragPoint.x()));
1630
1631 if(x_delta_pixel > 3)
1633 // else
1634 qDebug() << "Not asking for integration.";
1635}
1636
1637
1638void
1639BasePlotWidget::mouseWheelHandler([[maybe_unused]] QWheelEvent *event)
1640{
1641 // We should record the new range values each time the wheel is used to
1642 // zoom/unzoom.
1643
1644 m_context.m_xRange = QCPRange(xAxis->range());
1645 m_context.m_yRange = QCPRange(yAxis->range());
1646
1647 // qDebug() << "New x range: " << m_context.m_xRange;
1648 // qDebug() << "New y range: " << m_context.m_yRange;
1649
1651
1654
1655 event->accept();
1656}
1657
1658
1659void
1661 QCPAxis *axis,
1662 [[maybe_unused]] QCPAxis::SelectablePart part,
1663 QMouseEvent *event)
1664{
1665 // qDebug();
1666
1667 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
1668
1669 if(m_context.m_keyboardModifiers & Qt::ControlModifier)
1670 {
1671 // qDebug();
1672
1673 // If the Ctrl modifiers is active, then both axes are to be reset. Also
1674 // the histories are reset also.
1675
1676 rescaleAxes();
1678 }
1679 else
1680 {
1681 // qDebug();
1682
1683 // Only the axis passed as parameter is to be rescaled.
1684 // Reset the range of that axis to the max view possible.
1685
1686 axis->rescale();
1687
1689
1690 event->accept();
1691 }
1692
1693 // The double-click event does not cancel the mouse press event. That is, if
1694 // left-double-clicking, at the end of the operation the button still
1695 // "pressed". We need to remove manually the button from the pressed buttons
1696 // context member.
1697
1698 m_context.m_pressedMouseButtons ^= event->button();
1699
1701
1703
1704 replot();
1705}
1706
1707
1708bool
1709BasePlotWidget::isClickOntoXAxis(const QPointF &mousePoint)
1710{
1711 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1712
1713 if(layoutElement &&
1714 layoutElement == dynamic_cast<QCPLayoutElement *>(axisRect()))
1715 {
1716 // The graph is *inside* the axisRect that is the outermost envelope of
1717 // the graph. Thus, if we want to know if the click was indeed on an
1718 // axis, we need to check what selectable part of the the axisRect we
1719 // were
1720 // clicking:
1721 QCPAxis::SelectablePart selectablePart;
1722
1723 selectablePart = xAxis->getPartAt(mousePoint);
1724
1725 if(selectablePart == QCPAxis::spAxisLabel ||
1726 selectablePart == QCPAxis::spAxis ||
1727 selectablePart == QCPAxis::spTickLabels)
1728 return true;
1729 }
1730
1731 return false;
1732}
1733
1734
1735bool
1736BasePlotWidget::isClickOntoYAxis(const QPointF &mousePoint)
1737{
1738 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1739
1740 if(layoutElement &&
1741 layoutElement == dynamic_cast<QCPLayoutElement *>(axisRect()))
1742 {
1743 // The graph is *inside* the axisRect that is the outermost envelope of
1744 // the graph. Thus, if we want to know if the click was indeed on an
1745 // axis, we need to check what selectable part of the the axisRect we
1746 // were
1747 // clicking:
1748 QCPAxis::SelectablePart selectablePart;
1749
1750 selectablePart = yAxis->getPartAt(mousePoint);
1751
1752 if(selectablePart == QCPAxis::spAxisLabel ||
1753 selectablePart == QCPAxis::spAxis ||
1754 selectablePart == QCPAxis::spTickLabels)
1755 return true;
1756 }
1757
1758 return false;
1759}
1760
1761/// MOUSE-related EVENTS
1762
1763
1764/// MOUSE MOVEMENTS mouse/keyboard-triggered
1765
1766int
1768{
1769 // The user is dragging the mouse, probably to rescale the axes, but we need
1770 // to sort out in which direction the drag is happening.
1771
1772 // This function should be called after calculateDragDeltas, so that
1773 // m_context has the proper x/y delta values that we'll compare.
1774
1775 // Note that we cannot compare simply x or y deltas because the y axis might
1776 // have a different scale that the x axis. So we first need to convert the
1777 // positions to pixels.
1778
1779 double x_delta_pixel =
1780 fabs(xAxis->coordToPixel(m_context.m_currentDragPoint.x()) -
1781 xAxis->coordToPixel(m_context.m_startDragPoint.x()));
1782
1783 double y_delta_pixel =
1784 fabs(yAxis->coordToPixel(m_context.m_currentDragPoint.y()) -
1785 yAxis->coordToPixel(m_context.m_startDragPoint.y()));
1786
1787 if(x_delta_pixel > y_delta_pixel)
1788 return Qt::Horizontal;
1789
1790 return Qt::Vertical;
1791}
1792
1793
1794void
1796{
1797 // First convert the graph coordinates to pixel coordinates.
1798
1799 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1800 yAxis->coordToPixel(graph_coordinates.y()));
1801
1802 moveMouseCursorPixelCoordToGlobal(pixels_coordinates.toPoint());
1803}
1804
1805
1806void
1808{
1809 // qDebug() << "Calling set pos with new cursor position.";
1810 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1811}
1812
1813
1814void
1816{
1817 QPointF graph_coord = horizontalGetGraphCoordNewPointCountPixels(pixel_count);
1818
1819 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1820 yAxis->coordToPixel(graph_coord.y()));
1821
1822 // Now we need ton convert the new coordinates to the global position system
1823 // and to move the cursor to that new position. That will create an event to
1824 // move the mouse cursor.
1825
1826 moveMouseCursorPixelCoordToGlobal(pixel_coord.toPoint());
1827}
1828
1829
1830QPointF
1832{
1833 QPointF pixel_coordinates(
1834 xAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.x()) + pixel_count,
1835 yAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.y()));
1836
1837 // Now convert back to local coordinates.
1838
1839 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1840 yAxis->pixelToCoord(pixel_coordinates.y()));
1841
1842 return graph_coordinates;
1843}
1844
1845
1846void
1848{
1849
1850 QPointF graph_coord = verticalGetGraphCoordNewPointCountPixels(pixel_count);
1851
1852 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1853 yAxis->coordToPixel(graph_coord.y()));
1854
1855 // Now we need ton convert the new coordinates to the global position system
1856 // and to move the cursor to that new position. That will create an event to
1857 // move the mouse cursor.
1858
1859 moveMouseCursorPixelCoordToGlobal(pixel_coord.toPoint());
1860}
1861
1862
1863QPointF
1865{
1866 QPointF pixel_coordinates(
1867 xAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.x()),
1868 yAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.y()) + pixel_count);
1869
1870 // Now convert back to local coordinates.
1871
1872 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1873 yAxis->pixelToCoord(pixel_coordinates.y()));
1874
1875 return graph_coordinates;
1876}
1877
1878/// MOUSE MOVEMENTS mouse/keyboard-triggered
1879
1880
1881/// RANGE-related functions
1882
1883QCPRange
1884BasePlotWidget::getRangeX(bool &found_range, int index) const
1885{
1886 QCPGraph *graph_p = graph(index);
1887
1888 if(graph_p == nullptr)
1889 qFatal("Programming error.");
1890
1891 return graph_p->getKeyRange(found_range);
1892}
1893
1894
1895QCPRange
1896BasePlotWidget::getRangeY(bool &found_range, int index) const
1897{
1898 QCPGraph *graph_p = graph(index);
1899
1900 if(graph_p == nullptr)
1901 qFatal("Programming error.");
1902
1903 return graph_p->getValueRange(found_range);
1904}
1905
1906
1907QCPRange
1909 RangeType range_type,
1910 bool &found_range) const
1911{
1912
1913 // Iterate in all the graphs in this widget and return a QCPRange that has
1914 // its lower member as the greatest lower value of all
1915 // its upper member as the smallest upper value of all
1916
1917 if(!graphCount())
1918 {
1919 found_range = false;
1920
1921 return QCPRange(0, 1);
1922 }
1923
1924 if(graphCount() == 1)
1925 return graph()->getKeyRange(found_range);
1926
1927 bool found_at_least_one_range = false;
1928
1929 // Create an invalid range.
1930 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1931
1932 for(int iter = 0; iter < graphCount(); ++iter)
1933 {
1934 QCPRange temp_range;
1935
1936 bool found_range_for_iter = false;
1937
1938 QCPGraph *graph_p = graph(iter);
1939
1940 // Depending on the axis param, select the key or value range.
1941
1942 if(axis == Axis::x)
1943 temp_range = graph_p->getKeyRange(found_range_for_iter);
1944 else if(axis == Axis::y)
1945 temp_range = graph_p->getValueRange(found_range_for_iter);
1946 else
1947 qFatal("Cannot reach this point. Programming error.");
1948
1949 // Was a range found for the iterated graph ? If not skip this
1950 // iteration.
1951
1952 if(!found_range_for_iter)
1953 continue;
1954
1955 // While the innermost_range is invalid, we need to seed it with a good
1956 // one. So check this.
1957
1958 if(!QCPRange::validRange(result_range))
1959 qFatal("The obtained range is invalid !");
1960
1961 // At this point we know the obtained range is OK.
1962 result_range = temp_range;
1963
1964 // We found at least one valid range!
1965 found_at_least_one_range = true;
1966
1967 // At this point we have two valid ranges to compare. Depending on
1968 // range_type, we need to perform distinct comparisons.
1969
1970 if(range_type == RangeType::innermost)
1971 {
1972 if(temp_range.lower > result_range.lower)
1973 result_range.lower = temp_range.lower;
1974 if(temp_range.upper < result_range.upper)
1975 result_range.upper = temp_range.upper;
1976 }
1977 else if(range_type == RangeType::outermost)
1978 {
1979 if(temp_range.lower < result_range.lower)
1980 result_range.lower = temp_range.lower;
1981 if(temp_range.upper > result_range.upper)
1982 result_range.upper = temp_range.upper;
1983 }
1984 else
1985 qFatal("Cannot reach this point. Programming error.");
1986
1987 // Continue to next graph, if any.
1988 }
1989 // End of
1990 // for(int iter = 0; iter < graphCount(); ++iter)
1991
1992 // Let the caller know if we found at least one range.
1993 found_range = found_at_least_one_range;
1994
1995 return result_range;
1996}
1997
1998
1999QCPRange
2001{
2002
2003 return getRange(Axis::x, RangeType::innermost, found_range);
2004}
2005
2006
2007QCPRange
2009{
2010 return getRange(Axis::x, RangeType::outermost, found_range);
2011}
2012
2013
2014QCPRange
2016{
2017
2018 return getRange(Axis::y, RangeType::innermost, found_range);
2019}
2020
2021
2022QCPRange
2024{
2025 return getRange(Axis::y, RangeType::outermost, found_range);
2026}
2027
2028
2029/// RANGE-related functions
2030
2031
2032/// PLOTTING / REPLOTTING functions
2033
2034void
2036{
2037 // Get the current x lower/upper range, that is, leftmost/rightmost x
2038 // coordinate.
2039 double xLower = xAxis->range().lower;
2040 double xUpper = xAxis->range().upper;
2041
2042 // Get the current y lower/upper range, that is, bottommost/topmost y
2043 // coordinate.
2044 double yLower = yAxis->range().lower;
2045 double yUpper = yAxis->range().upper;
2046
2047 // This function is called only when the user has clicked on the x/y axis or
2048 // when the user has dragged the left mouse button with the Ctrl key
2049 // modifier. The m_context.m_wasClickOnXAxis is then simulated in the mouse
2050 // move handler. So we need to test which axis was clicked-on.
2051
2053 {
2054
2055 // We are changing the range of the X axis.
2056
2057 // What is the x delta ?
2058 double xDelta =
2060
2061 // If xDelta is < 0, the we were dragging from right to left, we are
2062 // compressing the view on the x axis, by adding new data to the right
2063 // hand size of the graph. So we add xDelta to the upper bound of the
2064 // range. Otherwise we are uncompressing the view on the x axis and
2065 // remove the xDelta from the upper bound of the range. This is why we
2066 // have the
2067 // '-'
2068 // and not '+' below;
2069
2070 // qDebug() << "Setting xaxis:" << xLower << "--" << xUpper - xDelta;
2071
2072 xAxis->setRange(xLower, xUpper - xDelta);
2073 }
2074 // End of
2075 // if(m_context.m_wasClickOnXAxis)
2076 else // that is, if(m_context.m_wasClickOnYAxis)
2077 {
2078 // We are changing the range of the Y axis.
2079
2080 // What is the y delta ?
2081 double yDelta =
2083
2084 // See above for an explanation of the computation.
2085
2086 yAxis->setRange(yLower, yUpper - yDelta);
2087
2088 // Old version
2089 // if(yDelta < 0)
2090 //{
2091 //// The dragging operation was from top to bottom, we are enlarging
2092 //// the range (thus, we are unzooming the view, since the widget
2093 //// always has the same size).
2094
2095 // yAxis->setRange(yLower, yUpper + fabs(yDelta));
2096 //}
2097 // else
2098 //{
2099 //// The dragging operation was from bottom to top, we are reducing
2100 //// the range (thus, we are zooming the view, since the widget
2101 //// always has the same size).
2102
2103 // yAxis->setRange(yLower, yUpper - fabs(yDelta));
2104 //}
2105 }
2106 // End of
2107 // else // that is, if(m_context.m_wasClickOnYAxis)
2108
2109 // Update the context with the current axes ranges
2110
2112
2114
2115 replot();
2116}
2117
2118
2119void
2121{
2122
2123 // double sorted_start_drag_point_x =
2124 // std::min(m_context.m_startDragPoint.x(), m_context.m_currentDragPoint.x());
2125
2126 // xAxis->setRange(sorted_start_drag_point_x,
2127 // sorted_start_drag_point_x + fabs(m_context.m_xDelta));
2128
2129 xAxis->setRange(
2131
2132 // Note that the y axis should be rescaled from current lower value to new
2133 // upper value matching the y-axis position of the cursor when the mouse
2134 // button was released.
2135
2136 yAxis->setRange(xAxis->range().lower,
2137 std::max<double>(m_context.m_yRegionRangeStart,
2139
2140 // qDebug() << "xaxis:" << xAxis->range().lower << "-" <<
2141 // xAxis->range().upper
2142 //<< "yaxis:" << yAxis->range().lower << "-" << yAxis->range().upper;
2143
2145
2148
2149 replot();
2150}
2151
2152
2153void
2155{
2156
2157 // Use the m_context.m_xRegionRangeStart/End values, but we need to sort the
2158 // values before using them, because now we want to really have the lower x
2159 // value. Simply craft a QCPRange that will swap the values if lower is not
2160 // < than upper QCustomPlot calls this normalization).
2161
2162 xAxis->setRange(
2164
2165 yAxis->setRange(
2167
2169
2172
2173 replot();
2174}
2175
2176
2177void
2179{
2180 qDebug();
2181
2182 // Sanity check
2184 qFatal(
2185 "This function can only be called if the mouse click was on one of the "
2186 "axes");
2187
2189 {
2190 xAxis->setRange(m_context.m_xRange.lower - m_context.m_xDelta,
2192 }
2193
2195 {
2196 yAxis->setRange(m_context.m_yRange.lower - m_context.m_yDelta,
2198 }
2199
2201
2202 // qDebug() << "The updated context:" << m_context.toString();
2203
2204 // We cannot store the new ranges in the history, because the pan operation
2205 // involved a huge quantity of micro-movements elicited upon each mouse move
2206 // cursor event so we would have a huge history.
2207 // updateAxesRangeHistory();
2208
2209 // Now that the context has the right range values, we can emit the
2210 // signal that will be used by this plot widget users, typically to
2211 // abide by the x/y range lock required by the user.
2212
2214
2215 replot();
2216}
2217
2218
2219void
2221 QCPRange yAxisRange,
2222 Axis axis)
2223{
2224 // qDebug() << "With axis:" << (int)axis;
2225
2226 if(static_cast<int>(axis) & static_cast<int>(Axis::x))
2227 {
2228 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2229 }
2230
2231 if(static_cast<int>(axis) & static_cast<int>(Axis::y))
2232 {
2233 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2234 }
2235
2236 // We do not want to update the history, because there would be way too
2237 // much history items, since this function is called upon mouse moving
2238 // handling and not only during mouse release events.
2239 // updateAxesRangeHistory();
2240
2241 replot();
2242}
2243
2244
2245void
2246BasePlotWidget::replotWithAxisRangeX(double lower, double upper)
2247{
2248 // qDebug();
2249
2250 xAxis->setRange(lower, upper);
2251
2252 replot();
2253}
2254
2255
2256void
2257BasePlotWidget::replotWithAxisRangeY(double lower, double upper)
2258{
2259 // qDebug();
2260
2261 yAxis->setRange(lower, upper);
2262
2263 replot();
2264}
2265
2266/// PLOTTING / REPLOTTING functions
2267
2268
2269/// PLOT ITEMS : TRACER TEXT ITEMS...
2270
2271//! Hide the selection line, the xDelta text and the zoom rectangle items.
2272void
2274{
2275 mp_xDeltaTextItem->setVisible(false);
2276 mp_yDeltaTextItem->setVisible(false);
2277
2278 // mp_zoomRectItem->setVisible(false);
2280
2281 // Force a replot to make sure the action is immediately visible by the
2282 // user, even without moving the mouse.
2283 replot();
2284}
2285
2286
2287//! Show the traces (vertical and horizontal).
2288void
2290{
2292
2293 mp_vPosTracerItem->setVisible(true);
2294 mp_hPosTracerItem->setVisible(true);
2295
2296 mp_vStartTracerItem->setVisible(true);
2297 mp_vEndTracerItem->setVisible(true);
2298
2299 // Force a replot to make sure the action is immediately visible by the
2300 // user, even without moving the mouse.
2301 replot();
2302}
2303
2304
2305//! Hide the traces (vertical and horizontal).
2306void
2308{
2310 mp_hPosTracerItem->setVisible(false);
2311 mp_vPosTracerItem->setVisible(false);
2312
2313 mp_vStartTracerItem->setVisible(false);
2314 mp_vEndTracerItem->setVisible(false);
2315
2316 // Force a replot to make sure the action is immediately visible by the
2317 // user, even without moving the mouse.
2318 replot();
2319}
2320
2321
2322void
2324 bool for_integration)
2325{
2326 // The user has dragged the mouse left button on the graph, which means he
2327 // is willing to draw a selection rectangle, either for zooming-in or for
2328 // integration.
2329
2330 if(mp_xDeltaTextItem != nullptr)
2331 mp_xDeltaTextItem->setVisible(false);
2332 if(mp_yDeltaTextItem != nullptr)
2333 mp_yDeltaTextItem->setVisible(false);
2334
2335 // Ensure the right selection rectangle is drawn.
2336
2337 updateSelectionRectangle(as_line_segment, for_integration);
2338
2339 // Note that if we draw a zoom rectangle, then we are certainly not
2340 // measuring anything. So set the boolean value to false so that the user of
2341 // this widget or derived classes know that there is nothing to perform upon
2342 // (like deconvolution, for example).
2343
2345
2346 // Also remove the delta value from the pipeline by sending a simple
2347 // distance without measurement signal.
2348
2349 emit xAxisMeasurementSignal(m_context, false);
2350
2351 replot();
2352}
2353
2354
2355void
2357{
2358 // The user is dragging the mouse over the graph and we want them to know what
2359 // is the x delta value, that is the span between the point at the start of
2360 // the drag and the current drag position.
2361
2362 // FIXME: is this still true?
2363 //
2364 // We do not want to show the position markers because the only horiontal
2365 // line to be visible must be contained between the start and end vertiacal
2366 // tracer items.
2367 if(mp_hPosTracerItem != nullptr)
2368 mp_hPosTracerItem->setVisible(false);
2369 if(mp_vPosTracerItem != nullptr)
2370 mp_vPosTracerItem->setVisible(false);
2371
2372 // We want to draw the text in the middle position of the leftmost-rightmost
2373 // point, even with skewed rectangle selection.
2374
2375 QPointF leftmost_point = m_context.m_selectionPolygon.getLeftMostPoint();
2376
2377 // qDebug() << "leftmost_point:" << leftmost_point;
2378
2379 QPointF rightmost_point = m_context.m_selectionPolygon.getRightMostPoint();
2380
2381 // qDebug() << "rightmost_point:" << rightmost_point;
2382
2383 double x_axis_center_position =
2384 leftmost_point.x() + (rightmost_point.x() - leftmost_point.x()) / 2;
2385
2386 // qDebug() << "x_axis_center_position:" << x_axis_center_position;
2387
2388 // We want the text to print inside the rectangle, always at the current drag
2389 // point so the eye can follow the delta value while looking where to drag the
2390 // mouse. To position the text inside the rectangle, we need to know what is
2391 // the drag direction.
2392
2393 // Set aside a point instance to store the pixel coordinates of the text.
2394 QPointF pixel_coordinates;
2395
2396 // What is the distance between the rectangle line at current drag point and
2397 // the text itself.
2398 int pixels_away_from_line = 15;
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 left
2402 // of the graph.
2403 if(static_cast<int>(m_context.m_dragDirections) &
2404 static_cast<int>(DragDirections::TOP_TO_BOTTOM))
2405 {
2406 // We need to print inside the rectangle, that is pixels_above_line pixels
2407 // to the bottom, 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
2415 double y_axis_pixel_coordinate =
2416 yAxis->coordToPixel(m_context.m_currentDragPoint.y());
2417
2418 double y_axis_modified_pixel_coordinate =
2419 y_axis_pixel_coordinate + pixels_away_from_line;
2420
2421 pixel_coordinates.setX(x_axis_center_position);
2422 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2423
2424 // Now convert back to graph coordinates.
2425
2426 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2427 yAxis->pixelToCoord(pixel_coordinates.y()));
2428 if(mp_xDeltaTextItem != nullptr)
2429 {
2430 mp_xDeltaTextItem->position->setCoords(x_axis_center_position,
2431 graph_coordinates.y());
2432 mp_xDeltaTextItem->setText(
2433 QString("%1").arg(m_context.m_xDelta, 0, 'f', 3));
2434 mp_xDeltaTextItem->setFont(QFont(font().family(), 9));
2435 mp_xDeltaTextItem->setVisible(true);
2436 }
2437
2438 // Set the boolean to true so that derived widgets know that something is
2439 // being measured, and they can act accordingly, for example by computing
2440 // deconvolutions in a mass spectrum.
2442
2443 replot();
2444
2445 // Let the caller know that we were measuring something.
2447
2448 return;
2449}
2450
2451
2452void
2454{
2456 return;
2457
2458 // The user is dragging the mouse over the graph and we want them to know what
2459 // is the y delta value, that is the span between the point at the top of
2460 // the selection polygon and the point at its bottom.
2461
2462 // FIXME: is this still true?
2463 //
2464 // We do not want to show the position markers because the only horiontal
2465 // line to be visible must be contained between the start and end vertiacal
2466 // tracer items.
2467 mp_hPosTracerItem->setVisible(false);
2468 mp_vPosTracerItem->setVisible(false);
2469
2470 // We want to draw the text in the middle position of the leftmost-rightmost
2471 // point, even with skewed rectangle selection.
2472
2473 QPointF leftmost_point = m_context.m_selectionPolygon.getLeftMostPoint();
2474 QPointF topmost_point = m_context.m_selectionPolygon.getTopMostPoint();
2475
2476 // qDebug() << "leftmost_point:" << leftmost_point;
2477
2478 QPointF rightmost_point = m_context.m_selectionPolygon.getRightMostPoint();
2479 QPointF bottommost_point = m_context.m_selectionPolygon.getBottomMostPoint();
2480
2481 // qDebug() << "rightmost_point:" << rightmost_point;
2482
2483 double x_axis_center_position =
2484 leftmost_point.x() + (rightmost_point.x() - leftmost_point.x()) / 2;
2485
2486 double y_axis_center_position =
2487 bottommost_point.y() + (topmost_point.y() - bottommost_point.y()) / 2;
2488
2489 // qDebug() << "x_axis_center_position:" << x_axis_center_position;
2490
2491 mp_yDeltaTextItem->position->setCoords(x_axis_center_position,
2492 y_axis_center_position);
2493 mp_yDeltaTextItem->setText(QString("%1").arg(m_context.m_yDelta, 0, 'f', 3));
2494 mp_yDeltaTextItem->setFont(QFont(font().family(), 9));
2495 mp_yDeltaTextItem->setVisible(true);
2496 mp_yDeltaTextItem->setRotation(90);
2497
2498 // Set the boolean to true so that derived widgets know that something is
2499 // being measured, and they can act accordingly, for example by computing
2500 // deconvolutions in a mass spectrum.
2502
2503 replot();
2504
2505 // Let the caller know that we were measuring something.
2507}
2508
2509
2510void
2512{
2513
2514 // We compute signed differentials. If the user does not want the sign,
2515 // fabs(double) is their friend.
2516
2517 // Compute the xAxis differential:
2518
2521
2522 // Same with the Y-axis range:
2523
2526
2527 // qDebug() << "xDelta:" << m_context.m_xDelta
2528 //<< "and yDelta:" << m_context.m_yDelta;
2529
2530 return;
2531}
2532
2533
2534bool
2536{
2537 // First get the height of the plot.
2538 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2539
2540 double heightDiff =
2542
2543 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2544
2545 if(heightDiffRatio > 10)
2546 {
2547 // qDebug() << "isVerticalDisplacementAboveThreshold: true";
2548 return true;
2549 }
2550
2551 // qDebug() << "isVerticalDisplacementAboveThreshold: false";
2552 return false;
2553}
2554
2555
2556void
2558{
2559
2560 // if(for_integration)
2561 // qDebug() << "for_integration:" << for_integration;
2562
2563 // When we make a linear selection, the selection polygon is a polygon that
2564 // has the following characteristics:
2565 //
2566 // the x range is the linear selection span
2567 //
2568 // the y range is the widest std::min -> std::max possible.
2569
2570 // This is how the selection polygon logic knows if its is mono-
2571 // two-dimensional.
2572
2573 // We want the top left point to effectively be the top left point, so check
2574 // the direction of the mouse cursor drag.
2575
2576 double x_range_start =
2578 double x_range_end =
2580
2581 double y_position = m_context.m_startDragPoint.y();
2582
2583 m_context.m_selectionPolygon.set1D(x_range_start, x_range_end);
2584
2585 // Top line
2586 mp_selectionRectangeLine1->start->setCoords(
2587 QPointF(x_range_start, y_position));
2588 mp_selectionRectangeLine1->end->setCoords(QPointF(x_range_end, y_position));
2589
2590 // Only if we are drawing a selection rectangle for integration, do we set
2591 // arrow heads to the line.
2592 if(for_integration)
2593 {
2594 mp_selectionRectangeLine1->setHead(QCPLineEnding::esSpikeArrow);
2595 mp_selectionRectangeLine1->setTail(QCPLineEnding::esSpikeArrow);
2596 }
2597 else
2598 {
2599 mp_selectionRectangeLine1->setHead(QCPLineEnding::esNone);
2600 mp_selectionRectangeLine1->setTail(QCPLineEnding::esNone);
2601 }
2602 mp_selectionRectangeLine1->setVisible(true);
2603
2604 // Right line: does not exist, start and end are the same end point of the top
2605 // line.
2606 mp_selectionRectangeLine2->start->setCoords(QPointF(x_range_end, y_position));
2607 mp_selectionRectangeLine2->end->setCoords(QPointF(x_range_end, y_position));
2608 mp_selectionRectangeLine2->setVisible(false);
2609
2610 // Bottom line: identical to the top line, but invisible
2611 mp_selectionRectangeLine3->start->setCoords(
2612 QPointF(x_range_start, y_position));
2613 mp_selectionRectangeLine3->end->setCoords(QPointF(x_range_end, y_position));
2614 mp_selectionRectangeLine3->setVisible(false);
2615
2616 // Left line: does not exist: start and end are the same end point of the top
2617 // line.
2618 mp_selectionRectangeLine4->start->setCoords(QPointF(x_range_end, y_position));
2619 mp_selectionRectangeLine4->end->setCoords(QPointF(x_range_end, y_position));
2620 mp_selectionRectangeLine4->setVisible(false);
2621}
2622
2623
2624void
2626{
2627
2628 // if(for_integration)
2629 // qDebug() << "for_integration:" << for_integration;
2630
2631 // We are handling a conventional rectangle. Just create four points
2632 // from top left to bottom right. But we want the top left point to be
2633 // effectively the top left point and the bottom point to be the bottom point.
2634 // So we need to try all four direction combinations, left to right or
2635 // converse versus top to bottom or converse.
2636
2638
2640 {
2641 // qDebug() << "Dragging from right to left";
2642
2644 {
2645 // qDebug() << "Dragging from top to bottom";
2646
2647 // TOP_LEFT_POINT
2652
2653 // TOP_RIGHT_POINT
2657
2658 // BOTTOM_RIGHT_POINT
2663
2664 // BOTTOM_LEFT_POINT
2669 }
2670 // End of
2671 // if(m_context.m_currentDragPoint.y() < m_context.m_startDragPoint.y())
2672 else
2673 {
2674 // qDebug() << "Dragging from bottom to top";
2675
2676 // TOP_LEFT_POINT
2681
2682 // TOP_RIGHT_POINT
2687
2688 // BOTTOM_RIGHT_POINT
2692
2693 // BOTTOM_LEFT_POINT
2698 }
2699 }
2700 // End of
2701 // if(m_context.m_currentDragPoint.x() < m_context.m_startDragPoint.x())
2702 else
2703 {
2704 // qDebug() << "Dragging from left to right";
2705
2707 {
2708 // qDebug() << "Dragging from top to bottom";
2709
2710 // TOP_LEFT_POINT
2714
2715 // TOP_RIGHT_POINT
2720
2721 // BOTTOM_RIGHT_POINT
2726
2727 // BOTTOM_LEFT_POINT
2732 }
2733 else
2734 {
2735 // qDebug() << "Dragging from bottom to top";
2736
2737 // TOP_LEFT_POINT
2742
2743 // TOP_RIGHT_POINT
2748
2749 // BOTTOM_RIGHT_POINT
2754
2755 // BOTTOM_LEFT_POINT
2759 }
2760 }
2761
2762 // qDebug() << "Now draw the lines with points:"
2763 //<< m_context.m_selectionPolygon.toString();
2764
2765 // Top line
2766 mp_selectionRectangeLine1->start->setCoords(
2768 mp_selectionRectangeLine1->end->setCoords(
2770
2771 // Only if we are drawing a selection rectangle for integration, do we
2772 // set arrow heads to the line.
2773 if(for_integration)
2774 {
2775 mp_selectionRectangeLine1->setHead(QCPLineEnding::esSpikeArrow);
2776 mp_selectionRectangeLine1->setTail(QCPLineEnding::esSpikeArrow);
2777 }
2778 else
2779 {
2780 mp_selectionRectangeLine1->setHead(QCPLineEnding::esNone);
2781 mp_selectionRectangeLine1->setTail(QCPLineEnding::esNone);
2782 }
2783
2784 mp_selectionRectangeLine1->setVisible(true);
2785
2786 // Right line
2787 mp_selectionRectangeLine2->start->setCoords(
2789 mp_selectionRectangeLine2->end->setCoords(
2791 mp_selectionRectangeLine2->setVisible(true);
2792
2793 // Bottom line
2794 mp_selectionRectangeLine3->start->setCoords(
2796 mp_selectionRectangeLine3->end->setCoords(
2798 mp_selectionRectangeLine3->setVisible(true);
2799
2800 // Left line
2801 mp_selectionRectangeLine4->start->setCoords(
2803 mp_selectionRectangeLine4->end->setCoords(
2805 mp_selectionRectangeLine4->setVisible(true);
2806}
2807
2808
2809void
2811{
2812
2813 // if(for_integration)
2814 // qDebug() << "for_integration:" << for_integration;
2815
2816 // We are handling a skewed rectangle, that is a rectangle that is
2817 // tilted either to the left or to the right.
2818
2819 // qDebug() << "m_context.m_selectRectangleWidth: "
2820 //<< m_context.m_selectRectangleWidth;
2821
2822 // Top line
2823 // start
2824
2825 // qDebug() << "m_context.m_startDragPoint: " <<
2826 // m_context.m_startDragPoint.x()
2827 //<< "-" << m_context.m_startDragPoint.y();
2828
2829 // qDebug() << "m_context.m_currentDragPoint: "
2830 //<< m_context.m_currentDragPoint.x() << "-"
2831 //<< m_context.m_currentDragPoint.y();
2832
2834
2836 {
2837 // qDebug() << "Dragging from right to left";
2838
2840 {
2841 // qDebug() << "Dragging from top to bottom";
2842
2847
2848 // m_context.m_selRectTopLeftPoint.setX(
2849 // m_context.m_startDragPoint.x() -
2850 // m_context.m_selectRectangleWidth);
2851 // m_context.m_selRectTopLeftPoint.setY(m_context.m_startDragPoint.y());
2852
2856
2857 // m_context.m_selRectTopRightPoint.setX(m_context.m_startDragPoint.x());
2858 // m_context.m_selRectTopRightPoint.setY(m_context.m_startDragPoint.y());
2859
2864
2865 // m_context.m_selRectBottomRightPoint.setX(
2866 // m_context.m_currentDragPoint.x() +
2867 // m_context.m_selectRectangleWidth);
2868 // m_context.m_selRectBottomRightPoint.setY(
2869 // m_context.m_currentDragPoint.y());
2870
2875
2876 // m_context.m_selRectBottomLeftPoint.setX(
2877 // m_context.m_currentDragPoint.x());
2878 // m_context.m_selRectBottomLeftPoint.setY(
2879 // m_context.m_currentDragPoint.y());
2880 }
2881 else
2882 {
2883 // qDebug() << "Dragging from bottom to top";
2884
2889
2890 // m_context.m_selRectTopLeftPoint.setX(
2891 // m_context.m_currentDragPoint.x());
2892 // m_context.m_selRectTopLeftPoint.setY(
2893 // m_context.m_currentDragPoint.y());
2894
2899
2900 // m_context.m_selRectTopRightPoint.setX(
2901 // m_context.m_currentDragPoint.x() +
2902 // m_context.m_selectRectangleWidth);
2903 // m_context.m_selRectTopRightPoint.setY(
2904 // m_context.m_currentDragPoint.y());
2905
2906
2910
2911 // m_context.m_selRectBottomRightPoint.setX(
2912 // m_context.m_startDragPoint.x());
2913 // m_context.m_selRectBottomRightPoint.setY(
2914 // m_context.m_startDragPoint.y());
2915
2920
2921 // m_context.m_selRectBottomLeftPoint.setX(
2922 // m_context.m_startDragPoint.x() -
2923 // m_context.m_selectRectangleWidth);
2924 // m_context.m_selRectBottomLeftPoint.setY(
2925 // m_context.m_startDragPoint.y());
2926 }
2927 }
2928 // End of
2929 // Dragging from right to left.
2930 else
2931 {
2932 // qDebug() << "Dragging from left to right";
2933
2935 {
2936 // qDebug() << "Dragging from top to bottom";
2937
2941
2942 // m_context.m_selRectTopLeftPoint.setX(m_context.m_startDragPoint.x());
2943 // m_context.m_selRectTopLeftPoint.setY(m_context.m_startDragPoint.y());
2944
2949
2950 // m_context.m_selRectTopRightPoint.setX(
2951 // m_context.m_startDragPoint.x() +
2952 // m_context.m_selectRectangleWidth);
2953 // m_context.m_selRectTopRightPoint.setY(m_context.m_startDragPoint.y());
2954
2959
2960 // m_context.m_selRectBottomRightPoint.setX(
2961 // m_context.m_currentDragPoint.x());
2962 // m_context.m_selRectBottomRightPoint.setY(
2963 // m_context.m_currentDragPoint.y());
2964
2969
2970 // m_context.m_selRectBottomLeftPoint.setX(
2971 // m_context.m_currentDragPoint.x() -
2972 // m_context.m_selectRectangleWidth);
2973 // m_context.m_selRectBottomLeftPoint.setY(
2974 // m_context.m_currentDragPoint.y());
2975 }
2976 else
2977 {
2978 // qDebug() << "Dragging from bottom to top";
2979
2984
2985 // m_context.m_selRectTopLeftPoint.setX(
2986 // m_context.m_currentDragPoint.x() -
2987 // m_context.m_selectRectangleWidth);
2988 // m_context.m_selRectTopLeftPoint.setY(
2989 // m_context.m_currentDragPoint.y());
2990
2995
2996 // m_context.m_selRectTopRightPoint.setX(
2997 // m_context.m_currentDragPoint.x());
2998 // m_context.m_selRectTopRightPoint.setY(
2999 // m_context.m_currentDragPoint.y());
3000
3005
3006 // m_context.m_selRectBottomRightPoint.setX(
3007 // m_context.m_startDragPoint.x() +
3008 // m_context.m_selectRectangleWidth);
3009 // m_context.m_selRectBottomRightPoint.setY(
3010 // m_context.m_startDragPoint.y());
3011
3015
3016 // m_context.m_selRectBottomLeftPoint.setX(
3017 // m_context.m_startDragPoint.x());
3018 // m_context.m_selRectBottomLeftPoint.setY(
3019 // m_context.m_startDragPoint.y());
3020 }
3021 }
3022 // End of Dragging from left to right.
3023
3024 // qDebug() << "Now draw the lines with points:"
3025 //<< m_context.m_selectionPolygon.toString();
3026
3027 // Top line
3028 mp_selectionRectangeLine1->start->setCoords(
3030 mp_selectionRectangeLine1->end->setCoords(
3032
3033 // Only if we are drawing a selection rectangle for integration, do we set
3034 // arrow heads to the line.
3035 if(for_integration)
3036 {
3037 mp_selectionRectangeLine1->setHead(QCPLineEnding::esSpikeArrow);
3038 mp_selectionRectangeLine1->setTail(QCPLineEnding::esSpikeArrow);
3039 }
3040 else
3041 {
3042 mp_selectionRectangeLine1->setHead(QCPLineEnding::esNone);
3043 mp_selectionRectangeLine1->setTail(QCPLineEnding::esNone);
3044 }
3045
3046 mp_selectionRectangeLine1->setVisible(true);
3047
3048 // Right line
3049 mp_selectionRectangeLine2->start->setCoords(
3051 mp_selectionRectangeLine2->end->setCoords(
3053 mp_selectionRectangeLine2->setVisible(true);
3054
3055 // Bottom line
3056 mp_selectionRectangeLine3->start->setCoords(
3058 mp_selectionRectangeLine3->end->setCoords(
3060 mp_selectionRectangeLine3->setVisible(true);
3061
3062 // Left line
3063 mp_selectionRectangeLine4->end->setCoords(
3065 mp_selectionRectangeLine4->start->setCoords(
3067 mp_selectionRectangeLine4->setVisible(true);
3068}
3069
3070
3071void
3073 bool for_integration)
3074{
3075
3076 // qDebug() << "as_line_segment:" << as_line_segment;
3077 // qDebug() << "for_integration:" << for_integration;
3078
3079 // We now need to construct the selection rectangle, either for zoom or for
3080 // integration.
3081
3082 // There are two situations :
3083 //
3084 // 1. if the rectangle should look like a line segment
3085 //
3086 // 2. if the rectangle should actually look like a rectangle. In this case,
3087 // there are two sub-situations:
3088 //
3089 // a. if the S key is down, then the rectangle is
3090 // skewed, that is its vertical sides are not parallel to the y axis.
3091 //
3092 // b. otherwise the rectangle is conventional.
3093
3094 if(as_line_segment)
3095 {
3096 update1DSelectionRectangle(for_integration);
3097 }
3098 else
3099 {
3100 if(!(m_context.m_keyboardModifiers & Qt::AltModifier))
3101 {
3102 update2DSelectionRectangleSquare(for_integration);
3103 }
3104 else if(m_context.m_keyboardModifiers & Qt::AltModifier)
3105 {
3106 update2DSelectionRectangleSkewed(for_integration);
3107 }
3108 }
3109
3110 // This code automatically sorts the ranges (range start is always less than
3111 // range end) even if the user actually selects from high to low (right to
3112 // left or bottom to top). This has implications in code that uses the
3113 // m_context data to perform some computations. This is why it is important
3114 // that m_dragDirections be set correctly to establish where the current drag
3115 // point is actually located (at which point).
3116
3121
3126
3127 // At this point, draw the text describing the widths.
3128
3129 // We want the x-delta on the bottom of the rectangle, inside it
3130 // and the y-delta on the vertical side of the rectangle, inside it.
3131
3132 // Draw the selection width text
3134}
3135
3136void
3138{
3139 mp_selectionRectangeLine1->setVisible(false);
3140 mp_selectionRectangeLine2->setVisible(false);
3141 mp_selectionRectangeLine3->setVisible(false);
3142 mp_selectionRectangeLine4->setVisible(false);
3143
3144 if(reset_values)
3145 {
3147 }
3148}
3149
3150
3151void
3153{
3155}
3156
3157
3160{
3161 // There are four lines that make the selection polygon. We want to know
3162 // which lines are visible.
3163
3164 int current_selection_polygon = static_cast<int>(PolygonType::NOT_SET);
3165
3166 if(mp_selectionRectangeLine1->visible())
3167 {
3168 current_selection_polygon |= static_cast<int>(PolygonType::TOP_LINE);
3169 // qDebug() << "current_selection_polygon:" << current_selection_polygon;
3170 }
3171 if(mp_selectionRectangeLine2->visible())
3172 {
3173 current_selection_polygon |= static_cast<int>(PolygonType::RIGHT_LINE);
3174 // qDebug() << "current_selection_polygon:" << current_selection_polygon;
3175 }
3176 if(mp_selectionRectangeLine3->visible())
3177 {
3178 current_selection_polygon |= static_cast<int>(PolygonType::BOTTOM_LINE);
3179 // qDebug() << "current_selection_polygon:" << current_selection_polygon;
3180 }
3181 if(mp_selectionRectangeLine4->visible())
3182 {
3183 current_selection_polygon |= static_cast<int>(PolygonType::LEFT_LINE);
3184 // qDebug() << "current_selection_polygon:" << current_selection_polygon;
3185 }
3186
3187 // qDebug() << "returning visibility:" << current_selection_polygon;
3188
3189 return static_cast<PolygonType>(current_selection_polygon);
3190}
3191
3192
3193bool
3195{
3196 // Sanity check
3197 int check = 0;
3198
3199 check += mp_selectionRectangeLine1->visible();
3200 check += mp_selectionRectangeLine2->visible();
3201 check += mp_selectionRectangeLine3->visible();
3202 check += mp_selectionRectangeLine4->visible();
3203
3204 if(check > 0)
3205 return true;
3206
3207 return false;
3208}
3209
3210
3211void
3213{
3214 // qDebug() << "Setting focus to the QCustomPlot:" << this;
3215
3216 QCustomPlot::setFocus();
3217
3218 // qDebug() << "Emitting setFocusSignal().";
3219
3220 emit setFocusSignal();
3221}
3222
3223
3224//! Redraw the background of the \p focusedPlotWidget plot widget.
3225void
3226BasePlotWidget::redrawPlotBackground(QWidget *focusedPlotWidget)
3227{
3228 if(focusedPlotWidget == nullptr)
3230 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3231 "-- "
3232 "ERROR focusedPlotWidget cannot be nullptr.");
3233
3234 if(dynamic_cast<QWidget *>(this) != focusedPlotWidget)
3235 {
3236 // The focused widget is not *this widget. We should make sure that
3237 // we were not the one that had the focus, because in this case we
3238 // need to redraw an unfocused background.
3239
3240 axisRect()->setBackground(m_unfocusedBrush);
3241 }
3242 else
3243 {
3244 axisRect()->setBackground(m_focusedBrush);
3245 }
3246
3247 replot();
3248}
3249
3250
3251void
3253{
3254 m_context.m_xRange = QCPRange(xAxis->range().lower, xAxis->range().upper);
3255 m_context.m_yRange = QCPRange(yAxis->range().lower, yAxis->range().upper);
3256
3257 // qDebug() << "The new updated context: " << m_context.toString();
3258}
3259
3260
3261const BasePlotContext &
3263{
3264 return m_context;
3265}
3266
3267
3268} // namespace pappso
int basePlotContextPtrMetaTypeId
int basePlotContextMetaTypeId
Qt::MouseButtons m_mouseButtonsAtMousePress
SelectionPolygon m_selectionPolygon
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
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 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 void update2DSelectionRectangleSquare(bool for_integration=false)
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.
QCPItemLine * mp_selectionRectangeLine2
QCPItemText * mp_xDeltaTextItem
Text describing the x-axis delta value during a drag operation.
virtual void updateSelectionRectangle(bool as_line_segment=false, bool for_integration=false)
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 bool setupWidget()
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 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 void drawYDeltaFeatures()
virtual bool isVerticalDisplacementAboveThreshold()
virtual void mousePressHandler(QMouseEvent *event)
KEYBOARD-related EVENTS.
virtual void verticalMoveMouseCursorCountPixels(int pixel_count)
void mouseWheelEventSignal(const BasePlotContext &context)
virtual void resetAxesRangeHistory()
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
virtual void setFocus()
PLOT ITEMS : TRACER TEXT ITEMS...
void keyReleaseEventSignal(const BasePlotContext &context)
virtual const QPen & getPen() const
virtual void updateContextXandYAxisRanges()
virtual void update1DSelectionRectangle(bool for_integration=false)
virtual PolygonType whatIsVisibleOfTheSelectionRectangle()
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 drawXDeltaFeatures()
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 update2DSelectionRectangleSkewed(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
void setPoint(PointSpecs point_spec, double x, double y)
QPointF getRightMostPoint() const
QPointF getLeftMostPoint() const
QPointF getBottomMostPoint() const
void set1D(double x_range_start, double x_range_end)
QPointF getPoint(PointSpecs point_spec) const
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
Axis
Definition: types.h:181