libpappsomspp
Library for mass spectrometry
pappso::BaseTracePlotWidget Class Reference

#include <basetraceplotwidget.h>

Inheritance diagram for pappso::BaseTracePlotWidget:
pappso::BasePlotWidget pappso::DriftSpecTracePlotWidget pappso::MassSpecTracePlotWidget pappso::TicXicChromTracePlotWidget

Public Member Functions

 BaseTracePlotWidget (QWidget *parent=0)
 
 BaseTracePlotWidget (QWidget *parent, const QString &x_axis_label, const QString &y_axis_label)
 
virtual ~BaseTracePlotWidget ()
 Destruct this BaseTracePlotWidget instance. More...
 
virtual void setGraphData (int graph_index, const std::vector< double > &keys, const std::vector< double > &values)
 
virtual void setGraphData (QCPGraph *graph_p, const std::vector< double > &keys, const std::vector< double > &values)
 
virtual void clearGraphData (int graph_index)
 
virtual void axisDoubleClickHandler (QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) override
 
virtual void axisRescale () override
 RANGE-related functions. More...
 
virtual void axisReframe () override
 
virtual void axisZoom () override
 
virtual void axisPan () override
 
virtual QCPGraph * addTrace (const pappso::Trace &trace, const QColor &color)
 
virtual bool findIntegrationLowerRangeForKey (int index, double key, QCPRange &range)
 Find a minimal integration range starting at an existing data point. More...
 
std::vector< double > getValuesX (int index) const
 
std::vector< double > getValuesY (int index) const
 
QCPRange getValueRangeOnKeyRange (QCPAbstractPlottable *plottable_p, bool &ok)
 
QCPRange getValueRangeOnKeyRange (int index, bool &ok)
 
double getYatX (double x, QCPGraph *graph_p)
 
double getYatX (double x, int index=0)
 
pappso::Trace toTrace (int index) const
 
pappso::Trace toTrace (const QCPGraph *graph_p) const
 
pappso::Trace toTrace (const QCPRange &x_axis_range, int index) const
 
pappso::Trace toTrace (const QCPRange &x_axis_range, const QCPGraph *graph_p) const
 
- Public Member Functions inherited from pappso::BasePlotWidget
 BasePlotWidget (QWidget *parent)
 
 BasePlotWidget (QWidget *parent, const QString &x_axis_label, const QString &y_axis_label)
 
virtual ~BasePlotWidget ()
 Destruct this BasePlotWidget instance. More...
 
virtual bool setupWidget ()
 
virtual void setPen (const QPen &pen)
 
virtual const QPen & getPen () const
 
virtual void setPlottingColor (QCPAbstractPlottable *plottable_p, const QColor &new_color)
 
virtual void setPlottingColor (int index, const QColor &new_color)
 
virtual QColor getPlottingColor (QCPAbstractPlottable *plottable_p) const
 
virtual QColor getPlottingColor (int index=0) const
 
virtual void setAxisLabelX (const QString &label)
 
virtual void setAxisLabelY (const QString &label)
 
virtual void resetAxesRangeHistory ()
 
virtual void updateAxesRangeHistory ()
 Create new axis range history items and append them to the history. More...
 
virtual void restorePreviousAxesRangeHistory ()
 Go up one history element in the axis history. More...
 
virtual void restoreAxesRangeHistory (std::size_t index)
 Get the axis histories at index index and update the plot ranges. More...
 
virtual void keyPressEvent (QKeyEvent *event)
 KEYBOARD-related EVENTS. More...
 
virtual void keyReleaseEvent (QKeyEvent *event)
 Handle specific key codes and trigger respective actions. More...
 
virtual void spaceKeyReleaseEvent (QKeyEvent *event)
 
virtual void directionKeyPressEvent (QKeyEvent *event)
 
virtual void directionKeyReleaseEvent (QKeyEvent *event)
 
virtual void mousePseudoButtonKeyPressEvent (QKeyEvent *event)
 
virtual void mousePseudoButtonKeyReleaseEvent (QKeyEvent *event)
 
virtual void mousePressHandler (QMouseEvent *event)
 KEYBOARD-related EVENTS. More...
 
virtual void mouseReleaseHandler (QMouseEvent *event)
 
virtual void mouseReleaseHandlerLeftButton ()
 
virtual void mouseReleaseHandlerRightButton ()
 
virtual void mouseWheelHandler (QWheelEvent *event)
 
virtual void mouseMoveHandler (QMouseEvent *event)
 KEYBOARD-related EVENTS. More...
 
virtual void mouseMoveHandlerNotDraggingCursor ()
 
virtual void mouseMoveHandlerDraggingCursor ()
 
virtual void mouseMoveHandlerLeftButtonDraggingCursor ()
 
virtual void mouseMoveHandlerRightButtonDraggingCursor ()
 
bool isClickOntoXAxis (const QPointF &mousePoint)
 
bool isClickOntoYAxis (const QPointF &mousePoint)
 
int dragDirection ()
 MOUSE-related EVENTS. More...
 
virtual void moveMouseCursorGraphCoordToGlobal (QPointF plot_coordinates)
 
virtual void moveMouseCursorPixelCoordToGlobal (QPointF local_coordinates)
 
virtual void horizontalMoveMouseCursorCountPixels (int pixel_count)
 
virtual QPointF horizontalGetGraphCoordNewPointCountPixels (int pixel_count)
 
virtual void verticalMoveMouseCursorCountPixels (int pixel_count)
 
virtual QPointF verticalGetGraphCoordNewPointCountPixels (int pixel_count)
 
