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