Main Page · Class Overview · Hierarchy · All Classes
Public Types | Public Functions | Public Members | Signals | Protected Functions
QCPItemTracer Class Reference

Item that sticks to QCPGraph data points. More...

Inheritance diagram for QCPItemTracer:
Inheritance graph

Public Types

enum  TracerStyle

Public Functions

 QCPItemTracer (QCustomPlot *parentPlot)
QPen pen () const
QPen selectedPen () const
QBrush brush () const
QBrush selectedBrush () const
double size () const
TracerStyle style () const
QCPGraphgraph () const
double graphKey () const
bool interpolating () const
void setPen (const QPen &pen)
void setSelectedPen (const QPen &pen)
void setBrush (const QBrush &brush)
void setSelectedBrush (const QBrush &brush)
void setSize (double size)
void setStyle (TracerStyle style)
void setGraph (QCPGraph *graph)
void setGraphKey (double key)
void setInterpolating (bool enabled)
virtual double selectTest (const QPointF &pos) const
void updatePosition ()
bool clipToAxisRect () const
QCPAxisclipKeyAxis () const
QCPAxisclipValueAxis () const
bool selectable () const
bool selected () const
void setClipToAxisRect (bool clip)
void setClipAxes (QCPAxis *keyAxis, QCPAxis *valueAxis)
void setClipKeyAxis (QCPAxis *axis)
void setClipValueAxis (QCPAxis *axis)
void setSelectable (bool selectable)
void setSelected (bool selected)
QList< QCPItemPosition * > positions () const
QList< QCPItemAnchor * > anchors () const
QCPItemPositionposition (const QString &name) const
QCPItemAnchoranchor (const QString &name) const
bool hasAnchor (const QString &name) const
bool visible () const
QCustomPlotparentPlot () const
QCPLayerlayer () const
bool antialiased () const
void setVisible (bool on)
bool setLayer (QCPLayer *layer)
bool setLayer (const QString &layerName)
void setAntialiased (bool enabled)

Public Members

QCPItemPosition *const position

Signals

void selectionChanged (bool selected)

Protected Functions

