Loading...
Searching...
No Matches
pappso::BaseTracePlotWidget Class Reference

`#include <basetraceplotwidget.h>`

Inheritance diagram for pappso::BaseTracePlotWidget:

## 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.
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.
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.
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.
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.
virtual void | restorePreviousAxesRangeHistory ()
| Go up one history element in the axis history.
virtual void | restoreAxesRangeHistory (std::size_t index)
| Get the axis histories at index `index` and update the plot ranges.
virtual void | keyPressEvent (QKeyEvent *event)
| KEYBOARD-related EVENTS.
virtual void | keyReleaseEvent (QKeyEvent *event)
| Handle specific key codes and trigger respective actions.
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.
virtual void | mouseReleaseHandler (QMouseEvent *event)
virtual void | mouseReleaseHandlerLeftButton ()
virtual void | mouseReleaseHandlerRightButton ()
virtual void | mouseWheelHandler (QWheelEvent *event)
virtual void | mouseMoveHandler (QMouseEvent *event)
| KEYBOARD-related EVENTS.
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.
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.
virtual QCPRange | getRangeY (bool &found_range, int index) const
QCPRange | getRange (Axis axis, RangeType range_type, bool &found_range) const
virtual QCPRange | getInnermostRangeX (bool &found_range) const
virtual QCPRange | getOutermostRangeX (bool &found_range) const
virtual QCPRange | getInnermostRangeY (bool &found_range) const
virtual QCPRange | getOutermostRangeY (bool &found_range) const
void | yMinMaxOnXAxisCurrentRange (double &min, double &max, QCPAbstractPlottable *plottable_p=nullptr)
void | yMinMaxOnXAxisCurrentRange (double &min, double &max, int index)
virtual void | replotWithAxesRanges (QCPRange xAxisRange, QCPRange yAxisRange, Axis axis)
virtual void | replotWithAxisRangeX (double lower, double upper)
virtual void | replotWithAxisRangeY (double lower, double upper)
virtual void | hideAllPlotItems ()
| PLOTTING / REPLOTTING functions.
virtual void | showTracers ()
| Show the traces (vertical and horizontal).
virtual void | hideTracers ()
| Hide the traces (vertical and horizontal).
virtual void | drawXScopeSpanFeatures ()
virtual void | drawYScopeSpanFeatures ()
virtual void | calculateDragDeltas ()
virtual bool | isVerticalDisplacementAboveThreshold ()
virtual void | drawSelectionRectangleAndPrepareZoom (bool as_line_segment=false, bool for_integration=false)
virtual void | updateIntegrationScopeDrawing (bool as_line_segment=false, bool for_integration=false)
virtual void | resetSelectionRectangle ()
virtual void | hideSelectionRectangle (bool reset_values=false)
virtual bool | isSelectionRectangleVisible ()
virtual SelectionDrawingLines | whatIsVisibleOfTheSelectionRectangle ()
virtual void | setFocus ()
| PLOT ITEMS : TRACER TEXT ITEMS...
virtual void | redrawPlotBackground (QWidget *focusedPlotWidget)
| Redraw the background of the `focusedPlotWidget` plot widget.
virtual void | updateContextXandYAxisRanges ()
virtual const BasePlotContext & | getContext () const

## Additional Inherited Members

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

## 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.

: BasePlotWidget(parent)
{
// We can afford to call createAllAncillaryItems() in this derived class
// because all the items will have been created *before* the addition of plots
// and then the rendering order will hide them to the viewer, since the
// rendering order is according to the order in which the items have been
// created.
//
// The fact that the ancillary items are created before trace plots is not a
// problem because the trace plots are sparse and do not effectively hide the
// data.
//
// But, in the color map plot widgets, we cannot afford to create the
// ancillary items *before* the plot itself because then, the rendering of the
// plot (created after) would screen off the ancillary items (created before).
//
// So, the createAllAncillaryItems() function needs to be called in the
// derived classes at the most appropriate moment in the setting up of the
// widget.
createAllAncillaryItems();
}
pappso::BasePlotWidget::createAllAncillaryItems
virtual void createAllAncillaryItems()
Definition baseplotwidget.cpp:221
pappso::BasePlotWidget::BasePlotWidget
BasePlotWidget(QWidget *parent)
Definition baseplotwidget.cpp:50

