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() << __FILE__ << __LINE__ << "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  // Draw the rectangle, true, as line segment and
1233  // false, true for integration
1235 
1236  // Draw the selection width text
1238  }
1239 
1240  // Draw the selection width text
1242 }
1243 
1244 
1245 void
1247 {
1248  // When the user clicks this widget it has to take focus.
1249  setFocus();
1250 
1251  QPointF mousePoint = event->localPos();
1252 
1253  m_context.m_lastPressedMouseButton = event->button();
1254  m_context.m_mouseButtonsAtMousePress = event->buttons();
1255 
1256  // The pressedMouseButtons must continually inform on the status of pressed
1257  // buttons so add the pressed button.
1258  m_context.m_pressedMouseButtons |= event->button();
1259 
1260  // qDebug().noquote() << m_context.toString();
1261 
1262  // In all the processing of the events, we need to know if the user is
1263  // clicking somewhere with the intent to change the plot ranges (reframing
1264  // or rescaling the plot).
1265  //
1266  // Reframing the plot means that the new x and y axes ranges are modified so
1267  // that they match the region that the user has encompassed by left clicking
1268  // the mouse and dragging it over the plot. That is we reframe the plot so
1269  // that it contains only the "selected" region.
1270  //
1271  // Rescaling the plot means the the new x|y axis range is modified such that
1272  // the lower axis range is constant and the upper axis range is moved either
1273  // left or right by the same amont as the x|y delta encompassed by the user
1274  // moving the mouse. The axis is thus either compressed (mouse movement is
1275  // leftwards) or un-compressed (mouse movement is rightwards).
1276 
1277  // There are two ways to perform axis range modifications:
1278  //
1279  // 1. By clicking on any of the axes
1280  // 2. By clicking on the plot region but using keyboard key modifiers, like
1281  // Alt and Ctrl.
1282  //
1283  // We need to know both cases separately which is why we need to perform a
1284  // number of tests below.
1285 
1286  // Let's check if the click is on the axes, either X or Y, because that
1287  // will allow us to take proper actions.
1288 
1289  if(isClickOntoXAxis(mousePoint))
1290  {
1291  // The X axis was clicked upon, we need to document that:
1292  // qDebug() << __FILE__ << __LINE__
1293  //<< "Layout element is axisRect and actually on an X axis part.";
1294 
1296 
1297  // int currentInteractions = interactions();
1298  // currentInteractions |= QCP::iRangeDrag;
1299  // setInteractions((QCP::Interaction)currentInteractions);
1300  // axisRect()->setRangeDrag(xAxis->orientation());
1301  }
1302  else
1303  m_context.m_wasClickOnXAxis = false;
1304 
1305  if(isClickOntoYAxis(mousePoint))
1306  {
1307  // The Y axis was clicked upon, we need to document that:
1308  // qDebug() << __FILE__ << __LINE__
1309  //<< "Layout element is axisRect and actually on an Y axis part.";
1310 
1312 
1313  // int currentInteractions = interactions();
1314  // currentInteractions |= QCP::iRangeDrag;
1315  // setInteractions((QCP::Interaction)currentInteractions);
1316  // axisRect()->setRangeDrag(yAxis->orientation());
1317  }
1318  else
1319  m_context.m_wasClickOnYAxis = false;
1320 
1321  // At this point, let's see if we need to remove the QCP::iRangeDrag bit:
1322 
1324  {
1325  // qDebug() << __FILE__ << __LINE__
1326  // << "Click outside of axes.";
1327 
1328  // int currentInteractions = interactions();
1329  // currentInteractions = currentInteractions & ~QCP::iRangeDrag;
1330  // setInteractions((QCP::Interaction)currentInteractions);
1331  }
1332 
1333  m_context.m_startDragPoint.setX(xAxis->pixelToCoord(mousePoint.x()));
1334  m_context.m_startDragPoint.setY(yAxis->pixelToCoord(mousePoint.y()));
1335 
1336  // Now install the vertical start tracer at the last cursor hovered
1337  // position.
1339  mp_vStartTracerItem->setVisible(true);
1340 
1342  yAxis->range().upper);
1344  yAxis->range().lower);
1345 
1346  replot();
1347 }
1348 
1349 
1350 void
1352 {
1353  // Now the real code of this function.
1354 
1355  m_context.m_lastReleasedMouseButton = event->button();
1356 
1357  // The event->buttons() is the description of the buttons that are pressed at
1358  // the moment the handler is invoked, that is now. If left and right were
1359  // pressed, and left was released, event->buttons() would be right.
1360  m_context.m_mouseButtonsAtMouseRelease = event->buttons();
1361 
1362  // The pressedMouseButtons must continually inform on the status of pressed
1363  // buttons so remove the released button.
1364  m_context.m_pressedMouseButtons ^= event->button();
1365 
1366  // qDebug().noquote() << m_context.toString();
1367 
1368  // We'll need to know if modifiers were pressed a the moment the user
1369  // released the mouse button.
1370  m_context.m_keyboardModifiers = QGuiApplication::keyboardModifiers();
1371 
1373  {
1374  // Let the user know that the mouse was *not* being dragged.
1375  m_context.m_wasMouseDragging = false;
1376 
1377  event->accept();
1378 
1379  return;
1380  }
1381 
1382  // Let the user know that the mouse was being dragged.
1384 
1385  // We cannot hide all items in one go because we rely on their visibility
1386  // to know what kind of dragging operation we need to perform (line-only
1387  // X-based zoom or rectangle-based X- and Y-based zoom, for example). The
1388  // only thing we know is that we can make the text invisible.
1389 
1390  // Same for the x delta text item
1391  mp_xDeltaTextItem->setVisible(false);
1392  mp_yDeltaTextItem->setVisible(false);
1393 
1394  // We do not show the end vertical region range marker.
1395  mp_vEndTracerItem->setVisible(false);
1396 
1397  // Horizontal position tracer.
1398  mp_hPosTracerItem->setVisible(true);
1399  mp_hPosTracerItem->start->setCoords(xAxis->range().lower,
1401  mp_hPosTracerItem->end->setCoords(xAxis->range().upper,
1403 
1404  // Vertical position tracer.
1405  mp_vPosTracerItem->setVisible(true);
1406 
1407  mp_vPosTracerItem->setVisible(true);
1409  yAxis->range().upper);
1411  yAxis->range().lower);
1412 
1413  // Force replot now because later that call might not be performed.
1414  replot();
1415 
1416  // If we were using the "quantum" display for the rescale of the axes
1417  // using the Ctrl-modified left button click drag in the axes, then reset
1418  // the count to 0.
1420 
1421  // Now that we have computed the useful ranges, we need to check what to do
1422  // depending on the button that was pressed.
1423 
1424  if(m_context.m_lastReleasedMouseButton == Qt::LeftButton)
1425  {
1427  }
1428  else if(m_context.m_lastReleasedMouseButton == Qt::RightButton)
1429  {
1431  }
1432 
1433  // By definition we are stopping the drag operation by releasing the mouse
1434  // button. Whatever that mouse button was pressed before and if there was
1435  // one pressed before. We cannot set that boolean value to false before
1436  // this place, because we call a number of routines above that need to know
1437  // that dragging was occurring. Like mouseReleaseHandledEvent(event) for
1438  // example.
1439 
1440  m_context.m_isMouseDragging = false;
1441 
1442  event->accept();
1443 
1444  return;
1445 }
1446 
1447 
1448 void
1450 {
1451 
1453  {
1454 
1455  // When the mouse move handler pans the plot, we cannot store each axes
1456  // range history element that would mean store a huge amount of such
1457  // elements, as many element as there are mouse move event handled by
1458  // the Qt event queue. But we can store an axis range history element
1459  // for the last situation of the mouse move: when the button is
1460  // released:
1461 
1463 
1465 
1466  replot();
1467 
1468  // Nothing else to do.
1469  return;
1470  }
1471 
1472  // There are two possibilities:
1473  //
1474  // 1. The full selection polygon (four lines) were currently drawn, which
1475  // means the user was willing to perform a zoom operation
1476  //
1477  // 2. Only the first top line was drawn, which means the user was dragging
1478  // the cursor horizontally. That might have two ends, as shown below.
1479 
1480  // So, first check what is drawn of the selection polygon.
1481 
1482  PolygonType current_selection_polygon_type =
1484 
1485  // Now that we know what was currently drawn of the selection polygon, we can
1486  // remove it. true to reset the values to 0.
1487  hideSelectionRectangle(true);
1488 
1489  // Force replot now because later that call might not be performed.
1490  replot();
1491 
1492  if(current_selection_polygon_type == PolygonType::FULL_POLYGON)
1493  {
1494  // qDebug() << "Yes, the full polygon was visible";
1495 
1496  // If we were dragging with the left button pressed and could draw a
1497  // rectangle, then we were preparing a zoom operation. Let's bring that
1498  // operation to its accomplishment.
1499 
1500  axisZoom();
1501 
1502  // qDebug() << "The selection polygon:"
1503  //<< m_context.m_selectionPolygon.toString();
1504 
1505  return;
1506  }
1507  else if(current_selection_polygon_type == PolygonType::TOP_LINE)
1508  {
1509  // qDebug() << "No, only the top line of the full polygon was visible";
1510 
1511  // The user was dragging the left mouse cursor and that may mean they were
1512  // measuring a distance or willing to perform a special zoom operation if
1513  // the Ctrl key was down.
1514 
1515  // If the user started by clicking in the plot region, dragged the mouse
1516  // cursor with the left button and pressed the Ctrl modifier, then that
1517  // means that they wanted to do a rescale over the x-axis in the form of a
1518  // reframing.
1519 
1520  if(m_context.m_keyboardModifiers & Qt::ControlModifier)
1521  {
1522  return axisReframe();
1523 
1524  // qDebug() << "The selection polygon:"
1525  //<< m_context.m_selectionPolygon.toString();
1526  }
1527  }
1528  else
1529  qDebug() << "Another possibility.";
1530 }
1531 
1532 
1533 void
1535 {
1536 
1537  // The right button is used for the integrations. Not for axis range
1538  // operations. So all we have to do is remove the various graphics items and
1539  // send a signal with the context that contains all the data required by the
1540  // user to perform the integrations over the right plot regions.
1541 
1542  // Whatever we were doing we need to make the selection line invisible:
1543 
1544  if(mp_xDeltaTextItem->visible())
1545  mp_xDeltaTextItem->setVisible(false);
1546  if(mp_yDeltaTextItem->visible())
1547  mp_yDeltaTextItem->setVisible(false);
1548 
1549  // Also make the vertical end tracer invisible.
1550  mp_vEndTracerItem->setVisible(false);
1551 
1552  // Once the integration is asked for, then the selection rectangle if of no
1553  // more use.
1555 
1556  // Force replot now because later that call might not be performed.
1557  replot();
1558 
1559  // Note that we only request an integration if the x-axis delta is enough.
1560 
1561  double x_delta_pixel =
1562  fabs(xAxis->coordToPixel(m_context.m_currentDragPoint.x()) -
1563  xAxis->coordToPixel(m_context.m_startDragPoint.x()));
1564 
1565  if(x_delta_pixel > 3)
1567  // else
1568  // qDebug() << "Not asking for integration.";
1569 }
1570 
1571 
1572 void
1573 BasePlotWidget::mouseWheelHandler([[maybe_unused]] QWheelEvent *event)
1574 {
1575  // We should record the new range values each time the wheel is used to
1576  // zoom/unzoom.
1577 
1578  m_context.m_xRange = QCPRange(xAxis->range());
1579  m_context.m_yRange = QCPRange(yAxis->range());
1580 
1581  // qDebug() << "New x range: " << m_context.m_xRange;
1582  // qDebug() << "New y range: " << m_context.m_yRange;
1583 
1585 
1588 
1589  event->accept();
1590 }
1591 
1592 
1593 void
1595  QCPAxis *axis,
1596  [[maybe_unused]] QCPAxis::SelectablePart part,
1597  QMouseEvent *event)
1598 {
1599  //qDebug();
1600 
1601  m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
1602 
1603  if(m_context.m_keyboardModifiers & Qt::ControlModifier)
1604  {
1605  //qDebug();
1606 
1607  // If the Ctrl modifiers is active, then both axes are to be reset. Also
1608  // the histories are reset also.
1609 
1610  rescaleAxes();
1612  }
1613  else
1614  {
1615  //qDebug();
1616  // Only the axis passed as parameter is to be rescaled.
1617  // Reset the range of that axis to the max view possible.
1618 
1619  axis->rescale();
1620 
1622 
1623  event->accept();
1624  }
1625 
1626  // The double-click event does not cancel the mouse press event. That is, if
1627  // left-double-clicking, at the end of the operation the button still
1628  // "pressed". We need to remove manually the button from the pressed buttons
1629  // context member.
1630 
1631  m_context.m_pressedMouseButtons ^= event->button();
1632 
1634 
1636 
1637  replot();
1638 }
1639 
1640 
1641 bool
1642 BasePlotWidget::isClickOntoXAxis(const QPointF &mousePoint)
1643 {
1644  QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1645 
1646  if(layoutElement &&
1647  layoutElement == dynamic_cast<QCPLayoutElement *>(axisRect()))
1648  {
1649  // The graph is *inside* the axisRect that is the outermost envelope of
1650  // the graph. Thus, if we want to know if the click was indeed on an
1651  // axis, we need to check what selectable part of the the axisRect we
1652  // were
1653  // clicking:
1654  QCPAxis::SelectablePart selectablePart;
1655 
1656  selectablePart = xAxis->getPartAt(mousePoint);
1657 
1658  if(selectablePart == QCPAxis::spAxisLabel ||
1659  selectablePart == QCPAxis::spAxis ||
1660  selectablePart == QCPAxis::spTickLabels)
1661  return true;
1662  }
1663 
1664  return false;
1665 }
1666 
1667 
1668 bool
1669 BasePlotWidget::isClickOntoYAxis(const QPointF &mousePoint)
1670 {
1671  QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1672 
1673  if(layoutElement &&
1674  layoutElement == dynamic_cast<QCPLayoutElement *>(axisRect()))
1675  {
1676  // The graph is *inside* the axisRect that is the outermost envelope of
1677  // the graph. Thus, if we want to know if the click was indeed on an
1678  // axis, we need to check what selectable part of the the axisRect we
1679  // were
1680  // clicking:
1681  QCPAxis::SelectablePart selectablePart;
1682 
1683  selectablePart = yAxis->getPartAt(mousePoint);
1684 
1685  if(selectablePart == QCPAxis::spAxisLabel ||
1686  selectablePart == QCPAxis::spAxis ||
1687  selectablePart == QCPAxis::spTickLabels)
1688  return true;
1689  }
1690 
1691  return false;
1692 }
1693 
1694 /// MOUSE-related EVENTS
1695 
1696 
1697 /// MOUSE MOVEMENTS mouse/keyboard-triggered
1698 
1699 int
1701 {
1702  // The user is dragging the mouse, probably to rescale the axes, but we need
1703  // to sort out in which direction the drag is happening.
1704 
1705  // This function should be called after calculateDragDeltas, so that
1706  // m_context has the proper x/y delta values that we'll compare.
1707 
1708  // Note that we cannot compare simply x or y deltas because the y axis might
1709  // have a different scale that the x axis. So we first need to convert the
1710  // positions to pixels.
1711 
1712  double x_delta_pixel =
1713  fabs(xAxis->coordToPixel(m_context.m_currentDragPoint.x()) -
1714  xAxis->coordToPixel(m_context.m_startDragPoint.x()));
1715 
1716  double y_delta_pixel =
1717  fabs(yAxis->coordToPixel(m_context.m_currentDragPoint.y()) -
1718  yAxis->coordToPixel(m_context.m_startDragPoint.y()));
1719 
1720  if(x_delta_pixel > y_delta_pixel)
1721  return Qt::Horizontal;
1722 
1723  return Qt::Vertical;
1724 }
1725 
1726 
1727 void
1729 {
1730  // First convert the graph coordinates to pixel coordinates.
1731 
1732  QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1733  yAxis->coordToPixel(graph_coordinates.y()));
1734 
1735  moveMouseCursorPixelCoordToGlobal(pixels_coordinates.toPoint());
1736 }
1737 
1738 
1739 void
1741 {
1742  // qDebug() << "Calling set pos with new cursor position.";
1743  QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1744 }
1745 
1746 
1747 void
1749 {
1750  QPointF graph_coord = horizontalGetGraphCoordNewPointCountPixels(pixel_count);
1751 
1752  QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1753  yAxis->coordToPixel(graph_coord.y()));
1754 
1755  // Now we need ton convert the new coordinates to the global position system
1756  // and to move the cursor to that new position. That will create an event to
1757  // move the mouse cursor.
1758 
1759  moveMouseCursorPixelCoordToGlobal(pixel_coord.toPoint());
1760 }
1761 
1762 
1763 QPointF
1765 {
1766  QPointF pixel_coordinates(
1767  xAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.x()) + pixel_count,
1768  yAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.y()));
1769 
1770  // Now convert back to local coordinates.
1771 
1772  QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1773  yAxis->pixelToCoord(pixel_coordinates.y()));
1774 
1775  return graph_coordinates;
1776 }
1777 
1778 
1779 void
1781 {
1782 
1783  QPointF graph_coord = verticalGetGraphCoordNewPointCountPixels(pixel_count);
1784 
1785  QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1786  yAxis->coordToPixel(graph_coord.y()));
1787 
1788  // Now we need ton convert the new coordinates to the global position system
1789  // and to move the cursor to that new position. That will create an event to
1790  // move the mouse cursor.
1791 
1792  moveMouseCursorPixelCoordToGlobal(pixel_coord.toPoint());
1793 }
1794 
1795 
1796 QPointF
1798 {
1799  QPointF pixel_coordinates(
1800  xAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.x()),
1801  yAxis->coordToPixel(m_context.m_lastCursorHoveredPoint.y()) + pixel_count);
1802 
1803  // Now convert back to local coordinates.
1804 
1805  QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1806  yAxis->pixelToCoord(pixel_coordinates.y()));
1807 
1808  return graph_coordinates;
1809 }
1810 
1811 /// MOUSE MOVEMENTS mouse/keyboard-triggered
1812 
1813 
1814 /// RANGE-related functions
1815 
1816 QCPRange
1817 BasePlotWidget::getRangeX(bool &found_range, int index) const
1818 {
1819  QCPGraph *graph_p = graph(index);
1820 
1821  if(graph_p == nullptr)
1822  qFatal("Programming error.");
1823 
1824  return graph_p->getKeyRange(found_range);
1825 }
1826 
1827 
1828 QCPRange
1829 BasePlotWidget::getRangeY(bool &found_range, int index) const
1830 {
1831  QCPGraph *graph_p = graph(index);
1832 
1833  if(graph_p == nullptr)
1834  qFatal("Programming error.");
1835 
1836  return graph_p->getValueRange(found_range);
1837 }
1838 
1839 
1840 QCPRange
1842  RangeType range_type,
1843  bool &found_range) const
1844 {
1845 
1846  // Iterate in all the graphs in this widget and return a QCPRange that has
1847  // its lower member as the greatest lower value of all
1848  // its upper member as the smallest upper value of all
1849 
1850  if(!graphCount())
1851  {
1852  found_range = false;
1853 
1854  return QCPRange(0, 1);
1855  }
1856 
1857  if(graphCount() == 1)
1858  return graph()->getKeyRange(found_range);
1859 
1860  bool found_at_least_one_range = false;
1861 
1862  // Create an invalid range.
1863  QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1864 
1865  for(int iter = 0; iter < graphCount(); ++iter)
1866  {
1867  QCPRange temp_range;
1868 
1869  bool found_range_for_iter = false;
1870 
1871  QCPGraph *graph_p = graph(iter);
1872 
1873  // Depending on the axis param, select the key or value range.
1874 
1875  if(axis == Axis::x)
1876  temp_range = graph_p->getKeyRange(found_range_for_iter);
1877  else if(axis == Axis::y)
1878  temp_range = graph_p->getValueRange(found_range_for_iter);
1879  else
1880  qFatal("Cannot reach this point. Programming error.");
1881 
1882  // Was a range found for the iterated graph ? If not skip this
1883  // iteration.
1884 
1885  if(!found_range_for_iter)
1886  continue;
1887 
1888  // While the innermost_range is invalid, we need to seed it with a good
1889  // one. So check this.
1890 
1891  if(!QCPRange::validRange(result_range))
1892  qFatal("The obtained range is invalid !");
1893 
1894  // At this point we know the obtained range is OK.
1895  result_range = temp_range;
1896 
1897  // We found at least one valid range!
1898  found_at_least_one_range = true;
1899 
1900  // At this point we have two valid ranges to compare. Depending on
1901  // range_type, we need to perform distinct comparisons.
1902 
1903  if(range_type == RangeType::innermost)
1904  {
1905  if(temp_range.lower > result_range.lower)
1906  result_range.lower = temp_range.lower;
1907  if(temp_range.upper < result_range.upper)
1908  result_range.upper = temp_range.upper;
1909  }
1910  else if(range_type == RangeType::outermost)
1911  {
1912  if(temp_range.lower < result_range.lower)
1913  result_range.lower = temp_range.lower;
1914  if(temp_range.upper > result_range.upper)
1915  result_range.upper = temp_range.upper;
1916  }
1917  else
1918  qFatal("Cannot reach this point. Programming error.");
1919 
1920  // Continue to next graph, if any.
1921  }
1922  // End of
1923  // for(int iter = 0; iter < graphCount(); ++iter)
1924 
1925  // Let the caller know if we found at least one range.
1926  found_range = found_at_least_one_range;
1927 
1928  return result_range;
1929 }
1930 
1931 
1932 QCPRange
1933 BasePlotWidget::getInnermostRangeX(bool &found_range) const
1934 {
1935 
1936  return getRange(Axis::x, RangeType::innermost, found_range);
1937 }
1938 
1939 
1940 QCPRange
1941 BasePlotWidget::getOutermostRangeX(bool &found_range) const
1942 {
1943  return getRange(Axis::x, RangeType::outermost, found_range);
1944 }
1945 
1946 
1947 QCPRange
1948 BasePlotWidget::getInnermostRangeY(bool &found_range) const
1949 {
1950 
1951  return getRange(Axis::y, RangeType::innermost, found_range);
1952 }
1953 
1954 
1955 QCPRange
1956 BasePlotWidget::getOutermostRangeY(bool &found_range) const
1957 {
1958  return getRange(Axis::y, RangeType::outermost, found_range);
1959 }
1960 
1961 
1962 /// RANGE-related functions
1963 
1964 
1965 /// PLOTTING / REPLOTTING functions
1966 
1967 void
1969 {
1970  // Get the current x lower/upper range, that is, leftmost/rightmost x
1971  // coordinate.
1972  double xLower = xAxis->range().lower;
1973  double xUpper = xAxis->range().upper;
1974 
1975  // Get the current y lower/upper range, that is, bottommost/topmost y
1976  // coordinate.
1977  double yLower = yAxis->range().lower;
1978  double yUpper = yAxis->range().upper;
1979 
1980  // This function is called only when the user has clicked on the x/y axis or
1981  // when the user has dragged the left mouse button with the Ctrl key
1982  // modifier. The m_context.m_wasClickOnXAxis is then simulated in the mouse
1983  // move handler. So we need to test which axis was clicked-on.
1984 
1986  {
1987 
1988  // We are changing the range of the X axis.
1989 
1990  // What is the x delta ?
1991  double xDelta =
1993 
1994  // If xDelta is < 0, the we were dragging from right to left, we are
1995  // compressing the view on the x axis, by adding new data to the right
1996  // hand size of the graph. So we add xDelta to the upper bound of the
1997  // range. Otherwise we are uncompressing the view on the x axis and
1998  // remove the xDelta from the upper bound of the range. This is why we
1999  // have the
2000  // '-'
2001  // and not '+' below;
2002 
2003  // qDebug() << "Setting xaxis:" << xLower << "--" << xUpper - xDelta;
2004 
2005  xAxis->setRange(xLower, xUpper - xDelta);
2006  }
2007  // End of
2008  // if(m_context.m_wasClickOnXAxis)
2009  else // that is, if(m_context.m_wasClickOnYAxis)
2010  {
2011  // We are changing the range of the Y axis.
2012 
2013  // What is the y delta ?
2014  double yDelta =
2016 
2017  // See above for an explanation of the computation.
2018 
2019  yAxis->setRange(yLower, yUpper - yDelta);
2020 
2021  // Old version
2022  // if(yDelta < 0)
2023  //{
2024  //// The dragging operation was from top to bottom, we are enlarging
2025  //// the range (thus, we are unzooming the view, since the widget
2026  //// always has the same size).
2027 
2028  // yAxis->setRange(yLower, yUpper + fabs(yDelta));
2029  //}
2030  // else
2031  //{
2032  //// The dragging operation was from bottom to top, we are reducing
2033  //// the range (thus, we are zooming the view, since the widget
2034  //// always has the same size).
2035 
2036  // yAxis->setRange(yLower, yUpper - fabs(yDelta));
2037  //}
2038  }
2039  // End of
2040  // else // that is, if(m_context.m_wasClickOnYAxis)
2041 
2042  // Update the context with the current axes ranges
2043 
2045 
2047 
2048  replot();
2049 }
2050 
2051 
2052 void
2054 {
2055 
2056  // double sorted_start_drag_point_x =
2057  // std::min(m_context.m_startDragPoint.x(), m_context.m_currentDragPoint.x());
2058 
2059  // xAxis->setRange(sorted_start_drag_point_x,
2060  // sorted_start_drag_point_x + fabs(m_context.m_xDelta));
2061 
2062  xAxis->setRange(
2064 
2065  // Note that the y axis should be rescaled from current lower value to new
2066  // upper value matching the y-axis position of the cursor when the mouse
2067  // button was released.
2068 
2069  yAxis->setRange(xAxis->range().lower,
2070  std::max<double>(m_context.m_yRegionRangeStart,
2072 
2073  // qDebug() << "xaxis:" << xAxis->range().lower << "-" <<
2074  // xAxis->range().upper
2075  //<< "yaxis:" << yAxis->range().lower << "-" << yAxis->range().upper;
2076 
2078 
2081 
2082  replot();
2083 }
2084 
2085 
2086 void
2088 {
2089 
2090  // Use the m_context.m_xRegionRangeStart/End values, but we need to sort the
2091  // values before using them, because now we want to really have the lower x
2092  // value. Simply craft a QCPRange that will swap the values if lower is not
2093  // < than upper QCustomPlot calls this normalization).
2094 
2095  xAxis->setRange(
2097 
2098  yAxis->setRange(
2100 
2102 
2105 
2106  replot();
2107 }
2108 
2109 
2110 void
2112 {
2113  // Sanity check
2115  qFatal(
2116  "This function can only be called if the mouse click was on one of the "
2117  "axes");
2118 
2119  // First update the x&y axis ranges that we'll need for panning.
2121 
2123  {
2124  xAxis->setRange(m_context.m_xRange.lower - m_context.m_xDelta,
2126  }
2127 
2129  {
2130  yAxis->setRange(m_context.m_yRange.lower - m_context.m_yDelta,
2132  }
2133 
2134  // We cannot store the new ranges in the history, because the pan operation
2135  // involved a huge quantity of micro-movements elicited upon each mouse move
2136  // cursor event so we would have a huge history.
2137  // updateAxesRangeHistory();
2138 
2139  // Now that the context has the right range values, we can emit the
2140  // signal that will be used by this plot widget users, typically to
2141  // abide by the x/y range lock required by the user.
2142 
2144 
2145  replot();
2146 }
2147 
2148 
2149 void
2151  QCPRange yAxisRange,
2152  Axis axis)
2153 {
2154  if(static_cast<int>(axis) & static_cast<int>(Axis::x))
2155  {
2156  xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2157  }
2158 
2159  if(static_cast<int>(axis) & static_cast<int>(Axis::y))
2160  {
2161  yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2162  }
2163 
2164  // We do not want to update the history, because there would be way too
2165  // much history items, since this function is called upon mouse moving
2166  // handling and not only during mouse release events.
2167  // updateAxesRangeHistory();
2168 
2169  replot();
2170 }
2171 
2172 
2173 void
2174 BasePlotWidget::replotWithAxisRangeX(double lower, double upper)
2175 {
2176  // qDebug();
2177 
2178  xAxis->setRange(lower, upper);
2179 
2180  replot();
2181 }
2182 
2183 
2184 void
2185 BasePlotWidget::replotWithAxisRangeY(double lower, double upper)
2186 {
2187  // qDebug();
2188 
2189  yAxis->setRange(lower, upper);
2190 
2191  replot();
2192 }
2193 
2194 /// PLOTTING / REPLOTTING functions
2195 
2196 
2197 /// PLOT ITEMS : TRACER TEXT ITEMS...
2198 
2199 //! Hide the selection line, the xDelta text and the zoom rectangle items.
2200 void
2202 {
2203  mp_xDeltaTextItem->setVisible(false);
2204  mp_yDeltaTextItem->setVisible(false);
2205 
2206  // mp_zoomRectItem->setVisible(false);
2208 
2209  // Force a replot to make sure the action is immediately visible by the
2210  // user, even without moving the mouse.
2211  replot();
2212 }
2213 
2214 
2215 //! Show the traces (vertical and horizontal).
2216 void
2218 {
2219  m_shouldTracersBeVisible = true;
2220 
2221  mp_vPosTracerItem->setVisible(true);
2222  mp_hPosTracerItem->setVisible(true);
2223 
2224  mp_vStartTracerItem->setVisible(true);
2225  mp_vEndTracerItem->setVisible(true);
2226 
2227  // Force a replot to make sure the action is immediately visible by the
2228  // user, even without moving the mouse.
2229  replot();
2230 }
2231 
2232 
2233 //! Hide the traces (vertical and horizontal).
2234 void
2236 {
2237  m_shouldTracersBeVisible = false;
2238  mp_hPosTracerItem->setVisible(false);
2239  mp_vPosTracerItem->setVisible(false);
2240 
2241  mp_vStartTracerItem->setVisible(false);
2242  mp_vEndTracerItem->setVisible(false);
2243 
2244  // Force a replot to make sure the action is immediately visible by the
2245  // user, even without moving the mouse.
2246  replot();
2247 }
2248 
2249 
2250 void
2252  bool for_integration)
2253 {
2254  // The user has dragged the mouse left button on the graph, which means he
2255  // is willing to draw a selection rectangle, either for zooming-in or for
2256  // integration.
2257 
2258  mp_xDeltaTextItem->setVisible(false);
2259  mp_yDeltaTextItem->setVisible(false);
2260 
2261  // Ensure the right selection rectangle is drawn.
2262 
2263  updateSelectionRectangle(as_line_segment, for_integration);
2264 
2265  // Note that if we draw a zoom rectangle, then we are certainly not
2266  // measuring anything. So set the boolean value to false so that the user of
2267  // this widget or derived classes know that there is nothing to perform upon
2268  // (like deconvolution, for example).
2269 
2271 
2272  // Also remove the delta value from the pipeline by sending a simple
2273  // distance without measurement signal.
2274 
2275  emit xAxisMeasurementSignal(m_context, false);
2276 
2277  replot();
2278 }
2279 
2280 
2281 void
2283 {
2284  // The user is dragging the mouse over the graph and we want them to know what
2285  // is the x delta value, that is the span between the point at the start of
2286  // the drag and the current drag position.
2287 
2288  // FIXME: is this still true?
2289  //
2290  // We do not want to show the position markers because the only horiontal
2291  // line to be visible must be contained between the start and end vertiacal
2292  // tracer items.
2293  mp_hPosTracerItem->setVisible(false);
2294  mp_vPosTracerItem->setVisible(false);
2295 
2296  // We want to draw the text in the middle position of the leftmost-rightmost
2297  // point, even with skewed rectangle selection.
2298 
2299  QPointF leftmost_point = m_context.m_selectionPolygon.getLeftMostPoint();
2300 
2301  // qDebug() << "leftmost_point:" << leftmost_point;
2302 
2303  QPointF rightmost_point = m_context.m_selectionPolygon.getRightMostPoint();
2304 
2305  // qDebug() << "rightmost_point:" << rightmost_point;
2306 
2307  double x_axis_center_position =
2308  leftmost_point.x() + (rightmost_point.x() - leftmost_point.x()) / 2;
2309 
2310  // qDebug() << "x_axis_center_position:" << x_axis_center_position;
2311 
2312  // We want the text to print inside the rectangle, always at the current drag
2313  // point so the eye can follow the delta value while looking where to drag the
2314  // mouse. To position the text inside the rectangle, we need to know what is
2315  // the drag direction.
2316 
2317  // Set aside a point instance to store the pixel coordinates of the text.
2318  QPointF pixel_coordinates;
2319 
2320  // What is the distance between the rectangle line at current drag point and
2321  // the text itself.
2322  int pixels_away_from_line = 15;
2323 
2324  // ATTENTION: the pixel coordinates for the vertical direction go in reverse
2325  // order with respect to the y axis values !!! That is pixel(0,0) is top left
2326  // of the graph.
2327  if(static_cast<int>(m_context.m_dragDirections) &
2328  static_cast<int>(DragDirections::TOP_TO_BOTTOM))
2329  {
2330  // We need to print inside the rectangle, that is pixels_above_line pixels
2331  // to the bottom, so with pixel y value decremented of that
2332  // pixels_above_line value (one would have expected to increment that
2333  // value, along the y axis, but the coordinates in pixel go in reverse
2334  // order).
2335 
2336  pixels_away_from_line *= -1;
2337  }
2338 
2339  double y_axis_pixel_coordinate =
2340  yAxis->coordToPixel(m_context.m_currentDragPoint.y());
2341 
2342  double y_axis_modified_pixel_coordinate =
2343  y_axis_pixel_coordinate + pixels_away_from_line;
2344 
2345  pixel_coordinates.setX(x_axis_center_position);
2346  pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2347 
2348  // Now convert back to graph coordinates.
2349 
2350  QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2351  yAxis->pixelToCoord(pixel_coordinates.y()));
2352  mp_xDeltaTextItem->position->setCoords(x_axis_center_position,
2353  graph_coordinates.y());
2354  mp_xDeltaTextItem->setText(QString("%1").arg(m_context.m_xDelta, 0, 'f', 3));
2355  mp_xDeltaTextItem->setFont(QFont(font().family(), 9));
2356  mp_xDeltaTextItem->setVisible(true);
2357 
2358  // Set the boolean to true so that derived widgets know that something is
2359  // being measured, and they can act accordingly, for example by computing
2360  // deconvolutions in a mass spectrum.
2362 
2363  replot();
2364 
2365  // Let the caller know that we were measuring something.
2366  emit xAxisMeasurementSignal(m_context, true);
2367 
2368  return;
2369 }
2370 
2371 
2372 void
2374 {
2376  return;
2377 
2378  // The user is dragging the mouse over the graph and we want them to know what
2379  // is the y delta value, that is the span between the point at the top of
2380  // the selection polygon and the point at its bottom.
2381 
2382  // FIXME: is this still true?
2383  //
2384  // We do not want to show the position markers because the only horiontal
2385  // line to be visible must be contained between the start and end vertiacal
2386  // tracer items.
2387  mp_hPosTracerItem->setVisible(false);
2388  mp_vPosTracerItem->setVisible(false);
2389 
2390  // We want to draw the text in the middle position of the leftmost-rightmost
2391  // point, even with skewed rectangle selection.
2392 
2393  QPointF leftmost_point = m_context.m_selectionPolygon.getLeftMostPoint();
2394  QPointF topmost_point = m_context.m_selectionPolygon.getTopMostPoint();
2395 
2396  // qDebug() << "leftmost_point:" << leftmost_point;
2397 
2398  QPointF rightmost_point = m_context.m_selectionPolygon.getRightMostPoint();
2399  QPointF bottommost_point = m_context.m_selectionPolygon.getBottomMostPoint();
2400 
2401  // qDebug() << "rightmost_point:" << rightmost_point;
2402 
2403  double x_axis_center_position =
2404  leftmost_point.x() + (rightmost_point.x() - leftmost_point.x()) / 2;
2405 
2406  double y_axis_center_position =
2407  bottommost_point.y() + (topmost_point.y() - bottommost_point.y()) / 2;
2408 
2409  // qDebug() << "x_axis_center_position:" << x_axis_center_position;
2410 
2411  mp_yDeltaTextItem->position->setCoords(x_axis_center_position,
2412  y_axis_center_position);
2413  mp_yDeltaTextItem->setText(QString("%1").arg(m_context.m_yDelta, 0, 'f', 3));
2414  mp_yDeltaTextItem->setFont(QFont(font().family(), 9));
2415  mp_yDeltaTextItem->setVisible(true);
2416  mp_yDeltaTextItem->setRotation(90);
2417 
2418  // Set the boolean to true so that derived widgets know that something is
2419  // being measured, and they can act accordingly, for example by computing
2420  // deconvolutions in a mass spectrum.
2422 
2423  replot();
2424 
2425  // Let the caller know that we were measuring something.
2426  emit xAxisMeasurementSignal(m_context, true);
2427 }
2428 
2429 
2430 void
2432 {
2433 
2434  // We compute signed differentials. If the user does not want the sign,
2435  // fabs(double) is their friend.
2436 
2437  // Compute the xAxis differential:
2438 
2441 
2442  // Same with the Y-axis range:
2443 
2446 
2447  // qDebug() << "xDelta:" << m_context.m_xDelta
2448  //<< "and yDelta:" << m_context.m_yDelta;
2449 
2450  return;
2451 }
2452 
2453 
2454 bool
2456 {
2457  // First get the height of the plot.
2458  double plotHeight = yAxis->range().upper - yAxis->range().lower;
2459 
2460  double heightDiff =
2462 
2463  double heightDiffRatio = (heightDiff / plotHeight) * 100;
2464 
2465  if(heightDiffRatio > 10)
2466  {
2467  // qDebug() << "isVerticalDisplacementAboveThreshold: true";
2468  return true;
2469  }
2470 
2471  // qDebug() << "isVerticalDisplacementAboveThreshold: false";
2472  return false;
2473 }
2474 
2475 
2476 void
2478 {
2479 
2480  // if(for_integration)
2481  // qDebug() << "for_integration:" << for_integration;
2482 
2483  // When we make a linear selection, the selection polygon is a polygon that
2484  // has the following characteristics:
2485  //
2486  // the x range is the linear selection span
2487  //
2488  // the y range is the widest std::min -> std::max possible.
2489 
2490  // This is how the selection polygon logic knows if its is mono-
2491  // two-dimensional.
2492 
2493  // We want the top left point to effectively be the top left point, so check
2494  // the direction of the mouse cursor drag.
2495 
2496  double x_range_start =
2498  double x_range_end =
2500 
2501  double y_position = m_context.m_startDragPoint.y();
2502 
2503  m_context.m_selectionPolygon.set1D(x_range_start, x_range_end);
2504 
2505  // Top line
2506  mp_selectionRectangeLine1->start->setCoords(
2507  QPointF(x_range_start, y_position));
2508  mp_selectionRectangeLine1->end->setCoords(QPointF(x_range_end, y_position));
2509 
2510  // Only if we are drawing a selection rectangle for integration, do we set
2511  // arrow heads to the line.
2512  if(for_integration)
2513  {
2514  mp_selectionRectangeLine1->setHead(QCPLineEnding::esSpikeArrow);
2515  mp_selectionRectangeLine1->setTail(QCPLineEnding::esSpikeArrow);
2516  }
2517  else
2518  {
2519  mp_selectionRectangeLine1->setHead(QCPLineEnding::esNone);
2520  mp_selectionRectangeLine1->setTail(QCPLineEnding::esNone);
2521  }
2522  mp_selectionRectangeLine1->setVisible(true);
2523 
2524  // Right line: does not exist, start and end are the same end point of the top
2525  // line.
2526  mp_selectionRectangeLine2->start->setCoords(QPointF(x_range_end, y_position));
2527  mp_selectionRectangeLine2->end->setCoords(QPointF(x_range_end, y_position));
2528  mp_selectionRectangeLine2->setVisible(false);
2529 
2530  // Bottom line: identical to the top line, but invisible
2531  mp_selectionRectangeLine3->start->setCoords(
2532  QPointF(x_range_start, y_position));
2533  mp_selectionRectangeLine3->end->setCoords(QPointF(x_range_end, y_position));
2534  mp_selectionRectangeLine3->setVisible(false);
2535 
2536  // Left line: does not exist: start and end are the same end point of the top
2537  // line.
2538  mp_selectionRectangeLine4->start->setCoords(QPointF(x_range_end, y_position));
2539  mp_selectionRectangeLine4->end->setCoords(QPointF(x_range_end, y_position));
2540  mp_selectionRectangeLine4->setVisible(false);
2541 }
2542 
2543 
2544 void
2546 {
2547 
2548  // if(for_integration)
2549  // qDebug() << "for_integration:" << for_integration;
2550 
2551  // We are handling a conventional rectangle. Just create four points
2552  // from top left to bottom right. But we want the top left point to be
2553  // effectively the top left point and the bottom point to be the bottom point.
2554  // So we need to try all four direction combinations, left to right or
2555  // converse versus top to bottom or converse.
2556 
2558 
2560  {
2561  // qDebug() << "Dragging from right to left";
2562 
2564  {
2565  // qDebug() << "Dragging from top to bottom";
2566 
2567  // TOP_LEFT_POINT
2572 
2573  // TOP_RIGHT_POINT
2577 
2578  // BOTTOM_RIGHT_POINT
2583 
2584  // BOTTOM_LEFT_POINT
2589  }
2590  // End of
2591  // if(m_context.m_currentDragPoint.y() < m_context.m_startDragPoint.y())
2592  else
2593  {
2594  // qDebug() << "Dragging from bottom to top";
2595 
2596  // TOP_LEFT_POINT
2601 
2602  // TOP_RIGHT_POINT
2607 
2608  // BOTTOM_RIGHT_POINT
2612 
2613  // BOTTOM_LEFT_POINT
2618  }
2619  }
2620  // End of
2621  // if(m_context.m_currentDragPoint.x() < m_context.m_startDragPoint.x())
2622  else
2623  {
2624  // qDebug() << "Dragging from left to right";
2625 
2627  {
2628  // qDebug() << "Dragging from top to bottom";
2629 
2630  // TOP_LEFT_POINT
2634 
2635  // TOP_RIGHT_POINT
2640 
2641  // BOTTOM_RIGHT_POINT
2646 
2647  // BOTTOM_LEFT_POINT
2652  }
2653  else
2654  {
2655  // qDebug() << "Dragging from bottom to top";
2656 
2657  // TOP_LEFT_POINT
2662 
2663  // TOP_RIGHT_POINT
2668 
2669  // BOTTOM_RIGHT_POINT
2674 
2675  // BOTTOM_LEFT_POINT
2679  }
2680  }
2681 
2682  // qDebug() << "Now draw the lines with points:"
2683  //<< m_context.m_selectionPolygon.toString();
2684 
2685  // Top line
2686  mp_selectionRectangeLine1->start->setCoords(
2688  mp_selectionRectangeLine1->end->setCoords(
2690 
2691  // Only if we are drawing a selection rectangle for integration, do we
2692  // set arrow heads to the line.
2693  if(for_integration)
2694  {
2695  mp_selectionRectangeLine1->setHead(QCPLineEnding::esSpikeArrow);
2696  mp_selectionRectangeLine1->setTail(QCPLineEnding::esSpikeArrow);
2697  }
2698  else
2699  {
2700  mp_selectionRectangeLine1->setHead(QCPLineEnding::esNone);
2701  mp_selectionRectangeLine1->setTail(QCPLineEnding::esNone);
2702  }
2703 
2704  mp_selectionRectangeLine1->setVisible(true);
2705 
2706  // Right line
2707  mp_selectionRectangeLine2->start->setCoords(
2709  mp_selectionRectangeLine2->end->setCoords(
2711  mp_selectionRectangeLine2->setVisible(true);
2712 
2713  // Bottom line
2714  mp_selectionRectangeLine3->start->setCoords(
2716  mp_selectionRectangeLine3->end->setCoords(
2718  mp_selectionRectangeLine3->setVisible(true);
2719 
2720  // Left line
2721  mp_selectionRectangeLine4->start->setCoords(
2723  mp_selectionRectangeLine4->end->setCoords(
2725  mp_selectionRectangeLine4->setVisible(true);
2726 }
2727 
2728 
2729 void
2731 {
2732 
2733  // if(for_integration)
2734  // qDebug() << "for_integration:" << for_integration;
2735 
2736  // We are handling a skewed rectangle, that is a rectangle that is
2737  // tilted either to the left or to the right.
2738 
2739  // qDebug() << "m_context.m_selectRectangleWidth: "
2740  //<< m_context.m_selectRectangleWidth;
2741 
2742  // Top line
2743  // start
2744 
2745  // qDebug() << "m_context.m_startDragPoint: " <<
2746  // m_context.m_startDragPoint.x()
2747  //<< "-" << m_context.m_startDragPoint.y();
2748 
2749  // qDebug() << "m_context.m_currentDragPoint: "
2750  //<< m_context.m_currentDragPoint.x() << "-"
2751  //<< m_context.m_currentDragPoint.y();
2752 
2754 
2756  {
2757  // qDebug() << "Dragging from right to left";
2758 
2760  {
2761  // qDebug() << "Dragging from top to bottom";
2762 
2767 
2768  // m_context.m_selRectTopLeftPoint.setX(
2769  // m_context.m_startDragPoint.x() -
2770  // m_context.m_selectRectangleWidth);
2771  // m_context.m_selRectTopLeftPoint.setY(m_context.m_startDragPoint.y());
2772 
2776 
2777  // m_context.m_selRectTopRightPoint.setX(m_context.m_startDragPoint.x());
2778  // m_context.m_selRectTopRightPoint.setY(m_context.m_startDragPoint.y());
2779 
2784 
2785  // m_context.m_selRectBottomRightPoint.setX(
2786  // m_context.m_currentDragPoint.x() +
2787  // m_context.m_selectRectangleWidth);
2788  // m_context.m_selRectBottomRightPoint.setY(
2789  // m_context.m_currentDragPoint.y());
2790 
2795 
2796  // m_context.m_selRectBottomLeftPoint.setX(
2797  // m_context.m_currentDragPoint.x());
2798  // m_context.m_selRectBottomLeftPoint.setY(
2799  // m_context.m_currentDragPoint.y());
2800  }
2801  else
2802  {
2803  // qDebug() << "Dragging from bottom to top";
2804 
2809 
2810  // m_context.m_selRectTopLeftPoint.setX(
2811  // m_context.m_currentDragPoint.x());
2812  // m_context.m_selRectTopLeftPoint.setY(
2813  // m_context.m_currentDragPoint.y());
2814 
2819 
2820  // m_context.m_selRectTopRightPoint.setX(
2821  // m_context.m_currentDragPoint.x() +
2822  // m_context.m_selectRectangleWidth);
2823  // m_context.m_selRectTopRightPoint.setY(
2824  // m_context.m_currentDragPoint.y());
2825 
2826 
2830 
2831  // m_context.m_selRectBottomRightPoint.setX(
2832  // m_context.m_startDragPoint.x());
2833  // m_context.m_selRectBottomRightPoint.setY(
2834  // m_context.m_startDragPoint.y());
2835 
2840 
2841  // m_context.m_selRectBottomLeftPoint.setX(
2842  // m_context.m_startDragPoint.x() -
2843  // m_context.m_selectRectangleWidth);
2844  // m_context.m_selRectBottomLeftPoint.setY(
2845  // m_context.m_startDragPoint.y());
2846  }
2847  }
2848  // End of
2849  // Dragging from right to left.
2850  else
2851  {
2852  // qDebug() << "Dragging from left to right";
2853 
2855  {
2856  // qDebug() << "Dragging from top to bottom";
2857 
2861 
2862  // m_context.m_selRectTopLeftPoint.setX(m_context.m_startDragPoint.x());
2863  // m_context.m_selRectTopLeftPoint.setY(m_context.m_startDragPoint.y());
2864 
2869 
2870  // m_context.m_selRectTopRightPoint.setX(
2871  // m_context.m_startDragPoint.x() +
2872  // m_context.m_selectRectangleWidth);
2873  // m_context.m_selRectTopRightPoint.setY(m_context.m_startDragPoint.y());
2874 
2879 
2880  // m_context.m_selRectBottomRightPoint.setX(
2881  // m_context.m_currentDragPoint.x());
2882  // m_context.m_selRectBottomRightPoint.setY(
2883  // m_context.m_currentDragPoint.y());
2884 
2889 
2890  // m_context.m_selRectBottomLeftPoint.setX(
2891  // m_context.m_currentDragPoint.x() -
2892  // m_context.m_selectRectangleWidth);
2893  // m_context.m_selRectBottomLeftPoint.setY(
2894  // m_context.m_currentDragPoint.y());
2895  }
2896  else
2897  {
2898  // qDebug() << "Dragging from bottom to top";
2899 
2904 
2905  // m_context.m_selRectTopLeftPoint.setX(
2906  // m_context.m_currentDragPoint.x() -
2907  // m_context.m_selectRectangleWidth);
2908  // m_context.m_selRectTopLeftPoint.setY(
2909  // m_context.m_currentDragPoint.y());
2910 
2915 
2916  // m_context.m_selRectTopRightPoint.setX(
2917  // m_context.m_currentDragPoint.x());
2918  // m_context.m_selRectTopRightPoint.setY(
2919  // m_context.m_currentDragPoint.y());
2920 
2925 
2926  // m_context.m_selRectBottomRightPoint.setX(
2927  // m_context.m_startDragPoint.x() +
2928  // m_context.m_selectRectangleWidth);
2929  // m_context.m_selRectBottomRightPoint.setY(
2930  // m_context.m_startDragPoint.y());
2931 
2935 
2936  // m_context.m_selRectBottomLeftPoint.setX(
2937  // m_context.m_startDragPoint.x());
2938  // m_context.m_selRectBottomLeftPoint.setY(
2939  // m_context.m_startDragPoint.y());
2940  }
2941  }
2942  // End of Dragging from left to right.
2943 
2944  // qDebug() << "Now draw the lines with points:"
2945  //<< m_context.m_selectionPolygon.toString();
2946 
2947  // Top line
2948  mp_selectionRectangeLine1->start->setCoords(
2950  mp_selectionRectangeLine1->end->setCoords(
2952 
2953  // Only if we are drawing a selection rectangle for integration, do we set
2954  // arrow heads to the line.
2955  if(for_integration)
2956  {
2957  mp_selectionRectangeLine1->setHead(QCPLineEnding::esSpikeArrow);
2958  mp_selectionRectangeLine1->setTail(QCPLineEnding::esSpikeArrow);
2959  }
2960  else
2961  {
2962  mp_selectionRectangeLine1->setHead(QCPLineEnding::esNone);
2963  mp_selectionRectangeLine1->setTail(QCPLineEnding::esNone);
2964  }
2965 
2966  mp_selectionRectangeLine1->setVisible(true);
2967 
2968  // Right line
2969  mp_selectionRectangeLine2->start->setCoords(
2971  mp_selectionRectangeLine2->end->setCoords(
2973  mp_selectionRectangeLine2->setVisible(true);
2974 
2975  // Bottom line
2976  mp_selectionRectangeLine3->start->setCoords(
2978  mp_selectionRectangeLine3->end->setCoords(
2980  mp_selectionRectangeLine3->setVisible(true);
2981 
2982  // Left line
2983  mp_selectionRectangeLine4->end->setCoords(
2985  mp_selectionRectangeLine4->start->setCoords(
2987  mp_selectionRectangeLine4->setVisible(true);
2988 }
2989 
2990 
2991 void
2993  bool for_integration)
2994 {
2995 
2996  // qDebug() << "as_line_segment:" << as_line_segment;
2997  // qDebug() << "for_integration:" << for_integration;
2998 
2999  // We now need to construct the selection rectangle, either for zoom or for
3000  // integration.
3001 
3002  // There are two situations :
3003  //
3004  // 1. if the rectangle should look like a line segment
3005  //
3006  // 2. if the rectangle should actually look like a rectangle. In this case,
3007  // there are two sub-situations:
3008  //
3009  // a. if the S key is down, then the rectangle is
3010  // skewed, that is its vertical sides are not parallel to the y axis.
3011  //
3012  // b. otherwise the rectangle is conventional.
3013 
3014  if(as_line_segment)
3015  {
3016  update1DSelectionRectangle(for_integration);
3017  }
3018  else
3019  {
3020  if(!(m_context.m_keyboardModifiers & Qt::AltModifier))
3021  {
3022  update2DSelectionRectangleSquare(for_integration);
3023  }
3024  else if(m_context.m_keyboardModifiers & Qt::AltModifier)
3025  {
3026  update2DSelectionRectangleSkewed(for_integration);
3027  }
3028  }
3029 
3030  // This code automatically sorts the ranges (range start is always less than
3031  // range end) even if the user actually selects from high to low (right to
3032  // left or bottom to top). This has implications in code that uses the
3033  // m_context data to perform some computations. This is why it is important
3034  // that m_dragDirections be set correctly to establish where the current drag
3035  // point is actually located (at which point).
3036 
3041 
3046 
3047  // At this point, draw the text describing the widths.
3048 
3049  // We want the x-delta on the bottom of the rectangle, inside it
3050  // and the y-delta on the vertical side of the rectangle, inside it.
3051 
3052  // Draw the selection width text
3054 }
3055 
3056 void
3058 {
3059  mp_selectionRectangeLine1->setVisible(false);
3060  mp_selectionRectangeLine2->setVisible(false);
3061  mp_selectionRectangeLine3->setVisible(false);
3062  mp_selectionRectangeLine4->setVisible(false);
3063 
3064  if(reset_values)
3065  {
3067  }
3068 }
3069 
3070 
3071 void
3073 {
3075 }
3076 
3077 
3080 {
3081  // There are four lines that make the selection polygon. We want to know
3082  // which lines are visible.
3083 
3084  int current_selection_polygon = static_cast<int>(PolygonType::NOT_SET);
3085 
3086  if(mp_selectionRectangeLine1->visible())
3087  {
3088  current_selection_polygon |= static_cast<int>(PolygonType::TOP_LINE);
3089  // qDebug() << "current_selection_polygon:" << current_selection_polygon;
3090  }
3091  if(mp_selectionRectangeLine2->visible())
3092  {
3093  current_selection_polygon |= static_cast<int>(PolygonType::RIGHT_LINE);
3094  // qDebug() << "current_selection_polygon:" << current_selection_polygon;
3095  }
3096  if(mp_selectionRectangeLine3->visible())
3097  {
3098  current_selection_polygon |= static_cast<int>(PolygonType::BOTTOM_LINE);
3099  // qDebug() << "current_selection_polygon:" << current_selection_polygon;
3100  }
3101  if(mp_selectionRectangeLine4->visible())
3102  {
3103  current_selection_polygon |= static_cast<int>(PolygonType::LEFT_LINE);
3104  // qDebug() << "current_selection_polygon:" << current_selection_polygon;
3105  }
3106 
3107  // qDebug() << "returning visibility:" << current_selection_polygon;
3108 
3109  return static_cast<PolygonType>(current_selection_polygon);
3110 }
3111 
3112 
3113 bool
3115 {
3116  // Sanity check
3117  int check = 0;
3118 
3119  check += mp_selectionRectangeLine1->visible();
3120  check += mp_selectionRectangeLine2->visible();
3121  check += mp_selectionRectangeLine3->visible();
3122  check += mp_selectionRectangeLine4->visible();
3123 
3124  if(check > 0)
3125  return true;
3126 
3127  return false;
3128 }
3129 
3130 
3131 void
3133 {
3134  // qDebug() << "Setting focus to the QCustomPlot:" << this;
3135 
3136  QCustomPlot::setFocus();
3137 
3138  // qDebug() << "Emitting setFocusSignal().";
3139 
3140  emit setFocusSignal();
3141 }
3142 
3143 
3144 //! Redraw the background of the \p focusedPlotWidget plot widget.
3145 void
3146 BasePlotWidget::redrawPlotBackground(QWidget *focusedPlotWidget)
3147 {
3148  if(focusedPlotWidget == nullptr)
3149  throw ExceptionNotPossible(
3150  "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3151  "-- "
3152  "ERROR focusedPlotWidget cannot be nullptr.");
3153 
3154  if(dynamic_cast<QWidget *>(this) != focusedPlotWidget)
3155  {
3156  // The focused widget is not *this widget. We should make sure that
3157  // we were not the one that had the focus, because in this case we
3158  // need to redraw an unfocused background.
3159 
3160  axisRect()->setBackground(m_unfocusedBrush);
3161  }
3162  else
3163  {
3164  axisRect()->setBackground(m_focusedBrush);
3165  }
3166 
3167  replot();
3168 }
3169 
3170 
3171 void
3173 {
3174  m_context.m_xRange = QCPRange(xAxis->range().lower, xAxis->range().upper);
3175  m_context.m_yRange = QCPRange(yAxis->range().lower, yAxis->range().upper);
3176 }
3177 
3178 
3179 const BasePlotContext &
3181 {
3182  return m_context;
3183 }
3184 
3185 
3186 } // 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