rock_widget_collection  0.1
Public Types | Public Slots | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
QCPLegend Class Reference

Manages a legend inside a QCustomPlot. More...

#include <qcustomplot.h>

Inherits QObject.

Public Types

enum  PositionStyle {
  PSManual, PSTopLeft, PSTop, PSTopRight,
  PSRight, PSBottomRight, PSBottom, PSBottomLeft,
  PSLeft
}
 

Public Slots

QPen borderPen () const
 
QBrush brush () const
 
QFont font () const
 
PositionStyle positionStyle () const
 
QPoint position () const
 
bool autoSize () const
 
QSize size () const
 
QSize minimumSize () const
 
bool visible () const
 
int paddingLeft () const
 
int paddingRight () const
 
int paddingTop () const
 
int paddingBottom () const
 
int marginLeft () const
 
int marginRight () const
 
int marginTop () const
 
int marginBottom () const
 
int itemSpacing () const
 
QSize iconSize () const
 
int iconTextPadding () const
 
QPen iconBorderPen () const
 
int getItemIndex (const QPoint *point)
 
void setBorderPen (const QPen &pen)
 
void setBrush (const QBrush &brush)
 
void setFont (const QFont &font)
 
void setPositionStyle (PositionStyle legendPositionStyle)
 
void setPosition (const QPoint &pixelPosition)
 
void setAutoSize (bool on)
 
void setSize (const QSize &size)
 
void setSize (int width, int height)
 
void setMinimumSize (const QSize &size)
 
void setMinimumSize (int width, int height)
 
void setVisible (bool on)
 
void setPaddingLeft (int padding)
 
void setPaddingRight (int padding)
 
void setPaddingTop (int padding)
 
void setPaddingBottom (int padding)
 
void setPadding (int left, int right, int top, int bottom)
 
void setMarginLeft (int margin)
 
void setMarginRight (int margin)
 
void setMarginTop (int margin)
 
void setMarginBottom (int margin)
 
void setMargin (int left, int right, int top, int bottom)
 
void setItemSpacing (int spacing)
 
void setIconSize (const QSize &size)
 
void setIconSize (int width, int height)
 
void setIconTextPadding (int padding)
 
void setIconBorderPen (const QPen &pen)
 
QCPAbstractLegendItemitem (int index) const
 
QCPPlottableLegendItemitemWithPlottable (const QCPAbstractPlottable *plottable) const
 
int itemCount () const
 
bool hasItem (QCPAbstractLegendItem *item) const
 
bool hasItemWithPlottable (const QCPAbstractPlottable *plottable) const
 
bool addItem (QCPAbstractLegendItem *item)
 
bool removeItem (int index)
 
bool removeItem (QCPAbstractLegendItem *item)
 
void clearItems ()
 
void reArrange ()
 

Public Member Functions

 QCPLegend (QCustomPlot *parentPlot)
 
virtual ~QCPLegend ()
 

Protected Member Functions

virtual void draw (QPainter *painter)
 
virtual void calculateAutoSize ()
 
virtual void calculateAutoPosition ()
 

Protected Attributes

QPen mBorderPen
 
QPen mIconBorderPen
 
QBrush mBrush
 
QFont mFont
 
QPoint mPosition
 
QSize mSize
 
QSize mMinimumSize
 
QSize mIconSize
 
PositionStyle mPositionStyle
 
bool mAutoSize
 
bool mVisible
 
int mPaddingLeft
 
int mPaddingRight
 
int mPaddingTop
 
int mPaddingBottom
 
int mMarginLeft
 
int mMarginRight
 
int mMarginTop
 
int mMarginBottom
 
int mItemSpacing
 
int mIconTextPadding
 
QCustomPlotmParentPlot
 
QList< QCPAbstractLegendItem * > mItems
 

Friends

class QCustomPlot
 

Detailed Description

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.

Member Enumeration Documentation

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.