References pappso::BasePlotWidget::createAllAncillaryItems().

## BaseTracePlotWidget() [2/2]

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

explicit

Definition at line 68 of file basetraceplotwidget.cpp.

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

References pappso::BasePlotWidget::createAllAncillaryItems().

## ~BaseTracePlotWidget()

pappso::BaseTracePlotWidget::~BaseTracePlotWidget | ( |  | ) |

virtual

Destruct `this` BaseTracePlotWidget instance.

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

Definition at line 101 of file basetraceplotwidget.cpp.

{
}

## Member Function Documentation

## addTrace()

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

virtual

Definition at line 184 of file basetraceplotwidget.cpp.

{
// qDebug();
if(!color.isValid())
throw PappsoException(
QString("The color to be used for the plot graph is invalid."));
// This seems to be unpleasant.
// setFocus();
QCPGraph *graph_p = addGraph();
graph_p->setLayer("plotsLayer");
// Now depracated as of 20200924
// graph_p->setData(QVector<double>::fromStdVector(trace.xValues()),
// QVector<double>::fromStdVector(trace.yValues()));
QVector<double> key_qvector;
QVector<double> value_qvector;
#if 0
// Now replace the graph's data. Note that the data are
// inherently sorted (true below).
// The begin() -- end() ranges constructor did not work as of
// Qt 5.14.2 this day: 20200721
key_qvector =
QVector(trace.xValues().begin(),
.trace.xValues()end());
value_qvector =
QVector(trace.yValues().begin(),
trace.yValues().end());
#endif
for(auto &value : trace.xValues())
{
key_qvector.push_back(value);
}
for(auto &value : trace.yValues())
{
value_qvector.push_back(value);
}
#if 0
qDebug() << "The size of the x values for trace is:" << key_qvector.size()
<< "and for y values is:" << value_qvector.size();
QString text;
for(qsizetype iter = 0; iter < key_qvector.size(); ++iter)
text += QString("(%1,%2)\n")
.arg(key_qvector.at(iter), 0, 'f', 6)
.arg(value_qvector.at(iter), 0, 'f', 6);
qDebug().noquote() << text;
#endif
graph_p->setData(key_qvector, value_qvector, true);
QPen pen = graph()->pen();
pen.setColor(color);
graph()->setPen(pen);
// Connect the signal of selection change so that we can re-emit it for the
// widget that is using *this widget.
connect(graph_p,
static_cast<void (QCPAbstractPlottable::*)(bool)>(
&QCPAbstractPlottable::selectionChanged),
[this, graph_p]() {
emit plottableSelectionChangedSignal(graph_p, graph_p->selected());
});
// Rescaling the axes is actually unpleasant if there are more than one
// graph in the plot widget and that we are adding one. So only, rescale if
// the number of graphs is == 1, that is we are adding the first one.
if(graphCount() == 1)
{
rescaleAxes();
resetAxesRangeHistory();
}
replot();
return graph_p;
}
pappso::BasePlotWidget::resetAxesRangeHistory
virtual void resetAxesRangeHistory()
Definition baseplotwidget.cpp:485
pappso::BasePlotWidget::plottableSelectionChangedSignal
void plottableSelectionChangedSignal(QCPAbstractPlottable *plottable_p, bool selected)
pappso::Trace::xValues
std::vector< pappso_double > xValues() const
Definition trace.cpp:688
pappso::Trace::yValues
std::vector< pappso_double > yValues() const
Definition trace.cpp:702

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
| ) |  |

override virtual

Reimplemented from pappso::BasePlotWidget.

Definition at line 523 of file basetraceplotwidget.cpp.

