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