561  {PSManual,
562  PSTopLeft,
563  PSTop,
564  PSTopRight,
565  PSRight,
566  PSBottomRight,
567  PSBottom,
568  PSBottomLeft,
569  PSLeft
570  };
Position is not changed automatically. Set manually via setPosition.
Definition: qcustomplot.h:561
Legend is positioned in the bottom right corner of the axis rect with distance to the border correspo...
Definition: qcustomplot.h:566
Legend is horizontally centered at the top of the axis rect with distance to the border corresponding...
Definition: qcustomplot.h:563
Legend is positioned in the top left corner of the axis rect with distance to the border correspondin...
Definition: qcustomplot.h:562
Legend is positioned in the top right corner of the axis rect with distance to the border correspondi...
Definition: qcustomplot.h:564
Legend is horizontally centered at the bottom of the axis rect with distance to the border correspond...
Definition: qcustomplot.h:567
Legend is vertically centered at the left of the axis rect with distance to the border corresponding ...
Definition: qcustomplot.h:569
Legend is vertically centered at the right of the axis rect with distance to the border corresponding...
Definition: qcustomplot.h:565
Legend is positioned in the bottom left corner of the axis rect with distance to the border correspon...
Definition: qcustomplot.h:568

Constructor & Destructor Documentation

QCPLegend::QCPLegend ( QCustomPlot parentPlot)
explicit

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.

2505  :
2506  QObject(parentPlot)
2507 {
2508  mParentPlot = parentPlot;
2509  setVisible(true);
2510  setBorderPen(QPen(Qt::black));
2511  setIconBorderPen(Qt::NoPen);
2512  setBrush(QBrush(Qt::white));
2513  setFont(parentPlot->font());
2515  setSize(100, 28);
2516  setMinimumSize(100, 0);
2517  setAutoSize(true);
2518 
2519  setMargin(12, 12, 12, 12);
2520  setPadding(8, 8, 3, 3);
2521  setIconSize(32, 18);
2522  setItemSpacing(3);
2523  setIconTextPadding(7);
2524 }
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...
Definition: qcustomplot.h:564
void setFont(const QFont &font)
void setVisible(bool on)
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
Definition: qcustomplot.h:656
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 ( )
virtual

Definition at line 2526 of file qcustomplot.cc.

2527 {
2528  clearItems();
2529 }
void clearItems()

Member Function Documentation

bool QCPLegend::addItem ( QCPAbstractLegendItem item)
slot

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.

2868 {
2869  if (!mItems.contains(item))
2870  {
2871  mItems.append(item);
2872  return true;
2873  } else
2874  return false;
2875 }
QList< QCPAbstractLegendItem * > mItems
Definition: qcustomplot.h:657
bool QCPLegend::autoSize ( ) const
inlineslot

Definition at line 583 of file qcustomplot.h.

583 { return mAutoSize; }
bool mAutoSize
Definition: qcustomplot.h:650
QPen QCPLegend::borderPen ( ) const
inlineslot

Definition at line 578 of file qcustomplot.h.

578 { return mBorderPen; }
QPen mBorderPen
Definition: qcustomplot.h:644
QBrush QCPLegend::brush ( ) const
inlineslot

Definition at line 579 of file qcustomplot.h.

579 { return mBrush; }
QBrush mBrush
Definition: qcustomplot.h:645
void QCPLegend::calculateAutoPosition ( )
protectedvirtual

Definition at line 3029 of file qcustomplot.cc.