{
// qDebug();
m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
if(m_context.m_keyboardModifiers & Qt::ControlModifier)
{
// qDebug();
// If the Ctrl modifiers is active, then both axes are to be reset. Also
// the histories are reset also.
rescaleAxes();
resetAxesRangeHistory();
}
else
{
// qDebug();
// Only the axis passed as parameter is to be rescaled.
// Reset the range of that axis to the max view possible, but for the y
// axis check if the Shift keyboard key is pressed. If so the full scale
// should be calculated only on the data in the current x range.
if(axis->orientation() == Qt::Vertical)
{
if(m_context.m_keyboardModifiers & Qt::ShiftModifier)
{
// In this case, we want to make a rescale of the Y axis such
// that it displays full scale the data in the current X axis
// range only.
bool ok = false;
QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
yAxis->setRange(value_range);
}
else
axis->rescale();
}
else
axis->rescale();
updateAxesRangeHistory();
event->accept();
}
// The double-click event does not cancel the mouse press event. That is, if
// left-double-clicking, at the end of the operation the button still
// "pressed". We need to remove manually the button from the pressed buttons
// context member.
m_context.m_pressedMouseButtons ^= event->button();
updateContextXandYAxisRanges();
emit plotRangesChangedSignal(m_context);
replot();
}
pappso::BasePlotContext::m_keyboardModifiers
Qt::KeyboardModifiers m_keyboardModifiers
Definition baseplotcontext.h:94
pappso::BasePlotContext::m_pressedMouseButtons
Qt::MouseButtons m_pressedMouseButtons
Definition baseplotcontext.h:99
pappso::BasePlotWidget::updateAxesRangeHistory
virtual void updateAxesRangeHistory()
Create new axis range history items and append them to the history.
Definition baseplotwidget.cpp:512
pappso::BasePlotWidget::updateContextXandYAxisRanges
virtual void updateContextXandYAxisRanges()
Definition baseplotwidget.cpp:3326
pappso::BasePlotWidget::plotRangesChangedSignal
void plotRangesChangedSignal(const BasePlotContext &context)
pappso::BasePlotWidget::m_context
BasePlotContext m_context
Definition baseplotwidget.h:272
pappso::BaseTracePlotWidget::getValueRangeOnKeyRange
QCPRange getValueRangeOnKeyRange(QCPAbstractPlottable *plottable_p, bool &ok)
Definition basetraceplotwidget.cpp:420

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

## axisPan()

void pappso::BaseTracePlotWidget::axisPan | ( |  | ) |

override virtual

Reimplemented from pappso::BasePlotWidget.

Definition at line 796 of file basetraceplotwidget.cpp.

{
// qDebug();
// Sanity check
if(!m_context.m_wasClickOnXAxis && !m_context.m_wasClickOnYAxis)
qFatal(
"This function can only be called if the mouse click was on one of the "
"axes");
if(m_context.m_wasClickOnXAxis)
{
xAxis->setRange(m_context.m_xRange.lower - m_context.m_xDelta,
m_context.m_xRange.upper - m_context.m_xDelta);
// If the shift modifier key is pressed, then the user want the y axis
// to be full scale.
if(m_context.m_keyboardModifiers & Qt::ShiftModifier)
{
bool ok = false;
QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
yAxis->setRange(value_range);
}
// else nothing to do we do not change the y axis scale.
}
if(m_context.m_wasClickOnYAxis)
{
yAxis->setRange(m_context.m_yRange.lower - m_context.m_yDelta,
m_context.m_yRange.upper - m_context.m_yDelta);
}
updateContextXandYAxisRanges();
// qDebug() << "The updated context:" << m_context.toString();
// We cannot store the new ranges in the history, because the pan operation
// involved a huge quantity of micro-movements elicited upon each mouse move
// cursor event so we would have a huge history.
// updateAxesRangeHistory();
// Now that the contex has the right range values, we can emit the
// signal that will be used by this plot widget users, typically to
// abide by the x/y range lock required by the user.
emit plotRangesChangedSignal(m_context);
replot();
}
pappso::BasePlotContext::m_xDelta
double m_xDelta
Definition baseplotcontext.h:88
pappso::BasePlotContext::m_wasClickOnXAxis
bool m_wasClickOnXAxis
Definition baseplotcontext.h:71
pappso::BasePlotContext::m_xRange
QCPRange m_xRange
Definition baseplotcontext.h:64
pappso::BasePlotContext::m_yDelta
double m_yDelta
Definition baseplotcontext.h:89
pappso::BasePlotContext::m_yRange
QCPRange m_yRange
Definition baseplotcontext.h:65
pappso::BasePlotContext::m_wasClickOnYAxis
bool m_wasClickOnYAxis
Definition baseplotcontext.h:72

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

## axisReframe()

void pappso::BaseTracePlotWidget::axisReframe | ( |  | ) |

