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 mouseMoveHandler (QMouseEvent *event)
 
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 (PlotAxis 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, PlotAxis whichAxis)
 
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 drawRectangleAndPrepareZoom ()
 
virtual void prepareXDeltaLineAndMeasure ()
 
virtual void drawXDeltaLineAndMeasure ()
 
virtual void drawXDeltaLineForIntegration ()
 
virtual void calculateDragDeltas ()
 
virtual void calculateDragDeltasAndUnSortedRegionCorners ()
 
virtual bool isProperSelectionRectangle ()
 
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 updateContextRanges ()
 
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 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 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
 
QCPItemRect * mp_zoomRectItem = nullptr
 Rectangle defining the borders of zoomed-in/out data. More...
 
QCPItemLine * mp_selectLineItem = nullptr
 Line that is printed when the user selects a range. More...
 
QCPItemText * mp_xDeltaTextItem = nullptr
 Text describing the x-axis delta value during a drag operation. More...
 
bool m_shouldTracersBeVisible = true
 Tells if the tracers should be visible. More...
 
QCPItemLine * mp_hPosTracerItem
 Horizontal position tracer. More...
 
QCPItemLine * mp_vPosTracerItem
 Vertical position tracer. More...
 
QCPItemLine * mp_vStartTracerItem
 Vertical selection start tracer (typically in green). More...
 
QCPItemLine * mp_vEndTracerItem
 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 }

◆ BaseTracePlotWidget() [2/2]

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

Definition at line 50 of file basetraceplotwidget.cpp.

53  : BasePlotWidget(parent, x_axis_label, y_axis_label)
54 {
55 }

◆ ~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 65 of file basetraceplotwidget.cpp.

66 {
67 }

Member Function Documentation

◆ addTrace()

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

Definition at line 149 of file basetraceplotwidget.cpp.

150 {
151  // qDebug();
152 
153  if(!color.isValid())
154  throw PappsoException(
155  QString("The color to be used for the plot graph is invalid."));
156 
157  // This seems to be unpleasant.
158  // setFocus();
159 
160  QCPGraph *graph_p = addGraph();
161 
162  // Now depracated as of 20200924
163  //graph_p->setData(QVector<double>::fromStdVector(trace.xValues()),
164  //QVector<double>::fromStdVector(trace.yValues()));
165 
166  QVector<double> key_qvector;
167  QVector<double> value_qvector;
168 
169 #pragma GCC warning "Filippo Rusconi: Please check if the bug was fixed in Qt"
170 
171 #if 0
172  // Now replace the graph's data. Note that the data are
173  // inherently sorted (true below).
174 
175  // The begin() -- end() ranges constructor did not work as of
176  // Qt 5.14.2 this day: 20200721
177 
178  key_qvector =
179  QVector(trace.xValues().begin(),
180  .trace.xValues()end());
181  value_qvector =
182  QVector(trace.yValues().begin(),
183  trace.yValues().end());
184 #endif
185 
186  for(auto &value : trace.xValues())
187  key_qvector.push_back(value);
188 
189  for(auto &value : trace.yValues())
190  value_qvector.push_back(value);
191 
192  graph_p->setData(key_qvector, value_qvector, true);
193 
194  QPen pen = graph()->pen();
195  pen.setColor(color);
196  graph()->setPen(pen);
197 
198  // Connect the signal of selection change so that we can re-emit it for the
199  // widget that is using *this widget.
200 
201  connect(graph_p,
202  static_cast<void (QCPAbstractPlottable::*)(bool)>(
203  &QCPAbstractPlottable::selectionChanged),
204  [this, graph_p]() {
205  emit plottableSelectionChangedSignal(graph_p, graph_p->selected());
206  });
207 
208  // Rescaling the axes is actually unpleasant if there are more than one
209  // graph in the plot widget and that we are adding one. So only, rescale if
210  // the number of graphs is == 1, that is we are adding the first one.
211 
212  if(graphCount() == 1)
213  {
214  rescaleAxes();
216  }
217 
218  replot();
219 
220  return graph_p;
221 }

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 467 of file basetraceplotwidget.cpp.

