A legend item representing a plottable with an icon and the plottable name. More...
Public Functions | |
QCPPlottableLegendItem (QCPLegend *parent, QCPAbstractPlottable *plottable) | |
QCPAbstractPlottable * | plottable () |
bool | textWrap () const |
void | setTextWrap (bool wrap) |
bool | antialiased () const |
QFont | font () const |
QColor | textColor () const |
QFont | selectedFont () const |
QColor | selectedTextColor () const |
bool | selectable () const |
bool | selected () const |
void | setAntialiased (bool enabled) |
void | setFont (const QFont &font) |
void | setTextColor (const QColor &color) |
void | setSelectedFont (const QFont &font) |
void | setSelectedTextColor (const QColor &color) |
void | setSelectable (bool selectable) |
void | setSelected (bool selected) |
Signals | |
void | selectionChanged (bool selected) |
Protected Functions | |
QPen | getIconBorderPen () const |
QColor | getTextColor () const |
QFont | getFont () const |
virtual void | draw (QCPPainter *painter, const QRect &rect) const |
virtual QSize | size (const QSize &targetSize) const |
void | applyAntialiasingHint (QCPPainter *painter) const |
A legend item representing a plottable with an icon and the plottable name.
This is the standard legend item for plottables. It displays an icon of the plottable next to the plottable name. The icon is drawn by the respective plottable itself (QCPAbstractPlottable::drawLegendIcon), and tries to give an intuitive symbol for the plottable. For example, the QCPGraph draws a centered horizontal line with a single scatter point in the middle and filling (if enabled) below.
Legend items of this type are always associated with one plottable (retrievable via the plottable() function and settable with the constructor). You may change the font of the plottable name with setFont. If setTextWrap is set to true, the plottable name will wrap at the right legend boundary (see QCPLegend::setMinimumSize). Icon padding and border pen is taken from the parent QCPLegend, see QCPLegend::setIconBorderPen and QCPLegend::setIconTextPadding.
The function QCPAbstractPlottable::addToLegend/QCPAbstractPlottable::removeFromLegend creates/removes legend items of this type in the default implementation. However, these functions may be reimplemented such that a different kind of legend item (e.g a direct subclass of QCPAbstractLegendItem) is used for that plottable.
QCPPlottableLegendItem::QCPPlottableLegendItem | ( | QCPLegend * | parent, |
QCPAbstractPlottable * | plottable | ||
) |
Creates a new legend item associated with plottable.
Once it's created, it can be added to the legend via QCPLegend::addItem.
A more convenient way of adding/removing a plottable to/from the legend is via the functions QCPAbstractPlottable::addToLegend and QCPAbstractPlottable::removeFromLegend.
void QCPPlottableLegendItem::setTextWrap | ( | bool | wrap | ) |
Sets whether the text of the legend item is wrapped at word boundaries to fit the with of the legend.
To prevent the legend autoSize feature (QCPLegend::setAutoSize) from compressing the text too strong by wrapping it very often, set an appropriate minimum width with QCPLegend::setMinimumSize.
QPen QCPPlottableLegendItem::getIconBorderPen | ( | ) | const [protected] |
Returns the pen that shall be used to draw the icon border, taking into account the selection state of this item.
QColor QCPPlottableLegendItem::getTextColor | ( | ) | const [protected] |
Returns the text color that shall be used to draw text, taking into account the selection state of this item.
QFont QCPPlottableLegendItem::getFont | ( | ) | const [protected] |
Returns the font that shall be used to draw text, taking into account the selection state of this item.
void QCPPlottableLegendItem::draw | ( | QCPPainter * | painter, |
const QRect & | rect | ||
) | const [protected, virtual] |
Draws the item with painter into rect.
The width of the passed rect is used as text wrapping width, when setTextWrap is enabled. The height is ignored. The rect is not used as a clipping rect (overpainting is not prevented inside this function), so you should set an appropriate clipping rect on the painter before calling this function. Ideally, the width of the rect should be the result of a preceding call to size.
Implements QCPAbstractLegendItem.
QSize QCPPlottableLegendItem::size | ( | const QSize & | targetSize | ) | const [protected, virtual] |
Calculates and returns the size of this item. If setTextWrap is enabled, the width of targetSize will be used as the text wrapping width. This does not guarantee, that the width of the returned QSize is the same as the width of targetSize, since wrapping occurs only at word boundaries. So a single word that extends beyond the width of targetSize, will stretch the returned QSize accordingly.
The height of targetSize is ignored. The height of the returned QSize is either the height of the icon or the height of the text bounding box, whichever is larger.
Implements QCPAbstractLegendItem.
void QCPAbstractLegendItem::setAntialiased | ( | bool | enabled | ) | [inherited] |
Sets whether this legend item is drawn antialiased or not.
Note that this setting may be overridden by QCustomPlot::setAntialiasedElements and QCustomPlot::setNotAntialiasedElements.
void QCPAbstractLegendItem::setFont | ( | const QFont & | font | ) | [inherited] |
Sets the default font of this specific legend item to font.
void QCPAbstractLegendItem::setTextColor | ( | const QColor & | color | ) | [inherited] |
Sets the default text color of this specific legend item to color.
void QCPAbstractLegendItem::setSelectedFont | ( | const QFont & | font | ) | [inherited] |
When this legend item is selected, font is used to draw generic text, instead of the normal font set with setFont.
void QCPAbstractLegendItem::setSelectedTextColor | ( | const QColor & | color | ) | [inherited] |
When this legend item is selected, color is used to draw generic text, instead of the normal color set with setTextColor.
void QCPAbstractLegendItem::setSelectable | ( | bool | selectable | ) | [inherited] |
Sets whether this specific legend item is selectable.
void QCPAbstractLegendItem::setSelected | ( | bool | selected | ) | [inherited] |
Sets whether this specific legend item is selected. The selection state of the parent QCPLegend is updated correspondingly.
It is possible to set the selection state of this item by calling this function directly, even if setSelectable is set to false.
void QCPAbstractLegendItem::selectionChanged | ( | bool | selected | ) | [signal, inherited] |
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.
void QCPAbstractLegendItem::applyAntialiasingHint | ( | QCPPainter * | painter | ) | const [protected, inherited] |
Sets the QPainter::Antialiasing render hint on the provided painter, depending on the setAntialiased state of this legend item as well as the overrides QCustomPlot::setAntialiasedElements and QCustomPlot::setNotAntialiasedElements.