virtual QCPRange getRangeX (bool &found_range, int index) const
 MOUSE MOVEMENTS mouse/keyboard-triggered. More...
 
virtual QCPRange getRangeY (bool &found_range, int index) const
 
QCPRange getRange (Axis axis, RangeType range_type, bool &found_range) const
 
virtual QCPRange getInnermostRangeX (bool &found_range) const
 
virtual QCPRange getOutermostRangeX (bool &found_range) const
 
virtual QCPRange getInnermostRangeY (bool &found_range) const
 
virtual QCPRange getOutermostRangeY (bool &found_range) const
 
void yMinMaxOnXAxisCurrentRange (double &min, double &max, QCPAbstractPlottable *plottable_p=nullptr)
 
void yMinMaxOnXAxisCurrentRange (double &min, double &max, int index)
 
virtual void replotWithAxesRanges (QCPRange xAxisRange, QCPRange yAxisRange, Axis axis)
 
virtual void replotWithAxisRangeX (double lower, double upper)
 
virtual void replotWithAxisRangeY (double lower, double upper)
 
virtual void hideAllPlotItems ()
 PLOTTING / REPLOTTING functions. More...
 
virtual void showTracers ()
 Show the traces (vertical and horizontal). More...
 
virtual void hideTracers ()
 Hide the traces (vertical and horizontal). More...
 
virtual void drawXDeltaFeatures ()
 
virtual void drawYDeltaFeatures ()
 
virtual void calculateDragDeltas ()
 
virtual bool isVerticalDisplacementAboveThreshold ()
 
virtual void drawSelectionRectangleAndPrepareZoom (bool as_line_segment=false, bool for_integration=false)
 
virtual void updateSelectionRectangle (bool as_line_segment=false, bool for_integration=false)
 
virtual void resetSelectionRectangle ()
 
virtual void hideSelectionRectangle (bool reset_values=false)
 
virtual bool isSelectionRectangleVisible ()
 
virtual PolygonType whatIsVisibleOfTheSelectionRectangle ()
 
virtual void setFocus ()
 PLOT ITEMS : TRACER TEXT ITEMS... More...
 
virtual void redrawPlotBackground (QWidget *focusedPlotWidget)
 Redraw the background of the focusedPlotWidget plot widget. More...
 
virtual void updateContextXandYAxisRanges ()
 
virtual const BasePlotContextgetContext () const
 

Additional Inherited Members

- Signals inherited from pappso::BasePlotWidget
void setFocusSignal ()
 
void lastCursorHoveredPointSignal (const QPointF &pointf)
 
void plotRangesChangedSignal (const BasePlotContext &context)
 
void xAxisMeasurementSignal (const BasePlotContext &context, bool with_delta)
 
void keyPressEventSignal (const BasePlotContext &context)
 
void keyReleaseEventSignal (const BasePlotContext &context)
 
void mouseReleaseEventSignal (const BasePlotContext &context)
 
void mouseWheelEventSignal (const BasePlotContext &context)
 
void plottableSelectionChangedSignal (QCPAbstractPlottable *plottable_p, bool selected)
 
void integrationRequestedSignal (const BasePlotContext &context)
 
void plottableDestructionRequestedSignal (BasePlotWidget *base_plot_widget_p, QCPAbstractPlottable *plottable_p, const BasePlotContext &context)
 
- Protected Member Functions inherited from pappso::BasePlotWidget
virtual void createAllAncillaryItems ()
 
virtual void update1DSelectionRectangle (bool for_integration=false)
 
virtual void update2DSelectionRectangleSquare (bool for_integration=false)
 
virtual void update2DSelectionRectangleSkewed (bool for_integration=false)
 
virtual QString allLayerNamesToString () const
 
virtual QString layerableLayerName (QCPLayerable *layerable_p) const
 
virtual int layerableLayerIndex (QCPLayerable *layerable_p) const
 
- Protected Attributes inherited from pappso::BasePlotWidget
QString m_name = "NOT_SET"
 Name of the plot widget. More...
 
QString m_desc = "NOT_SET"
 Description of the plot widget. More...
 
QString m_fileName
 The name of the data file from which the mass data were read. More...
 
QString m_axisLabelX
 
QString m_axisLabelY
 
BasePlotContext m_context
 
int m_leftMousePseudoButtonKey = Qt::Key_Less
 
int m_rightMousePseudoButtonKey = Qt::Key_Greater
 
QCPItemLine * mp_selectionRectangeLine1 = nullptr
 Rectangle defining the borders of zoomed-in/out data. More...
 
QCPItemLine * mp_selectionRectangeLine2 = nullptr
 
QCPItemLine * mp_selectionRectangeLine3 = nullptr
 
QCPItemLine * mp_selectionRectangeLine4 = nullptr
 
QCPItemText * mp_xDeltaTextItem = nullptr
 Text describing the x-axis delta value during a drag operation. More...
 
QCPItemText * mp_yDeltaTextItem = nullptr
 
bool m_shouldTracersBeVisible = true
 Tells if the tracers should be visible. More...
 
QCPItemLine * mp_hPosTracerItem = nullptr
 Horizontal position tracer. More...
 
QCPItemLine * mp_vPosTracerItem = nullptr
 Vertical position tracer. More...
 
QCPItemLine * mp_vStartTracerItem = nullptr
 Vertical selection start tracer (typically in green). More...
 
QCPItemLine * mp_vEndTracerItem = nullptr
 Vertical selection end tracer (typically in red). More...
 