3030 {
3031  if (mPositionStyle == PSTopLeft)
3032  {
3033  mPosition = mParentPlot->mAxisRect.topLeft() + QPoint(mMarginLeft, mMarginTop);
3034  } else if (mPositionStyle == PSTop)
3035  {
3036  mPosition = mParentPlot->mAxisRect.topLeft() + QPoint(mParentPlot->mAxisRect.width()/2.0-mSize.width()/2.0, mMarginTop);
3037  } else if (mPositionStyle == PSTopRight)
3038  {
3039  mPosition = mParentPlot->mAxisRect.topRight() + QPoint(-mMarginRight-mSize.width(), mMarginTop);
3040  } else if (mPositionStyle == PSRight)
3041  {
3042  mPosition = mParentPlot->mAxisRect.topRight() + QPoint(-mMarginRight-mSize.width(), mParentPlot->mAxisRect.height()/2.0-mSize.height()/2.0);
3043  } else if (mPositionStyle == PSBottomRight)
3044  {
3045  mPosition = mParentPlot->mAxisRect.bottomRight() + QPoint(-mMarginRight-mSize.width(), -mMarginBottom-mSize.height());
3046  } else if (mPositionStyle == PSBottom)
3047  {
3048  mPosition = mParentPlot->mAxisRect.bottomLeft() + QPoint(mParentPlot->mAxisRect.width()/2.0-mSize.width()/2.0, -mMarginBottom-mSize.height());
3049  } else if (mPositionStyle == PSBottomLeft)
3050  {
3051  mPosition = mParentPlot->mAxisRect.bottomLeft() + QPoint(mMarginLeft, -mMarginBottom-mSize.height());
3052  } else if (mPositionStyle == PSLeft)
3053  {
3054  mPosition = mParentPlot->mAxisRect.topLeft() + QPoint(mMarginLeft, mParentPlot->mAxisRect.height()/2.0-mSize.height()/2.0);
3055  }
3056 }
Legend is positioned in the bottom right corner of the axis rect with distance to the border correspo...
Definition: qcustomplot.h:566
Legend is horizontally centered at the top of the axis rect with distance to the border corresponding...
Definition: qcustomplot.h:563
QRect mAxisRect
Definition: qcustomplot.h:1014
int mMarginBottom
Definition: qcustomplot.h:652
Legend is positioned in the top left corner of the axis rect with distance to the border correspondin...
Definition: qcustomplot.h:562
QPoint mPosition
Definition: qcustomplot.h:647
PositionStyle mPositionStyle
Definition: qcustomplot.h:649
Legend is positioned in the top right corner of the axis rect with distance to the border correspondi...
Definition: qcustomplot.h:564
Legend is horizontally centered at the bottom of the axis rect with distance to the border correspond...
Definition: qcustomplot.h:567
Legend is vertically centered at the left of the axis rect with distance to the border corresponding ...
Definition: qcustomplot.h:569
Legend is vertically centered at the right of the axis rect with distance to the border corresponding...
Definition: qcustomplot.h:565
int mMarginLeft
Definition: qcustomplot.h:652
QSize mSize
Definition: qcustomplot.h:648
int mMarginTop
Definition: qcustomplot.h:652
QCustomPlot * mParentPlot
Definition: qcustomplot.h:656
int mMarginRight
Definition: qcustomplot.h:652
Legend is positioned in the bottom left corner of the axis rect with distance to the border correspon...
Definition: qcustomplot.h:568
void QCPLegend::calculateAutoSize ( )
protectedvirtual

Definition at line 2989 of file qcustomplot.cc.

2990 {
2991  int width = mMinimumSize.width()-mPaddingLeft-mPaddingRight; // start with minimum width and only expand from there
2992  int currentTop;
2993  bool repeat = true;
2994  int repeatCount = 0;
2995  while (repeat && repeatCount < 3) // repeat until we find self-consistent width (usually 2 runs)
2996  {
2997  repeat = false;
2998  currentTop = mPaddingTop;
2999  for (int i=0; i<mItems.size(); ++i)
3000  {
3001  QSize s = mItems.at(i)->size(QSize(width, 0));
3002  currentTop += s.height();
3003  if (i < mItems.size()-1) // vertical spacer for all but last item
3004  currentTop += mItemSpacing;
3005  if (width < s.width())
3006  {
3007  width = s.width();
3008  repeat = true; // changed width, so need a new run with new width to let other items adapt their height to that new width
3009  }
3010  }
3011  repeatCount++;
3012  }
3013  if (repeat)
3014  qDebug() << FUNCNAME << "hit repeat limit for iterative width calculation";
3015  currentTop += mPaddingBottom;
3016  width += mPaddingLeft+mPaddingRight;
3017 
3018  mSize.setWidth(width);
3019  if (currentTop > mMinimumSize.height())
3020  mSize.setHeight(currentTop);
3021  else
3022  mSize.setHeight(mMinimumSize.height());
3023 }
int mPaddingBottom
Definition: qcustomplot.h:651
int mPaddingLeft
Definition: qcustomplot.h:651
QSize mMinimumSize
Definition: qcustomplot.h:648
int mItemSpacing
Definition: qcustomplot.h:653
int mPaddingTop
Definition: qcustomplot.h:651
QSize mSize
Definition: qcustomplot.h:648
#define FUNCNAME
Definition: qcustomplot.h:50
int mPaddingRight
Definition: qcustomplot.h:651
QList< QCPAbstractLegendItem * > mItems
Definition: qcustomplot.h:657
void QCPLegend::clearItems ( )
slot

