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

A rectangle. More...

Inheritance diagram for QCPItemRect:
Inheritance graph

Public Functions

 QCPItemRect (QCustomPlot *parentPlot)
QPen pen () const
QPen selectedPen () const
QBrush brush () const
QBrush selectedBrush () const
void setPen (const QPen &pen)
void setSelectedPen (const QPen &pen)
void setBrush (const QBrush &brush)
void setSelectedBrush (const QBrush &brush)
virtual double selectTest (const QPointF &pos, bool onlySelectable, QVariant *details=0) const
bool clipToAxisRect () const
QCPAxisRectclipAxisRect () const
bool selectable () const
bool selected () const
void setClipToAxisRect (bool clip)
void setClipAxisRect (QCPAxisRect *rect)
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
QCPLayerableparentLayerable () const
QCPLayerlayer () const
bool antialiased () const
void setVisible (bool on)
bool setLayer (QCPLayer *layer)
bool setLayer (const QString &layerName)
void setAntialiased (bool enabled)
bool realVisibility () const

Public Members

QCPItemPosition *const topLeft
QCPItemPosition *const bottomRight
QCPItemAnchor *const top
QCPItemAnchor *const topRight
QCPItemAnchor *const right
QCPItemAnchor *const bottom
QCPItemAnchor *const bottomLeft
QCPItemAnchor *const left

Signals

void selectionChanged (bool selected)

Protected Types

enum  AnchorIndex

Protected Functions

virtual void draw (QCPPainter *painter)
virtual QPointF anchorPixelPoint (int anchorId) const
QPen mainPen () const
QBrush mainBrush () const
virtual QCP::Interaction selectionCategory () const
virtual QRect clipRect () const
virtual void applyDefaultAntialiasingHint (QCPPainter *painter) const
virtual void selectEvent (QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged)
virtual void deselectEvent (bool *selectionStateChanged)
double distSqrToLine (const QPointF &start, const QPointF &end, const QPointF &point) const
double rectSelectTest (const QRectF &rect, const QPointF &pos, bool filledRect) const
QCPItemPositioncreatePosition (const QString &name)
QCPItemAnchorcreateAnchor (const QString &name, int anchorId)
virtual void parentPlotInitialized (QCustomPlot *parentPlot)
void initializeParentPlot (QCustomPlot *parentPlot)
void setParentLayerable (QCPLayerable *parentLayerable)
bool moveToLayer (QCPLayer *layer, bool prepend)
void applyAntialiasingHint (QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const

Detailed Description

A rectangle.

QCPItemRect.png
Rectangle example. Blue dotted circles are anchors, solid blue discs are positions.

It has two positions, topLeft and bottomRight, which define the rectangle.

Constructor & Destructor Documentation

QCPItemRect::QCPItemRect ( QCustomPlot parentPlot)

Creates a rectangle item and sets default values.

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

Member Function Documentation

void QCPItemRect::setPen ( const QPen &  pen)

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

See Also
setSelectedPen, setBrush
void QCPItemRect::setSelectedPen ( const QPen &  pen)

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

See Also
setPen, setSelected
void QCPItemRect::setBrush ( const QBrush &  brush)

Sets the brush that will be used to fill the rectangle. To disable filling, set brush to Qt::NoBrush.

See Also
setSelectedBrush, setPen
void QCPItemRect::setSelectedBrush ( const QBrush &  brush)

Sets the brush that will be used to fill the rectangle when selected. To disable filling, set brush to Qt::NoBrush.

See Also
setBrush
double QCPItemRect::selectTest ( const QPointF &  pos,
bool  onlySelectable,
QVariant *  details = 0 
) const
virtual

This function is used to decide whether a click hits a layerable object 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 object. If the object is either invisible or the distance couldn't be determined, -1.0 is returned. Further, if onlySelectable is true and the object is not selectable, -1.0 is returned, too.

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 the selectionTolerance of the parent QCustomPlot multiplied by 0.99). 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, and the finally selected object is notified via the selectEvent/deselectEvent methods.