471 {
472 
473  m_context.keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
474 
475  if(m_context.keyboardModifiers & Qt::ControlModifier)
476  {
477 
478  // If the Ctrl modifiers is active, then both axes are to be reset. Also
479  // the histories are reset also.
480 
481  rescaleAxes();
483  }
484  else
485  {
486  // Only the axis passed as parameter is to be rescaled.
487  // Reset the range of that axis to the max view possible, but for the y
488  // axis check if the Shift keyboard key is pressed. If so the full scale
489  // should be calculated only on the data in the current x range.
490 
491  if(axis->orientation() == Qt::Vertical)
492  {
493  if(m_context.keyboardModifiers & Qt::ShiftModifier)
494  {
495 
496  // In this case, we want to make a rescale of the Y axis such
497  // that it displays full scale the data in the current X axis
498  // range only.
499 
500  bool ok = false;
501 
502  QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
503 
504  yAxis->setRange(value_range);
505  }
506  else
507  axis->rescale();
508  }
509  else
510  axis->rescale();
511 
513 
514  event->accept();
515  }
516 
517  // The double-click event does not cancel the mouse press event. That is, if
518  // left-double-clicking, at the end of the operation the button still
519  // "pressed". We need to remove manually the button from the pressed buttons
520  // context member.
521 
522  m_context.pressedMouseButtons ^= event->button();
523 
525 
527 
528  replot();
529 }

References getValueRangeOnKeyRange(), pappso::BasePlotContext::keyboardModifiers, pappso::BasePlotWidget::m_context, pappso::BasePlotWidget::plotRangesChangedSignal(), pappso::BasePlotContext::pressedMouseButtons, pappso::BasePlotWidget::resetAxesRangeHistory(), pappso::BasePlotWidget::updateAxesRangeHistory(), and pappso::BasePlotWidget::updateContextRanges().

◆ axisPan()

void pappso::BaseTracePlotWidget::axisPan ( )
overridevirtual

Reimplemented from pappso::BasePlotWidget.

Definition at line 735 of file basetraceplotwidget.cpp.

736 {
738  {
739  xAxis->setRange(m_context.xRange.lower - m_context.xDelta,
740  m_context.xRange.upper - m_context.xDelta);
741 
742  // If the shift modifier key is pressed, then the user want the y axis
743  // to be full scale.
744  if(m_context.keyboardModifiers & Qt::ShiftModifier)
745  {
746 
747  bool ok = false;
748 
749  QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
750 
751  yAxis->setRange(value_range);
752  }
753  // else nothing to do we do not change the y axis scale.
754  }
755 
757  {
758  yAxis->setRange(m_context.yRange.lower - m_context.yDelta,
759  m_context.yRange.upper - m_context.yDelta);
760  }
761 
763 
764  // We cannot store the new ranges in the history, because the pan operation
765  // involved a huge quantity of micro-movements elicited upon each mouse move
766  // cursor event so we would have a huge history.
767  // updateAxesRangeHistory();
768 
769  // Now that the contex has the right range values, we can emit the
770  // signal that will be used by this plot widget users, typically to
771  // abide by the x/y range lock required by the user.
772 
774 
775  replot();
776 }

References getValueRangeOnKeyRange(), pappso::BasePlotContext::keyboardModifiers, pappso::BasePlotWidget::m_context, pappso::BasePlotWidget::plotRangesChangedSignal(), pappso::BasePlotWidget::updateContextRanges(), pappso::BasePlotContext::wasClickOnXAxis, pappso::BasePlotContext::wasClickOnYAxis, pappso::BasePlotContext::xDelta, pappso::BasePlotContext::xRange, pappso::BasePlotContext::yDelta, and pappso::BasePlotContext::yRange.

◆ axisReframe()

void pappso::BaseTracePlotWidget::axisReframe ( )
overridevirtual

Reimplemented from pappso::BasePlotWidget.

Definition at line 653 of file basetraceplotwidget.cpp.