Removes all items from the legend.

Definition at line 2911 of file qcustomplot.cc.

2912 {
2913  qDeleteAll(mItems);
2914  mItems.clear();
2915 }
QList< QCPAbstractLegendItem * > mItems
Definition: qcustomplot.h:657
void QCPLegend::draw ( QPainter *  painter)
protectedvirtual

Definition at line 2935 of file qcustomplot.cc.

2936 {
2937  if (!mVisible) return;
2938  painter->save();
2939  painter->setBrush(mBrush);
2940  painter->setPen(mBorderPen);
2941  // draw background rect:
2942  painter->drawRect(QRect(mPosition, mSize));
2943  // draw legend items:
2944  painter->setClipRect(QRect(mPosition, mSize).adjusted(1, 1, 0, 0));
2945  painter->setPen(QPen());
2946  painter->setBrush(Qt::NoBrush);
2947  int currentTop = mPosition.y()+mPaddingTop;
2948  for (int i=0; i<mItems.size(); ++i)
2949  {
2950  QSize itemSize = mItems.at(i)->size(QSize(mSize.width(), 0));
2951  painter->save(); // this might be user subclass, so we save painter outside - just in case
2952  mItems.at(i)->draw(painter, QRect(QPoint(mPosition.x()+mPaddingLeft, currentTop), itemSize));
2953  painter->restore();
2954  currentTop += itemSize.height()+mItemSpacing;
2955  }
2956  painter->restore();
2957 }
QBrush mBrush
Definition: qcustomplot.h:645
QPoint mPosition
Definition: qcustomplot.h:647
int mPaddingLeft
Definition: qcustomplot.h:651
bool mVisible
Definition: qcustomplot.h:650
int mItemSpacing
Definition: qcustomplot.h:653
int mPaddingTop
Definition: qcustomplot.h:651
QSize mSize
Definition: qcustomplot.h:648
QList< QCPAbstractLegendItem * > mItems
Definition: qcustomplot.h:657
QPen mBorderPen
Definition: qcustomplot.h:644
QFont QCPLegend::font ( ) const
inlineslot

Definition at line 580 of file qcustomplot.h.

580 { return mFont; }
QFont mFont
Definition: qcustomplot.h:646
int QCPLegend::getItemIndex ( const QPoint *  point)
slot

Definition at line 2959 of file qcustomplot.cc.

2960 {
2961  if (!mVisible) return -1;
2962 
2963  int currentTop = mPosition.y() + mPaddingTop;
2964 
2965  for (int i=0; i<mItems.size(); ++i)
2966  {
2967  QSize itemSize = mItems.at(i)->size(QSize(mSize.width(), 0));
2968  QPoint itemPosTopLeft = QPoint(mPosition.x()+mPaddingLeft, currentTop);
2969 
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())
2974  {
2975  return i;
2976  }
2977 
2978  currentTop += itemSize.height()+mItemSpacing;
2979  }
2980 
2981  return -1;
2982 }
QPoint mPosition
Definition: qcustomplot.h:647
int mPaddingLeft
Definition: qcustomplot.h:651
bool mVisible
Definition: qcustomplot.h:650
int mItemSpacing
Definition: qcustomplot.h:653
int mPaddingTop
Definition: qcustomplot.h:651
QSize mSize
Definition: qcustomplot.h:648
QList< QCPAbstractLegendItem * > mItems
Definition: qcustomplot.h:657
bool QCPLegend::hasItem ( QCPAbstractLegendItem item) const
slot