override virtual

Reimplemented from pappso::BasePlotWidget.

Definition at line 713 of file basetraceplotwidget.cpp.

{
// qDebug();
// double sorted_start_drag_point_x =
// std::min(m_context.m_startDragPoint.x(), m_context.m_currentDragPoint.x());
// xAxis->setRange(sorted_start_drag_point_x,
// sorted_start_drag_point_x + fabs(m_context.m_xDelta));
xAxis->setRange(
QCPRange(m_context.m_xRegionRangeStart, m_context.m_xRegionRangeEnd));
// Note that the y axis should be rescaled from current lower value to new
// upper value matching the y-axis position of the cursor when the mouse
// button was released.
yAxis->setRange(xAxis->range().lower,
std::max<double>(m_context.m_yRegionRangeStart,
m_context.m_yRegionRangeEnd));
// qDebug() << "xaxis:" << xAxis->range().lower << "-" <<
// xAxis->range().upper
//<< "yaxis:" << yAxis->range().lower << "-" << yAxis->range().upper;
// If the shift modifier key is pressed, then the user want the y axis
// to be full scale.
if(m_context.m_keyboardModifiers & Qt::ShiftModifier)
{
bool ok = false;
QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
yAxis->setRange(value_range);
}
// else do nothing, let the y axis range as is.
updateContextXandYAxisRanges();
updateAxesRangeHistory();
emit plotRangesChangedSignal(m_context);
replot();
}
pappso::BasePlotContext::m_xRegionRangeStart
double m_xRegionRangeStart
Definition baseplotcontext.h:82
pappso::BasePlotContext::m_yRegionRangeStart
double m_yRegionRangeStart
Definition baseplotcontext.h:85
pappso::BasePlotContext::m_yRegionRangeEnd
double m_yRegionRangeEnd
Definition baseplotcontext.h:86
pappso::BasePlotContext::m_xRegionRangeEnd
double m_xRegionRangeEnd
Definition baseplotcontext.h:83

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

## axisRescale()

void pappso::BaseTracePlotWidget::axisRescale | ( |  | ) |

override virtual

RANGE-related functions.

PLOTTING / REPLOTTING functions

Reimplemented from pappso::BasePlotWidget.

Definition at line 593 of file basetraceplotwidget.cpp.

{
double xLower = xAxis->range().lower;
double xUpper = xAxis->range().upper;
// Get the current y lower/upper range.
double yLower = yAxis->range().lower;
double yUpper = yAxis->range().upper;
// This function is called only when the user has clicked on the x/y axis or
// when the user has dragged the left mouse button with the Ctrl key
// modifier. The m_context.m_wasClickOnXAxis is then simulated in the mouse
// move handler. So we need to test which axis was clicked-on.
if(m_context.m_wasClickOnXAxis)
{
// We are changing the range of the X axis.
// What is the x delta ?
double xDelta =
m_context.m_currentDragPoint.x() - m_context.m_startDragPoint.x();
// If xDelta is < 0, the we were dragging from right to left, we are
// compressing the view on the x axis, by adding new data to the right
// hand size of the graph. So we add xDelta to the upper bound of the
// range. Otherwise we are uncompressing the view on the x axis and
// remove the xDelta from the upper bound of the range. This is why we
// have the
// '-'
// and not '+' below;
// qDebug() << "Setting xaxis:" << xLower << "--" << xUpper - xDelta;
xAxis->setRange(xLower, xUpper - xDelta);
// Old version
// if(xDelta < 0)
//{
//// The dragging operation was from right to left, we are enlarging
//// the range (thus, we are unzooming the view, since the widget
//// always has the same size).
// xAxis->setRange(xLower, xUpper + fabs(xDelta));
//}
// else
//{
//// The dragging operation was from left to right, we are reducing
//// the range (thus, we are zooming the view, since the widget
//// always has the same size).
// xAxis->setRange(xLower, xUpper - fabs(xDelta));
//}
// We may either leave the scale of the Y axis as is (default) or
// the user may want an automatic scale of the Y axis such that the
// data displayed in the new X axis range are full scale on the Y
// axis. For this, the Shift modifier key should be pressed.
if(m_context.m_keyboardModifiers & Qt::ShiftModifier)
{
// In this case, we want to make a rescale of the Y axis such that
// it displays full scale the data in the current X axis range only.
bool ok = false;
QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
yAxis->setRange(value_range);
}
// else, do leave the Y axis range unchanged.
}
// End of
// if(m_context.m_wasClickOnXAxis)
else // that is, if(m_context.m_wasClickOnYAxis)
{
// We are changing the range of the Y axis.
// What is the y delta ?
double yDelta =
m_context.m_currentDragPoint.y() - m_context.m_startDragPoint.y();
// See above for an explanation of the computation.
yAxis->setRange(yLower, yUpper - yDelta);
// Old version
// if(yDelta < 0)
//{
//// The dragging operation was from top to bottom, we are enlarging
//// the range (thus, we are unzooming the view, since the widget
//// always has the same size).
// yAxis->setRange(yLower, yUpper + fabs(yDelta));
//}
// else
//{
//// The dragging operation was from bottom to top, we are reducing
//// the range (thus, we are zooming the view, since the widget
//// always has the same size).
// yAxis->setRange(yLower, yUpper - fabs(yDelta));
//}
}
// End of
// else // that is, if(m_context.m_wasClickOnYAxis)
// Update the context with the current axes ranges
updateContextXandYAxisRanges();
emit plotRangesChangedSignal(m_context);
replot();
}
pappso::BasePlotContext::m_startDragPoint
QPointF m_startDragPoint
Definition baseplotcontext.h:53
pappso::BasePlotContext::m_currentDragPoint
QPointF m_currentDragPoint
Definition baseplotcontext.h:54

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

