QCPGraph

Search for usage in LXR

Inheritance diagram for QCPGraph:

Public Types

enum  LineStyle {
  lsNone , lsLine , lsStepLeft , lsStepRight ,
  lsStepCenter , lsImpulse
}
 

Public Member Functions

 QCPGraph (QCPAxis *keyAxis, QCPAxis *valueAxis)
 
bool adaptiveSampling () const
 
void addData (const QVector< double > &keys, const QVector< double > &values, bool alreadySorted=false)
 
void addData (double key, double value)
 
QCPGraphchannelFillGraph () const
 
QSharedPointer< QCPGraphDataContainerdata () const
 
virtual QCPRange getKeyRange (bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const override
 
virtual QCPRange getValueRange (bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const override
 
LineStyle lineStyle () const
 
int scatterSkip () const
 
QCPScatterStyle scatterStyle () const
 
virtual double selectTest (const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const override
 
void setAdaptiveSampling (bool enabled)
 
void setChannelFillGraph (QCPGraph *targetGraph)
 
void setData (const QVector< double > &keys, const QVector< double > &values, bool alreadySorted=false)
 
void setData (QSharedPointer< QCPGraphDataContainer > data)
 
void setLineStyle (LineStyle ls)
 
void setScatterSkip (int skip)
 
void setScatterStyle (const QCPScatterStyle &style)
 
- Public Member Functions inherited from QCPAbstractPlottable1D< QCPGraphData >
 QCPAbstractPlottable1D (QCPAxis *keyAxis, QCPAxis *valueAxis)
 
virtual int dataCount () const override
 
virtual double dataMainKey (int index) const override
 
virtual double dataMainValue (int index) const override
 
virtual QPointF dataPixelPosition (int index) const override
 
virtual double dataSortKey (int index) const override
 
virtual QCPRange dataValueRange (int index) const override
 
virtual int findBegin (double sortKey, bool expandedRange=true) const override
 
virtual int findEnd (double sortKey, bool expandedRange=true) const override
 
virtual QCPPlottableInterface1Dinterface1D () override
 
virtual QCPDataSelection selectTestRect (const QRectF &rect, bool onlySelectable) const override
 
virtual bool sortKeyIsMainKey () const override
 
- Public Member Functions inherited from QCPAbstractPlottable
 QCPAbstractPlottable (QCPAxis *keyAxis, QCPAxis *valueAxis)
 
bool addToLegend ()
 
bool addToLegend (QCPLegend *legend)
 
bool antialiasedFill () const
 
bool antialiasedScatters () const
 
QBrush brush () const
 
const QPointF coordsToPixels (double key, double value) const
 
void coordsToPixels (double key, double value, double &x, double &y) const
 
QCPAxiskeyAxis () const
 
QString name () const
 
QPen pen () const
 
void pixelsToCoords (const QPointF &pixelPos, double &key, double &value) const
 
void pixelsToCoords (double x, double y, double &key, double &value) const
 
bool removeFromLegend () const
 
bool removeFromLegend (QCPLegend *legend) const
 
void rescaleAxes (bool onlyEnlarge=false) const
 
void rescaleKeyAxis (bool onlyEnlarge=false) const
 
void rescaleValueAxis (bool onlyEnlarge=false, bool inKeyRange=false) const
 
QCP::SelectionType selectable () const
 
bool selected () const
 
QCPDataSelection selection () const
 
QCPSelectionDecoratorselectionDecorator () const
 
void setAntialiasedFill (bool enabled)
 
void setAntialiasedScatters (bool enabled)
 
void setBrush (const QBrush &brush)
 
void setKeyAxis (QCPAxis *axis)
 
void setName (const QString &name)
 
void setPen (const QPen &pen)
 
Q_SLOT void setSelectable (QCP::SelectionType selectable)
 
Q_SLOT void setSelection (QCPDataSelection selection)
 
void setSelectionDecorator (QCPSelectionDecorator *decorator)
 
void setValueAxis (QCPAxis *axis)
 
QCPAxisvalueAxis () const
 
- Public Member Functions inherited from QCPLayerable
 QCPLayerable (QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=nullptr)
 
bool antialiased () const
 
QCPLayerlayer () const
 
QCPLayerableparentLayerable () const
 
QCustomPlotparentPlot () const
 
bool realVisibility () const
 
void setAntialiased (bool enabled)
 
bool setLayer (const QString &layerName)
 
Q_SLOT bool setLayer (QCPLayer *layer)
 
void setVisible (bool on)
 
bool visible () const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
QBindable< QStringbindableObjectName ()
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo () const const
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isQuickItemType () const const
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_GADGET_EXPORT (EXPORT_MACRO)
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_MOC_INCLUDE Q_MOC_INCLUDE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setObjectName (QAnyStringView name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool setProperty (const char *name, QVariant &&value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds interval, Qt::TimerType timerType)
 
QThreadthread () const const
 

Protected Member Functions

QVector< QPointFdataToImpulseLines (const QVector< QCPGraphData > &data) const
 
QVector< QPointFdataToLines (const QVector< QCPGraphData > &data) const
 
QVector< QPointFdataToStepCenterLines (const QVector< QCPGraphData > &data) const
 
QVector< QPointFdataToStepLeftLines (const QVector< QCPGraphData > &data) const
 
QVector< QPointFdataToStepRightLines (const QVector< QCPGraphData > &data) const
 
virtual void draw (QCPPainter *painter) override
 
virtual void drawFill (QCPPainter *painter, QVector< QPointF > *lines) const
 
virtual void drawImpulsePlot (QCPPainter *painter, const QVector< QPointF > &lines) const
 
virtual void drawLegendIcon (QCPPainter *painter, const QRectF &rect) const override
 
virtual void drawLinePlot (QCPPainter *painter, const QVector< QPointF > &lines) const
 
virtual void drawScatterPlot (QCPPainter *painter, const QVector< QPointF > &scatters, const QCPScatterStyle &style) const
 
int findIndexAboveX (const QVector< QPointF > *data, double x) const
 
int findIndexAboveY (const QVector< QPointF > *data, double y) const
 
int findIndexBelowX (const QVector< QPointF > *data, double x) const
 
int findIndexBelowY (const QVector< QPointF > *data, double y) const
 
const QPolygonF getChannelFillPolygon (const QVector< QPointF > *thisData, QCPDataRange thisSegment, const QVector< QPointF > *otherData, QCPDataRange otherSegment) const
 
QPointF getFillBasePoint (QPointF matchingDataPoint) const
 
const QPolygonF getFillPolygon (const QVector< QPointF > *lineData, QCPDataRange segment) const
 
void getLines (QVector< QPointF > *lines, const QCPDataRange &dataRange) const
 
QVector< QCPDataRangegetNonNanSegments (const QVector< QPointF > *lineData, Qt::Orientation keyOrientation) const
 
virtual void getOptimizedLineData (QVector< QCPGraphData > *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const
 
virtual void getOptimizedScatterData (QVector< QCPGraphData > *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const
 
QVector< QPair< QCPDataRange, QCPDataRange > > getOverlappingSegments (QVector< QCPDataRange > thisSegments, const QVector< QPointF > *thisData, QVector< QCPDataRange > otherSegments, const QVector< QPointF > *otherData) const
 
void getScatters (QVector< QPointF > *scatters, const QCPDataRange &dataRange) const
 
void getVisibleDataBounds (QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const
 
double pointDistance (const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const
 
bool segmentsIntersect (double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const
 
- Protected Member Functions inherited from QCPAbstractPlottable1D< QCPGraphData >
void drawPolyline (QCPPainter *painter, const QVector< QPointF > &lineData) const
 
void getDataSegments (QList< QCPDataRange > &selectedSegments, QList< QCPDataRange > &unselectedSegments) const
 
- Protected Member Functions inherited from QCPAbstractPlottable
void applyDefaultAntialiasingHint (QCPPainter *painter) const override
 
void applyFillAntialiasingHint (QCPPainter *painter) const
 
void applyScattersAntialiasingHint (QCPPainter *painter) const
 
virtual QRect clipRect () const override
 
virtual void deselectEvent (bool *selectionStateChanged) override
 
virtual void selectEvent (QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) override
 
virtual QCP::Interaction selectionCategory () const override
 
- Protected Member Functions inherited from QCPLayerable
void applyAntialiasingHint (QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const
 
void initializeParentPlot (QCustomPlot *parentPlot)
 
virtual void mouseDoubleClickEvent (QMouseEvent *event, const QVariant &details)
 
virtual void mouseMoveEvent (QMouseEvent *event, const QPointF &startPos)
 
virtual void mousePressEvent (QMouseEvent *event, const QVariant &details)
 
virtual void mouseReleaseEvent (QMouseEvent *event, const QPointF &startPos)
 
bool moveToLayer (QCPLayer *layer, bool prepend)
 
virtual void parentPlotInitialized (QCustomPlot *parentPlot)
 
void setParentLayerable (QCPLayerable *parentLayerable)
 
virtual void wheelEvent (QWheelEvent *event)
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Protected Attributes

bool mAdaptiveSampling
 
QPointer< QCPGraphmChannelFillGraph
 
LineStyle mLineStyle
 
int mScatterSkip
 
QCPScatterStyle mScatterStyle
 
- Protected Attributes inherited from QCPAbstractPlottable1D< QCPGraphData >
QSharedPointer< QCPDataContainer< QCPGraphData > > mDataContainer
 
- Protected Attributes inherited from QCPAbstractPlottable
bool mAntialiasedFill
 
bool mAntialiasedScatters
 
QBrush mBrush
 
QPointer< QCPAxismKeyAxis
 
QString mName
 
QPen mPen
 
QCP::SelectionType mSelectable
 
QCPDataSelection mSelection
 
QCPSelectionDecoratormSelectionDecorator
 
QPointer< QCPAxismValueAxis
 
- Protected Attributes inherited from QCPLayerable
bool mAntialiased
 
QCPLayermLayer
 
QPointer< QCPLayerablemParentLayerable
 
QCustomPlotmParentPlot
 
bool mVisible
 

Additional Inherited Members

- Properties inherited from QObject
 objectName
 
- Signals inherited from QCPAbstractPlottable
void selectableChanged (QCP::SelectionType selectable)
 
void selectionChanged (bool selected)
 
void selectionChanged (const QCPDataSelection &selection)
 
- Signals inherited from QCPLayerable
void layerChanged (QCPLayer *newLayer)
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
- Public Attributes inherited from QObject
typedef QObjectList
 

Detailed Description

A plottable representing a graph in a plot.

Usually you create new graphs by calling QCustomPlot::addGraph. The resulting instance can be accessed via QCustomPlot::graph.

To plot data, assign it with the setData or addData functions. Alternatively, you can also access and modify the data via the data method, which returns a pointer to the internal QCPGraphDataContainer.

Graphs are used to display single-valued data. Single-valued means that there should only be one data point per unique key coordinate. In other words, the graph can't have loops. If you do want to plot non-single-valued curves, rather use the QCPCurve plottable.

Gaps in the graph line can be created by adding data points with NaN as value (qQNaN() or std::numeric_limits<double>::quiet_NaN()) in between the two data points that shall be separated.

Changing the appearance

The appearance of the graph is mainly determined by the line style, scatter style, brush and pen of the graph (setLineStyle, setScatterStyle, setBrush, setPen).

Filling under or between graphs

QCPGraph knows two types of fills: Normal graph fills towards the zero-value-line parallel to the key axis of the graph, and fills between two graphs, called channel fills. To enable a fill, just set a brush with setBrush which is neither Qt::NoBrush nor fully transparent.

By default, a normal fill towards the zero-value-line will be drawn. To set up a channel fill between this graph and another one, call setChannelFillGraph with the other graph as parameter.

See also
QCustomPlot::addGraph, QCustomPlot::graph

Definition at line 5436 of file qcustomplot.h.

Member Enumeration Documentation

◆ LineStyle

Defines how the graph's line is represented visually in the plot. The line is drawn with the current pen of the graph (setPen).

See also
setLineStyle
Enumerator
lsNone 

data points are not connected with any lines (e.g.

data only represented with symbols according to the scatter style, see setScatterStyle)

lsLine 

data points are connected by a straight line

lsStepLeft 

line is drawn as steps where the step height is the value of the left data point

lsStepRight 

line is drawn as steps where the step height is the value of the right data point

lsStepCenter 

line is drawn as steps where the step is in between two data points

lsImpulse 

each data point is represented by a line parallel to the value axis, which reaches from the data point to the zero-value-line

Definition at line 5452 of file qcustomplot.h.

Constructor & Destructor Documentation

◆ QCPGraph()

QCPGraph::QCPGraph ( QCPAxis * keyAxis,
QCPAxis * valueAxis )
explicit

Constructs a graph which uses keyAxis as its key axis ("x") and valueAxis as its value axis ("y"). keyAxis and valueAxis must reside in the same QCustomPlot instance and not have the same orientation. If either of these restrictions is violated, a corresponding message is printed to the debug output (qDebug), the construction is not aborted, though.

The created QCPGraph is automatically registered with the QCustomPlot instance inferred from keyAxis. This QCustomPlot instance takes ownership of the QCPGraph, so do not delete it manually but use QCustomPlot::removePlottable() instead.

To directly create a graph inside a plot, you can also use the simpler QCustomPlot::addGraph function.

Definition at line 20875 of file qcustomplot.cpp.

◆ ~QCPGraph()

QCPGraph::~QCPGraph ( )
overridevirtual

Definition at line 20893 of file qcustomplot.cpp.

Member Function Documentation

◆ adaptiveSampling()

bool QCPGraph::adaptiveSampling ( ) const
inline

Definition at line 5471 of file qcustomplot.h.

◆ addData() [1/2]

void QCPGraph::addData ( const QVector< double > & keys,
const QVector< double > & values,
bool alreadySorted = false )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Adds the provided points in keys and values to the current data. The provided vectors should have equal length. Else, the number of added points will be the size of the smallest vector.

If you can guarantee that the passed data points are sorted by keys in ascending order, you can set alreadySorted to true, to improve performance by saving a sorting run.

Alternatively, you can also access and modify the data directly via the data method, which returns a pointer to the internal data container.

Definition at line 21049 of file qcustomplot.cpp.

◆ addData() [2/2]

void QCPGraph::addData ( double key,
double value )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Adds the provided data point as key and value to the current data.

Alternatively, you can also access and modify the data directly via the data method, which returns a pointer to the internal data container.

Definition at line 21075 of file qcustomplot.cpp.

◆ channelFillGraph()

QCPGraph * QCPGraph::channelFillGraph ( ) const
inline

Definition at line 5470 of file qcustomplot.h.

◆ data()

QSharedPointer< QCPGraphDataContainer > QCPGraph::data ( ) const
inline

Returns a shared pointer to the internal data storage of type QCPGraphDataContainer. You may use it to directly manipulate the data, which may be more convenient and faster than using the regular setData or addData methods.

Definition at line 5466 of file qcustomplot.h.

◆ dataToImpulseLines()

QVector< QPointF > QCPGraph::dataToImpulseLines ( const QVector< QCPGraphData > & data) const
protected

Takes raw data points in plot coordinates as data, and returns a vector containing pixel coordinate points which are suitable for drawing the line style lsImpulse.

The source of data is usually getOptimizedLineData, and this method is called in getLines if the line style is set accordingly.

See also
dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, getLines, drawImpulsePlot

Definition at line 21534 of file qcustomplot.cpp.

◆ dataToLines()

QVector< QPointF > QCPGraph::dataToLines ( const QVector< QCPGraphData > & data) const
protected

Takes raw data points in plot coordinates as data, and returns a vector containing pixel coordinate points which are suitable for drawing the line style lsLine.

The source of data is usually getOptimizedLineData, and this method is called in getLines if the line style is set accordingly.

See also
dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot

Definition at line 21340 of file qcustomplot.cpp.

◆ dataToStepCenterLines()

QVector< QPointF > QCPGraph::dataToStepCenterLines ( const QVector< QCPGraphData > & data) const
protected

Takes raw data points in plot coordinates as data, and returns a vector containing pixel coordinate points which are suitable for drawing the line style lsStepCenter.

The source of data is usually getOptimizedLineData, and this method is called in getLines if the line style is set accordingly.

See also
dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToImpulseLines, getLines, drawLinePlot

Definition at line 21474 of file qcustomplot.cpp.

◆ dataToStepLeftLines()

QVector< QPointF > QCPGraph::dataToStepLeftLines ( const QVector< QCPGraphData > & data) const
protected

Takes raw data points in plot coordinates as data, and returns a vector containing pixel coordinate points which are suitable for drawing the line style lsStepLeft.

The source of data is usually getOptimizedLineData, and this method is called in getLines if the line style is set accordingly.

See also
dataToLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot

Definition at line 21378 of file qcustomplot.cpp.

◆ dataToStepRightLines()

QVector< QPointF > QCPGraph::dataToStepRightLines ( const QVector< QCPGraphData > & data) const
protected

Takes raw data points in plot coordinates as data, and returns a vector containing pixel coordinate points which are suitable for drawing the line style lsStepRight.

The source of data is usually getOptimizedLineData, and this method is called in getLines if the line style is set accordingly.

See also
dataToLines, dataToStepLeftLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot

Definition at line 21426 of file qcustomplot.cpp.

◆ draw()

void QCPGraph::draw ( QCPPainter * painter)
overrideprotectedvirtual

This function draws the layerable with the specified painter. It is only called by QCustomPlot, if the layerable is visible (setVisible).

Before this function is called, the painter's antialiasing state is set via applyDefaultAntialiasingHint, see the documentation there. Further, the clipping rectangle was set to clipRect.

Implements QCPAbstractPlottable.

Definition at line 21122 of file qcustomplot.cpp.

◆ drawFill()

void QCPGraph::drawFill ( QCPPainter * painter,
QVector< QPointF > * lines ) const
protectedvirtual

Draws the fill of the graph using the specified painter, with the currently set brush.

Depending on whether a normal fill or a channel fill (setChannelFillGraph) is needed, getFillPolygon or getChannelFillPolygon are used to find the according fill polygons.

In order to handle NaN Data points correctly (the fill needs to be split into disjoint areas), this method first determines a list of non-NaN segments with getNonNanSegments, on which to operate. In the channel fill case, getOverlappingSegments is used to consolidate the non-NaN segments of the two involved graphs, before passing the overlapping pairs to getChannelFillPolygon.

Pass the points of this graph's line as lines, in pixel coordinates.

See also
drawLinePlot, drawImpulsePlot, drawScatterPlot

Definition at line 21585 of file qcustomplot.cpp.

◆ drawImpulsePlot()

void QCPGraph::drawImpulsePlot ( QCPPainter * painter,
const QVector< QPointF > & lines ) const
protectedvirtual

Draws impulses from the provided data, i.e. it connects all line pairs in lines, given in pixel coordinates. The lines necessary for impulses are generated by dataToImpulseLines from the regular graph data points.

See also
drawLinePlot, drawScatterPlot

Definition at line 21650 of file qcustomplot.cpp.

◆ drawLegendIcon()

void QCPGraph::drawLegendIcon ( QCPPainter * painter,
const QRectF & rect ) const
overrideprotectedvirtual

called by QCPLegend::draw (via QCPPlottableLegendItem::draw) to create a graphical representation of this plottable inside rect, next to the plottable name.

The passed painter has its cliprect set to rect, so painting outside of rect won't appear outside the legend icon border.

Implements QCPAbstractPlottable.

Definition at line 21190 of file qcustomplot.cpp.

◆ drawLinePlot()

void QCPGraph::drawLinePlot ( QCPPainter * painter,
const QVector< QPointF > & lines ) const
protectedvirtual

Draws lines between the points in lines, given in pixel coordinates.

See also
drawScatterPlot, drawImpulsePlot, QCPAbstractPlottable1D::drawPolyline

Definition at line 21633 of file qcustomplot.cpp.

◆ drawScatterPlot()

void QCPGraph::drawScatterPlot ( QCPPainter * painter,
const QVector< QPointF > & scatters,
const QCPScatterStyle & style ) const
protectedvirtual

Draws scatter symbols at every point passed in scatters, given in pixel coordinates. The scatters will be drawn with painter and have the appearance as specified in style.

See also
drawLinePlot, drawImpulsePlot

Definition at line 21619 of file qcustomplot.cpp.

◆ findIndexAboveX()

int QCPGraph::findIndexAboveX ( const QVector< QPointF > * data,
double x ) const
protected

Finds the smallest index of data, whose points x value is just above x. Assumes x values in data points are ordered ascending, as is ensured by getLines/ getScatters if the key axis is horizontal.

Used to calculate the channel fill polygon, see getChannelFillPolygon.

Definition at line 22330 of file qcustomplot.cpp.

◆ findIndexAboveY()

int QCPGraph::findIndexAboveY ( const QVector< QPointF > * data,
double y ) const
protected

Finds the smallest index of data, whose points y value is just above y. Assumes y values in data points are ordered ascending, as is ensured by getLines/ getScatters if the key axis is vertical.

Used to calculate the channel fill polygon, see getChannelFillPolygon.

Definition at line 22376 of file qcustomplot.cpp.

◆ findIndexBelowX()

int QCPGraph::findIndexBelowX ( const QVector< QPointF > * data,
double x ) const
protected

Finds the highest index of data, whose points x value is just below x. Assumes x values in data points are ordered ascending, as is ensured by getLines/ getScatters if the key axis is horizontal.

Used to calculate the channel fill polygon, see getChannelFillPolygon.

Definition at line 22353 of file qcustomplot.cpp.

◆ findIndexBelowY()

int QCPGraph::findIndexBelowY ( const QVector< QPointF > * data,
double y ) const
protected

Finds the highest index of data, whose points y value is just below y. Assumes y values in data points are ordered ascending, as is ensured by getLines/ getScatters if the key axis is vertical.

Used to calculate the channel fill polygon, see getChannelFillPolygon.

Definition at line 22458 of file qcustomplot.cpp.

◆ getChannelFillPolygon()

const QPolygonF QCPGraph::getChannelFillPolygon ( const QVector< QPointF > * thisData,
QCPDataRange thisSegment,
const QVector< QPointF > * otherData,
QCPDataRange otherSegment ) const
protected

Returns the polygon needed for drawing (partial) channel fills between this graph and the graph specified by setChannelFillGraph.

The data points of this graph are passed as pixel coordinates via thisData, the data of the other graph as otherData. The returned polygon will be calculated for the specified data segments thisSegment and otherSegment, pertaining to the respective thisData and otherData, respectively.

The passed thisSegment and otherSegment should correspond to the segment pairs returned by getOverlappingSegments, to make sure only segments that actually have key coordinate overlap need to be processed here.

For increased performance due to implicit sharing, keep the returned QPolygonF const.

See also
drawFill, getOverlappingSegments, getNonNanSegments

Definition at line 22223 of file qcustomplot.cpp.

◆ getFillBasePoint()

QPointF QCPGraph::getFillBasePoint ( QPointF matchingDataPoint) const
protected

Returns the point which closes the fill polygon on the zero-value-line parallel to the key axis. The logarithmic axis scale case is a bit special, since the zero-value-line in pixel coordinates is in positive or negative infinity. So this case is handled separately by just closing the fill polygon on the axis which lies in the direction towards the zero value.

matchingDataPoint will provide the key (in pixels) of the returned point. Depending on whether the key axis of this graph is horizontal or vertical, matchingDataPoint will provide the x or y value of the returned point, respectively.

Definition at line 22133 of file qcustomplot.cpp.

◆ getFillPolygon()

const QPolygonF QCPGraph::getFillPolygon ( const QVector< QPointF > * lineData,
QCPDataRange segment ) const
protected

Returns the polygon needed for drawing normal fills between this graph and the key axis.

Pass the graph's data points (in pixel coordinates) as lineData, and specify the segment which shall be used for the fill. The collection of lineData points described by segment must not contain NaN data points (see getNonNanSegments).

The returned fill polygon will be closed at the key axis (the zero-value line) for linear value axes. For logarithmic value axes the polygon will reach just beyond the corresponding axis rect side (see getFillBasePoint).

For increased performance (due to implicit sharing), keep the returned QPolygonF const.

See also
drawFill, getNonNanSegments

Definition at line 22192 of file qcustomplot.cpp.

◆ getKeyRange()

QCPRange QCPGraph::getKeyRange ( bool & foundRange,
QCP::SignDomain inSignDomain = QCP::sdBoth ) const
overridevirtual

Returns the coordinate range that all data in this plottable span in the key axis dimension. For logarithmic plots, one can set inSignDomain to either QCP::sdNegative or QCP::sdPositive in order to restrict the returned range to that sign domain. E.g. when only negative range is wanted, set inSignDomain to QCP::sdNegative and all positive points will be ignored for range calculation. For no restriction, just set inSignDomain to QCP::sdBoth (default). foundRange is an output parameter that indicates whether a range could be found or not. If this is false, you shouldn't use the returned range (e.g. no points in data).

Note that foundRange is not the same as QCPRange::validRange, since the range returned by this function may have size zero (e.g. when there is only one data point). In this case foundRange would return true, but the returned range is not a valid range in terms of QCPRange::validRange.

See also
rescaleAxes, getValueRange

Implements QCPAbstractPlottable.

Definition at line 21110 of file qcustomplot.cpp.

◆ getLines()

void QCPGraph::getLines ( QVector< QPointF > * lines,
const QCPDataRange & dataRange ) const
protected

This method retrieves an optimized set of data points via getOptimizedLineData, and branches out to the line style specific functions such as dataToLines, dataToStepLeftLines, etc. according to the line style of the graph.

lines will be filled with points in pixel coordinates, that can be drawn with the according draw functions like drawLinePlot and drawImpulsePlot. The points returned in lines aren't necessarily the original data points. For example, step line styles require additional points to form the steps when drawn. If the line style of the graph is lsNone, the lines vector will be empty.

dataRange specifies the beginning and ending data indices that will be taken into account for conversion. In this function, the specified range may exceed the total data bounds without harm: a correspondingly trimmed data range will be used. This takes the burden off the user of this function to check for valid indices in dataRange, e.g. when extending ranges coming from getDataSegments.

See also
getScatters

Definition at line 21244 of file qcustomplot.cpp.

◆ getNonNanSegments()

QVector< QCPDataRange > QCPGraph::getNonNanSegments ( const QVector< QPointF > * lineData,
Qt::Orientation keyOrientation ) const
protected

This method goes through the passed points in lineData and returns a list of the segments which don't contain NaN data points.

keyOrientation defines whether the x or y member of the passed QPointF is used to check for NaN. If keyOrientation is Qt::Horizontal, the y member is checked, if it is Qt::Vertical, the x member is checked.

See also
getOverlappingSegments, drawFill

Definition at line 21979 of file qcustomplot.cpp.

◆ getOptimizedLineData()

void QCPGraph::getOptimizedLineData ( QVector< QCPGraphData > * lineData,
const QCPGraphDataContainer::const_iterator & begin,
const QCPGraphDataContainer::const_iterator & end ) const
protectedvirtual

Returns via lineData the data points that need to be visualized for this graph when plotting graph lines, taking into consideration the currently visible axis ranges and, if setAdaptiveSampling is enabled, local point densities. The considered data can be restricted further by begin and end, e.g. to only plot a certain segment of the data (see getDataSegments).

This method is used by getLines to retrieve the basic working set of data.

See also
getOptimizedScatterData

Definition at line 21676 of file qcustomplot.cpp.

◆ getOptimizedScatterData()

void QCPGraph::getOptimizedScatterData ( QVector< QCPGraphData > * scatterData,
QCPGraphDataContainer::const_iterator begin,
QCPGraphDataContainer::const_iterator end ) const
protectedvirtual

Returns via scatterData the data points that need to be visualized for this graph when plotting scatter points, taking into consideration the currently visible axis ranges and, if setAdaptiveSampling is enabled, local point densities. The considered data can be restricted further by begin and end, e.g. to only plot a certain segment of the data (see getDataSegments).

This method is used by getScatters to retrieve the basic working set of data.

See also
getOptimizedLineData

Definition at line 21768 of file qcustomplot.cpp.

◆ getOverlappingSegments()

QVector< QPair< QCPDataRange, QCPDataRange > > QCPGraph::getOverlappingSegments ( QVector< QCPDataRange > thisSegments,
const QVector< QPointF > * thisData,
QVector< QCPDataRange > otherSegments,
const QVector< QPointF > * otherData ) const
protected

This method takes two segment lists (e.g. created by getNonNanSegments) thisSegments and otherSegments, and their associated point data thisData and otherData.

It returns all pairs of segments (the first from thisSegments, the second from otherSegments), which overlap in plot coordinates.

This method is useful in the case of a channel fill between two graphs, when only those non-NaN segments which actually overlap in their key coordinate shall be considered for drawing a channel fill polygon.

It is assumed that the passed segments in thisSegments are ordered ascending by index, and that the segments don't overlap themselves. The same is assumed for the segments in otherSegments. This is fulfilled when the segments are obtained via getNonNanSegments.

See also
getNonNanSegments, segmentsIntersect, drawFill, getChannelFillPolygon

Definition at line 22037 of file qcustomplot.cpp.

◆ getScatters()

void QCPGraph::getScatters ( QVector< QPointF > * scatters,
const QCPDataRange & dataRange ) const
protected

This method retrieves an optimized set of data points via getOptimizedScatterData and then converts them to pixel coordinates. The resulting points are returned in scatters, and can be passed to drawScatterPlot.

dataRange specifies the beginning and ending data indices that will be taken into account for conversion. In this function, the specified range may exceed the total data bounds without harm: a correspondingly trimmed data range will be used. This takes the burden off the user of this function to check for valid indices in dataRange, e.g. when extending ranges coming from getDataSegments.

Definition at line 21285 of file qcustomplot.cpp.

◆ getValueRange()

QCPRange QCPGraph::getValueRange ( bool & foundRange,
QCP::SignDomain inSignDomain = QCP::sdBoth,
const QCPRange & inKeyRange = QCPRange() ) const
overridevirtual

Returns the coordinate range that the data points in the specified key range (inKeyRange) span in the value axis dimension. For logarithmic plots, one can set inSignDomain to either QCP::sdNegative or QCP::sdPositive in order to restrict the returned range to that sign domain. E.g. when only negative range is wanted, set inSignDomain to QCP::sdNegative and all positive points will be ignored for range calculation. For no restriction, just set inSignDomain to QCP::sdBoth (default). foundRange is an output parameter that indicates whether a range could be found or not. If this is false, you shouldn't use the returned range (e.g. no points in data).

If inKeyRange has both lower and upper bound set to zero (is equal to QCPRange()), all data points are considered, without any restriction on the keys.

Note that foundRange is not the same as QCPRange::validRange, since the range returned by this function may have size zero (e.g. when there is only one data point). In this case foundRange would return true, but the returned range is not a valid range in terms of QCPRange::validRange.

See also
rescaleAxes, getKeyRange

Implements QCPAbstractPlottable.

Definition at line 21116 of file qcustomplot.cpp.

◆ getVisibleDataBounds()

void QCPGraph::getVisibleDataBounds ( QCPGraphDataContainer::const_iterator & begin,
QCPGraphDataContainer::const_iterator & end,
const QCPDataRange & rangeRestriction ) const
protected

This method outputs the currently visible data range via begin and end. The returned range will also never exceed rangeRestriction.

This method takes into account that the drawing of data lines at the axis rect border always requires the points just outside the visible axis range. So begin and end may actually indicate a range that contains one additional data point to the left and right of the visible axis range.

Definition at line 21949 of file qcustomplot.cpp.

◆ lineStyle()

LineStyle QCPGraph::lineStyle ( ) const
inline

Definition at line 5467 of file qcustomplot.h.

◆ pointDistance()

double QCPGraph::pointDistance ( const QPointF & pixelPoint,
QCPGraphDataContainer::const_iterator & closestData ) const
protected

Calculates the minimum distance in pixels the graph's representation has from the given pixelPoint. This is used to determine whether the graph was clicked or not, e.g. in selectTest. The closest data point to pixelPoint is returned in closestData. Note that if the graph has a line representation, the returned distance may be smaller than the distance to the closestData point, since the distance to the graph line is also taken into account.

If either the graph has no data or if the line style is lsNone and the scatter style's shape is QCPScatterStyle::ssNone (i.e. there is no visual representation of the graph), returns -1.0.

Definition at line 22402 of file qcustomplot.cpp.

◆ scatterSkip()

int QCPGraph::scatterSkip ( ) const
inline

Definition at line 5469 of file qcustomplot.h.

◆ scatterStyle()

QCPScatterStyle QCPGraph::scatterStyle ( ) const
inline

Definition at line 5468 of file qcustomplot.h.

◆ segmentsIntersect()

bool QCPGraph::segmentsIntersect ( double aLower,
double aUpper,
double bLower,
double bUpper,
int & bPrecedence ) const
protected

Returns whether the segments defined by the coordinates (aLower, aUpper) and (bLower, bUpper) have overlap.

The output parameter bPrecedence indicates whether the b segment reaches farther than the a segment or not. If bPrecedence returns 1, segment b reaches the farthest to higher coordinates (i.e. bUpper > aUpper). If it returns -1, segment a reaches the farthest. Only if both segment's upper bounds are identical, 0 is returned as bPrecedence.

It is assumed that the lower bounds always have smaller or equal values than the upper bounds.

See also
getOverlappingSegments

Definition at line 22100 of file qcustomplot.cpp.

◆ selectTest()

double QCPGraph::selectTest ( const QPointF & pos,
bool onlySelectable,
QVariant * details = nullptr ) const
overridevirtual

Implements a selectTest specific to this plottable's point geometry.

If details is not 0, it will be set to a QCPDataSelection, describing the closest data point to pos.

\seebaseclassmethod QCPAbstractPlottable::selectTest

Reimplemented from QCPAbstractPlottable1D< QCPGraphData >.

Definition at line 21088 of file qcustomplot.cpp.

◆ setAdaptiveSampling()

void QCPGraph::setAdaptiveSampling ( bool enabled)

Sets whether adaptive sampling shall be used when plotting this graph. QCustomPlot's adaptive sampling technique can drastically improve the replot performance for graphs with a larger number of points (e.g. above 10,000), without notably changing the appearance of the graph.

By default, adaptive sampling is enabled. Even if enabled, QCustomPlot decides whether adaptive sampling shall actually be used on a per-graph basis. So leaving adaptive sampling enabled has no disadvantage in almost all cases.

A line plot of 500,000 points without and with adaptive sampling

As can be seen, line plots experience no visual degradation from adaptive sampling. Outliers are reproduced reliably, as well as the overall shape of the data set. The replot time reduces dramatically though. This allows QCustomPlot to display large amounts of data in realtime.

A scatter plot of 100,000 points without and with adaptive sampling

Care must be taken when using high-density scatter plots in combination with adaptive sampling. The adaptive sampling algorithm treats scatter plots more carefully than line plots which still gives a significant reduction of replot times, but not quite as much as for line plots. This is because scatter plots inherently need more data points to be preserved in order to still resemble the original, non-adaptive-sampling plot. As shown above, the results still aren't quite identical, as banding occurs for the outer data points. This is in fact intentional, such that the boundaries of the data cloud stay visible to the viewer. How strong the banding appears, depends on the point density, i.e. the number of points in the plot.

For some situations with scatter plots it might thus be desirable to manually turn adaptive sampling off. For example, when saving the plot to disk. This can be achieved by setting enabled to false before issuing a command like QCustomPlot::savePng, and setting enabled back to true afterwards.

Definition at line 21032 of file qcustomplot.cpp.

◆ setChannelFillGraph()

void QCPGraph::setChannelFillGraph ( QCPGraph * targetGraph)

Sets the target graph for filling the area between this graph and targetGraph with the current brush (setBrush).

When targetGraph is set to 0, a normal graph fill to the zero-value-line will be shown. To disable any filling, set the brush to Qt::NoBrush.

See also
setBrush

Definition at line 20981 of file qcustomplot.cpp.

◆ setData() [1/2]

void QCPGraph::setData ( const QVector< double > & keys,
const QVector< double > & values,
bool alreadySorted = false )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Replaces the current data with the provided points in keys and values. The provided vectors should have equal length. Else, the number of added points will be the size of the smallest vector.

If you can guarantee that the passed data points are sorted by keys in ascending order, you can set alreadySorted to true, to improve performance by saving a sorting run.

See also
addData

Definition at line 20928 of file qcustomplot.cpp.

◆ setData() [2/2]

void QCPGraph::setData ( QSharedPointer< QCPGraphDataContainer > data)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Replaces the current data container with the provided data container.

Since a QSharedPointer is used, multiple QCPGraphs may share the same data container safely. Modifying the data in the container will then affect all graphs that share the container. Sharing can be achieved by simply exchanging the data containers wrapped in shared pointers:

If you do not wish to share containers, but create a copy from an existing container, rather use the QCPDataContainer<DataType>::set method on the graph's data container directly:

See also
addData

Definition at line 20912 of file qcustomplot.cpp.

◆ setLineStyle()

void QCPGraph::setLineStyle ( LineStyle ls)

Sets how the single data points are connected in the plot. For scatter-only plots, set ls to lsNone and setScatterStyle to the desired scatter style.

See also
setScatterStyle

Definition at line 20940 of file qcustomplot.cpp.

◆ setScatterSkip()

void QCPGraph::setScatterSkip ( int skip)

If scatters are displayed (scatter style not QCPScatterStyle::ssNone), skip number of scatter points are skipped/not drawn after every drawn scatter point.

This can be used to make the data appear sparser while for example still having a smooth line, and to improve performance for very high density plots.

If skip is set to 0 (default), all scatter points are drawn.

See also
setScatterStyle

Definition at line 20967 of file qcustomplot.cpp.

◆ setScatterStyle()

void QCPGraph::setScatterStyle ( const QCPScatterStyle & style)

Sets the visual appearance of single data points in the plot. If set to QCPScatterStyle::ssNone, no scatter points are drawn (e.g. for line-only-plots with appropriate line style).

See also
QCPScatterStyle, setLineStyle

Definition at line 20951 of file qcustomplot.cpp.

Member Data Documentation

◆ mAdaptiveSampling

bool QCPGraph::mAdaptiveSampling
protected

Definition at line 5497 of file qcustomplot.h.

◆ mChannelFillGraph

QPointer<QCPGraph> QCPGraph::mChannelFillGraph
protected

Definition at line 5496 of file qcustomplot.h.

◆ mLineStyle

LineStyle QCPGraph::mLineStyle
protected

Definition at line 5493 of file qcustomplot.h.

◆ mScatterSkip

int QCPGraph::mScatterSkip
protected

Definition at line 5495 of file qcustomplot.h.

◆ mScatterStyle

QCPScatterStyle QCPGraph::mScatterStyle
protected

Definition at line 5494 of file qcustomplot.h.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:59:53 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.