Returns whether the legend contains item.

Definition at line 2844 of file qcustomplot.cc.

2845 {
2846  return mItems.contains(item);
2847 }
QList< QCPAbstractLegendItem * > mItems
Definition: qcustomplot.h:657
bool QCPLegend::hasItemWithPlottable ( const QCPAbstractPlottable plottable) const
slot

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.

2856 {
2857  return itemWithPlottable(plottable);
2858 }
QCPPlottableLegendItem * itemWithPlottable(const QCPAbstractPlottable *plottable) const
QPen QCPLegend::iconBorderPen ( ) const
inlineslot

Definition at line 598 of file qcustomplot.h.

598 { return mIconBorderPen; }
QPen mIconBorderPen
Definition: qcustomplot.h:644
QSize QCPLegend::iconSize ( ) const
inlineslot

Definition at line 596 of file qcustomplot.h.

596 { return mIconSize; }
QSize mIconSize
Definition: qcustomplot.h:648
int QCPLegend::iconTextPadding ( ) const
inlineslot

Definition at line 597 of file qcustomplot.h.

597 { return mIconTextPadding; }
int mIconTextPadding
Definition: qcustomplot.h:653
QCPAbstractLegendItem * QCPLegend::item ( int  index) const
slot

Returns the item with index i.

See also
itemCount

Definition at line 2805 of file qcustomplot.cc.

2806 {
2807  if (index >= 0 && index < mItems.size())
2808  return mItems[index];
2809  else
2810  return 0;
2811 }
QList< QCPAbstractLegendItem * > mItems
Definition: qcustomplot.h:657
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.

2837 {
2838  return mItems.size();
2839 }
QList< QCPAbstractLegendItem * > mItems
Definition: qcustomplot.h:657
int QCPLegend::itemSpacing ( ) const
inlineslot

Definition at line 595 of file qcustomplot.h.

595 { return mItemSpacing; }
int mItemSpacing
Definition: qcustomplot.h:653
QCPPlottableLegendItem * QCPLegend::itemWithPlottable ( const QCPAbstractPlottable plottable) const
slot

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.

2820 {
2821  for (int i=0; i<mItems.size(); ++i)
2822  {
2823  if (QCPPlottableLegendItem *lip = dynamic_cast<QCPPlottableLegendItem*>(mItems.at(i)))
2824  {
2825  if (lip->plottable() == plottable)
2826  return lip;
2827  }
2828  }
2829  return 0;
2830 }
A legend item representing a plottable with an icon and the plottable name.
Definition: qcustomplot.h:533
QList< QCPAbstractLegendItem * > mItems
Definition: qcustomplot.h:657
int QCPLegend::marginBottom ( ) const
inlineslot

Definition at line 594 of file qcustomplot.h.

594 { return mMarginBottom; }
int mMarginBottom
Definition: qcustomplot.h:652
int QCPLegend::marginLeft ( ) const
inlineslot

Definition at line 591 of file qcustomplot.h.

591 { return mMarginLeft; }
int mMarginLeft
Definition: qcustomplot.h:652
int QCPLegend::marginRight ( ) const
inlineslot

Definition at line 592 of file qcustomplot.h.

592 { return mMarginRight; }
int mMarginRight
Definition: qcustomplot.h:652
int QCPLegend::marginTop ( ) const
inlineslot

Definition at line 593 of file qcustomplot.h.

593 { return mMarginTop; }
int mMarginTop
Definition: qcustomplot.h:652
QSize QCPLegend::minimumSize ( ) const
inlineslot

Definition at line 585 of file qcustomplot.h.

585 { return mMinimumSize; }
QSize mMinimumSize
Definition: qcustomplot.h:648
int QCPLegend::paddingBottom ( ) const
inlineslot