## axisZoom()

void pappso::BaseTracePlotWidget::axisZoom | ( |  | ) |

override virtual

Reimplemented from pappso::BasePlotWidget.

Definition at line 761 of file basetraceplotwidget.cpp.

{
// Use the m_context.m_xRegionRangeStart/End values, but we need to sort the
// values before using them, because now we want to really have the lower x
// value. Simply craft a QCPRange that will swap the values if lower is not
// < than upper QCustomPlot calls this normalization).
xAxis->setRange(
QCPRange(m_context.m_xRegionRangeStart, m_context.m_xRegionRangeEnd));
// If the shift modifier key is pressed, then the user want the y axis
// to be full scale.
if(m_context.m_keyboardModifiers & Qt::ShiftModifier)
{
bool ok = false;
QCPRange value_range = getValueRangeOnKeyRange(nullptr, ok);
yAxis->setRange(value_range);
}
else
yAxis->setRange(
QCPRange(m_context.m_yRegionRangeStart, m_context.m_yRegionRangeEnd));
updateContextXandYAxisRanges();
updateAxesRangeHistory();
emit plotRangesChangedSignal(m_context);
replot();
}

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

## clearGraphData()

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

virtual

Definition at line 168 of file basetraceplotwidget.cpp.

{
QCPGraph *graph_p = graph(graph_index);
if(graph_p == nullptr)
qFatal("Programming error.");
graph_p->data().clear();
rescaleAxes();
resetAxesRangeHistory();
replot();
}

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

{
// Given a key double value, we want to know what is the range that will
// frame correctly the key double value if that key value is not exactly
// the one of a point of the trace.
// First of all get the keys of the graph.
QCPGraph *theGraph = graph(index);
if(theGraph == nullptr)
throw ExceptionNotPossible(
"basetraceplotwidget.cpp @ indIntegrationLowerRangeForKey() -- ERROR "
"theGraph cannot be nullptr.");
// QCPGraphDataContainer is a typedef QCPDataContainer<QCPGraphData> and
// QCPDataContainer< DataType > is a Class Template. So in this context,
// DataType is QCPGraphData.
// QCPGraphData is the data point, that is the (key,value) pair.
QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
theGraph->data();
QCPDataRange dataRange = graph_data_container_p->dataRange();
if(!dataRange.isValid())
return false;
if(!dataRange.size())
return false;
if(dataRange.size() > 1)
{
double firstKey = graph_data_container_p->at(dataRange.begin())->key;
double lastKey = graph_data_container_p->at(dataRange.end())->key;
// There is one check to be done: the user might erroneously set the mouse
// cursor beyond the last point of the graph. If that is the case, then
// upper key needs to be that very point. All we need to do is return the
// lower key, that is the pre-last key of the keys list. No need to
// iterate in the keys list.
if(key > lastKey)
{
// No need to search for the key in the keys, just get the lower key
// immediately, that is, the key that is one slot left the last key.
range.lower = graph_data_container_p->at(dataRange.end() - 2)->key;
range.upper = graph_data_container_p->at(dataRange.end() - 1)->key;
return true;
}
// Likewise, if the cursor is set left of the first plot point, then that
// will be the lower range point. All we need is to provide the upper
// range point as the second point of the plot.
if(key < firstKey)
{
range.lower = firstKey;
range.upper = graph_data_container_p->at(dataRange.begin() + 1)->key;
return true;
}
// Finally the generic case where the user point to any point *in* the
// graph.
range.lower =
graph_data_container_p->findBegin(key, /*expandedRange*/ true)->key;
range.upper =
std::prev(graph_data_container_p->findEnd(key, /*expandedRange*/ true))
->key;
return true;
}
return false;
}