details is an optional output parameter. Every layerable subclass may place any information in details. This information will be passed to selectEvent when the parent QCustomPlot decides on the basis of this selectTest call, that the object was successfully selected. The subsequent call to selectEvent will carry the details. This is useful for multi-part objects (like QCPAxis). This way, a possibly complex calculation to decide which part was clicked is only done once in selectTest. The result (i.e. the actually clicked part) can then be placed in details. So in the subsequent selectEvent, the decision which part was selected doesn't have to be done a second time for a single selection operation.

You may pass 0 as details to indicate that you are not interested in those selection details.

See Also
selectEvent, deselectEvent, QCustomPlot::setInteractions

Implements QCPAbstractItem.

void QCPItemRect::draw ( QCPPainter painter)
protectedvirtual

Draws this item with the provided painter.

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

Implements QCPAbstractItem.

QPointF QCPItemRect::anchorPixelPoint ( int  anchorId) const
protectedvirtual

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 from QCPAbstractItem.

QPen QCPItemRect::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 QCPItemRect::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 an axis rect or whether it shall be visible on the entire QCustomPlot. The axis rect can be set with setClipAxisRect.

See Also
setClipAxisRect
void QCPAbstractItem::setClipAxisRect ( QCPAxisRect rect)
inherited

Sets the clip axis rect. It defines the rect that will be used to clip the item when setClipToAxisRect is set to true.

See Also
setClipToAxisRect
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.

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
setSelectable, selectTest
QList< QCPItemPosition * > QCPAbstractItem::positions ( ) const
inlineinherited

Returns all positions of the item in a list.

See Also
anchors, position
QList< QCPItemAnchor * > QCPAbstractItem::anchors ( ) const
inlineinherited

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. This is because every position is also an anchor (QCPItemPosition inherits from QCPItemAnchor).

See Also
anchor, position
void QCPAbstractItem::selectionChanged ( bool  selected)
signalinherited

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

QCP::Interaction QCPAbstractItem::selectionCategory ( ) const
protectedvirtualinherited

Returns the selection category this layerable shall belong to. The selection category is used in conjunction with QCustomPlot::setInteractions to control which objects are selectable and which aren't.

Subclasses that don't fit any of the normal QCP::Interaction values can use QCP::iSelectOther. This is what the default implementation returns.

See Also
QCustomPlot::setInteractions

Reimplemented from QCPLayerable.

QRect QCPAbstractItem::clipRect ( ) const
protectedvirtualinherited

Returns the rect the visual representation of this item is clipped to. This depends on the current setting of setClipToAxisRect as well as the axis rect set with setClipAxisRect.

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
protectedvirtualinherited

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 with QCustomPlot::setAntialiasedElements and QCustomPlot::setNotAntialiasedElements.

See Also
setAntialiased

Implements QCPLayerable.

void QCPAbstractItem::selectEvent ( QMouseEvent *  event,
bool  additive,
const QVariant &  details,
bool *  selectionStateChanged 
)
protectedvirtualinherited

This event is called when the layerable shall be selected, as a consequence of a click by the user. Subclasses should react to it by setting their selection state appropriately. The default implementation does nothing.

event is the mouse event that caused the selection. additive indicates, whether the user was holding the multi-select-modifier while performing the selection (see QCustomPlot::setMultiSelectModifier). if additive is true, the selection state must be toggled (i.e. become selected when unselected and unselected when selected).

Every selectEvent is preceded by a call to selectTest, which has returned positively (i.e. returned a value greater than 0 and less than the selection tolerance of the parent QCustomPlot). The details data you output from selectTest is feeded back via details here. You may use it to transport any kind of information from the selectTest to the possibly subsequent selectEvent. Usually details is used to transfer which part was clicked, if it is a layerable that has multiple individually selectable parts (like QCPAxis). This way selectEvent doesn't need to do the calculation again to find out which part was actually clicked.

selectionStateChanged is an output parameter. If the pointer is non-null, this function must set the value either to true or false, depending on whether the selection state of this layerable was actually changed. For layerables that only are selectable as a whole and not in parts, this is simple: if additive is true, selectionStateChanged must also be set to true, because the selection toggles. If additive is false, selectionStateChanged is only set to true, if the layerable was previously unselected and now is switched to the selected state.