std::size_t m_lastAxisRangeHistoryIndex = 0
 Index of the last axis range history item. More...
 
std::vector< QCPRange * > m_xAxisRangeHistory
 List of x axis ranges occurring during the panning zooming actions. More...
 
std::vector< QCPRange * > m_yAxisRangeHistory
 List of y axis ranges occurring during the panning zooming actions. More...
 
int m_mouseMoveHandlerSkipAmount = 10
 How many mouse move events must be skipped *‍/. More...
 
int m_mouseMoveHandlerSkipCount = 0
 Counter to handle the "fat data" mouse move event handling. More...
 
QColor m_unfocusedColor = QColor("lightgray")
 Color used for the background of unfocused plot. More...
 
QBrush m_unfocusedBrush = QBrush(m_unfocusedColor)
 Color used for the background of unfocused plot. More...
 
QColor m_focusedColor = QColor(Qt::transparent)
 Color used for the background of focused plot. More...
 
QBrush m_focusedBrush = QBrush(m_focusedColor)
 Color used for the background of focused plot. More...
 
QPen m_pen
 Pen used to draw the graph and textual elements in the plot widget. More...
 

Detailed Description

Definition at line 59 of file basetraceplotwidget.h.

Constructor & Destructor Documentation

◆ BaseTracePlotWidget() [1/2]

pappso::BaseTracePlotWidget::BaseTracePlotWidget ( QWidget *  parent = 0)
explicit

Definition at line 44 of file basetraceplotwidget.cpp.

45  : BasePlotWidget(parent)
46 {
47  // We can afford to call createAllAncillaryItems() in this derived class
48  // because all the items will have been created *before* the addition of plots
49  // and then the rendering order will hide them to the viewer, since the
50  // rendering order is according to the order in which the items have been
51  // created.
52  //
53  // The fact that the ancillary items are created before trace plots is not a
54  // problem because the trace plots are sparse and do not effectively hide the
55  // data.
56  //
57  // But, in the color map plot widgets, we cannot afford to create the
58  // ancillary items *before* the plot itself because then, the rendering of the
59  // plot (created after) would screen off the ancillary items (created before).
60  //
61  // So, the createAllAncillaryItems() function needs to be called in the
62  // derived classes at the most appropriate moment in the setting up of the
63  // widget.
65 }
virtual void createAllAncillaryItems()
BasePlotWidget(QWidget *parent)

References pappso::BasePlotWidget::createAllAncillaryItems().

◆ BaseTracePlotWidget() [2/2]

pappso::BaseTracePlotWidget::BaseTracePlotWidget ( QWidget *  parent,
const QString &  x_axis_label,
const QString &  y_axis_label 
)
explicit

Definition at line 68 of file basetraceplotwidget.cpp.

71  : BasePlotWidget(parent, x_axis_label, y_axis_label)
72 {
73  // We can afford to call createAllAncillaryItems() in this derived class
74  // because all the items will have been created *before* the addition of plots
75  // and then the rendering order will hide them to the viewer, since the
76  // rendering order is according to the order in which the items have been
77  // created.
78  //
79  // The fact that the ancillary items are created before trace plots is not a
80  // problem because the trace plots are sparse and do not effectively hide the
81  // data.
82  //
83  // But, in the color map plot widgets, we cannot afford to create the
84  // ancillary items *before* the plot itself because then, the rendering of the
85  // plot (created after) would screen off the ancillary items (created before).
86  //
87  // So, the createAllAncillaryItems() function needs to be called in the
88  // derived classes at the most appropriate moment in the setting up of the
89  // widget.
91 }

References pappso::BasePlotWidget::createAllAncillaryItems().

◆ ~BaseTracePlotWidget()

pappso::BaseTracePlotWidget::~BaseTracePlotWidget ( )
virtual

Destruct this BaseTracePlotWidget instance.

The destruction involves clearing the history, deleting all the axis range history items for x and y axes.

Definition at line 101 of file basetraceplotwidget.cpp.

102 {
103 }

Member Function Documentation

◆ addTrace()

QCPGraph * pappso::BaseTracePlotWidget::addTrace ( const pappso::Trace trace,
const QColor &  color 
)
virtual

Definition at line 185 of file basetraceplotwidget.cpp.

186 {
187  // qDebug();
188 
189  if(!color.isValid())
190  throw PappsoException(
191  QString("The color to be used for the plot graph is invalid."));
192 
193  // This seems to be unpleasant.
194  // setFocus();
195 
196  QCPGraph *graph_p = addGraph();
197 
198  graph_p->setLayer("plotsLayer");
199 
200  // Now depracated as of 20200924
201  // graph_p->setData(QVector<double>::fromStdVector(trace.xValues()),
202  // QVector<double>::fromStdVector(trace.yValues()));
203 
204  QVector<double> key_qvector;
205  QVector<double> value_qvector;
206 
207 #pragma GCC warning "Filippo Rusconi: Please check if the bug was fixed in Qt"
208 
209 #if 0
210  // Now replace the graph's data. Note that the data are
211  // inherently sorted (true below).
212 
213  // The begin() -- end() ranges constructor did not work as of
214  // Qt 5.14.2 this day: 20200721
215 
216  key_qvector =
217  QVector(trace.xValues().begin(),
218  .trace.xValues()end());
219  value_qvector =
220  QVector(trace.yValues().begin(),
221  trace.yValues().end());
222 #endif
223 
224  for(auto &value : trace.xValues())
225  key_qvector.push_back(value);
226 
227  for(auto &value : trace.yValues())
228  value_qvector.push_back(value);
229 
230  graph_p->setData(key_qvector, value_qvector, true);
231 
232  QPen pen = graph()->pen();
233  pen.setColor(color);
234  graph()->setPen(pen);
235 
236  // Connect the signal of selection change so that we can re-emit it for the
237  // widget that is using *this widget.
238 
239  connect(graph_p,
240  static_cast<void (QCPAbstractPlottable::*)(bool)>(
241  &QCPAbstractPlottable::selectionChanged),
242  [this, graph_p]() {
243  emit plottableSelectionChangedSignal(graph_p, graph_p->selected());
244  });
245 
246  // Rescaling the axes is actually unpleasant if there are more than one
247  // graph in the plot widget and that we are adding one. So only, rescale if
248  // the number of graphs is == 1, that is we are adding the first one.
249 
250  if(graphCount() == 1)
251  {
252  rescaleAxes();
254  }
255 
256  replot();
257 
258  return graph_p;
259 }
virtual void resetAxesRangeHistory()
void plottableSelectionChangedSignal(QCPAbstractPlottable *plottable_p, bool selected)
std::vector< pappso_double > xValues() const
Definition: trace.cpp:572
std::vector< pappso_double > yValues() const
Definition: trace.cpp:586