## getValueRangeOnKeyRange() [1/2]

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

Definition at line 477 of file basetraceplotwidget.cpp.

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

References getValueRangeOnKeyRange().

## getValueRangeOnKeyRange() [2/2]

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

Definition at line 420 of file basetraceplotwidget.cpp.

{
// The X axis range is set. But we want to find for that X axis range the
// min and max Y values. This function is useful when the user asks that
// while changing the X axis range, the trace be always in full scale on the
// Y axis.
QCPRange key_range(xAxis->range().lower, xAxis->range().upper);
if(plottable_p != nullptr)
{
return plottable_p->getValueRange(ok, QCP::SignDomain::sdBoth, key_range);
}
else
{
// How many graphs are currently plotted in this plot widget ?
int graph_count = graphCount();
// Iterate in each graph and get the y max value. Then compare with the
// largest one and update if necessary. Store the pointer to the graph
// that has a larger y value. At the end of the iteration, it will be
// the winner.
double temp_min_value = std::numeric_limits<double>::max();
double temp_max_value = std::numeric_limits<double>::min();
bool found_range = false;
for(int iter = 0; iter < graph_count; ++iter)
{
QCPGraph *plottable_p = graph(iter);
QCPRange value_range =
plottable_p->getValueRange(ok, QCP::SignDomain::sdBoth, key_range);
if(ok)
found_range = true;
if(value_range.lower < temp_min_value)
temp_min_value = value_range.lower;
if(value_range.upper > temp_max_value)
temp_max_value = value_range.upper;
}
// At this point return the range.
ok = found_range;
return QCPRange(temp_min_value, temp_max_value);
}
}

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

## getValuesX()

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

Definition at line 372 of file basetraceplotwidget.cpp.

{
std::vector<double> keys;
QCPGraph *graph_p = graph(graph_index);
if(graph_p == nullptr)
qFatal("Programming error.");
QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
graph_p->data();
// Iterate in the keys
auto beginIt = graph_data_container_p->begin();
auto endIt = graph_data_container_p->end();
for(auto iter = beginIt; iter != endIt; ++iter)
keys.push_back(iter->key);
return keys;
}

## getValuesY()

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

Definition at line 396 of file basetraceplotwidget.cpp.

{
std::vector<double> values;
QCPGraph *graph_p = graph(graph_index);
if(graph_p == nullptr)
qFatal("Programming error.");
QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
graph_p->data();
// Iterate in the values
auto beginIt = graph_data_container_p->begin();
auto endIt = graph_data_container_p->end();
for(auto iter = beginIt; iter != endIt; ++iter)
values.push_back(iter->key);
return values;
}

## getYatX() [1/2]

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

Definition at line 511 of file basetraceplotwidget.cpp.

{
QCPGraph *graph_p = graph(index);
if(graph_p == nullptr)
qFatal("Programming error.");
return getYatX(x, graph_p);
}
pappso::BaseTracePlotWidget::getYatX
double getYatX(double x, QCPGraph *graph_p)
Definition basetraceplotwidget.cpp:495
pappso::PeptideIonCter::x
@ x

References getYatX(), and pappso::x.

## getYatX() [2/2]

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

Definition at line 495 of file basetraceplotwidget.cpp.