654 {
655 
656  // double sorted_start_drag_point_x =
657  // std::min(m_context.startDragPoint.x(), m_context.currentDragPoint.x());
658 
659  // xAxis->setRange(sorted_start_drag_point_x,
660  // sorted_start_drag_point_x + fabs(m_context.xDelta));
661 
662  xAxis->setRange(
664 
665  // Note that the y axis should be rescaled from current lower value to new
666  // upper value matching the y-axis position of the cursor when the mouse
667  // button was released.
668 
669  yAxis->setRange(
670  xAxis->range().lower,
672 
673  // qDebug() << "xaxis:" << xAxis->range().lower << "-" <<
674  // xAxis->range().upper
675  //<< "yaxis:" << yAxis->range().lower << "-" << yAxis->range().upper;
676 
677  // If the shift modifier key is pressed, then the user want the y axis
678  // to be full scale.
679  if(m_context.keyboardModifiers & Qt::ShiftModifier)
680  {
681 
682  bool ok = false;
683 
684  QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
685 
686  yAxis->setRange(value_range);
687  }
688  // else do nothing, let the y axis range as is.
689 
691 
694 
695  replot();
696 }

References getValueRangeOnKeyRange(), pappso::BasePlotContext::keyboardModifiers, pappso::BasePlotWidget::m_context, pappso::BasePlotWidget::plotRangesChangedSignal(), pappso::BasePlotWidget::updateAxesRangeHistory(), pappso::BasePlotWidget::updateContextRanges(), pappso::BasePlotContext::xRegionRangeEnd, pappso::BasePlotContext::xRegionRangeStart, pappso::BasePlotContext::yRegionRangeEnd, and pappso::BasePlotContext::yRegionRangeStart.

◆ axisRescale()

void pappso::BaseTracePlotWidget::axisRescale ( )
overridevirtual

RANGE-related functions.

PLOTTING / REPLOTTING functions

Reimplemented from pappso::BasePlotWidget.

Definition at line 533 of file basetraceplotwidget.cpp.

534 {
535  double xLower = xAxis->range().lower;
536  double xUpper = xAxis->range().upper;
537 
538  // Get the current y lower/upper range.
539  double yLower = yAxis->range().lower;
540  double yUpper = yAxis->range().upper;
541 
542  // This function is called only when the user has clicked on the x/y axis or
543  // when the user has dragged the left mouse button with the Ctrl key
544  // modifier. The m_context.wasClickOnXAxis is then simulated in the mouse
545  // move handler. So we need to test which axis was clicked-on.
546 
548  {
549 
550  // We are changing the range of the X axis.
551 
552  // What is the x delta ?
553  double xDelta =
555 
556  // If xDelta is < 0, the we were dragging from right to left, we are
557  // compressing the view on the x axis, by adding new data to the right
558  // hand size of the graph. So we add xDelta to the upper bound of the
559  // range. Otherwise we are uncompressing the view on the x axis and
560  // remove the xDelta from the upper bound of the range. This is why we
561  // have the
562  // '-'
563  // and not '+' below;
564 
565  // qDebug() << "Setting xaxis:" << xLower << "--" << xUpper - xDelta;
566 
567  xAxis->setRange(xLower, xUpper - xDelta);
568 
569 
570  // Old version
571  // if(xDelta < 0)
572  //{
573  //// The dragging operation was from right to left, we are enlarging
574  //// the range (thus, we are unzooming the view, since the widget
575  //// always has the same size).
576 
577  // xAxis->setRange(xLower, xUpper + fabs(xDelta));
578  //}
579  // else
580  //{
581  //// The dragging operation was from left to right, we are reducing
582  //// the range (thus, we are zooming the view, since the widget
583  //// always has the same size).
584 
585  // xAxis->setRange(xLower, xUpper - fabs(xDelta));
586  //}
587 
588  // We may either leave the scale of the Y axis as is (default) or
589  // the user may want an automatic scale of the Y axis such that the
590  // data displayed in the new X axis range are full scale on the Y
591  // axis. For this, the Shift modifier key should be pressed.
592 
593  if(m_context.keyboardModifiers & Qt::ShiftModifier)
594  {
595 
596  // In this case, we want to make a rescale of the Y axis such that
597  // it displays full scale the data in the current X axis range only.
598 
599  bool ok = false;
600 
601  QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
602 
603  yAxis->setRange(value_range);
604  }
605  // else, do leave the Y axis range unchanged.
606  }
607  // End of
608  // if(m_context.wasClickOnXAxis)
609  else // that is, if(m_context.wasClickOnYAxis)
610  {
611  // We are changing the range of the Y axis.
612 
613  // What is the y delta ?
614  double yDelta =
616 
617  // See above for an explanation of the computation.
618 
619  yAxis->setRange(yLower, yUpper - yDelta);
620 
621  // Old version
622  // if(yDelta < 0)
623  //{
624  //// The dragging operation was from top to bottom, we are enlarging
625  //// the range (thus, we are unzooming the view, since the widget
626  //// always has the same size).
627 
628  // yAxis->setRange(yLower, yUpper + fabs(yDelta));
629  //}
630  // else
631  //{
632  //// The dragging operation was from bottom to top, we are reducing
633  //// the range (thus, we are zooming the view, since the widget
634  //// always has the same size).
635 
636  // yAxis->setRange(yLower, yUpper - fabs(yDelta));
637  //}
638  }
639  // End of
640  // else // that is, if(m_context.wasClickOnYAxis)
641 
642  // Update the context with the current axes ranges
643 
645 
647 
648  replot();
649 }

References pappso::BasePlotContext::currentDragPoint, getValueRangeOnKeyRange(), pappso::BasePlotContext::keyboardModifiers, pappso::BasePlotWidget::m_context, pappso::BasePlotWidget::plotRangesChangedSignal(), pappso::BasePlotContext::startDragPoint, pappso::BasePlotWidget::updateContextRanges(), and pappso::BasePlotContext::wasClickOnXAxis.

◆ axisZoom()

void pappso::BaseTracePlotWidget::axisZoom ( )
overridevirtual

Reimplemented from pappso::BasePlotWidget.

Definition at line 700 of file basetraceplotwidget.cpp.

701 {
702 
703  // Use the m_context.xRegionRangeStart/End values, but we need to sort the
704  // values before using them, because now we want to really have the lower x
705  // value. Simply craft a QCPRange that will swap the values if lower is not
706  // < than upper QCustomPlot calls this normalization).
707 
708  xAxis->setRange(
710 
711  // If the shift modifier key is pressed, then the user want the y axis
712  // to be full scale.
713  if(m_context.keyboardModifiers & Qt::ShiftModifier)
714  {
715 
716  bool ok = false;
717 
718  QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
719 
720  yAxis->setRange(value_range);
721  }
722  else
723  yAxis->setRange(
725 
727 
730 
731  replot();
732 }

References getValueRangeOnKeyRange(), pappso::BasePlotContext::keyboardModifiers, pappso::BasePlotWidget::m_context, pappso::BasePlotWidget::plotRangesChangedSignal(), pappso::BasePlotWidget::updateAxesRangeHistory(), pappso::BasePlotWidget::updateContextRanges(), pappso::BasePlotContext::xRegionRangeEnd, pappso::BasePlotContext::xRegionRangeStart, pappso::BasePlotContext::yRegionRangeEnd, and pappso::BasePlotContext::yRegionRangeStart.

◆ clearGraphData()

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

Definition at line 133 of file basetraceplotwidget.cpp.

134 {
135  QCPGraph *graph_p = graph(graph_index);
136 
137  if(graph_p == nullptr)
138  qFatal("Programming error.");
139 
140  graph_p->data().clear();
141 
142  rescaleAxes();
144  replot();
145 }

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 233 of file basetraceplotwidget.cpp.

236 {
237 
238  // Given a key double value, we want to know what is the range that will
239  // frame correctly the key double value if that key value is not exactly
240  // the one of a point of the trace.
241 
242  // First of all get the keys of the graph.
243 
244  QCPGraph *theGraph = graph(index);
245 
246  if(theGraph == nullptr)
247  throw ExceptionNotPossible(
248  "basetraceplotwidget.cpp @ indIntegrationLowerRangeForKey() -- ERROR "
249  "theGraph cannot be nullptr.");
250 
251  // QCPGraphDataContainer is a typedef QCPDataContainer<QCPGraphData> and
252  // QCPDataContainer< DataType > is a Class Template. So in this context,
253  // DataType is QCPGraphData.
254  // QCPGraphData is the data point, that is the (key,value) pair.
255  QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
256  theGraph->data();
257 
258  QCPDataRange dataRange = graph_data_container_p->dataRange();
259 
260  if(!dataRange.isValid())
261  return false;
262 
263  if(!dataRange.size())
264  return false;
265 
266  if(dataRange.size() > 1)
267  {
268  double firstKey = graph_data_container_p->at(dataRange.begin())->key;
269  double lastKey = graph_data_container_p->at(dataRange.end())->key;
270 
271  // There is one check to be done: the user might erroneously set the mouse
272  // cursor beyond the last point of the graph. If that is the case, then
273  // upper key needs to be that very point. All we need to do is return the
274  // lower key, that is the pre-last key of the keys list. No need to
275  // iterate in the keys list.
276 
277  if(key > lastKey)
278  {
279  // No need to search for the key in the keys, just get the lower key
280  // immediately, that is, the key that is one slot left the last key.
281  range.lower = graph_data_container_p->at(dataRange.end() - 2)->key;
282  range.upper = graph_data_container_p->at(dataRange.end() - 1)->key;
283 
284  return true;
285  }
286 
287  // Likewise, if the cursor is set left of the first plot point, then that
288  // will be the lower range point. All we need is to provide the upper
289  // range point as the second point of the plot.
290 
291  if(key < firstKey)
292  {
293  range.lower = firstKey;
294  range.upper = graph_data_container_p->at(dataRange.begin() + 1)->key;
295 
296  return true;
297  }
298 
299  // Finally the generic case where the user point to any point *in* the
300  // graph.
301 
302  range.lower =
303  graph_data_container_p->findBegin(key, /*expandedRange*/ true)->key;
304  range.upper =
305  std::prev(graph_data_container_p->findEnd(key, /*expandedRange*/ true))
306  ->key;
307 
308  return true;
309  }
310 
311  return false;
312 }

◆ getValueRangeOnKeyRange() [1/2]

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

Definition at line 421 of file basetraceplotwidget.cpp.

422 {
423 
424  // The X axis range is set. But we want to find for that X axis range the
425  // min and max Y values. This function is useful when the user asks that
426  // while changing the X axis range, the trace be always in full scale on the
427  // Y axis.
428 
429  QCPAbstractPlottable *plottable_p = plottable(index);
430 
431  if(plottable_p == nullptr)
432  qFatal("Programming error.");
433 
434  return getValueRangeOnKeyRange(plottable_p, ok);
435 }

References getValueRangeOnKeyRange().

◆ getValueRangeOnKeyRange() [2/2]

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

Definition at line 364 of file basetraceplotwidget.cpp.

366 {
367 
368  // The X axis range is set. But we want to find for that X axis range the
369  // min and max Y values. This function is useful when the user asks that
370  // while changing the X axis range, the trace be always in full scale on the
371  // Y axis.
372 
373  QCPRange key_range(xAxis->range().lower, xAxis->range().upper);
374 
375  if(plottable_p != nullptr)
376  {
377 
378  return plottable_p->getValueRange(ok, QCP::SignDomain::sdBoth, key_range);
379  }
380  else
381  {
382 
383  // How many graphs are currently plotted in this plot widget ?
384  int graph_count = graphCount();
385 
386  // Iterate in each graph and get the y max value. Then compare with the
387  // largest one and update if necessary. Store the pointer to the graph
388  // that has a larger y value. At the end of the iteration, it will be
389  // the winner.
390 
391  double temp_min_value = std::numeric_limits<double>::max();
392  double temp_max_value = std::numeric_limits<double>::min();
393 
394  bool found_range = false;
395 
396  for(int iter = 0; iter < graph_count; ++iter)
397  {
398  QCPGraph *plottable_p = graph(iter);
399 
400  QCPRange value_range =
401  plottable_p->getValueRange(ok, QCP::SignDomain::sdBoth, key_range);
402 
403  if(ok)
404  found_range = true;
405 
406  if(value_range.lower < temp_min_value)
407  temp_min_value = value_range.lower;
408  if(value_range.upper > temp_max_value)
409  temp_max_value = value_range.upper;
410  }
411 
412  // At this point return the range.
413 
414  ok = found_range;
415  return QCPRange(temp_min_value, temp_max_value);
416  }
417 }

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

◆ getValuesX()

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

Definition at line 316 of file basetraceplotwidget.cpp.

317 {
318  std::vector<double> keys;
319 
320  QCPGraph *graph_p = graph(graph_index);
321 
322  if(graph_p == nullptr)
323  qFatal("Programming error.");
324 
325  QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
326  graph_p->data();
327 
328  // Iterate in the keys
329  auto beginIt = graph_data_container_p->begin();
330  auto endIt = graph_data_container_p->end();
331 
332  for(auto iter = beginIt; iter != endIt; ++iter)
333  keys.push_back(iter->key);
334 
335  return keys;
336 }

◆ getValuesY()

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

Definition at line 340 of file basetraceplotwidget.cpp.

341 {
342  std::vector<double> values;
343 
344  QCPGraph *graph_p = graph(graph_index);
345 
346  if(graph_p == nullptr)
347  qFatal("Programming error.");
348 
349  QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
350  graph_p->data();
351 
352  // Iterate in the values
353  auto beginIt = graph_data_container_p->begin();
354  auto endIt = graph_data_container_p->end();
355 
356  for(auto iter = beginIt; iter != endIt; ++iter)
357  values.push_back(iter->key);
358 
359  return values;
360 }

◆ getYatX() [1/2]

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

Definition at line 455 of file basetraceplotwidget.cpp.

456 {
457  QCPGraph *graph_p = graph(index);
458 
459  if(graph_p == nullptr)
460  qFatal("Programming error.");
461 
462  return getYatX(x, graph_p);
463 }

References getYatX(), and pappso::y.

◆ getYatX() [2/2]

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

Definition at line 439 of file basetraceplotwidget.cpp.

440 {
441  if(graph_p == nullptr)
442  qFatal("Programming error.");
443 
444  QCPItemTracer tracer(this);
445  tracer.setGraph(graph_p);
446  tracer.setInterpolating(true);
447  tracer.setGraphKey(x);
448  tracer.updatePosition();
449 
450  return tracer.position->value();
451 }

References pappso::y.

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 71 of file basetraceplotwidget.cpp.

74 {
75  QCPGraph *graph_p = graph(graph_index);
76 
77  if(graph_p == nullptr)
78  qFatal("Programming error.");
79 
80  return setGraphData(graph_p, keys, values);
81 }

◆ setGraphData() [2/2]

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

Definition at line 85 of file basetraceplotwidget.cpp.

88 {
89  if(graph_p == nullptr)
90  qFatal("Pointer cannot be nullptr.");
91 
92  // Version that is now deprecated (20200924)
93  // graph_p->setData(QVector<double>::fromStdVector(keys),
94  // QVector<double>::fromStdVector(values));
95 
96  QVector<double> key_qvector;
97  QVector<double> value_qvector;
98 
99 #pragma GCC warning "Filippo Rusconi: Please check if the bug was fixed in Qt"
100 
101 #if 0
102  // Now replace the graph's data. Note that the data are
103  // inherently sorted (true below).
104 
105  // The begin() -- end() ranges constructor did not work as of
106  // Qt 5.14.2 this day: 20200721
107 
108  key_qvector =
109  QVector(keys.begin(),
110  keys.end());
111  value_qvector =
112  QVector(values.begin(),
113  values.end());
114 #endif
115 
116  for(auto &value : keys)
117  key_qvector.push_back(value);
118 
119  for(auto &value : values)
120  value_qvector.push_back(value);
121 
122  graph_p->setData(key_qvector, value_qvector, true);
123 
124  graph_p->setPen(m_pen);
125 
126  rescaleAxes();
128  replot();
129 }

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 789 of file basetraceplotwidget.cpp.

790 {
791  if(graph_p == nullptr)
792  qFatal("Programming error. Pointer cannot be nullptr.");
793 
794  pappso::Trace trace;
795 
796  QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
797  graph_p->data();
798 
799  // Iterate in the keys
800  auto beginIt = graph_data_container_p->begin();
801  auto endIt = graph_data_container_p->end();
802 
803  for(auto iter = beginIt; iter != endIt; ++iter)
804  trace.push_back(pappso::DataPoint(iter->key, iter->value));
805 
806  return trace;
807 }

◆ toTrace() [2/4]

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

Definition at line 823 of file basetraceplotwidget.cpp.

825 {
826 
827  // Make a Trace with the data in the range.
828  Trace data_trace;
829 
830  QSharedPointer<QCPGraphDataContainer> graph_data_container_sp;
831 
832  graph_data_container_sp = graph_p->data();
833 
834  // Grab the iterator to the start to the x axis range
835  auto beginIt = graph_data_container_sp->findBegin(x_axis_range.lower,
836  /*expandedRange*/ true);
837  // Grab the iterator to the end of the axis range
838  auto endIt = graph_data_container_sp->findEnd(x_axis_range.upper,
839  /*expandedRange*/ true);
840 
841  for(auto iter = beginIt; iter != endIt; ++iter)
842  data_trace.push_back(DataPoint(iter->key, iter->value));
843 
844  return data_trace;
845 }

◆ toTrace() [3/4]

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

Definition at line 811 of file basetraceplotwidget.cpp.

812 {
813  QCPGraph *graph_p = graph(index);
814 
815  if(graph_p == nullptr)
816  qFatal("Programming error.");
817 
818  return toTrace(x_axis_range, graph_p);
819 }

References toTrace().

◆ toTrace() [4/4]

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

Definition at line 780 of file basetraceplotwidget.cpp.

781 {
782  QCPGraph *graph_p = graph(index);
783 
784  return toTrace(graph_p);
785 }

Referenced by toTrace().


The documentation for this class was generated from the following files:
pappso::BasePlotContext::xRegionRangeStart
double xRegionRangeStart
Definition: baseplotwidget.h:104
pappso::BasePlotWidget::updateAxesRangeHistory
virtual void updateAxesRangeHistory()
Create new axis range history items and append them to the history.
Definition: baseplotwidget.cpp:393
pappso::BasePlotContext::pressedMouseButtons
Qt::MouseButtons pressedMouseButtons
Definition: baseplotwidget.h:121
pappso::BasePlotWidget::m_pen
QPen m_pen
Pen used to draw the graph and textual elements in the plot widget.
Definition: baseplotwidget.h:392
pappso::BasePlotContext::currentDragPoint
QPointF currentDragPoint
Definition: baseplotwidget.h:82
pappso::BasePlotWidget::BasePlotWidget
BasePlotWidget(QWidget *parent)
Definition: baseplotwidget.cpp:114
pappso::BaseTracePlotWidget::getValueRangeOnKeyRange
QCPRange getValueRangeOnKeyRange(QCPAbstractPlottable *plottable_p, bool &ok)
Definition: basetraceplotwidget.cpp:364
pappso::BasePlotContext::xRange
QCPRange xRange
Definition: baseplotwidget.h:86
pappso::BasePlotContext::wasClickOnXAxis
bool wasClickOnXAxis
Definition: baseplotwidget.h:93
pappso::DataPoint
Definition: datapoint.h:21
pappso::BasePlotWidget::updateContextRanges
virtual void updateContextRanges()
Definition: baseplotwidget.cpp:2225
pappso::BasePlotWidget::plottableSelectionChangedSignal
void plottableSelectionChangedSignal(QCPAbstractPlottable *plottable_p, bool selected)
pappso::BasePlotContext::keyboardModifiers
Qt::KeyboardModifiers keyboardModifiers
Definition: baseplotwidget.h:116
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:132
pappso::BaseTracePlotWidget::toTrace
pappso::Trace toTrace(int index) const
Definition: basetraceplotwidget.cpp:780
pappso::BasePlotContext::yRegionRangeStart
double yRegionRangeStart
Definition: baseplotwidget.h:107
pappso::BasePlotContext::yRange
QCPRange yRange
Definition: baseplotwidget.h:87
pappso::BasePlotWidget::resetAxesRangeHistory
virtual void resetAxesRangeHistory()
Definition: baseplotwidget.cpp:366
pappso::BasePlotContext::wasClickOnYAxis
bool wasClickOnYAxis
Definition: baseplotwidget.h:94
pappso::Trace::xValues
std::vector< pappso_double > xValues() const
Definition: trace.cpp:544
pappso::BasePlotContext::xRegionRangeEnd
double xRegionRangeEnd
Definition: baseplotwidget.h:105
pappso::BaseTracePlotWidget::setGraphData
virtual void setGraphData(int graph_index, const std::vector< double > &keys, const std::vector< double > &values)
Definition: basetraceplotwidget.cpp:71
pappso::BasePlotContext::yDelta
double yDelta
Definition: baseplotwidget.h:111
pappso::BasePlotContext::yRegionRangeEnd
double yRegionRangeEnd
Definition: baseplotwidget.h:108
pappso::Trace::yValues
std::vector< pappso_double > yValues() const
Definition: trace.cpp:558
pappso::BasePlotContext::xDelta
double xDelta
Definition: baseplotwidget.h:110
pappso::BaseTracePlotWidget::getYatX
double getYatX(double x, QCPGraph *graph_p)
Definition: basetraceplotwidget.cpp:439
pappso::BasePlotContext::startDragPoint
QPointF startDragPoint
Definition: baseplotwidget.h:81
pappso::BasePlotWidget::m_context
BasePlotContext m_context
Definition: baseplotwidget.h:312
pappso::BasePlotWidget::plotRangesChangedSignal
void plotRangesChangedSignal(const BasePlotContext &context)