Manages a legend inside a QCustomPlot.
More...
#include <qcustomplot.h>
Inherits QObject.
Manages a legend inside a QCustomPlot.
Doesn't need to be instantiated externally, rather access QCustomPlot::legend
Definition at line 554 of file qcustomplot.h.
◆ PositionStyle
Defines where the legend is positioned inside the QCustomPlot axis rect.
| Enumerator |
|---|
| PSManual | Position is not changed automatically. Set manually via setPosition.
|
| PSTopLeft | Legend is positioned in the top left corner of the axis rect with distance to the border corresponding to the currently set top and left margins.
|
| PSTop | Legend is horizontally centered at the top of the axis rect with distance to the border corresponding to the currently set top margin.
|
| PSTopRight | Legend is positioned in the top right corner of the axis rect with distance to the border corresponding to the currently set top and right margins.
|
| PSRight | Legend is vertically centered at the right of the axis rect with distance to the border corresponding to the currently set right margin.
|
| PSBottomRight | Legend is positioned in the bottom right corner of the axis rect with distance to the border corresponding to the currently set bottom and right margins.
|
| PSBottom | Legend is horizontally centered at the bottom of the axis rect with distance to the border corresponding to the currently set bottom margin.
|
| PSBottomLeft | Legend is positioned in the bottom left corner of the axis rect with distance to the border corresponding to the currently set bottom and left margins.
|
| PSLeft | Legend is vertically centered at the left of the axis rect with distance to the border corresponding to the currently set left margin.
|
Definition at line 561 of file qcustomplot.h.
Position is not changed automatically. Set manually via setPosition.
Legend is positioned in the bottom right corner of the axis rect with distance to the border correspo...
Legend is horizontally centered at the top of the axis rect with distance to the border corresponding...
Legend is positioned in the top left corner of the axis rect with distance to the border correspondin...
Legend is positioned in the top right corner of the axis rect with distance to the border correspondi...
Legend is horizontally centered at the bottom of the axis rect with distance to the border correspond...
Legend is vertically centered at the left of the axis rect with distance to the border corresponding ...
Legend is vertically centered at the right of the axis rect with distance to the border corresponding...
Legend is positioned in the bottom left corner of the axis rect with distance to the border correspon...
◆ QCPLegend()
Constructs a new QCPLegend instance with parentPlot as the containing plot and default values. Under normal usage, QCPLegend needn't be instantiated outside of QCustomPlot. Access QCustomPlot::legend to modify the legend (set to invisible by default, see setVisible).
Definition at line 2505 of file qcustomplot.cc.
void setIconTextPadding(int padding)
void setPositionStyle(PositionStyle legendPositionStyle)
void setBrush(const QBrush &brush)
void setSize(const QSize &size)
Legend is positioned in the top right corner of the axis rect with distance to the border correspondi...
void setFont(const QFont &font)
void setIconBorderPen(const QPen &pen)
void setAutoSize(bool on)
void setMargin(int left, int right, int top, int bottom)
void setItemSpacing(int spacing)
QCustomPlot * mParentPlot
void setPadding(int left, int right, int top, int bottom)
void setBorderPen(const QPen &pen)
void setIconSize(const QSize &size)
void setMinimumSize(const QSize &size)
◆ ~QCPLegend()
| QCPLegend::~QCPLegend |
( |
| ) |
|
|
virtual |
◆ addItem
Adds item to the legend, if it's not present already.
Returns true on sucess, i.e. if the item wasn't in the list already and has been successfully added.
The legend takes ownership of the item.
Definition at line 2867 of file qcustomplot.cc.
2869 if (!
mItems.contains(item))
QList< QCPAbstractLegendItem * > mItems
◆ autoSize
| bool QCPLegend::autoSize |
( |
| ) |
const |
|
inlineslot |
◆ borderPen
| QPen QCPLegend::borderPen |
( |
| ) |
const |
|
inlineslot |
◆ brush
| QBrush QCPLegend::brush |
( |
| ) |
const |
|
inlineslot |
◆ calculateAutoPosition()
| void QCPLegend::calculateAutoPosition |
( |
| ) |
|
|
protectedvirtual |
Definition at line 3029 of file qcustomplot.cc.
Legend is positioned in the bottom right corner of the axis rect with distance to the border correspo...
Legend is horizontally centered at the top of the axis rect with distance to the border corresponding...
Legend is positioned in the top left corner of the axis rect with distance to the border correspondin...
PositionStyle mPositionStyle
Legend is positioned in the top right corner of the axis rect with distance to the border correspondi...
Legend is horizontally centered at the bottom of the axis rect with distance to the border correspond...
Legend is vertically centered at the left of the axis rect with distance to the border corresponding ...
Legend is vertically centered at the right of the axis rect with distance to the border corresponding...
QCustomPlot * mParentPlot
Legend is positioned in the bottom left corner of the axis rect with distance to the border correspon...
◆ calculateAutoSize()
| void QCPLegend::calculateAutoSize |
( |
| ) |
|
|
protectedvirtual |
Definition at line 2989 of file qcustomplot.cc.
2994 int repeatCount = 0;
2995 while (repeat && repeatCount < 3)
2999 for (
int i=0; i<
mItems.size(); ++i)
3001 QSize s =
mItems.at(i)->size(QSize(width, 0));
3002 currentTop += s.height();
3005 if (width < s.width())
3014 qDebug() <<
FUNCNAME <<
"hit repeat limit for iterative width calculation";
3018 mSize.setWidth(width);
3020 mSize.setHeight(currentTop);
QList< QCPAbstractLegendItem * > mItems
◆ clearItems
| void QCPLegend::clearItems |
( |
| ) |
|
|
slot |
Removes all items from the legend.
Definition at line 2911 of file qcustomplot.cc.
QList< QCPAbstractLegendItem * > mItems
◆ draw()
| void QCPLegend::draw |
( |
QPainter * |
painter | ) |
|
|
protectedvirtual |
Definition at line 2935 of file qcustomplot.cc.
2939 painter->setBrush(
mBrush);
2944 painter->setClipRect(QRect(
mPosition,
mSize).adjusted(1, 1, 0, 0));
2945 painter->setPen(QPen());
2946 painter->setBrush(Qt::NoBrush);
2948 for (
int i=0; i<
mItems.size(); ++i)
2950 QSize itemSize =
mItems.at(i)->size(QSize(
mSize.width(), 0));
QList< QCPAbstractLegendItem * > mItems
◆ font
| QFont QCPLegend::font |
( |
| ) |
const |
|
inlineslot |
◆ getItemIndex
| int QCPLegend::getItemIndex |
( |
const QPoint * |
point | ) |
|
|
slot |
Definition at line 2959 of file qcustomplot.cc.
2965 for (
int i=0; i<
mItems.size(); ++i)
2967 QSize itemSize =
mItems.at(i)->size(QSize(
mSize.width(), 0));
2970 if (point->x() >= itemPosTopLeft.x() &&
2971 point->x() <= itemPosTopLeft.x()+itemSize.width() &&
2972 point->y() >= itemPosTopLeft.y() &&
2973 point->y() <= itemPosTopLeft.y()+itemSize.height())
QList< QCPAbstractLegendItem * > mItems
◆ hasItem
Returns whether the legend contains item.
Definition at line 2844 of file qcustomplot.cc.
2846 return mItems.contains(item);
QList< QCPAbstractLegendItem * > mItems
◆ hasItemWithPlottable
Returns whether the legend contains a QCPPlottableLegendItem which is associated with plottable (e.g. a QCPGraph*). If such an item isn't in the legend, returns false.
- See also
- itemWithPlottable
Definition at line 2855 of file qcustomplot.cc.
QCPPlottableLegendItem * itemWithPlottable(const QCPAbstractPlottable *plottable) const
◆ iconBorderPen
| QPen QCPLegend::iconBorderPen |
( |
| ) |
const |
|
inlineslot |
◆ iconSize
| QSize QCPLegend::iconSize |
( |
| ) |
const |
|
inlineslot |
◆ iconTextPadding
| int QCPLegend::iconTextPadding |
( |
| ) |
const |
|
inlineslot |
◆ item
Returns the item with index i.
- See also
- itemCount
Definition at line 2805 of file qcustomplot.cc.
2807 if (index >= 0 && index <
mItems.size())
QList< QCPAbstractLegendItem * > mItems
◆ itemCount
| int QCPLegend::itemCount |
( |
| ) |
const |
|
slot |
Returns the number of items currently in the legend.
- See also
- item
Definition at line 2836 of file qcustomplot.cc.
QList< QCPAbstractLegendItem * > mItems
◆ itemSpacing
| int QCPLegend::itemSpacing |
( |
| ) |
const |
|
inlineslot |
◆ itemWithPlottable
Returns the QCPPlottableLegendItem which is associated with plottable (e.g. a QCPGraph*). If such an item isn't in the legend, returns 0.
- See also
- hasItemWithPlottable
Definition at line 2819 of file qcustomplot.cc.
2821 for (
int i=0; i<
mItems.size(); ++i)
2825 if (lip->plottable() == plottable)
A legend item representing a plottable with an icon and the plottable name.
QList< QCPAbstractLegendItem * > mItems
◆ marginBottom
| int QCPLegend::marginBottom |
( |
| ) |
const |
|
inlineslot |
◆ marginLeft
| int QCPLegend::marginLeft |
( |
| ) |
const |
|
inlineslot |
◆ marginRight
| int QCPLegend::marginRight |
( |
| ) |
const |
|
inlineslot |
◆ marginTop
| int QCPLegend::marginTop |
( |
| ) |
const |
|
inlineslot |
◆ minimumSize
| QSize QCPLegend::minimumSize |
( |
| ) |
const |
|
inlineslot |
◆ paddingBottom
| int QCPLegend::paddingBottom |
( |
| ) |
const |
|
inlineslot |
◆ paddingLeft
| int QCPLegend::paddingLeft |
( |
| ) |
const |
|
inlineslot |
◆ paddingRight
| int QCPLegend::paddingRight |
( |
| ) |
const |
|
inlineslot |
◆ paddingTop
| int QCPLegend::paddingTop |
( |
| ) |
const |
|
inlineslot |
◆ position
| QPoint QCPLegend::position |
( |
| ) |
const |
|
inlineslot |
◆ positionStyle
◆ reArrange
| void QCPLegend::reArrange |
( |
| ) |
|
|
slot |
If setAutoSize is true, the size needed to fit all legend contents is calculated and applied. Finally, the automatic positioning of the legend is performed, depending on the setPositionStyle setting.
Definition at line 2922 of file qcustomplot.cc.
virtual void calculateAutoPosition()
virtual void calculateAutoSize()
◆ removeItem [1/2]
| bool QCPLegend::removeItem |
( |
int |
index | ) |
|
|
slot |
Removes the item with index index from the legend.
Returns true, if successfull.
- See also
- itemCount, clearItems
Definition at line 2884 of file qcustomplot.cc.
2886 if (index >= 0 && index <
mItems.size())
QList< QCPAbstractLegendItem * > mItems
◆ removeItem [2/2]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Removes item from the legend.
Returns true, if successfull.
- See also
- clearItems
Definition at line 2903 of file qcustomplot.cc.
bool removeItem(int index)
QList< QCPAbstractLegendItem * > mItems
◆ setAutoSize
| void QCPLegend::setAutoSize |
( |
bool |
on | ) |
|
|
slot |
Sets whether the size of the legend should be calculated automatically to fit all the content (plus padding), or whether the size must be specified manually with setSize.
If the autoSize mechanism is enabled, the legend will have the smallest possible size to still display all its content. For items with text wrapping (QCPPlottableLegendItem::setTextWrap) this means, they would become very compressed, i.e. wrapped at every word. To prevent this, set a reasonable setMinimumSize width.
Definition at line 2589 of file qcustomplot.cc.
◆ setBorderPen
| void QCPLegend::setBorderPen |
( |
const QPen & |
pen | ) |
|
|
slot |
Sets the pen, the border of the entire legend is drawn with.
Definition at line 2534 of file qcustomplot.cc.
◆ setBrush
| void QCPLegend::setBrush |
( |
const QBrush & |
brush | ) |
|
|
slot |
◆ setFont
| void QCPLegend::setFont |
( |
const QFont & |
font | ) |
|
|
slot |
Sets the default font of legend text. Legend items that draw text (e.g. the name of a graph) will use this font by default. However, a different font can be specified on a per-item-basis by accessing the specific legend item.
Definition at line 2552 of file qcustomplot.cc.
2555 for (
int i=0; i<
mItems.size(); ++i)
QList< QCPAbstractLegendItem * > mItems
◆ setIconBorderPen
| void QCPLegend::setIconBorderPen |
( |
const QPen & |
pen | ) |
|
|
slot |
Sets the default pen used to draw a border around each legend icon. Legend items that draw an icon (e.g. a visual representation of the graph) will use this pen by default. However, different values can be specified on a per-item-basis by accessing the specific legend item.
If no border is wanted, set this to Qt::NoPen.
Definition at line 2795 of file qcustomplot.cc.
◆ setIconSize [1/2]
| void QCPLegend::setIconSize |
( |
const QSize & |
size | ) |
|
|
slot |
Sets the default size of legend icons. Legend items that draw an icon (e.g. a visual representation of the graph) will use this size by default. However, different values can be specified on a per-item-basis by accessing the specific legend item.
Definition at line 2762 of file qcustomplot.cc.
◆ setIconSize [2/2]
| void QCPLegend::setIconSize |
( |
int |
width, |
|
|
int |
height |
|
) |
| |
|
slot |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2769 of file qcustomplot.cc.
◆ setIconTextPadding
| void QCPLegend::setIconTextPadding |
( |
int |
padding | ) |
|
|
slot |
Sets the default horizontal space in pixels between the legend icon and the text next to it. Legend items that draw an icon (e.g. a visual representation of the graph) and text (e.g. the name of the graph) will use this space by default. However, different values can be specified on a per-item-basis by accessing the specific legend item.
- See also
- setItemSpacing
Definition at line 2783 of file qcustomplot.cc.
◆ setItemSpacing
| void QCPLegend::setItemSpacing |
( |
int |
spacing | ) |
|
|
slot |
◆ setMargin
| void QCPLegend::setMargin |
( |
int |
left, |
|
|
int |
right, |
|
|
int |
top, |
|
|
int |
bottom |
|
) |
| |
|
slot |
◆ setMarginBottom
| void QCPLegend::setMarginBottom |
( |
int |
margin | ) |
|
|
slot |
◆ setMarginLeft
| void QCPLegend::setMarginLeft |
( |
int |
margin | ) |
|
|
slot |
◆ setMarginRight
| void QCPLegend::setMarginRight |
( |
int |
margin | ) |
|
|
slot |
◆ setMarginTop
| void QCPLegend::setMarginTop |
( |
int |
margin | ) |
|
|
slot |
◆ setMinimumSize [1/2]
| void QCPLegend::setMinimumSize |
( |
const QSize & |
size | ) |
|
|
slot |
◆ setMinimumSize [2/2]
| void QCPLegend::setMinimumSize |
( |
int |
width, |
|
|
int |
height |
|
) |
| |
|
slot |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2633 of file qcustomplot.cc.
◆ setPadding
| void QCPLegend::setPadding |
( |
int |
left, |
|
|
int |
right, |
|
|
int |
top, |
|
|
int |
bottom |
|
) |
| |
|
slot |
Sets the padding of the legend. Padding is the space by what the legend box is made larger than minimally needed for the content to fit. I.e. it's the space left blank on each side inside the legend.
Definition at line 2691 of file qcustomplot.cc.
◆ setPaddingBottom
| void QCPLegend::setPaddingBottom |
( |
int |
padding | ) |
|
|
slot |
Sets the bottom padding of the legend. Padding is the space by what the legend box is made larger than minimally needed for the content to fit. I.e. it's the space left blank on each side inside the legend.
Definition at line 2681 of file qcustomplot.cc.
◆ setPaddingLeft
| void QCPLegend::setPaddingLeft |
( |
int |
padding | ) |
|
|
slot |
Sets the left padding of the legend. Padding is the space by what the legend box is made larger than minimally needed for the content to fit. I.e. it's the space left blank on each side inside the legend.
Definition at line 2651 of file qcustomplot.cc.
◆ setPaddingRight
| void QCPLegend::setPaddingRight |
( |
int |
padding | ) |
|
|
slot |
Sets the right padding of the legend. Padding is the space by what the legend box is made larger than minimally needed for the content to fit. I.e. it's the space left blank on each side inside the legend.
Definition at line 2661 of file qcustomplot.cc.
◆ setPaddingTop
| void QCPLegend::setPaddingTop |
( |
int |
padding | ) |
|
|
slot |
Sets the top padding of the legend. Padding is the space by what the legend box is made larger than minimally needed for the content to fit. I.e. it's the space left blank on each side inside the legend.
Definition at line 2671 of file qcustomplot.cc.
◆ setPosition
| void QCPLegend::setPosition |
( |
const QPoint & |
pixelPosition | ) |
|
|
slot |
◆ setPositionStyle
| void QCPLegend::setPositionStyle |
( |
PositionStyle |
legendPositionStyle | ) |
|
|
slot |
Sets the position style of the legend. If the legendPositionStyle is not PSManual, the position is found automatically depending on the specific legendPositionStyle and the legend margins. If legendPositionStyle is PSManual, the exact pixel position of the legend must be specified via setPosition. Margins have no effect in that case.
- See also
- setMargin
Definition at line 2566 of file qcustomplot.cc.
PositionStyle mPositionStyle
◆ setSize [1/2]
| void QCPLegend::setSize |
( |
const QSize & |
size | ) |
|
|
slot |
Sets the size of the legend. Setting the size manually with this function only has an effect, if setAutoSize is set to false.
If you want to control the minimum size (or the text-wrapping width) while still leaving the autoSize mechanism enabled, consider using setMinimumSize.
- See also
- setAutoSize, setMinimumSize
Definition at line 2603 of file qcustomplot.cc.
◆ setSize [2/2]
| void QCPLegend::setSize |
( |
int |
width, |
|
|
int |
height |
|
) |
| |
|
slot |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2610 of file qcustomplot.cc.
2612 mSize = QSize(width, height);
◆ setVisible
| void QCPLegend::setVisible |
( |
bool |
on | ) |
|
|
slot |
◆ size
| QSize QCPLegend::size |
( |
| ) |
const |
|
inlineslot |
◆ visible
| bool QCPLegend::visible |
( |
| ) |
const |
|
inlineslot |
◆ QCustomPlot
◆ mAutoSize
| bool QCPLegend::mAutoSize |
|
protected |
◆ mBorderPen
| QPen QCPLegend::mBorderPen |
|
protected |
◆ mBrush
◆ mFont
◆ mIconBorderPen
| QPen QCPLegend::mIconBorderPen |
|
protected |
◆ mIconSize
| QSize QCPLegend::mIconSize |
|
protected |
◆ mIconTextPadding
| int QCPLegend::mIconTextPadding |
|
protected |
◆ mItems
◆ mItemSpacing
| int QCPLegend::mItemSpacing |
|
protected |
◆ mMarginBottom
| int QCPLegend::mMarginBottom |
|
protected |
◆ mMarginLeft
| int QCPLegend::mMarginLeft |
|
protected |
◆ mMarginRight
| int QCPLegend::mMarginRight |
|
protected |
◆ mMarginTop
| int QCPLegend::mMarginTop |
|
protected |
◆ mMinimumSize
| QSize QCPLegend::mMinimumSize |
|
protected |
◆ mPaddingBottom
| int QCPLegend::mPaddingBottom |
|
protected |
◆ mPaddingLeft
| int QCPLegend::mPaddingLeft |
|
protected |
◆ mPaddingRight
| int QCPLegend::mPaddingRight |
|
protected |
◆ mPaddingTop
| int QCPLegend::mPaddingTop |
|
protected |
◆ mParentPlot
◆ mPosition
| QPoint QCPLegend::mPosition |
|
protected |
◆ mPositionStyle
◆ mSize
◆ mVisible
The documentation for this class was generated from the following files:
- /build/rock-master-18.09-gui-rock-widget-collection-0.20180124/src/plot2d/qcustomplot.h
- /build/rock-master-18.09-gui-rock-widget-collection-0.20180124/src/plot2d/qcustomplot.cc