{
if(graph_p == nullptr)
qFatal("Programming error.");
QCPItemTracer tracer(this);
tracer.setGraph(graph_p);
tracer.setInterpolating(true);
tracer.setGraphKey(x);
tracer.updatePosition();
return tracer.position->value();
}

References pappso::x.

Referenced by getYatX().

## setGraphData() [1/2]

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

virtual

Definition at line 107 of file basetraceplotwidget.cpp.

{
QCPGraph *graph_p = graph(graph_index);
if(graph_p == nullptr)
qFatal("Programming error.");
return setGraphData(graph_p, keys, values);
}
pappso::BaseTracePlotWidget::setGraphData
virtual void setGraphData(int graph_index, const std::vector< double > &keys, const std::vector< double > &values)
Definition basetraceplotwidget.cpp:107

References setGraphData().

Referenced by setGraphData().

## setGraphData() [2/2]

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

virtual

Definition at line 121 of file basetraceplotwidget.cpp.

{
if(graph_p == nullptr)
qFatal("Pointer cannot be nullptr.");
// Version that is now deprecated (20200924)
// graph_p->setData(QVector<double>::fromStdVector(keys),
// QVector<double>::fromStdVector(values));
QVector<double> key_qvector;
QVector<double> value_qvector;
#if 0
// Now replace the graph's data. Note that the data are
// inherently sorted (true below).
// The begin() -- end() ranges constructor did not work as of
// Qt 5.14.2 this day: 20200721
key_qvector =
QVector(keys.begin(),
keys.end());
value_qvector =
QVector(values.begin(),
values.end());
#endif
for(auto &value : keys)
key_qvector.push_back(value);
for(auto &value : values)
value_qvector.push_back(value);
graph_p->setData(key_qvector, value_qvector, true);
graph_p->setPen(m_pen);
rescaleAxes();
resetAxesRangeHistory();
replot();
}
pappso::BasePlotWidget::m_pen
QPen m_pen
Pen used to draw the graph and textual elements in the plot widget.
Definition baseplotwidget.h:356

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

{
if(graph_p == nullptr)
qFatal("Programming error. Pointer cannot be nullptr.");
pappso::Trace trace;
QSharedPointer<QCPGraphDataContainer> graph_data_container_p =
graph_p->data();
// Iterate in the keys
auto beginIt = graph_data_container_p->begin();
auto endIt = graph_data_container_p->end();
for(auto iter = beginIt; iter != endIt; ++iter)
trace.push_back(pappso::DataPoint(iter->key, iter->value));
return trace;
}
pappso::Trace
A simple container of DataPoint instances.
Definition trace.h:148
pappso::DataPoint
Definition datapoint.h:22

## toTrace() [2/4]

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

Definition at line 894 of file basetraceplotwidget.cpp.

{
// Make a Trace with the data in the range.
Trace data_trace;
QSharedPointer<QCPGraphDataContainer> graph_data_container_sp;
graph_data_container_sp = graph_p->data();
// Grab the iterator to the start to the x axis range
auto beginIt = graph_data_container_sp->findBegin(x_axis_range.lower,
/*expandedRange*/ true);
// Grab the iterator to the end of the axis range
auto endIt = graph_data_container_sp->findEnd(x_axis_range.upper,
/*expandedRange*/ true);
for(auto iter = beginIt; iter != endIt; ++iter)
data_trace.push_back(DataPoint(iter->key, iter->value));
return data_trace;
}

## toTrace() [3/4]

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

Definition at line 882 of file basetraceplotwidget.cpp.

{
QCPGraph *graph_p = graph(index);
if(graph_p == nullptr)
qFatal("Programming error.");
return toTrace(x_axis_range, graph_p);
}
pappso::BaseTracePlotWidget::toTrace
pappso::Trace toTrace(int index) const
Definition basetraceplotwidget.cpp:851

References toTrace().

## toTrace() [4/4]

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

Definition at line 851 of file basetraceplotwidget.cpp.

{
QCPGraph *graph_p = graph(index);
return toTrace(graph_p);
}

References toTrace().

Referenced by toTrace(), and toTrace().

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

- pappsomspp/widget/plotwidget/basetraceplotwidget.h
- pappsomspp/widget/plotwidget/basetraceplotwidget.cpp