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

44  : BasePlotWidget(parent)
45 {
46 }

◆ BaseTracePlotWidget() [2/2]

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

Definition at line 49 of file basetraceplotwidget.cpp.

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

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

65 {
66 }

Member Function Documentation

◆ addTrace()

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

Definition at line 119 of file basetraceplotwidget.cpp.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

◆ getValueRangeOnKeyRange() [1/2]

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

Definition at line 367 of file basetraceplotwidget.cpp.

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

References getValueRangeOnKeyRange().

◆ getValueRangeOnKeyRange() [2/2]

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

Definition at line 310 of file basetraceplotwidget.cpp.

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

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

◆ getValuesX()

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

Definition at line 262 of file basetraceplotwidget.cpp.

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

◆ getValuesY()

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

Definition at line 286 of file basetraceplotwidget.cpp.

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

◆ getYatX() [1/2]

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

Definition at line 401 of file basetraceplotwidget.cpp.

402 {
403  QCPGraph *graph_p = graph(index);
404 
405  if(graph_p == nullptr)
406  qFatal("Programming error.");
407 
408  return getYatX(x, graph_p);
409 }

References getYatX(), and pappso::x.

◆ getYatX() [2/2]

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

Definition at line 385 of file basetraceplotwidget.cpp.

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

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

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

◆ setGraphData() [2/2]

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

Definition at line 84 of file basetraceplotwidget.cpp.

87 {
88  if(graph_p == nullptr)
89  qFatal("Pointer cannot be nullptr.");
90 
91  graph_p->setData(QVector<double>::fromStdVector(keys),
92  QVector<double>::fromStdVector(values));
93 
94  graph_p->setPen(m_pen);
95 
96  rescaleAxes();
98  replot();
99 }

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

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

◆ toTrace() [2/4]

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

Definition at line 768 of file basetraceplotwidget.cpp.

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

◆ toTrace() [3/4]

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

Definition at line 756 of file basetraceplotwidget.cpp.

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

References toTrace().

◆ toTrace() [4/4]

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

Definition at line 725 of file basetraceplotwidget.cpp.

726 {
727  QCPGraph *graph_p = graph(index);
728 
729  return toTrace(graph_p);
730 }

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:392
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:499
pappso::BasePlotContext::currentDragPoint
QPointF currentDragPoint
Definition: baseplotwidget.h:82
pappso::BasePlotWidget::BasePlotWidget
BasePlotWidget(QWidget *parent)
Definition: baseplotwidget.cpp:111
pappso::BaseTracePlotWidget::getValueRangeOnKeyRange
QCPRange getValueRangeOnKeyRange(QCPAbstractPlottable *plottable_p, bool &ok)
Definition: basetraceplotwidget.cpp:310
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:511
pappso::BasePlotWidget::updateContextRanges
virtual void updateContextRanges()
Definition: baseplotwidget.cpp:2220
pappso::PeptideIonCter::x
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:125
pappso::BaseTracePlotWidget::toTrace
pappso::Trace toTrace(int index) const
Definition: basetraceplotwidget.cpp:725
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:365
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:70
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:385
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)