virtual void draw (QCPPainter *painter)
QPen mainPen () const
QBrush mainBrush () const
virtual QRect clipRect () const
virtual void applyDefaultAntialiasingHint (QCPPainter *painter) const
double distSqrToLine (const QPointF &start, const QPointF &end, const QPointF &point) const
double rectSelectTest (const QRectF &rect, const QPointF &pos, bool filledRect) const
virtual QPointF anchorPixelPoint (int anchorId) const
QCPItemPositioncreatePosition (const QString &name)
QCPItemAnchorcreateAnchor (const QString &name, int anchorId)
bool moveToLayer (QCPLayer *layer, bool prepend)
void applyAntialiasingHint (QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const

Detailed Description

Item that sticks to QCPGraph data points.

QCPItemTracer.png
Tracer example. Blue dotted circles are anchors, solid blue discs are positions.

The tracer can be connected with a QCPGraph via setGraph. Then it will automatically adopt the coordinate axes of the graph and update its position to be on the graph's data. This means the key stays controllable via setGraphKey, but the value will follow the graph data. If a QCPGraph is connected, note that setting the coordinates directly via position will have no effect, i.e. be overriden in the next redraw (this is when the coodinate update happens).

If the specified key in setGraphKey is outside the key bounds of the graph, the tracer will stay at the respective end of the graph.

With setInterpolating you may specify whether the tracer may only stay exactly on data points or whether it interpolates data points linearly, if given a key that lies between two data points of the graph.

The tracer has different visual styles, see setStyle. It is also possible to make the tracer have no own visual appearance (set the style to tsNone), and just connect other item positions to the tracer position (used as an anchor) via QCPItemPosition::setParentAnchor.

Note:
The tracer position is only automatically updated upon redraws. This means when, for example, the data of the graph changes and you immediately afterwards (without a redraw) read the position coordinates of the tracer, they will not reflect the updated data of the graph. In this case you should call updatePosition manually, prior to reading the tracer coordinates.

Member Enumeration Documentation

The different visual appearances a tracer item can have. Some styles size may be controlled with setSize.

See also:
setStyle
Enumerator:
tsNone 

The tracer is not visible.

tsPlus 

A plus shaped crosshair with limited size.

tsCrosshair 

A plus shaped crosshair which spans the complete axis rect.

tsCircle 

A circle.

tsSquare 

A square.


Constructor & Destructor Documentation

Creates a tracer item and sets default values.

The constructed item can be added to the plot with QCustomPlot::addItem.


Member Function Documentation

void QCPItemTracer::setPen ( const QPen &  pen)

Sets the pen that will be used to draw the line of the tracer

See also:
setSelectedPen, setBrush
void QCPItemTracer::setSelectedPen ( const QPen &  pen)

Sets the pen that will be used to draw the line of the tracer when selected

See also:
setPen, setSelected
void QCPItemTracer::setBrush ( const QBrush &  brush)

Sets the brush that will be used to draw any fills of the tracer

See also:
setSelectedBrush, setPen
void QCPItemTracer::setSelectedBrush ( const QBrush &  brush)

Sets the brush that will be used to draw any fills of the tracer, when selected.

See also:
setBrush, setSelected
void QCPItemTracer::setSize ( double  size)

Sets the size of the tracer in pixels, if the style supports setting a size (e.g. tsSquare does, tsCrosshair does not).

Sets the style/visual appearance of the tracer.

If you only want to use the tracer position as an anchor for other items, set style to tsNone.

void QCPItemTracer::setGraph ( QCPGraph graph)

Sets the QCPGraph this tracer sticks to. The tracer position will be set to type QCPItemPosition::ptPlotCoords and the axes will be set to the axes of graph.

To free the tracer from any graph, set graph to 0. The tracer position can then be placed freely like any other item position. This is the state the tracer will assume when its graph gets deleted while still attached to it.

See also:
setGraphKey
void QCPItemTracer::setGraphKey ( double  key)

Sets the key of the graph's data point the tracer will be positioned at. This is the only free cordinate of a tracer when attached to a graph.

Depending on setInterpolating, the tracer will be either positioned on the data point closest to key, or will stay exactly at key and interpolate the value linearly.

See also:
setGraph, setInterpolating
void QCPItemTracer::setInterpolating ( bool  enabled)

Sets whether the value of the graph's data points shall be interpolated, when positioning the tracer.

If enabled is set to false and a key is given with setGraphKey, the tracer is placed on the data point of the graph which is closest to the key, but which is not necessarily exactly there. If enabled is true, the tracer will be positioned exactly at the specified key, and the appropriate value will be interpolated from the graph's data points linearly.

See also:
setGraph, setGraphKey
double QCPItemTracer::selectTest ( const QPointF &  pos) const [virtual]

This function is used to decide whether a click hits an item or not.

pos is a point in pixel coordinates on the QCustomPlot surface. This function returns the shortest pixel distance of this point to the item. If the item is either invisible or the distance couldn't be determined, -1.0 is returned. setSelectable has no influence on the return value of this function.

If the item is represented not by single lines but by an area like QCPItemRect or QCPItemText, a click inside the area returns a constant value greater zero (typically 99% of the selectionTolerance of the parent QCustomPlot). If the click lies outside the area, this function returns -1.0.

Providing a constant value for area objects allows selecting line objects even when they are obscured by such area objects, by clicking close to the lines (i.e. closer than 0.99*selectionTolerance).

The actual setting of the selection state is not done by this function. This is handled by the parent QCustomPlot when the mouseReleaseEvent occurs.

See also:
setSelected, QCustomPlot::setInteractions

Implements QCPAbstractItem.

If the tracer is connected with a graph (setGraph), this function updates the tracer's position to reside on the graph data, depending on the configured key (setGraphKey).

It is called automatically on every redraw and normally doesn't need to be called manually. One exception is when you want to read the tracer coordinates via position and are not sure that the graph's data (or the tracer key with setGraphKey) hasn't changed since the last redraw. In that situation, call this function before accessing position, to make sure you don't get out-of-date coordinates.

If there is no graph set on this tracer, this function does nothing.

void QCPItemTracer::draw ( QCPPainter painter) [protected, virtual]

Draws this item with the provided painter. Called by QCustomPlot::draw on all its visible items.

The cliprect of the provided painter is set to the rect returned by clipRect before this function is called. For items this depends on the clipping settings defined by setClipToAxisRect, setClipKeyAxis and setClipValueAxis.

Implements QCPAbstractItem.

QPen QCPItemTracer::mainPen ( ) const [protected]

Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected and mSelectedPen when it is.

QBrush QCPItemTracer::mainBrush ( ) const [protected]

Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item is not selected and mSelectedBrush when it is.

void QCPAbstractItem::setClipToAxisRect ( bool  clip) [inherited]

Sets whether the item shall be clipped to the axis rect or whether it shall be visible on the entire QCustomPlot. The axis rect is defined by the clip axes which can be set via setClipAxes or individually with setClipKeyAxis and setClipValueAxis.

void QCPAbstractItem::setClipAxes ( QCPAxis keyAxis,
QCPAxis valueAxis 
) [inherited]

Sets both clip axes. Together they define the axis rect that will be used to clip the item when setClipToAxisRect is set to true.

See also:
setClipToAxisRect, setClipKeyAxis, setClipValueAxis
void QCPAbstractItem::setClipKeyAxis ( QCPAxis axis) [inherited]

Sets the clip key axis. Together with the clip value axis it defines the axis rect that will be used to clip the item when setClipToAxisRect is set to true.

See also:
setClipToAxisRect, setClipAxes, setClipValueAxis
void QCPAbstractItem::setClipValueAxis ( QCPAxis axis) [inherited]

Sets the clip value axis. Together with the clip key axis it defines the axis rect that will be used to clip the item when setClipToAxisRect is set to true.

See also:
setClipToAxisRect, setClipAxes, setClipKeyAxis
void QCPAbstractItem::setSelectable ( bool  selectable) [inherited]

Sets whether the user can (de-)select this item by clicking on the QCustomPlot surface. (When QCustomPlot::setInteractions contains QCustomPlot::iSelectItems.)

However, even when selectable was set to false, it is possible to set the selection manually, by calling setSelected directly.

See also:
QCustomPlot::setInteractions, setSelected
void QCPAbstractItem::setSelected ( bool  selected) [inherited]

Sets whether this item is selected or not. When selected, it might use a different visual appearance (e.g. pen and brush), this depends on the specific item, though.

The entire selection mechanism for items is handled automatically when QCustomPlot::setInteractions contains QCustomPlot::iSelectItems. You only need to call this function when you wish to change the selection state manually.

This function can change the selection state even when setSelectable was set to false.

emits the selectionChanged signal when selected is different from the previous selection state.

See also:
selectTest
QList< QCPItemPosition * > QCPAbstractItem::positions ( ) const [inline, inherited]

Returns all positions of the item in a list.

See also:
anchors, position
QList< QCPItemAnchor * > QCPAbstractItem::anchors ( ) const [inline, inherited]

Returns all anchors of the item in a list. Note that since a position (QCPItemPosition) is always also an anchor, the list will also contain the positions of this item.

See also:
positions, anchor
QCPItemPosition * QCPAbstractItem::position ( const QString &  name) const [inherited]

Returns the QCPItemPosition with the specified name. If this item doesn't have a position by that name, returns 0.

This function provides an alternative way to access item positions. Normally, you access positions direcly by their member pointers (which typically have the same variable name as name).

See also:
positions, anchor
QCPItemAnchor * QCPAbstractItem::anchor ( const QString &  name) const [inherited]

Returns the QCPItemAnchor with the specified name. If this item doesn't have an anchor by that name, returns 0.

This function provides an alternative way to access item anchors. Normally, you access anchors direcly by their member pointers (which typically have the same variable name as name).

See also:
anchors, position
bool QCPAbstractItem::hasAnchor ( const QString &  name) const [inherited]

Returns whether this item has an anchor with the specified name.

Note that you can check for positions with this function, too, because every position is also an anchor (QCPItemPosition inherits from QCPItemAnchor).

See also:
anchor, position
QRect QCPAbstractItem::clipRect ( ) const [protected, virtual, inherited]

Returns the rect the visual representation of this item is clipped to. This depends on the current setting of setClipToAxisRect aswell as the clip axes set with setClipAxes.

If the item is not clipped to an axis rect, the QCustomPlot::viewport rect is returned.

See also:
draw

Reimplemented from QCPLayerable.

void QCPAbstractItem::applyDefaultAntialiasingHint ( QCPPainter painter) const [protected, virtual, inherited]

A convenience function to easily set the QPainter::Antialiased hint on the provided painter before drawing item lines.

This is the antialiasing state the painter passed to the draw method is in by default.

This function takes into account the local setting of the antialiasing flag as well as the overrides set e.g. with QCustomPlot::setNotAntialiasedElements.

See also:
setAntialiased

Implements QCPLayerable.

double QCPAbstractItem::distSqrToLine ( const QPointF &  start,
const QPointF &  end,
const QPointF &  point 
) const [protected, inherited]

Finds the shortest squared distance of point to the line segment defined by start and end.

This function may be used to help with the implementation of the selectTest function for specific items.

Note:
This function is identical to QCPAbstractPlottable::distSqrToLine
See also:
rectSelectTest
double QCPAbstractItem::rectSelectTest ( const QRectF &  rect,
const QPointF &  pos,
bool  filledRect 
) const [protected, inherited]

A convenience function which returns the selectTest value for a specified rect and a specified click position pos. filledRect defines whether a click inside the rect should also be considered a hit or whether only the rect border is sensitive to hits.

This function may be used to help with the implementation of the selectTest function for specific items.

For example, if your item consists of four rects, call this function four times, once for each rect, in your selectTest reimplementation. Finally, return the minimum of all four returned values which were greater or equal to zero. (Because this function may return -1.0 when pos doesn't hit rect at all). If all calls returned -1.0, return -1.0, too, because your item wasn't hit.

See also:
distSqrToLine
QPointF QCPAbstractItem::anchorPixelPoint ( int  anchorId) const [protected, virtual, inherited]

Returns the pixel position of the anchor with Id anchorId. This function must be reimplemented in item subclasses if they want to provide anchors (QCPItemAnchor).

For example, if the item has two anchors with id 0 and 1, this function takes one of these anchor ids and returns the respective pixel points of the specified anchor.

See also:
createAnchor

Reimplemented in QCPItemBracket, QCPItemText, QCPItemPixmap, QCPItemRect, and QCPItemEllipse.

QCPItemPosition * QCPAbstractItem::createPosition ( const QString &  name) [protected, inherited]

Creates a QCPItemPosition, registers it with this item and returns a pointer to it. The specified name must be a unique string that is usually identical to the variable name of the position member (This is needed to provide the name based position access to positions).

Don't delete positions created by this function manually, as the item will take care of it.

Use this function in the constructor (initialization list) of the specific item subclass to create each position member. Don't create QCPItemPositions with new yourself, because they won't be registered with the item properly.

See also:
createAnchor
QCPItemAnchor * QCPAbstractItem::createAnchor ( const QString &  name,
int  anchorId 
) [protected, inherited]

Creates a QCPItemAnchor, registers it with this item and returns a pointer to it. The specified name must be a unique string that is usually identical to the variable name of the anchor member (This is needed to provide the name based anchor access to anchors).

The anchorId must be a number identifying the created anchor. It is recommended to create an enum (e.g. "AnchorIndex") for this on each item that uses anchors. This id is used by the anchor to identify itself when it calls QCPAbstractItem::anchorPixelPoint. That function then returns the correct pixel coordinates for the passed anchor id.

Don't delete anchors created by this function manually, as the item will take care of it.

Use this function in the constructor (initialization list) of the specific item subclass to create each anchor member. Don't create QCPItemAnchors with new yourself, because then they won't be registered with the item properly.

See also:
createPosition
void QCPAbstractItem::selectionChanged ( bool  selected) [signal, inherited]

This signal is emitted when the selection state of this item has changed, either by user interaction or by a direct call to setSelected.

void QCPLayerable::setVisible ( bool  on) [inherited]

Sets the visibility of this layerable object. If an object is not visible, it will not be drawn on the QCustomPlot surface, and user interaction with it (e.g. click/selection) is not possible.

bool QCPLayerable::setLayer ( QCPLayer layer) [inherited]

Sets the layer of this layerable object. The object will be placed on top of the other objects already on layer.

Returns true on success, i.e. if layer is a valid layer.

bool QCPLayerable::setLayer ( const QString &  layerName) [inherited]

This is an overloaded function.

Sets the layer of this layerable object by name

Returns true on success, i.e. if layerName is a valid layer name.

void QCPLayerable::setAntialiased ( bool  enabled) [inherited]

Sets whether this object will be drawn antialiased or not.

Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and QCustomPlot::setNotAntialiasedElements.

bool QCPLayerable::moveToLayer ( QCPLayer layer,
bool  prepend 
) [protected, inherited]

Moves this layerable object to layer. If prepend is true, this object will be prepended to the new layer's list, i.e. it will be drawn below the objects already on the layer. If it is false, the object will be appended.

Returns true on success, i.e. if layer is a valid layer.

void QCPLayerable::applyAntialiasingHint ( QCPPainter painter,
bool  localAntialiased,
QCP::AntialiasedElement  overrideElement 
) const [protected, inherited]

Sets the QPainter::Antialiasing render hint on the provided painter, depending on the localAntialiased value as well as the overrides QCustomPlot::setAntialiasedElements and QCustomPlot::setNotAntialiasedElements. Which override enum this function takes into account is controlled via overrideElement.


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