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

121 {
122  // qDebug();
123 
124  if(!color.isValid())
125  throw PappsoException(
126  QString("The color to be used for the plot graph is invalid."));
127 
128  // This seems to be unpleasant.
129  // setFocus();
130 
131  QCPGraph *graph_p = addGraph();
132 
133  graph_p->setData(QVector<double>::fromStdVector(trace.xToVector()),
134  QVector<double>::fromStdVector(trace.yToVector()));
135 
136  QPen pen = graph()->pen();
137  pen.setColor(color);
138  graph()->setPen(pen);
139 
140  // Connect the signal of selection change so that we can re-emit it for the
141  // widget that is using *this widget.
142 
143  connect(graph_p,
144  static_cast<void (QCPAbstractPlottable::*)(bool)>(
145  &QCPAbstractPlottable::selectionChanged),
146  [this, graph_p]() {
147  emit plottableSelectionChangedSignal(graph_p, graph_p->selected());
148  });
149 
150  // Rescaling the axes is actually unpleasant if there are more than one
151  // graph in the plot widget and that we are adding one. So only, rescale if
152  // the number of graphs is == 1, that is we are adding the first one.
153 
154  if(graphCount() == 1)
155  {
156  rescaleAxes();
158  }
159 
160  replot();
161 
162  return graph_p;
163 }

References pappso::BasePlotWidget::plottableSelectionChangedSignal(), pappso::BasePlotWidget::resetAxesRangeHistory(), pappso::Trace::xToVector(), and pappso::Trace::yToVector().

◆ axisDoubleClickHandler()

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

Reimplemented from pappso::BasePlotWidget.

Definition at line 409 of file basetraceplotwidget.cpp.

413 {
414 
415  m_context.keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
416 
417  if(m_context.keyboardModifiers & Qt::ControlModifier)
418  {
419 
420  // If the Ctrl modifiers is active, then both axes are to be reset. Also
421  // the histories are reset also.
422 
423  rescaleAxes();
425  }
426  else
427  {
428  // Only the axis passed as parameter is to be rescaled.
429  // Reset the range of that axis to the max view possible, but for the y
430  // axis check if the Shift keyboard key is pressed. If so the full scale
431  // should be calculated only on the data in the current x range.
432 
433  if(axis->orientation() == Qt::Vertical)
434  {
435  if(m_context.keyboardModifiers & Qt::ShiftModifier)
436  {
437 
438  // In this case, we want to make a rescale of the Y axis such
439  // that it displays full scale the data in the current X axis
440  // range only.
441 
442  bool ok = false;
443 
444  QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
445 
446  yAxis->setRange(value_range);
447  }
448  else
449  axis->rescale();
450  }
451  else
452  axis->rescale();
453 
455 
456  event->accept();
457  }
458 
459  // The double-click event does not cancel the mouse press event. That is, if
460  // left-double-clicking, at the end of the operation the button still
461  // "pressed". We need to remove manually the button from the pressed buttons
462  // context member.
463 
464  m_context.pressedMouseButtons ^= event->button();
465 
467 
469 
470  replot();
471 }

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

678 {
680  {
681  xAxis->setRange(m_context.xRange.lower - m_context.xDelta,
682  m_context.xRange.upper - m_context.xDelta);
683 
684  // If the shift modifier key is pressed, then the user want the y axis
685  // to be full scale.
686  if(m_context.keyboardModifiers & Qt::ShiftModifier)
687  {
688 
689  bool ok = false;
690 
691  QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
692 
693  yAxis->setRange(value_range);
694  }
695  // else nothing to do we do not change the y axis scale.
696  }
697 
699  {
700  yAxis->setRange(m_context.yRange.lower - m_context.yDelta,
701  m_context.yRange.upper - m_context.yDelta);
702  }
703 
705 
706  // We cannot store the new ranges in the history, because the pan operation
707  // involved a huge quantity of micro-movements elicited upon each mouse move
708  // cursor event so we would have a huge history.
709  // updateAxesRangeHistory();
710 
711  // Now that the contex has the right range values, we can emit the
712  // signal that will be used by this plot widget users, typically to
713  // abide by the x/y range lock required by the user.
714 
716 
717  replot();
718 }

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