Definition at line 590 of file qcustomplot.h.

590 { return mPaddingBottom; }
int mPaddingBottom
Definition: qcustomplot.h:651
int QCPLegend::paddingLeft ( ) const
inlineslot

Definition at line 587 of file qcustomplot.h.

587 { return mPaddingLeft; }
int mPaddingLeft
Definition: qcustomplot.h:651
int QCPLegend::paddingRight ( ) const
inlineslot

Definition at line 588 of file qcustomplot.h.

588 { return mPaddingRight; }
int mPaddingRight
Definition: qcustomplot.h:651
int QCPLegend::paddingTop ( ) const
inlineslot

Definition at line 589 of file qcustomplot.h.

589 { return mPaddingTop; }
int mPaddingTop
Definition: qcustomplot.h:651
QPoint QCPLegend::position ( ) const
inlineslot

Definition at line 582 of file qcustomplot.h.

582 { return mPosition; }
QPoint mPosition
Definition: qcustomplot.h:647
PositionStyle QCPLegend::positionStyle ( ) const
inlineslot

Definition at line 581 of file qcustomplot.h.

581 { return mPositionStyle; }
PositionStyle mPositionStyle
Definition: qcustomplot.h:649
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.

2923 {
2924  if (mAutoSize)
2925  {
2927  }
2929 }
virtual void calculateAutoPosition()
bool mAutoSize
Definition: qcustomplot.h:650
virtual void calculateAutoSize()
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.

2885 {
2886  if (index >= 0 && index < mItems.size())
2887  {
2888  delete mItems.at(index);
2889  mItems.removeAt(index);
2890  return true;
2891  } else
2892  return false;
2893 }
QList< QCPAbstractLegendItem * > mItems
Definition: qcustomplot.h:657
bool QCPLegend::removeItem ( QCPAbstractLegendItem item)
slot

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.

2904 {
2905  return removeItem(mItems.indexOf(item));
2906 }
bool removeItem(int index)
QList< QCPAbstractLegendItem * > mItems
Definition: qcustomplot.h:657
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.

2590 {
2591  mAutoSize = on;
2592 }
bool mAutoSize
Definition: qcustomplot.h:650
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.

2535 {
2536  mBorderPen = pen;
2537 }
QPen mBorderPen
Definition: qcustomplot.h:644
void QCPLegend::setBrush ( const QBrush &  brush)
slot

Sets the brush of the legend background.

Definition at line 2542 of file qcustomplot.cc.

2543 {
2544  mBrush = brush;
2545 }
QBrush mBrush
Definition: qcustomplot.h:645
QBrush brush() const
Definition: qcustomplot.h:579
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.

2553 {
2554  mFont = font;
2555  for (int i=0; i<mItems.size(); ++i)
2556  mItems.at(i)->setFont(mFont);
2557 }
QFont font() const
Definition: qcustomplot.h:580
QFont mFont
Definition: qcustomplot.h:646
QList< QCPAbstractLegendItem * > mItems
Definition: qcustomplot.h:657
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.

2796 {
2797  mIconBorderPen = pen;
2798 }
QPen mIconBorderPen
Definition: qcustomplot.h:644
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.

2763 {
2764  mIconSize = size;
2765 }
QSize mIconSize
Definition: qcustomplot.h:648
QSize size() const
Definition: qcustomplot.h:584
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.

2770 {
2771  mIconSize.setWidth(width);
2772  mIconSize.setHeight(height);
2773 }
QSize mIconSize
Definition: qcustomplot.h:648
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.

2784 {
2785  mIconTextPadding = padding;
2786 }
int mIconTextPadding
Definition: qcustomplot.h:653
void QCPLegend::setItemSpacing ( int  spacing)
slot

Sets the vertical space between two legend items in the legend.

See also
setIconTextPadding, setPadding

Definition at line 2752 of file qcustomplot.cc.

2753 {
2754  mItemSpacing = spacing;
2755 }
int mItemSpacing
Definition: qcustomplot.h:653
void QCPLegend::setMargin ( int  left,
int  right,
int  top,
int  bottom 
)
slot

