QCPAbstractLegendItem Class Reference
Author: Emanuel Eichhammer

· · · ·
Public Functions | Signals | Protected Functions
QCPAbstractLegendItem Class Referenceabstract

The abstract base class for all entries in a QCPLegend. More...

Inheritance diagram for QCPAbstractLegendItem:

## Public Functions
| QCPAbstractLegendItem (QCPLegend *parent)
QCPLegend * | parentLegend () const
QFont | font () const
QColor | textColor () const
QFont | selectedFont () const
QColor | selectedTextColor () const
bool | selectable () const
bool | selected () const
void | setFont (const QFont &font)
void | setTextColor (const QColor &color)
void | setSelectedFont (const QFont &font)
void | setSelectedTextColor (const QColor &color)
Q_SLOT void | setSelectable (bool selectable)
Q_SLOT void | setSelected (bool selected)
virtual double | selectTest (const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const
Public Functions inherited from QCPLayoutElement
| QCPLayoutElement (QCustomPlot *parentPlot=nullptr)
QCPLayout * | layout () const
QRect | rect () const
QRect | outerRect () const
QMargins | margins () const
QMargins | minimumMargins () const
QCP::MarginSides | autoMargins () const
QSize | minimumSize () const
QSize | maximumSize () const
SizeConstraintRect | sizeConstraintRect () const
QCPMarginGroup * | marginGroup (QCP::MarginSide side) const
QHash< QCP::MarginSide, QCPMarginGroup * > | marginGroups () const
void | setOuterRect (const QRect &rect)
void | setMargins (const QMargins &margins)
void | setMinimumMargins (const QMargins &margins)
void | setAutoMargins (QCP::MarginSides sides)
void | setMinimumSize (const QSize &size)
void | setMinimumSize (int width, int height)
void | setMaximumSize (const QSize &size)
void | setMaximumSize (int width, int height)
void | setSizeConstraintRect (SizeConstraintRect constraintRect)
void | setMarginGroup (QCP::MarginSides sides, QCPMarginGroup *group)
virtual void | update (UpdatePhase phase)
virtual QSize | minimumOuterSizeHint () const
virtual QSize | maximumOuterSizeHint () const
virtual QList< QCPLayoutElement * > | elements (bool recursive) const
Public Functions inherited from QCPLayerable
| QCPLayerable (QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=nullptr)
bool | visible () const
QCustomPlot * | parentPlot () const
QCPLayerable * | parentLayerable () const
QCPLayer * | layer () const
bool | antialiased () const
void | setVisible (bool on)
Q_SLOT bool | setLayer (QCPLayer *layer)
bool | setLayer (const QString &layerName)
void | setAntialiased (bool enabled)
bool | realVisibility () const

## Signals
void | selectionChanged (bool selected)
void | selectableChanged (bool selectable)
Signals inherited from QCPLayerable
void | layerChanged (QCPLayer *newLayer)

## Protected Functions
virtual QCP::Interaction | selectionCategory () const
virtual void | applyDefaultAntialiasingHint (QCPPainter *painter) const
virtual QRect | clipRect () const
virtual void | draw (QCPPainter *painter)=0
virtual void | selectEvent (QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged)
virtual void | deselectEvent (bool *selectionStateChanged)
Protected Functions inherited from QCPLayoutElement
virtual int | calculateAutoMargin (QCP::MarginSide side)
virtual void | layoutChanged ()
virtual void | parentPlotInitialized (QCustomPlot *parentPlot)
Protected Functions inherited from QCPLayerable
virtual void | mousePressEvent (QMouseEvent *event, const QVariant &details)
virtual void | mouseMoveEvent (QMouseEvent *event, const QPointF &startPos)
virtual void | mouseReleaseEvent (QMouseEvent *event, const QPointF &startPos)
virtual void | mouseDoubleClickEvent (QMouseEvent *event, const QVariant &details)
virtual void | wheelEvent (QWheelEvent *event)
void | initializeParentPlot (QCustomPlot *parentPlot)
void | setParentLayerable (QCPLayerable *parentLayerable)
bool | moveToLayer (QCPLayer *layer, bool prepend)
void | applyAntialiasingHint (QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const

## Additional Inherited Members
Public Types inherited from QCPLayoutElement
enum | UpdatePhase
enum | SizeConstraintRect

## Detailed Description

The abstract base class for all entries in a QCPLegend.

It defines a very basic interface for entries in a QCPLegend. For representing plottables in the legend, the subclass QCPPlottableLegendItem is more suitable.

Only derive directly from this class when you need absolute freedom (e.g. a custom legend entry that's not even associated with a plottable).

You must implement the following pure virtual functions:

- draw (from QCPLayerable)

You inherit the following members you may use:

QCPLegend *mParentLegend | A pointer to the parent QCPLegend.
QFont mFont | The generic font of the item. You should use this font for all or at least the most prominent text of the item.

## Constructor & Destructor Documentation

## § QCPAbstractLegendItem()

QCPAbstractLegendItem::QCPAbstractLegendItem | ( | QCPLegend * | parent | ) |
| explicit

Constructs a QCPAbstractLegendItem and associates it with the QCPLegend parent. This does not cause the item to be added to parent, so QCPLegend::addItem must be called separately.

## Member Function Documentation

## § setFont()

void QCPAbstractLegendItem::setFont | ( | const QFont & | font | ) |

Sets the default font of this specific legend item to font.

See also
  setTextColor, QCPLegend::setFont

## § setTextColor()

void QCPAbstractLegendItem::setTextColor | ( | const QColor & | color | ) |

Sets the default text color of this specific legend item to color.

See also
  setFont, QCPLegend::setTextColor

## § setSelectedFont()

void QCPAbstractLegendItem::setSelectedFont | ( | const QFont & | font | ) |

When this legend item is selected, font is used to draw generic text, instead of the normal font set with setFont.

See also
  setFont, QCPLegend::setSelectedFont

## § setSelectedTextColor()

void QCPAbstractLegendItem::setSelectedTextColor | ( | const QColor & | color | ) |

When this legend item is selected, color is used to draw generic text, instead of the normal color set with setTextColor.

See also
  setTextColor, QCPLegend::setSelectedTextColor

## § setSelectable()

void QCPAbstractLegendItem::setSelectable | ( | bool | selectable | ) |

Sets whether this specific legend item is selectable.

See also
  setSelectedParts, QCustomPlot::setInteractions

## § setSelected()

void QCPAbstractLegendItem::setSelected | ( | bool | selected | ) |

Sets whether this specific legend item is selected.

It is possible to set the selection state of this item by calling this function directly, even if setSelectable is set to false.

See also
  setSelectableParts, QCustomPlot::setInteractions

## § selectTest()

double QCPAbstractLegendItem::selectTest | ( | const QPointF & | pos,
|  | bool | onlySelectable,
|  | QVariant * | details = `nullptr`
| ) |  | const
| virtual

Layout elements are sensitive to events inside their outer rect. If pos is within the outer rect, this method returns a value corresponding to 0.99 times the parent plot's selection tolerance. However, layout elements are not selectable by default. So if onlySelectable is true, -1.0 is returned.

See QCPLayerable::selectTest for a general explanation of this virtual method.

QCPLayoutElement subclasses may reimplement this method to provide more specific selection test behaviour.

Reimplemented from QCPLayoutElement.

## § selectionChanged

void QCPAbstractLegendItem::selectionChanged | ( | bool | selected | ) |
| signal

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

## § selectionCategory()

QCP::Interaction QCPAbstractLegendItem::selectionCategory | ( |  | ) | const
| protectedvirtual

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.

## § applyDefaultAntialiasingHint()

void QCPAbstractLegendItem::applyDefaultAntialiasingHint | ( | QCPPainter * | painter | ) | const
| protectedvirtual

This function applies the default antialiasing setting to the specified painter, using the function applyAntialiasingHint. It is the antialiasing state the painter is put in, when draw is called on the layerable. If the layerable has multiple entities whose antialiasing setting may be specified individually, this function should set the antialiasing state of the most prominent entity. In this case however, the draw function usually calls the specialized versions of this function before drawing each entity, effectively overriding the setting of the default antialiasing hint.

First example: QCPGraph has multiple entities that have an antialiasing setting: The graph line, fills and scatters. Those can be configured via QCPGraph::setAntialiased, QCPGraph::setAntialiasedFill and QCPGraph::setAntialiasedScatters. Consequently, there isn't only the QCPGraph::applyDefaultAntialiasingHint function (which corresponds to the graph line's antialiasing), but specialized ones like QCPGraph::applyFillAntialiasingHint and QCPGraph::applyScattersAntialiasingHint. So before drawing one of those entities, QCPGraph::draw calls the respective specialized applyAntialiasingHint function.

Second example: QCPItemLine consists only of a line so there is only one antialiasing setting which can be controlled with QCPItemLine::setAntialiased. (This function is inherited by all layerables. The specialized functions, as seen on QCPGraph, must be added explicitly to the respective layerable subclass.) Consequently it only has the normal QCPItemLine::applyDefaultAntialiasingHint. The QCPItemLine::draw function doesn't need to care about setting any antialiasing states, because the default antialiasing hint is already set on the painter when the draw function is called, and that's the state it wants to draw the line with.

Reimplemented from QCPLayoutElement.

## § clipRect()

QRect QCPAbstractLegendItem::clipRect | ( |  | ) | const
| protectedvirtual

Returns the clipping rectangle of this layerable object. By default, this is the viewport of the parent QCustomPlot. Specific subclasses may reimplement this function to provide different clipping rects.

The returned clipping rect is set on the painter before the draw function of the respective object is called.

Reimplemented from QCPLayerable.

## § draw()

virtual void QCPAbstractLegendItem::draw | ( | QCPPainter * | painter | ) |
| protectedpure virtual

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.

Reimplemented from QCPLayoutElement.

Implemented in QCPPlottableLegendItem, and QCPPolarLegendItem.

## § selectEvent()

void QCPAbstractLegendItem::selectEvent | ( | QMouseEvent * | event,
|  | bool | additive,
|  | const QVariant & | details,
|  | bool * | selectionStateChanged
| ) |  |
| protectedvirtual

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

## § deselectEvent()

void QCPAbstractLegendItem::deselectEvent | ( | bool * | selectionStateChanged | ) |
| protectedvirtual

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.

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

- src/layoutelements/layoutelement-legend.h
- src/layoutelements/layoutelement-legend.cpp