QCPFinancial

Search for usage in LXR

Inheritance diagram for QCPFinancial:

Public Types

enum  ChartStyle { csOhlc , csCandlestick }
 
enum  WidthType { wtAbsolute , wtAxisRectRatio , wtPlotCoords }
 
- Public Types inherited from QObject
typedef  QObjectList
 

Public Member Functions

 QCPFinancial (QCPAxis *keyAxis, QCPAxis *valueAxis)
 
void addData (const QVector< double > &keys, const QVector< double > &open, const QVector< double > &high, const QVector< double > &low, const QVector< double > &close, bool alreadySorted=false)
 
void addData (double key, double open, double high, double low, double close)
 
QBrush brushNegative () const
 
QBrush brushPositive () const
 
ChartStyle chartStyle () const
 
QSharedPointer< QCPFinancialDataContainerdata () 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
 
QPen penNegative () const
 
QPen penPositive () const
 
virtual double selectTest (const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const override
 
virtual QCPDataSelection selectTestRect (const QRectF &rect, bool onlySelectable) const override
 
void setBrushNegative (const QBrush &brush)
 
void setBrushPositive (const QBrush &brush)
 
void setChartStyle (ChartStyle style)
 
void setData (const QVector< double > &keys, const QVector< double > &open, const QVector< double > &high, const QVector< double > &low, const QVector< double > &close, bool alreadySorted=false)
 
void setData (QSharedPointer< QCPFinancialDataContainer > data)
 
void setPenNegative (const QPen &pen)
 
void setPenPositive (const QPen &pen)
 
void setTwoColored (bool twoColored)
 
void setWidth (double width)
 
void setWidthType (WidthType widthType)
 
bool twoColored () const
 
double width () const
 
WidthType widthType () const
 
- Public Member Functions inherited from QCPAbstractPlottable1D< QCPFinancialData >
 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 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
 
- Public Member Functions inherited from QCPPlottableInterface1D

Static Public Member Functions

static QCPFinancialDataContainer timeSeriesToOhlc (const QVector< double > &time, const QVector< double > &value, double timeBinSize, double timeBinOffset=0)
 
- 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)
 

Protected Member Functions