Sets the margin of the legend. Margins are the distances the legend will keep to the axis rect, when setPositionStyle is not PSManual.

Definition at line 2739 of file qcustomplot.cc.

2740 {
2741  mMarginLeft = left;
2742  mMarginRight = right;
2743  mMarginTop = top;
2744  mMarginBottom = bottom;
2745 }
int mMarginBottom
Definition: qcustomplot.h:652
int mMarginLeft
Definition: qcustomplot.h:652
int mMarginTop
Definition: qcustomplot.h:652
int mMarginRight
Definition: qcustomplot.h:652
void QCPLegend::setMarginBottom ( int  margin)
slot

Sets the bottom margin of the legend. Margins are the distances the legend will keep to the axis rect, when setPositionStyle is not PSManual.

Definition at line 2730 of file qcustomplot.cc.

2731 {
2732  mMarginBottom = margin;
2733 }
int mMarginBottom
Definition: qcustomplot.h:652
void QCPLegend::setMarginLeft ( int  margin)
slot

Sets the left margin of the legend. Margins are the distances the legend will keep to the axis rect, when setPositionStyle is not PSManual.

Definition at line 2703 of file qcustomplot.cc.

2704 {
2705  mMarginLeft = margin;
2706 }
int mMarginLeft
Definition: qcustomplot.h:652
void QCPLegend::setMarginRight ( int  margin)
slot

Sets the right margin of the legend. Margins are the distances the legend will keep to the axis rect, when setPositionStyle is not PSManual.

Definition at line 2712 of file qcustomplot.cc.

2713 {
2714  mMarginRight = margin;
2715 }
int mMarginRight
Definition: qcustomplot.h:652
void QCPLegend::setMarginTop ( int  margin)
slot

Sets the top margin of the legend. Margins are the distances the legend will keep to the axis rect, when setPositionStyle is not PSManual.

Definition at line 2721 of file qcustomplot.cc.

2722 {
2723  mMarginTop = margin;
2724 }
int mMarginTop
Definition: qcustomplot.h:652
void QCPLegend::setMinimumSize ( const QSize &  size)
slot

Sets the minimum size of the legend when setAutoSize is enabled.

If text wrapping is enabled in the legend items (e.g. QCPPlottableLegendItem::setTextWrap), this minimum size defines the width at which the wrapping will occur. Note that the wrapping will happen only at word boundaries, so the actual size might still be bigger than the size given here, but not smaller.

If setAutoSize is not enabled, the minimum size is ignored. Setting a smaller legend size with setSize manually, is not prevented.

See also
setAutoSize, setSize, QCPPlottableLegendItem::setTextWrap

Definition at line 2626 of file qcustomplot.cc.

2627 {
2628  mMinimumSize = size;
2629 }
QSize mMinimumSize
Definition: qcustomplot.h:648
QSize size() const
Definition: qcustomplot.h:584
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.

2634 {
2635  mMinimumSize = QSize(width, height);
2636 }
QSize mMinimumSize
Definition: qcustomplot.h:648
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.

2692 {
2693  mPaddingLeft = left;
2694  mPaddingRight = right;
2695  mPaddingTop = top;
2696  mPaddingBottom = bottom;
2697 }
int mPaddingBottom
Definition: qcustomplot.h:651
int mPaddingLeft
Definition: qcustomplot.h:651
int mPaddingTop
Definition: qcustomplot.h:651
int mPaddingRight
Definition: qcustomplot.h:651
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.

2682 {
2683  mPaddingBottom = padding;
2684 }
int mPaddingBottom
Definition: qcustomplot.h:651
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.

2652 {
2653  mPaddingLeft = padding;
2654 }
int mPaddingLeft
Definition: qcustomplot.h:651
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.

2662 {
2663  mPaddingRight = padding;
2664 }
int mPaddingRight
Definition: qcustomplot.h:651
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.