References pappso::BasePlotWidget::plottableSelectionChangedSignal(), pappso::BasePlotWidget::resetAxesRangeHistory(), pappso::Trace::xValues(), and pappso::Trace::yValues().

◆ axisDoubleClickHandler()

void pappso::BaseTracePlotWidget::axisDoubleClickHandler ( QCPAxis *  axis,
QCPAxis::SelectablePart  part,
QMouseEvent *  event 
)
overridevirtual

Reimplemented from pappso::BasePlotWidget.

Definition at line 505 of file basetraceplotwidget.cpp.

509 {
510 
511  m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
512 
513  if(m_context.m_keyboardModifiers & Qt::ControlModifier)
514  {
515 
516  // If the Ctrl modifiers is active, then both axes are to be reset. Also
517  // the histories are reset also.
518 
519  rescaleAxes();
521  }
522  else
523  {
524  // Only the axis passed as parameter is to be rescaled.
525  // Reset the range of that axis to the max view possible, but for the y
526  // axis check if the Shift keyboard key is pressed. If so the full scale
527  // should be calculated only on the data in the current x range.
528 
529  if(axis->orientation() == Qt::Vertical)
530  {
531  if(m_context.m_keyboardModifiers & Qt::ShiftModifier)
532  {
533 
534  // In this case, we want to make a rescale of the Y axis such
535  // that it displays full scale the data in the current X axis
536  // range only.
537 
538  bool ok = false;
539 
540  QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
541 
542  yAxis->setRange(value_range);
543  }
544  else
545  axis->rescale();
546  }
547  else
548  axis->rescale();
549 
551 
552  event->accept();
553  }
554 
555  // The double-click event does not cancel the mouse press event. That is, if
556  // left-double-clicking, at the end of the operation the button still
557  // "pressed". We need to remove manually the button from the pressed buttons
558  // context member.
559 
560  m_context.m_pressedMouseButtons ^= event->button();
561 
563 
565 
566  replot();
567 }
Qt::KeyboardModifiers m_keyboardModifiers
Qt::MouseButtons m_pressedMouseButtons
virtual void updateAxesRangeHistory()
Create new axis range history items and append them to the history.
virtual void updateContextXandYAxisRanges()
void plotRangesChangedSignal(const BasePlotContext &context)
BasePlotContext m_context
QCPRange getValueRangeOnKeyRange(QCPAbstractPlottable *plottable_p, bool &ok)

References getValueRangeOnKeyRange(), pappso::BasePlotWidget::m_context, pappso::BasePlotContext::m_keyboardModifiers, pappso::BasePlotContext::m_pressedMouseButtons, pappso::BasePlotWidget::plotRangesChangedSignal(), pappso::BasePlotWidget::resetAxesRangeHistory(), pappso::BasePlotWidget::updateAxesRangeHistory(), and pappso::BasePlotWidget::updateContextXandYAxisRanges().

◆ axisPan()

void pappso::BaseTracePlotWidget::axisPan ( )
overridevirtual

Reimplemented from pappso::BasePlotWidget.

Definition at line 773 of file basetraceplotwidget.cpp.