double candlestickSelectTest (const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const
 
virtual void draw (QCPPainter *painter) override
 
void drawCandlestickPlot (QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected)
 
virtual void drawLegendIcon (QCPPainter *painter, const QRectF &rect) const override
 
void drawOhlcPlot (QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected)
 
double getPixelWidth (double key, double keyPixel) const
 
void getVisibleDataBounds (QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const
 
double ohlcSelectTest (const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const
 
QRectF selectionHitBox (QCPFinancialDataContainer::const_iterator it) const
 
- Protected Member Functions inherited from QCPAbstractPlottable1D< QCPFinancialData >
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

QBrush mBrushNegative
 
QBrush mBrushPositive
 
ChartStyle mChartStyle
 
QPen mPenNegative
 
QPen mPenPositive
 
bool mTwoColored
 
double mWidth
 
WidthType mWidthType
 
- Protected Attributes inherited from QCPAbstractPlottable1D< QCPFinancialData >
QSharedPointer< QCPDataContainer< QCPFinancialData > > 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)
 

Detailed Description

A plottable representing a financial stock chart.

This plottable represents time series data binned to certain intervals, mainly used for stock charts. The two common representations OHLC (Open-High-Low-Close) bars and Candlesticks can be set via setChartStyle.

The data is passed via setData as a set of open/high/low/close values at certain keys (typically times). This means the data must be already binned appropriately. If data is only available as a series of values (e.g. price against time), you can use the static convenience function timeSeriesToOhlc to generate binned OHLC-data which can then be passed to setData.

The width of the OHLC bars/candlesticks can be controlled with setWidth and setWidthType. A typical choice is to set the width type to wtPlotCoords (the default) and the width to (or slightly less than) one time bin interval width.

Changing the appearance

Charts can be either single- or two-colored (setTwoColored). If set to be single-colored, lines are drawn with the plottable's pen (setPen) and fills with the brush (setBrush).

If set to two-colored, positive changes of the value during an interval (close >= open) are represented with a different pen and brush than negative changes (close < open). These can be configured with setPenPositive, setPenNegative, setBrushPositive, and setBrushNegative. In two-colored mode, the normal plottable pen/brush is ignored. Upon selection however, the normal selected pen/brush (provided by the selectionDecorator) is used, irrespective of whether the chart is single- or two-colored.

Usage

Like all data representing objects in QCustomPlot, the QCPFinancial is a plottable (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies (QCustomPlot::plottable, QCustomPlot::removePlottable, etc.)

Usually, you first create an instance:

which registers it with the QCustomPlot instance of the passed axes. Note that this QCustomPlot instance takes ownership of the plottable, so do not delete it manually but use QCustomPlot::removePlottable() instead. The newly created plottable can be modified, e.g.:

Here we have used the static helper method timeSeriesToOhlc, to turn a time-price data series into a 24-hour binned open-high-low-close data series as QCPFinancial uses.

Definition at line 6189 of file qcustomplot.h.

Member Enumeration Documentation

◆ ChartStyle

Defines the possible representations of OHLC data in the plot.

See also
setChartStyle
Enumerator
csOhlc 

Open-High-Low-Close bar representation.

csCandlestick 

Candlestick representation.

Definition at line 6220 of file qcustomplot.h.

◆ WidthType

Defines the ways the width of the financial bar can be specified. Thus it defines what the number passed to setWidth actually means.

See also
setWidthType, setWidth
Enumerator
wtAbsolute 

width is in absolute pixels

wtAxisRectRatio 

width is given by a fraction of the axis rect size

wtPlotCoords 

width is in key coordinates and thus scales with the key axis range

Definition at line 6209 of file qcustomplot.h.

Constructor & Destructor Documentation

◆ QCPFinancial()

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

Constructs a financial chart 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 QCPFinancial is automatically registered with the QCustomPlot instance inferred from keyAxis. This QCustomPlot instance takes ownership of the QCPFinancial, so do not delete it manually but use QCustomPlot::removePlottable() instead.

Definition at line 27100 of file qcustomplot.cpp.

◆ ~QCPFinancial()

QCPFinancial::~QCPFinancial ( )
overridevirtual

Definition at line 27114 of file qcustomplot.cpp.

Member Function Documentation

◆ addData() [1/2]

void QCPFinancial::addData ( const QVector< double > & keys,
const QVector< double > & open,
const QVector< double > & high,
const QVector< double > & low,
const QVector< double > & close,
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, open, high, low and close 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.

See also
timeSeriesToOhlc

Definition at line 27270 of file qcustomplot.cpp.

◆ addData() [2/2]

void QCPFinancial::addData ( double key,
double open,
double high,
double low,
double close )

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, open, high, low and close 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.

See also
timeSeriesToOhlc

Definition at line 27302 of file qcustomplot.cpp.

◆ brushNegative()

QBrush QCPFinancial::brushNegative ( ) const
inline

Definition at line 6235 of file qcustomplot.h.

◆ brushPositive()

QBrush QCPFinancial::brushPositive ( ) const
inline

Definition at line 6234 of file qcustomplot.h.

◆ candlestickSelectTest()

double QCPFinancial::candlestickSelectTest ( const QPointF & pos,
const QCPFinancialDataContainer::const_iterator & begin,
const QCPFinancialDataContainer::const_iterator & end,
QCPFinancialDataContainer::const_iterator & closestDataPoint ) const
protected

This method is a helper function for selectTest. It is used to test for selection when the chart style is csCandlestick. It only tests against the data points between begin and end.

Like selectTest, this method returns the shortest distance of pos to the graphical representation of the plottable, and closestDataPoint will point to the respective data point.

Definition at line 27770 of file qcustomplot.cpp.

◆ chartStyle()

ChartStyle QCPFinancial::chartStyle ( ) const
inline

Definition at line 6230 of file qcustomplot.h.

◆ data()

QSharedPointer< QCPFinancialDataContainer > QCPFinancial::data ( ) const
inline

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

Definition at line 6229 of file qcustomplot.h.

◆ draw()

void QCPFinancial::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 27447 of file qcustomplot.cpp.

◆ drawCandlestickPlot()

void QCPFinancial::drawCandlestickPlot ( QCPPainter * painter,
const QCPFinancialDataContainer::const_iterator & begin,
const QCPFinancialDataContainer::const_iterator & end,
bool isSelected )
protected

Draws the data from begin to end-1 as Candlesticks with the provided painter.

This method is a helper function for draw. It is used when the chart style is csCandlestick.

Definition at line 27603 of file qcustomplot.cpp.

◆ drawLegendIcon()

void QCPFinancial::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 27482 of file qcustomplot.cpp.

◆ drawOhlcPlot()

void QCPFinancial::drawOhlcPlot ( QCPPainter * painter,
const QCPFinancialDataContainer::const_iterator & begin,
const QCPFinancialDataContainer::const_iterator & end,
bool isSelected )
protected

Draws the data from begin to end-1 as OHLC bars with the provided painter.

This method is a helper function for draw. It is used when the chart style is csOhlc.

Definition at line 27546 of file qcustomplot.cpp.

◆ getKeyRange()

QCPRange QCPFinancial::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 27373 of file qcustomplot.cpp.

◆ getPixelWidth()

double QCPFinancial::getPixelWidth ( double key,
double keyPixel ) const
protected

This function is used to determine the width of the bar at coordinate key, according to the specified width (setWidth) and width type (setWidthType). Provide the pixel position of key in keyPixel (because usually this was already calculated via QCPAxis::coordToPixel when this function is called).

It returns the number of pixels the bar extends to higher keys, relative to the key coordinate. So with a non-reversed horizontal axis, the return value is positive. With a reversed horizontal axis, the return value is negative. This is important so the open/close flags on the csOhlc bar are drawn to the correct side.

Definition at line 27680 of file qcustomplot.cpp.

◆ getValueRange()

QCPRange QCPFinancial::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 27388 of file qcustomplot.cpp.

◆ getVisibleDataBounds()

void QCPFinancial::getVisibleDataBounds ( QCPFinancialDataContainer::const_iterator & begin,
QCPFinancialDataContainer::const_iterator & end ) const
protected

called by the drawing methods to determine which data (key) range is visible at the current key axis range setting, so only that needs to be processed.

begin returns an iterator to the lowest data point that needs to be taken into account when plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, begin may still be just outside the visible range.

end returns the iterator just above the highest data point that needs to be taken into account. Same as before, end may also lie just outside of the visible range

if the plottable contains no data, both begin and end point to constEnd.

Definition at line 27850 of file qcustomplot.cpp.

◆ ohlcSelectTest()

double QCPFinancial::ohlcSelectTest ( const QPointF & pos,
const QCPFinancialDataContainer::const_iterator & begin,
const QCPFinancialDataContainer::const_iterator & end,
QCPFinancialDataContainer::const_iterator & closestDataPoint ) const
protected

This method is a helper function for selectTest. It is used to test for selection when the chart style is csOhlc. It only tests against the data points between begin and end.

Like selectTest, this method returns the shortest distance of pos to the graphical representation of the plottable, and closestDataPoint will point to the respective data point.

Definition at line 27723 of file qcustomplot.cpp.

◆ penNegative()

QPen QCPFinancial::penNegative ( ) const
inline

Definition at line 6237 of file qcustomplot.h.

◆ penPositive()

QPen QCPFinancial::penPositive ( ) const
inline

Definition at line 6236 of file qcustomplot.h.

◆ selectionHitBox()

QRectF QCPFinancial::selectionHitBox ( QCPFinancialDataContainer::const_iterator it) const
protected

Returns the hit box in pixel coordinates that will be used for data selection with the selection rect (selectTestRect), of the data point given by it.

Definition at line 27868 of file qcustomplot.cpp.

◆ selectTest()

double QCPFinancial::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< QCPFinancialData >.

Definition at line 27338 of file qcustomplot.cpp.

◆ selectTestRect()

QCPDataSelection QCPFinancial::selectTestRect ( const QRectF & rect,
bool onlySelectable ) const
overridevirtual

Returns a data selection containing all the data points of this plottable which are contained (or hit by) rect. This is used mainly in the selection rect interaction for data selection (data selection mechanism).

If onlySelectable is true, an empty QCPDataSelection is returned if this plottable is not selectable (i.e. if QCPAbstractPlottable::setSelectable is QCP::stNone).

Note
rect must be a normalized rect (positive or zero width and height). This is especially important when using the rect of QCPSelectionRect::accepted, which is not necessarily normalized. Use QRect::normalized() when passing a rect which might not be normalized.

Reimplemented from QCPAbstractPlottable1D< QCPFinancialData >.

Definition at line 27310 of file qcustomplot.cpp.

◆ setBrushNegative()

void QCPFinancial::setBrushNegative ( const QBrush & brush)

If setTwoColored is set to true, this function controls the brush that is used to draw fills of data points with a negative trend (i.e. bars/candlesticks with close < open).

If twoColored is false, the normal plottable's pen and brush are used (setPen, setBrush).

See also
setBrushPositive, setPenNegative, setPenPositive

Definition at line 27223 of file qcustomplot.cpp.

◆ setBrushPositive()

void QCPFinancial::setBrushPositive ( const QBrush & brush)

If setTwoColored is set to true, this function controls the brush that is used to draw fills of data points with a positive trend (i.e. bars/candlesticks with close >= open).

If twoColored is false, the normal plottable's pen and brush are used (setPen, setBrush).

See also
setBrushNegative, setPenPositive, setPenNegative

Definition at line 27209 of file qcustomplot.cpp.

◆ setChartStyle()

void QCPFinancial::setChartStyle ( QCPFinancial::ChartStyle style)

Sets which representation style shall be used to display the OHLC data.

Definition at line 27158 of file qcustomplot.cpp.

◆ setData() [1/2]

void QCPFinancial::setData ( const QVector< double > & keys,
const QVector< double > & open,
const QVector< double > & high,
const QVector< double > & low,
const QVector< double > & close,
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, open, high, low and close. 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, timeSeriesToOhlc

Definition at line 27149 of file qcustomplot.cpp.

◆ setData() [2/2]

void QCPFinancial::setData ( QSharedPointer< QCPFinancialDataContainer > 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 QCPFinancials may share the same data container safely. Modifying the data in the container will then affect all financials 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 financial's data container directly:

See also
addData, timeSeriesToOhlc

Definition at line 27133 of file qcustomplot.cpp.

◆ setPenNegative()

void QCPFinancial::setPenNegative ( const QPen & pen)

If setTwoColored is set to true, this function controls the pen that is used to draw outlines of data points with a negative trend (i.e. bars/candlesticks with close < open).

If twoColored is false, the normal plottable's pen and brush are used (setPen, setBrush).

See also
setPenPositive, setBrushNegative, setBrushPositive

Definition at line 27251 of file qcustomplot.cpp.

◆ setPenPositive()

void QCPFinancial::setPenPositive ( const QPen & pen)

If setTwoColored is set to true, this function controls the pen that is used to draw outlines of data points with a positive trend (i.e. bars/candlesticks with close >= open).

If twoColored is false, the normal plottable's pen and brush are used (setPen, setBrush).

See also
setPenNegative, setBrushPositive, setBrushNegative

Definition at line 27237 of file qcustomplot.cpp.

◆ setTwoColored()

void QCPFinancial::setTwoColored ( bool twoColored)

Sets whether this chart shall contrast positive from negative trends per data point by using two separate colors to draw the respective bars/candlesticks.

If twoColored is false, the normal plottable's pen and brush are used (setPen, setBrush).

See also
setPenPositive, setPenNegative, setBrushPositive, setBrushNegative

Definition at line 27195 of file qcustomplot.cpp.

◆ setWidth()

void QCPFinancial::setWidth ( double width)

Sets the width of the individual bars/candlesticks to width in plot key coordinates.

A typical choice is to set it to (or slightly less than) one bin interval width.

Definition at line 27168 of file qcustomplot.cpp.

◆ setWidthType()

void QCPFinancial::setWidthType ( QCPFinancial::WidthType widthType)

Sets how the width of the financial bars is defined. See the documentation of WidthType for an explanation of the possible values for widthType.

The default value is wtPlotCoords.

See also
setWidth

Definition at line 27181 of file qcustomplot.cpp.

◆ timeSeriesToOhlc()

QCPFinancialDataContainer QCPFinancial::timeSeriesToOhlc ( const QVector< double > & time,
const QVector< double > & value,
double timeBinSize,
double timeBinOffset = 0 )
static

A convenience function that converts time series data (value against time) to OHLC binned data points. The return value can then be passed on to QCPFinancialDataContainer::set(const QCPFinancialDataContainer&).

The size of the bins can be controlled with timeBinSize in the same units as time is given. For example, if the unit of time is seconds and single OHLC/Candlesticks should span an hour each, set timeBinSize to 3600.

timeBinOffset allows to control precisely at what time coordinate a bin should start. The value passed as timeBinOffset doesn't need to be in the range encompassed by the time keys. It merely defines the mathematical offset/phase of the bins that will be used to process the data.

Definition at line 27407 of file qcustomplot.cpp.

◆ twoColored()

bool QCPFinancial::twoColored ( ) const
inline

Definition at line 6233 of file qcustomplot.h.

◆ width()

double QCPFinancial::width ( ) const
inline

Definition at line 6231 of file qcustomplot.h.

◆ widthType()

WidthType QCPFinancial::widthType ( ) const
inline

Definition at line 6232 of file qcustomplot.h.

Member Data Documentation

◆ mBrushNegative

QBrush QCPFinancial::mBrushNegative
protected

Definition at line 6270 of file qcustomplot.h.

◆ mBrushPositive

QBrush QCPFinancial::mBrushPositive
protected

Definition at line 6270 of file qcustomplot.h.

◆ mChartStyle

ChartStyle QCPFinancial::mChartStyle
protected

Definition at line 6266 of file qcustomplot.h.

◆ mPenNegative

QPen QCPFinancial::mPenNegative
protected

Definition at line 6271 of file qcustomplot.h.

◆ mPenPositive

QPen QCPFinancial::mPenPositive
protected

Definition at line 6271 of file qcustomplot.h.

◆ mTwoColored

bool QCPFinancial::mTwoColored
protected

Definition at line 6269 of file qcustomplot.h.

◆ mWidth

double QCPFinancial::mWidth
protected

Definition at line 6267 of file qcustomplot.h.

◆ mWidthType

WidthType QCPFinancial::mWidthType
protected

Definition at line 6268 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 Mon Nov 4 2024 16:38:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.