2672 {
2673  mPaddingTop = padding;
2674 }
int mPaddingTop
Definition: qcustomplot.h:651
void QCPLegend::setPosition ( const QPoint &  pixelPosition)
slot

Sets the exact pixel Position of the legend inside the QCustomPlot widget, if setPositionStyle is set to PSManual. Margins have no effect in that case.

Definition at line 2575 of file qcustomplot.cc.

2576 {
2577  mPosition = pixelPosition;
2578 }
QPoint mPosition
Definition: qcustomplot.h:647
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.

2567 {
2568  mPositionStyle = legendPositionStyle;
2569 }
PositionStyle mPositionStyle
Definition: qcustomplot.h:649
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.

2604 {
2605  mSize = size;
2606 }
QSize size() const
Definition: qcustomplot.h:584
QSize mSize
Definition: qcustomplot.h:648
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.

2611 {
2612  mSize = QSize(width, height);
2613 }
QSize mSize
Definition: qcustomplot.h:648
void QCPLegend::setVisible ( bool  on)
slot

Sets the visibility of the legend.

Definition at line 2641 of file qcustomplot.cc.

2642 {
2643  mVisible = on;
2644 }
bool mVisible
Definition: qcustomplot.h:650
QSize QCPLegend::size ( ) const
inlineslot

Definition at line 584 of file qcustomplot.h.

584 { return mSize; }
QSize mSize
Definition: qcustomplot.h:648
bool QCPLegend::visible ( ) const
inlineslot

Definition at line 586 of file qcustomplot.h.

586 { return mVisible; }
bool mVisible
Definition: qcustomplot.h:650

Friends And Related Function Documentation

friend class QCustomPlot
friend

Definition at line 664 of file qcustomplot.h.

Member Data Documentation

bool QCPLegend::mAutoSize
protected

Definition at line 650 of file qcustomplot.h.

QPen QCPLegend::mBorderPen
protected

Definition at line 644 of file qcustomplot.h.

QBrush QCPLegend::mBrush
protected

Definition at line 645 of file qcustomplot.h.

QFont QCPLegend::mFont
protected

Definition at line 646 of file qcustomplot.h.

QPen QCPLegend::mIconBorderPen
protected

Definition at line 644 of file qcustomplot.h.

QSize QCPLegend::mIconSize
protected

Definition at line 648 of file qcustomplot.h.

int QCPLegend::mIconTextPadding
protected

Definition at line 653 of file qcustomplot.h.

QList<QCPAbstractLegendItem*> QCPLegend::mItems
protected

Definition at line 657 of file qcustomplot.h.

int QCPLegend::mItemSpacing
protected

Definition at line 653 of file qcustomplot.h.

int QCPLegend::mMarginBottom
protected

Definition at line 652 of file qcustomplot.h.

int QCPLegend::mMarginLeft
protected

Definition at line 652 of file qcustomplot.h.

int QCPLegend::mMarginRight
protected

Definition at line 652 of file qcustomplot.h.

int QCPLegend::mMarginTop
protected

Definition at line 652 of file qcustomplot.h.

QSize QCPLegend::mMinimumSize
protected

Definition at line 648 of file qcustomplot.h.

int QCPLegend::mPaddingBottom
protected

Definition at line 651 of file qcustomplot.h.

int QCPLegend::mPaddingLeft
protected

Definition at line 651 of file qcustomplot.h.

int QCPLegend::mPaddingRight
protected

Definition at line 651 of file qcustomplot.h.

int QCPLegend::mPaddingTop
protected

Definition at line 651 of file qcustomplot.h.

QCustomPlot* QCPLegend::mParentPlot
protected

Definition at line 656 of file qcustomplot.h.

QPoint QCPLegend::mPosition
protected

Definition at line 647 of file qcustomplot.h.

PositionStyle QCPLegend::mPositionStyle
protected

Definition at line 649 of file qcustomplot.h.

QSize QCPLegend::mSize
protected

Definition at line 648 of file qcustomplot.h.

bool QCPLegend::mVisible
protected

Definition at line 650 of file qcustomplot.h.


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