596 {
597 
598  // double sorted_start_drag_point_x =
599  // std::min(m_context.startDragPoint.x(), m_context.currentDragPoint.x());
600 
601  // xAxis->setRange(sorted_start_drag_point_x,
602  // sorted_start_drag_point_x + fabs(m_context.xDelta));
603 
604  xAxis->setRange(
606 
607  // Note that the y axis should be rescaled from current lower value to new
608  // upper value matching the y-axis position of the cursor when the mouse
609  // button was released.
610 
611  yAxis->setRange(
612  xAxis->range().lower,
614 
615  // qDebug() << "xaxis:" << xAxis->range().lower << "-" <<
616  // xAxis->range().upper
617  //<< "yaxis:" << yAxis->range().lower << "-" << yAxis->range().upper;
618 
619  // If the shift modifier key is pressed, then the user want the y axis
620  // to be full scale.
621  if(m_context.keyboardModifiers & Qt::ShiftModifier)
622  {
623 
624  bool ok = false;
625 
626  QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
627 
628  yAxis->setRange(value_range);
629  }
630  // else do nothing, let the y axis range as is.
631 
633 
636 
637  replot();
638 }

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

476 {
477  double xLower = xAxis->range().lower;
478  double xUpper = xAxis->range().upper;
479 
480  // Get the current y lower/upper range.
481  double yLower = yAxis->range().lower;
482  double yUpper = yAxis->range().upper;
483 
484  // This function is called only when the user has clicked on the x/y axis or
485  // when the user has dragged the left mouse button with the Ctrl key
486  // modifier. The m_context.wasClickOnXAxis is then simulated in the mouse
487  // move handler. So we need to test which axis was clicked-on.
488 
490  {
491 
492  // We are changing the range of the X axis.
493 
494  // What is the x delta ?
495  double xDelta =
497 
498  // If xDelta is < 0, the we were dragging from right to left, we are
499  // compressing the view on the x axis, by adding new data to the right
500  // hand size of the graph. So we add xDelta to the upper bound of the
501  // range. Otherwise we are uncompressing the view on the x axis and
502  // remove the xDelta from the upper bound of the range. This is why we
503  // have the
504  // '-'
505  // and not '+' below;
506 
507  // qDebug() << "Setting xaxis:" << xLower << "--" << xUpper - xDelta;
508 
509  xAxis->setRange(xLower, xUpper - xDelta);
510 
511 
512  // Old version
513  // if(xDelta < 0)
514  //{
515  //// The dragging operation was from right to left, we are enlarging
516  //// the range (thus, we are unzooming the view, since the widget
517  //// always has the same size).
518 
519  // xAxis->setRange(xLower, xUpper + fabs(xDelta));
520  //}
521  // else
522  //{
523  //// The dragging operation was from left to right, we are reducing
524  //// the range (thus, we are zooming the view, since the widget
525  //// always has the same size).
526 
527  // xAxis->setRange(xLower, xUpper - fabs(xDelta));
528  //}
529 
530  // We may either leave the scale of the Y axis as is (default) or
531  // the user may want an automatic scale of the Y axis such that the
532  // data displayed in the new X axis range are full scale on the Y
533  // axis. For this, the Shift modifier key should be pressed.
534 
535  if(m_context.keyboardModifiers & Qt::ShiftModifier)
536  {
537 
538  // In this case, we want to make a rescale of the Y axis such that
539  // it displays full scale the data in the current X axis range only.
540 
541  bool ok = false;
542 
543  QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
544 
545  yAxis->setRange(value_range);
546  }
547  // else, do leave the Y axis range unchanged.
548  }
549  // End of
550  // if(m_context.wasClickOnXAxis)
551  else // that is, if(m_context.wasClickOnYAxis)
552  {
553  // We are changing the range of the Y axis.
554 
555  // What is the y delta ?
556  double yDelta =
558 
559  // See above for an explanation of the computation.
560 
561  yAxis->setRange(yLower, yUpper - yDelta);
562 
563  // Old version
564  // if(yDelta < 0)
565  //{
566  //// The dragging operation was from top to bottom, we are enlarging
567  //// the range (thus, we are unzooming the view, since the widget
568  //// always has the same size).
569 
570  // yAxis->setRange(yLower, yUpper + fabs(yDelta));
571  //}
572  // else
573  //{
574  //// The dragging operation was from bottom to top, we are reducing
575  //// the range (thus, we are zooming the view, since the widget
576  //// always has the same size).
577 
578  // yAxis->setRange(yLower, yUpper - fabs(yDelta));
579  //}
580  }
581  // End of
582  // else // that is, if(m_context.wasClickOnYAxis)
583 
584  // Update the context with the current axes ranges
585 
587 
589 
590  replot();
591 }

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

643 {
644 
645  // Use the m_context.xRegionRangeStart/End values, but we need to sort the
646  // values before using them, because now we want to really have the lower x
647  // value. Simply craft a QCPRange that will swap the values if lower is not
648  // < than upper QCustomPlot calls this normalization).
649 
650  xAxis->setRange(
652 
653  // If the shift modifier key is pressed, then the user want the y axis
654  // to be full scale.
655  if(m_context.keyboardModifiers & Qt::ShiftModifier)
656  {
657 
658  bool ok = false;
659 
660  QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
661 
662  yAxis->setRange(value_range);
663  }
664  else
665  yAxis->setRange(
667 
669 
672 
673  replot();
674 }

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

105 {
106  QCPGraph *graph_p = graph(graph_index);
107 
108  if(graph_p == nullptr)
109  qFatal("Programming error.");
110 
111  graph_p->data().clear();
112 
113  rescaleAxes();
115  replot();
116 }

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

178 {
179 
180  // Given a key double value, we want to know what is the range that will
181  // frame correctly the key double value if that key value is not exactly
182  // the one of a point of the trace.
183 
184  // First of all get the keys of the graph.
185 
186  QCPGraph *theGraph = graph(index);
187 
188  if(theGraph == nullptr)
189  throw ExceptionNotPossible(
190  "basetraceplotwidget.cpp @ indIntegrationLowerRangeForKey() -- ERROR "
191  "theGraph cannot be nullptr.");
192 
193  // QCPGraphDataContainer is a typedef QCPDataContainer<QCPGraphData> and
194  // QCPDataContainer< DataType > is a Class Template. So in this context,
195  // DataType is QCPGraphData.
196  // QCPGraphData is the data point, that is the (key,value) pair.
197  QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
198  theGraph->data();
199 
200  QCPDataRange dataRange = graph_data_container_p->dataRange();
201 
202  if(!dataRange.isValid())
203  return false;
204 
205  if(!dataRange.size())
206  return false;
207 
208  if(dataRange.size() > 1)
209  {
210  double firstKey = graph_data_container_p->at(dataRange.begin())->key;
211  double lastKey = graph_data_container_p->at(dataRange.end())->key;
212 
213  // There is one check to be done: the user might erroneously set the mouse
214  // cursor beyond the last point of the graph. If that is the case, then
215  // upper key needs to be that very point. All we need to do is return the
216  // lower key, that is the pre-last key of the keys list. No need to
217  // iterate in the keys list.
218 
219  if(key > lastKey)
220  {
221  // No need to search for the key in the keys, just get the lower key
222  // immediately, that is, the key that is one slot left the last key.
223  range.lower = graph_data_container_p->at(dataRange.end() - 2)->key;
224  range.upper = graph_data_container_p->at(dataRange.end() - 1)->key;
225 
226  return true;
227  }
228 
229  // Likewise, if the cursor is set left of the first plot point, then that
230  // will be the lower range point. All we need is to provide the upper
231  // range point as the second point of the plot.
232 
233  if(key < firstKey)
234  {
235  range.lower = firstKey;
236  range.upper = graph_data_container_p->at(dataRange.begin() + 1)->key;
237 
238  return true;
239  }
240 
241  // Finally the generic case where the user point to any point *in* the
242  // graph.
243 
244  range.lower =
245  graph_data_container_p->findBegin(key, /*expandedRange*/ true)->key;
246  range.upper =
247  std::prev(graph_data_container_p->findEnd(key, /*expandedRange*/ true))
248  ->key;
249 
250  return true;
251  }
252 
253  return false;
254 }

◆ getValueRangeOnKeyRange() [1/2]

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

Definition at line 363 of file basetraceplotwidget.cpp.

364 {
365 
366  // The X axis range is set. But we want to find for that X axis range the
367  // min and max Y values. This function is useful when the user asks that
368  // while changing the X axis range, the trace be always in full scale on the
369  // Y axis.
370 
371  QCPAbstractPlottable *plottable_p = plottable(index);
372 
373  if(plottable_p == nullptr)
374  qFatal("Programming error.");
375 
376  return getValueRangeOnKeyRange(plottable_p, ok);
377 }

References getValueRangeOnKeyRange().

◆ getValueRangeOnKeyRange() [2/2]

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

Definition at line 306 of file basetraceplotwidget.cpp.

308 {
309 
310  // The X axis range is set. But we want to find for that X axis range the
311  // min and max Y values. This function is useful when the user asks that
312  // while changing the X axis range, the trace be always in full scale on the
313  // Y axis.
314 
315  QCPRange key_range(xAxis->range().lower, xAxis->range().upper);
316 
317  if(plottable_p != nullptr)
318  {
319 
320  return plottable_p->getValueRange(ok, QCP::SignDomain::sdBoth, key_range);
321  }
322  else
323  {
324 
325  // How many graphs are currently plotted in this plot widget ?
326  int graph_count = graphCount();
327 
328  // Iterate in each graph and get the y max value. Then compare with the
329  // largest one and update if necessary. Store the pointer to the graph
330  // that has a larger y value. At the end of the iteration, it will be
331  // the winner.
332 
333  double temp_min_value = std::numeric_limits<double>::max();
334  double temp_max_value = std::numeric_limits<double>::min();
335 
336  bool found_range = false;
337 
338  for(int iter = 0; iter < graph_count; ++iter)
339  {
340  QCPGraph *plottable_p = graph(iter);
341 
342  QCPRange value_range =
343  plottable_p->getValueRange(ok, QCP::SignDomain::sdBoth, key_range);
344 
345  if(ok)
346  found_range = true;
347 
348  if(value_range.lower < temp_min_value)
349  temp_min_value = value_range.lower;
350  if(value_range.upper > temp_max_value)
351  temp_max_value = value_range.upper;
352  }
353 
354  // At this point return the range.
355 
356  ok = found_range;
357  return QCPRange(temp_min_value, temp_max_value);
358  }
359 }

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

◆ getValuesX()

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

Definition at line 258 of file basetraceplotwidget.cpp.

259 {
260  std::vector<double> keys;
261 
262  QCPGraph *graph_p = graph(graph_index);
263 
264  if(graph_p == nullptr)
265  qFatal("Programming error.");
266 
267  QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
268  graph_p->data();
269 
270  // Iterate in the keys
271  auto beginIt = graph_data_container_p->begin();
272  auto endIt = graph_data_container_p->end();
273 
274  for(auto iter = beginIt; iter != endIt; ++iter)
275  keys.push_back(iter->key);
276 
277  return keys;
278 }

◆ getValuesY()

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

Definition at line 282 of file basetraceplotwidget.cpp.

283 {
284  std::vector<double> values;
285 
286  QCPGraph *graph_p = graph(graph_index);
287 
288  if(graph_p == nullptr)
289  qFatal("Programming error.");
290 
291  QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
292  graph_p->data();
293 
294  // Iterate in the values
295  auto beginIt = graph_data_container_p->begin();
296  auto endIt = graph_data_container_p->end();
297 
298  for(auto iter = beginIt; iter != endIt; ++iter)
299  values.push_back(iter->key);
300 
301  return values;
302 }

◆ getYatX() [1/2]

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

Definition at line 397 of file basetraceplotwidget.cpp.

398 {
399  QCPGraph *graph_p = graph(index);
400 
401  if(graph_p == nullptr)
402  qFatal("Programming error.");
403 
404  return getYatX(x, graph_p);
405 }

References getYatX(), and pappso::x.

◆ getYatX() [2/2]

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

Definition at line 381 of file basetraceplotwidget.cpp.

382 {
383  if(graph_p == nullptr)
384  qFatal("Programming error.");
385 
386  QCPItemTracer tracer(this);
387  tracer.setGraph(graph_p);
388  tracer.setInterpolating(true);
389  tracer.setGraphKey(x);
390  tracer.updatePosition();
391 
392  return tracer.position->value();
393 }

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 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  graph_p->setData(QVector<double>::fromStdVector(keys),
93  QVector<double>::fromStdVector(values));
94 
95  graph_p->setPen(m_pen);
96 
97  rescaleAxes();
99  replot();
100 }

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

732 {
733  if(graph_p == nullptr)
734  qFatal("Programming error. Pointer cannot be nullptr.");
735 
736  pappso::Trace trace;
737 
738  QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
739  graph_p->data();
740 
741  // Iterate in the keys
742  auto beginIt = graph_data_container_p->begin();
743  auto endIt = graph_data_container_p->end();
744 
745  for(auto iter = beginIt; iter != endIt; ++iter)
746  trace.push_back(pappso::DataPoint(iter->key, iter->value));
747 
748  return trace;
749 }

◆ toTrace() [2/4]

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

Definition at line 765 of file basetraceplotwidget.cpp.

767 {
768 
769  // Make a Trace with the data in the range.
770  Trace data_trace;
771 
772  QSharedPointer<QCPGraphDataContainer> graph_data_container_sp;
773 
774  graph_data_container_sp = graph_p->data();
775 
776  // Grab the iterator to the start to the x axis range
777  auto beginIt = graph_data_container_sp->findBegin(x_axis_range.lower,
778  /*expandedRange*/ true);
779  // Grab the iterator to the end of the axis range
780  auto endIt = graph_data_container_sp->findEnd(x_axis_range.upper,
781  /*expandedRange*/ true);
782 
783  for(auto iter = beginIt; iter != endIt; ++iter)
784  data_trace.push_back(DataPoint(iter->key, iter->value));
785 
786  return data_trace;
787 }

◆ toTrace() [3/4]

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

Definition at line 753 of file basetraceplotwidget.cpp.

754 {
755  QCPGraph *graph_p = graph(index);
756 
757  if(graph_p == nullptr)
758  qFatal("Programming error.");
759 
760  return toTrace(x_axis_range, graph_p);
761 }

References toTrace().

◆ toTrace() [4/4]

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

Definition at line 722 of file basetraceplotwidget.cpp.

723 {
724  QCPGraph *graph_p = graph(index);
725 
726  return toTrace(graph_p);
727 }

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::Trace::xToVector
std::vector< pappso_double > xToVector() const
Definition: trace.cpp:495
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:306
pappso::BasePlotContext::xRange
QCPRange xRange
Definition: baseplotwidget.h:86
pappso::BasePlotContext::wasClickOnXAxis
bool wasClickOnXAxis
Definition: baseplotwidget.h:93
pappso::DataPoint
Definition: datapoint.h:20
pappso::Trace::yToVector
std::vector< pappso_double > yToVector() const
Definition: trace.cpp:507
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:126
pappso::BaseTracePlotWidget::toTrace
pappso::Trace toTrace(int index) const
Definition: basetraceplotwidget.cpp:722
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::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::BasePlotContext::xDelta
double xDelta
Definition: baseplotwidget.h:110
pappso::BaseTracePlotWidget::getYatX
double getYatX(double x, QCPGraph *graph_p)
Definition: basetraceplotwidget.cpp:381
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)