774 {
776  {
777  xAxis->setRange(m_context.m_xRange.lower - m_context.m_xDelta,
779 
780  // If the shift modifier key is pressed, then the user want the y axis
781  // to be full scale.
782  if(m_context.m_keyboardModifiers & Qt::ShiftModifier)
783  {
784 
785  bool ok = false;
786 
787  QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
788 
789  yAxis->setRange(value_range);
790  }
791  // else nothing to do we do not change the y axis scale.
792  }
793 
795  {
796  yAxis->setRange(m_context.m_yRange.lower - m_context.m_yDelta,
798  }
799 
801 
802  // We cannot store the new ranges in the history, because the pan operation
803  // involved a huge quantity of micro-movements elicited upon each mouse move
804  // cursor event so we would have a huge history.
805  // updateAxesRangeHistory();
806 
807  // Now that the contex has the right range values, we can emit the
808  // signal that will be used by this plot widget users, typically to
809  // abide by the x/y range lock required by the user.
810 
812 
813  replot();
814 }

References getValueRangeOnKeyRange(), pappso::BasePlotWidget::m_context, pappso::BasePlotContext::m_keyboardModifiers, pappso::BasePlotContext::m_wasClickOnXAxis, pappso::BasePlotContext::m_wasClickOnYAxis, pappso::BasePlotContext::m_xDelta, pappso::BasePlotContext::m_xRange, pappso::BasePlotContext::m_yDelta, pappso::BasePlotContext::m_yRange, pappso::BasePlotWidget::plotRangesChangedSignal(), and pappso::BasePlotWidget::updateContextXandYAxisRanges().

◆ axisReframe()

void pappso::BaseTracePlotWidget::axisReframe ( )
overridevirtual

Reimplemented from pappso::BasePlotWidget.

Definition at line 691 of file basetraceplotwidget.cpp.

692 {
693 
694  // double sorted_start_drag_point_x =
695  // std::min(m_context.m_startDragPoint.x(), m_context.m_currentDragPoint.x());
696 
697  // xAxis->setRange(sorted_start_drag_point_x,
698  // sorted_start_drag_point_x + fabs(m_context.m_xDelta));
699 
700  xAxis->setRange(
702 
703  // Note that the y axis should be rescaled from current lower value to new
704  // upper value matching the y-axis position of the cursor when the mouse
705  // button was released.
706 
707  yAxis->setRange(xAxis->range().lower,
708  std::max<double>(m_context.m_yRegionRangeStart,
710 
711  // qDebug() << "xaxis:" << xAxis->range().lower << "-" <<
712  // xAxis->range().upper
713  //<< "yaxis:" << yAxis->range().lower << "-" << yAxis->range().upper;
714 
715  // If the shift modifier key is pressed, then the user want the y axis
716  // to be full scale.
717  if(m_context.m_keyboardModifiers & Qt::ShiftModifier)
718  {
719 
720  bool ok = false;
721 
722  QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
723 
724  yAxis->setRange(value_range);
725  }
726  // else do nothing, let the y axis range as is.
727 
729 
732 
733  replot();
734 }

References getValueRangeOnKeyRange(), pappso::BasePlotWidget::m_context, pappso::BasePlotContext::m_keyboardModifiers, pappso::BasePlotContext::m_xRegionRangeEnd, pappso::BasePlotContext::m_xRegionRangeStart, pappso::BasePlotContext::m_yRegionRangeEnd, pappso::BasePlotContext::m_yRegionRangeStart, pappso::BasePlotWidget::plotRangesChangedSignal(), pappso::BasePlotWidget::updateAxesRangeHistory(), and pappso::BasePlotWidget::updateContextXandYAxisRanges().

◆ axisRescale()

void pappso::BaseTracePlotWidget::axisRescale ( )
overridevirtual

RANGE-related functions.

PLOTTING / REPLOTTING functions

Reimplemented from pappso::BasePlotWidget.

Definition at line 571 of file basetraceplotwidget.cpp.

572 {
573  double xLower = xAxis->range().lower;
574  double xUpper = xAxis->range().upper;
575 
576  // Get the current y lower/upper range.
577  double yLower = yAxis->range().lower;
578  double yUpper = yAxis->range().upper;
579 
580  // This function is called only when the user has clicked on the x/y axis or
581  // when the user has dragged the left mouse button with the Ctrl key
582  // modifier. The m_context.m_wasClickOnXAxis is then simulated in the mouse
583  // move handler. So we need to test which axis was clicked-on.
584 
586  {
587 
588  // We are changing the range of the X axis.
589 
590  // What is the x delta ?
591  double xDelta =
593 
594  // If xDelta is < 0, the we were dragging from right to left, we are
595  // compressing the view on the x axis, by adding new data to the right
596  // hand size of the graph. So we add xDelta to the upper bound of the
597  // range. Otherwise we are uncompressing the view on the x axis and
598  // remove the xDelta from the upper bound of the range. This is why we
599  // have the
600  // '-'
601  // and not '+' below;
602 
603  // qDebug() << "Setting xaxis:" << xLower << "--" << xUpper - xDelta;
604 
605  xAxis->setRange(xLower, xUpper - xDelta);
606 
607 
608  // Old version
609  // if(xDelta < 0)
610  //{
611  //// The dragging operation was from right to left, we are enlarging
612  //// the range (thus, we are unzooming the view, since the widget
613  //// always has the same size).
614 
615  // xAxis->setRange(xLower, xUpper + fabs(xDelta));
616  //}
617  // else
618  //{
619  //// The dragging operation was from left to right, we are reducing
620  //// the range (thus, we are zooming the view, since the widget
621  //// always has the same size).
622 
623  // xAxis->setRange(xLower, xUpper - fabs(xDelta));
624  //}
625 
626  // We may either leave the scale of the Y axis as is (default) or
627  // the user may want an automatic scale of the Y axis such that the
628  // data displayed in the new X axis range are full scale on the Y
629  // axis. For this, the Shift modifier key should be pressed.
630 
631  if(m_context.m_keyboardModifiers & Qt::ShiftModifier)
632  {
633 
634  // In this case, we want to make a rescale of the Y axis such that
635  // it displays full scale the data in the current X axis range only.
636 
637  bool ok = false;
638 
639  QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
640 
641  yAxis->setRange(value_range);
642  }
643  // else, do leave the Y axis range unchanged.
644  }
645  // End of
646  // if(m_context.m_wasClickOnXAxis)
647  else // that is, if(m_context.m_wasClickOnYAxis)
648  {
649  // We are changing the range of the Y axis.
650 
651  // What is the y delta ?
652  double yDelta =
654 
655  // See above for an explanation of the computation.
656 
657  yAxis->setRange(yLower, yUpper - yDelta);
658 
659  // Old version
660  // if(yDelta < 0)
661  //{
662  //// The dragging operation was from top to bottom, we are enlarging
663  //// the range (thus, we are unzooming the view, since the widget
664  //// always has the same size).
665 
666  // yAxis->setRange(yLower, yUpper + fabs(yDelta));
667  //}
668  // else
669  //{
670  //// The dragging operation was from bottom to top, we are reducing
671  //// the range (thus, we are zooming the view, since the widget
672  //// always has the same size).
673 
674  // yAxis->setRange(yLower, yUpper - fabs(yDelta));
675  //}
676  }
677  // End of
678  // else // that is, if(m_context.m_wasClickOnYAxis)
679 
680  // Update the context with the current axes ranges
681 
683 
685 
686  replot();
687 }

References getValueRangeOnKeyRange(), pappso::BasePlotWidget::m_context, pappso::BasePlotContext::m_currentDragPoint, pappso::BasePlotContext::m_keyboardModifiers, pappso::BasePlotContext::m_startDragPoint, pappso::BasePlotContext::m_wasClickOnXAxis, pappso::BasePlotWidget::plotRangesChangedSignal(), and pappso::BasePlotWidget::updateContextXandYAxisRanges().

◆ axisZoom()

void pappso::BaseTracePlotWidget::axisZoom ( )
overridevirtual

Reimplemented from pappso::BasePlotWidget.

Definition at line 738 of file basetraceplotwidget.cpp.

739 {
740 
741  // Use the m_context.m_xRegionRangeStart/End values, but we need to sort the
742  // values before using them, because now we want to really have the lower x
743  // value. Simply craft a QCPRange that will swap the values if lower is not
744  // < than upper QCustomPlot calls this normalization).
745 
746  xAxis->setRange(
748 
749  // If the shift modifier key is pressed, then the user want the y axis
750  // to be full scale.
751  if(m_context.m_keyboardModifiers & Qt::ShiftModifier)
752  {
753 
754  bool ok = false;
755 
756  QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
757 
758  yAxis->setRange(value_range);
759  }
760  else
761  yAxis->setRange(
763 
765 
768 
769  replot();
770 }

References getValueRangeOnKeyRange(), pappso::BasePlotWidget::m_context, pappso::BasePlotContext::m_keyboardModifiers, pappso::BasePlotContext::m_xRegionRangeEnd, pappso::BasePlotContext::m_xRegionRangeStart, pappso::BasePlotContext::m_yRegionRangeEnd, pappso::BasePlotContext::m_yRegionRangeStart, pappso::BasePlotWidget::plotRangesChangedSignal(), pappso::BasePlotWidget::updateAxesRangeHistory(), and pappso::BasePlotWidget::updateContextXandYAxisRanges().

◆ clearGraphData()

void pappso::BaseTracePlotWidget::clearGraphData ( int  graph_index)
virtual

Definition at line 169 of file basetraceplotwidget.cpp.

170 {
171  QCPGraph *graph_p = graph(graph_index);
172 
173  if(graph_p == nullptr)
174  qFatal("Programming error.");
175 
176  graph_p->data().clear();
177 
178  rescaleAxes();
180  replot();
181 }

References pappso::BasePlotWidget::resetAxesRangeHistory().

◆ findIntegrationLowerRangeForKey()

bool pappso::BaseTracePlotWidget::findIntegrationLowerRangeForKey ( int  index,
double  key,
QCPRange &  range 
)
virtual

Find a minimal integration range starting at an existing data point.

If the user clicks onto a plot at a location that is not a true data point, get a data range that begins at the preceding data point and that ends at the clicked location point.

Definition at line 271 of file basetraceplotwidget.cpp.

274 {
275 
276  // Given a key double value, we want to know what is the range that will
277  // frame correctly the key double value if that key value is not exactly
278  // the one of a point of the trace.
279 
280  // First of all get the keys of the graph.
281 
282  QCPGraph *theGraph = graph(index);
283 
284  if(theGraph == nullptr)
285  throw ExceptionNotPossible(
286  "basetraceplotwidget.cpp @ indIntegrationLowerRangeForKey() -- ERROR "
287  "theGraph cannot be nullptr.");
288 
289  // QCPGraphDataContainer is a typedef QCPDataContainer<QCPGraphData> and
290  // QCPDataContainer< DataType > is a Class Template. So in this context,
291  // DataType is QCPGraphData.
292  // QCPGraphData is the data point, that is the (key,value) pair.
293  QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
294  theGraph->data();
295 
296  QCPDataRange dataRange = graph_data_container_p->dataRange();
297 
298  if(!dataRange.isValid())
299  return false;
300 
301  if(!dataRange.size())
302  return false;
303 
304  if(dataRange.size() > 1)
305  {
306  double firstKey = graph_data_container_p->at(dataRange.begin())->key;
307  double lastKey = graph_data_container_p->at(dataRange.end())->key;
308 
309  // There is one check to be done: the user might erroneously set the mouse
310  // cursor beyond the last point of the graph. If that is the case, then
311  // upper key needs to be that very point. All we need to do is return the
312  // lower key, that is the pre-last key of the keys list. No need to
313  // iterate in the keys list.
314 
315  if(key > lastKey)
316  {
317  // No need to search for the key in the keys, just get the lower key
318  // immediately, that is, the key that is one slot left the last key.
319  range.lower = graph_data_container_p->at(dataRange.end() - 2)->key;
320  range.upper = graph_data_container_p->at(dataRange.end() - 1)->key;
321 
322  return true;
323  }
324 
325  // Likewise, if the cursor is set left of the first plot point, then that
326  // will be the lower range point. All we need is to provide the upper
327  // range point as the second point of the plot.
328 
329  if(key < firstKey)
330  {
331  range.lower = firstKey;
332  range.upper = graph_data_container_p->at(dataRange.begin() + 1)->key;
333 
334  return true;
335  }
336 
337  // Finally the generic case where the user point to any point *in* the
338  // graph.
339 
340  range.lower =
341  graph_data_container_p->findBegin(key, /*expandedRange*/ true)->key;
342  range.upper =
343  std::prev(graph_data_container_p->findEnd(key, /*expandedRange*/ true))
344  ->key;
345 
346  return true;
347  }
348 
349  return false;
350 }

◆ getValueRangeOnKeyRange() [1/2]

QCPRange pappso::BaseTracePlotWidget::getValueRangeOnKeyRange ( int  index,
bool &  ok 
)

Definition at line 459 of file basetraceplotwidget.cpp.

460 {
461 
462  // The X axis range is set. But we want to find for that X axis range the
463  // min and max Y values. This function is useful when the user asks that
464  // while changing the X axis range, the trace be always in full scale on the
465  // Y axis.
466 
467  QCPAbstractPlottable *plottable_p = plottable(index);
468 
469  if(plottable_p == nullptr)
470  qFatal("Programming error.");
471 
472  return getValueRangeOnKeyRange(plottable_p, ok);
473 }

References getValueRangeOnKeyRange().

◆ getValueRangeOnKeyRange() [2/2]

QCPRange pappso::BaseTracePlotWidget::getValueRangeOnKeyRange ( QCPAbstractPlottable *  plottable_p,
bool &  ok 
)

Definition at line 402 of file basetraceplotwidget.cpp.

404 {
405 
406  // The X axis range is set. But we want to find for that X axis range the
407  // min and max Y values. This function is useful when the user asks that
408  // while changing the X axis range, the trace be always in full scale on the
409  // Y axis.
410 
411  QCPRange key_range(xAxis->range().lower, xAxis->range().upper);
412 
413  if(plottable_p != nullptr)
414  {
415 
416  return plottable_p->getValueRange(ok, QCP::SignDomain::sdBoth, key_range);
417  }
418  else
419  {
420 
421  // How many graphs are currently plotted in this plot widget ?
422  int graph_count = graphCount();
423 
424  // Iterate in each graph and get the y max value. Then compare with the
425  // largest one and update if necessary. Store the pointer to the graph
426  // that has a larger y value. At the end of the iteration, it will be
427  // the winner.
428 
429  double temp_min_value = std::numeric_limits<double>::max();
430  double temp_max_value = std::numeric_limits<double>::min();
431 
432  bool found_range = false;
433 
434  for(int iter = 0; iter < graph_count; ++iter)
435  {
436  QCPGraph *plottable_p = graph(iter);
437 
438  QCPRange value_range =
439  plottable_p->getValueRange(ok, QCP::SignDomain::sdBoth, key_range);
440 
441  if(ok)
442  found_range = true;
443 
444  if(value_range.lower < temp_min_value)
445  temp_min_value = value_range.lower;
446  if(value_range.upper > temp_max_value)
447  temp_max_value = value_range.upper;
448  }
449 
450  // At this point return the range.
451 
452  ok = found_range;
453  return QCPRange(temp_min_value, temp_max_value);
454  }
455 }

Referenced by axisDoubleClickHandler(), axisPan(), axisReframe(), axisRescale(), axisZoom(), and getValueRangeOnKeyRange().

◆ getValuesX()

std::vector< double > pappso::BaseTracePlotWidget::getValuesX ( int  index) const

Definition at line 354 of file basetraceplotwidget.cpp.

355 {
356  std::vector<double> keys;
357 
358  QCPGraph *graph_p = graph(graph_index);
359 
360  if(graph_p == nullptr)
361  qFatal("Programming error.");
362 
363  QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
364  graph_p->data();
365 
366  // Iterate in the keys
367  auto beginIt = graph_data_container_p->begin();
368  auto endIt = graph_data_container_p->end();
369 
370  for(auto iter = beginIt; iter != endIt; ++iter)
371  keys.push_back(iter->key);
372 
373  return keys;
374 }

◆ getValuesY()

std::vector< double > pappso::BaseTracePlotWidget::getValuesY ( int  index) const

Definition at line 378 of file basetraceplotwidget.cpp.

379 {
380  std::vector<double> values;
381 
382  QCPGraph *graph_p = graph(graph_index);
383 
384  if(graph_p == nullptr)
385  qFatal("Programming error.");
386 
387  QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
388  graph_p->data();
389 
390  // Iterate in the values
391  auto beginIt = graph_data_container_p->begin();
392  auto endIt = graph_data_container_p->end();
393 
394  for(auto iter = beginIt; iter != endIt; ++iter)
395  values.push_back(iter->key);
396 
397  return values;
398 }

◆ getYatX() [1/2]

double pappso::BaseTracePlotWidget::getYatX ( double  x,
int  index = 0 
)

Definition at line 493 of file basetraceplotwidget.cpp.

494 {
495  QCPGraph *graph_p = graph(index);
496 
497  if(graph_p == nullptr)
498  qFatal("Programming error.");
499 
500  return getYatX(x, graph_p);
501 }
double getYatX(double x, QCPGraph *graph_p)

References getYatX(), and pappso::x.

◆ getYatX() [2/2]

double pappso::BaseTracePlotWidget::getYatX ( double  x,
QCPGraph *  graph_p 
)

Definition at line 477 of file basetraceplotwidget.cpp.

478 {
479  if(graph_p == nullptr)
480  qFatal("Programming error.");
481 
482  QCPItemTracer tracer(this);
483  tracer.setGraph(graph_p);
484  tracer.setInterpolating(true);
485  tracer.setGraphKey(x);
486  tracer.updatePosition();
487 
488  return tracer.position->value();
489 }

References pappso::x.

Referenced by getYatX().

◆ setGraphData() [1/2]

void pappso::BaseTracePlotWidget::setGraphData ( int  graph_index,
const std::vector< double > &  keys,
const std::vector< double > &  values 
)
virtual

Definition at line 107 of file basetraceplotwidget.cpp.

110 {
111  QCPGraph *graph_p = graph(graph_index);
112 
113  if(graph_p == nullptr)
114  qFatal("Programming error.");
115 
116  return setGraphData(graph_p, keys, values);
117 }
virtual void setGraphData(int graph_index, const std::vector< double > &keys, const std::vector< double > &values)

◆ setGraphData() [2/2]

void pappso::BaseTracePlotWidget::setGraphData ( QCPGraph *  graph_p,
const std::vector< double > &  keys,
const std::vector< double > &  values 
)
virtual

Definition at line 121 of file basetraceplotwidget.cpp.

124 {
125  if(graph_p == nullptr)
126  qFatal("Pointer cannot be nullptr.");
127 
128  // Version that is now deprecated (20200924)
129  // graph_p->setData(QVector<double>::fromStdVector(keys),
130  // QVector<double>::fromStdVector(values));
131 
132  QVector<double> key_qvector;
133  QVector<double> value_qvector;
134 
135 #pragma GCC warning "Filippo Rusconi: Please check if the bug was fixed in Qt"
136 
137 #if 0
138  // Now replace the graph's data. Note that the data are
139  // inherently sorted (true below).
140 
141  // The begin() -- end() ranges constructor did not work as of
142  // Qt 5.14.2 this day: 20200721
143 
144  key_qvector =
145  QVector(keys.begin(),
146  keys.end());
147  value_qvector =
148  QVector(values.begin(),
149  values.end());
150 #endif
151 
152  for(auto &value : keys)
153  key_qvector.push_back(value);
154 
155  for(auto &value : values)
156  value_qvector.push_back(value);
157 
158  graph_p->setData(key_qvector, value_qvector, true);
159 
160  graph_p->setPen(m_pen);
161 
162  rescaleAxes();
164  replot();
165 }
QPen m_pen
Pen used to draw the graph and textual elements in the plot widget.

References pappso::BasePlotWidget::m_pen, and pappso::BasePlotWidget::resetAxesRangeHistory().

◆ toTrace() [1/4]

pappso::Trace pappso::BaseTracePlotWidget::toTrace ( const QCPGraph *  graph_p) const

Definition at line 827 of file basetraceplotwidget.cpp.

828 {
829  if(graph_p == nullptr)
830  qFatal("Programming error. Pointer cannot be nullptr.");
831 
832  pappso::Trace trace;
833 
834  QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
835  graph_p->data();
836 
837  // Iterate in the keys
838  auto beginIt = graph_data_container_p->begin();
839  auto endIt = graph_data_container_p->end();
840 
841  for(auto iter = beginIt; iter != endIt; ++iter)
842  trace.push_back(pappso::DataPoint(iter->key, iter->value));
843 
844  return trace;
845 }
A simple container of DataPoint instances.
Definition: trace.h:148

◆ toTrace() [2/4]

pappso::Trace pappso::BaseTracePlotWidget::toTrace ( const QCPRange &  x_axis_range,
const QCPGraph *  graph_p 
) const

Definition at line 861 of file basetraceplotwidget.cpp.

863 {
864 
865  // Make a Trace with the data in the range.
866  Trace data_trace;
867 
868  QSharedPointer<QCPGraphDataContainer> graph_data_container_sp;
869 
870  graph_data_container_sp = graph_p->data();
871 
872  // Grab the iterator to the start to the x axis range
873  auto beginIt = graph_data_container_sp->findBegin(x_axis_range.lower,
874  /*expandedRange*/ true);
875  // Grab the iterator to the end of the axis range
876  auto endIt = graph_data_container_sp->findEnd(x_axis_range.upper,
877  /*expandedRange*/ true);
878 
879  for(auto iter = beginIt; iter != endIt; ++iter)
880  data_trace.push_back(DataPoint(iter->key, iter->value));
881 
882  return data_trace;
883 }

◆ toTrace() [3/4]

pappso::Trace pappso::BaseTracePlotWidget::toTrace ( const QCPRange &  x_axis_range,
int  index 
) const

Definition at line 849 of file basetraceplotwidget.cpp.

850 {
851  QCPGraph *graph_p = graph(index);
852 
853  if(graph_p == nullptr)
854  qFatal("Programming error.");
855 
856  return toTrace(x_axis_range, graph_p);
857 }
pappso::Trace toTrace(int index) const

References toTrace().

◆ toTrace() [4/4]

pappso::Trace pappso::BaseTracePlotWidget::toTrace ( int  index) const

Definition at line 818 of file basetraceplotwidget.cpp.

819 {
820  QCPGraph *graph_p = graph(index);
821 
822  return toTrace(graph_p);
823 }

Referenced by toTrace().


The documentation for this class was generated from the following files: