17 #include <qlayoutitem.h> 24 class QwtLegendLayoutItem
QWT_FINAL:
public QLayoutItem
28 virtual ~QwtLegendLayoutItem();
35 virtual Qt::Orientations expandingDirections() const
QWT_OVERRIDE;
37 virtual
bool hasHeightForWidth() const QWT_OVERRIDE;
38 virtual
int heightForWidth(
int ) const QWT_OVERRIDE;
39 virtual
bool isEmpty() const QWT_OVERRIDE;
40 virtual QSize maximumSize() const QWT_OVERRIDE;
41 virtual
int minimumHeightForWidth(
int ) const QWT_OVERRIDE;
42 virtual QSize minimumSize() const QWT_OVERRIDE;
43 virtual
void setGeometry( const QRect & ) QWT_OVERRIDE;
44 virtual QSize sizeHint() const QWT_OVERRIDE;
56 QwtLegendLayoutItem::QwtLegendLayoutItem(
58 d_legendItem( legendItem ),
63 QwtLegendLayoutItem::~QwtLegendLayoutItem()
67 const QwtPlotItem *QwtLegendLayoutItem::plotItem()
const 82 Qt::Orientations QwtLegendLayoutItem::expandingDirections()
const 84 return Qt::Horizontal;
87 bool QwtLegendLayoutItem::hasHeightForWidth()
const 89 return !d_data.title().isEmpty();
92 int QwtLegendLayoutItem::minimumHeightForWidth(
int w )
const 94 return d_legendItem->heightForWidth( d_data, w );
97 int QwtLegendLayoutItem::heightForWidth(
int w )
const 99 return d_legendItem->heightForWidth( d_data, w );
102 bool QwtLegendLayoutItem::isEmpty()
const 107 QSize QwtLegendLayoutItem::maximumSize()
const 109 return QSize( QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX );
112 QSize QwtLegendLayoutItem::minimumSize()
const 114 return d_legendItem->minimumSize( d_data );
117 QSize QwtLegendLayoutItem::sizeHint()
const 119 return minimumSize();
122 void QwtLegendLayoutItem::setGeometry(
const QRect &rect )
127 QRect QwtLegendLayoutItem::geometry()
const 139 borderPen( Qt::NoPen ),
140 backgroundBrush( Qt::NoBrush ),
142 canvasAlignment( Qt::AlignRight | Qt::AlignBottom )
144 canvasOffset[ 0 ] = canvasOffset[1] = 10;
146 layout->setMaxColumns( 2 );
148 layout->setSpacing( 0 );
149 layout->setContentsMargins( 0, 0, 0, 0 );
266 margin = qMax( margin, 0 );
267 if ( margin != this->
margin() )
270 margin, margin, margin, margin );
283 d_data->
layout->getContentsMargins( &left, NULL, NULL, NULL );
296 spacing = qMax( spacing, 0 );
321 margin = qMax( margin, 0 );
348 spacing = qMax( spacing, 0 );
406 Qt::Orientations orientations,
int numPixels )
411 bool isChanged =
false;
415 if ( orientations & Qt::Horizontal )
417 if ( numPixels != offset[0] )
419 offset[0] = numPixels;
424 if ( orientations & Qt::Vertical )
426 if ( numPixels != offset[1] )
428 offset[1] = numPixels;
445 Qt::Orientation orientation )
const 447 const int index = ( orientation == Qt::Vertical ) ? 1 : 0;
459 radius =
qwtMaxF( 0.0, radius );
589 const QRectF &canvasRect )
const 606 const QwtLegendLayoutItem *layoutItem =
615 layoutItem->data(), layoutItem->geometry() );
631 QPainter *painter,
const QRectF &rect )
const 639 painter->drawRoundedRect( rect, radius, radius );
657 int x = qRound( canvasRect.center().x() );
658 rect.moveCenter( QPoint( x, rect.center().y() ) );
663 rect.moveRight(
qwtFloor( canvasRect.right() - offset ) );
668 rect.moveLeft(
qwtCeil( canvasRect.left() + offset ) );
673 int y = qRound( canvasRect.center().y() );
674 rect.moveCenter( QPoint( rect.center().x(), y ) );
679 rect.moveBottom(
qwtFloor( canvasRect.bottom() - offset ) );
684 rect.moveTop(
qwtCeil( canvasRect.top() + offset ) );
700 if ( plotItem == NULL )
708 layoutItems = it.value();
710 bool changed =
false;
712 if ( data.size() != layoutItems.size() )
716 for (
int i = 0; i < layoutItems.size(); i++ )
719 delete layoutItems[i];
726 if ( !data.isEmpty() )
728 layoutItems.reserve( data.size() );
730 for (
int i = 0; i < data.size(); i++ )
732 QwtLegendLayoutItem *layoutItem =
733 new QwtLegendLayoutItem(
this, plotItem );
735 layoutItems += layoutItem;
738 d_data->
map.insert( plotItem, layoutItems );
742 for (
int i = 0; i < data.size(); i++ )
744 if ( layoutItems[i]->
data().values() != data[i].values() )
746 layoutItems[i]->setData( data[i] );
782 const QRectF &rect )
const 784 Q_UNUSED( plotItem );
787 const QRectF r = rect.toRect().adjusted( m, m, -m, -m );
789 painter->setClipRect( r, Qt::IntersectClip );
796 QRectF iconRect( r.topLeft(), graphic.
defaultSize() );
799 QPoint( iconRect.center().x(), rect.center().y() ) );
801 graphic.
render( painter, iconRect, Qt::KeepAspectRatio );
812 const QRectF textRect = r.adjusted( titleOff, 0, 0, 0 );
813 text.
draw( painter, textRect );
839 h = graphic.height();
847 h = qMax( h,
qwtCeil( sz.height() ) );
850 if ( graphic.width() > 0 && !text.
isEmpty() )
853 size += QSize( w, h );
871 return graphic.height();
873 if ( graphic.width() > 0 )
879 return qMax( graphic.height(), h );
903 layoutItems = it.value();
906 geometries.reserve(layoutItems.size());
908 for (
int i = 0; i < layoutItems.size(); i++ )
909 geometries += layoutItems[i]->
geometry();
void setSpacing(int)
Set the spacing between the legend items.
QwtDynGridLayout * layout
BackgroundMode backgroundMode() const
void setBackgroundMode(BackgroundMode)
Set the background mode.
Each item has a background.
virtual QSize minimumSize(const QwtLegendData &) const
The legend has a background.
void render(QPainter *) const
Replay all recorded painter commands.
void setFont(const QFont &)
BackgroundMode
Background mode.
QMap< const QwtPlotItem *, QList< QwtLegendLayoutItem * > > map
QWT_CONSTEXPR float qwtMaxF(float a, float b)
virtual int heightForWidth(const QwtLegendData &, int width) const
void setBackgroundBrush(const QBrush &)
Set the background brush.
void setFont(const QFont &)
A class which draws a legend inside the plot canvas.
QSizeF defaultSize() const
Default size.
virtual QRect geometry(const QRectF &canvasRect) const
void draw(QPainter *painter, const QRectF &rect) const
void clearLegend()
Remove all items from the legend.
Qt::Alignment alignmentInCanvas() const
virtual QLayoutItem * takeAt(int index) QWT_OVERRIDE
virtual void drawBackground(QPainter *, const QRectF &rect) const
void setTextPen(const QPen &)
Set the pen for drawing text labels.
void setMargin(int)
Set the margin around legend items.
void setAlignmentInCanvas(Qt::Alignment)
Set the alignmnet.
int qwtFloor(qreal value)
virtual ~QwtPlotLegendItem()
Destructor.
The QwtDynGridLayout class lays out widgets in a grid, adjusting the number of columns and rows to th...
double heightForWidth(double width) const
QList< const QwtPlotItem * > plotItems() const
virtual void updateLegend(const QwtPlotItem *, const QList< QwtLegendData > &) QWT_OVERRIDE
void setMaxColumns(uint maxColumns)
virtual int rtti() const QWT_OVERRIDE
virtual QSize sizeHint() const QWT_OVERRIDE
QBrush backgroundBrush() const
void setOffsetInCanvas(Qt::Orientations, int numPixels)
Set the distance between the legend and the canvas border.
A class representing a text.
virtual QLayoutItem * itemAt(int index) const QWT_OVERRIDE
void setZ(double z)
Set the z value.
virtual void draw(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const QWT_OVERRIDE
A paint device for scalable graphics.
QwtPlotLegendItem::BackgroundMode backgroundMode
void setBorderRadius(double)
virtual void itemChanged()
void setBorderPen(const QPen &)
virtual void addItem(QLayoutItem *) QWT_OVERRIDE
Add an item to the next free position.
double borderRadius() const
int offsetInCanvas(Qt::Orientation) const
Qt::Alignment canvasAlignment
QwtPlotLegendItem()
Constructor.
Base class for items on the plot canvas.
virtual void invalidate() QWT_OVERRIDE
Invalidate all internal caches.
QList< QRect > legendGeometries(const QwtPlotItem *) const
void setItemInterest(ItemInterest, bool on=true)
uint maxColumns() const
Return the upper limit for the number of columns.
virtual bool isEmpty() const QWT_OVERRIDE
virtual void setGeometry(const QRect &) QWT_OVERRIDE
virtual int count() const QWT_OVERRIDE
Attributes of an entry on a legend.
virtual void drawLegendData(QPainter *, const QwtPlotItem *, const QwtLegendData &, const QRectF &) const
void setMaxColumns(uint)
Limit the number of columns.