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