See Also
selectTest, deselectEvent

Reimplemented from QCPLayerable.

void QCPAbstractItem::deselectEvent ( bool *  selectionStateChanged)
protectedvirtualinherited

This event is called when the layerable shall be deselected, either as consequence of a user interaction or a call to QCustomPlot::deselectAll. Subclasses should react to it by unsetting their selection appropriately.

just as in selectEvent, the output parameter selectionStateChanged (if non-null), must return true or false when the selection state of this layerable has changed or not changed, respectively.

See Also
selectTest, selectEvent

Reimplemented from QCPLayerable.

double QCPAbstractItem::distSqrToLine ( const QPointF &  start,
const QPointF &  end,
const QPointF &  point 
) const
protectedinherited

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
protectedinherited

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
QCPItemPosition * QCPAbstractItem::createPosition ( const QString &  name)
protectedinherited

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

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
QCPLayerable * QCPLayerable::parentLayerable ( ) const
inlineinherited

Returns the parent layerable of this layerable. The parent layerable is used to provide visibility hierarchies in conjunction with the method realVisibility. This way, layerables only get drawn if their parent layerables are visible, too.

Note that a parent layerable is not necessarily also the QObject parent for memory management. Further, a layerable doesn't always have a parent layerable, so this function may return 0.

A parent layerable is set implicitly with when placed inside layout elements and doesn't need to be set manually by the user.

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 and 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::realVisibility ( ) const
inherited

Returns whether this layerable is visible, taking possible direct layerable parent visibility into account. This is the method that is consulted to decide whether a layerable shall be drawn or not.

If this layerable has a direct layerable parent (usually set via hierarchies implemented in subclasses, like in the case of QCPLayoutElement), this function returns true only if this layerable has its visibility set to true and the parent layerable's realVisibility returns true.

If this layerable doesn't have a direct layerable parent, returns the state of this layerable's visibility.

void QCPLayerable::parentPlotInitialized ( QCustomPlot parentPlot)
protectedvirtualinherited

This function is called by initializeParentPlot, to allow subclasses to react on the setting of a parent plot. This is the case when 0 was passed as parent plot in the constructor, and the parent plot is set at a later time.

For example, QCPLayoutElement/QCPLayout hierarchies may be created independently of any QCustomPlot at first. When they are then added to a layout inside the QCustomPlot, the top level element of the hierarchy gets its parent plot initialized with initializeParentPlot. To propagate the parent plot to all the children of the hierarchy, the top level element then uses this function to pass the parent plot on to its child elements.

The default implementation does nothing.

See Also
initializeParentPlot

Reimplemented in QCPLegend, and QCPLayoutElement.

void QCPLayerable::initializeParentPlot ( QCustomPlot parentPlot)
protectedinherited

Sets the parent plot of this layerable. Use this function once to set the parent plot if you have passed 0 in the constructor. It can not be used to move a layerable from one QCustomPlot to another one.

Note that, unlike when passing a non-null parent plot in the constructor, this function does not make parentPlot the QObject-parent of this layerable. If you want this, call QObject::setParent(parentPlot) in addition to this function.

Further, you will probably want to set a layer (setLayer) after calling this function, to make the layerable appear on the QCustomPlot.

The parent plot change will be propagated to subclasses via a call to parentPlotInitialized so they can react accordingly (e.g. also initialize the parent plot of child layerables, like QCPLayout does).

void QCPLayerable::setParentLayerable ( QCPLayerable parentLayerable)
protectedinherited

Sets the parent layerable of this layerable to parentLayerable. Note that parentLayerable does not become the QObject-parent (for memory management) of this layerable.

The parent layerable has influence on the return value of the realVisibility method. Only layerables with a fully visible parent tree will return true for realVisibility, and thus be drawn.

See Also
realVisibility
bool QCPLayerable::moveToLayer ( QCPLayer layer,
bool  prepend 
)
protectedinherited

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
protectedinherited

Sets the QCPainter::setAntialiasing state 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: