14 #include <qlayoutitem.h> 79 return Qt::Horizontal;
104 return QSize( QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX );
134 borderPen(
Qt::NoPen ),
135 backgroundBrush(
Qt::NoBrush ),
137 borderDistance( 10 ),
138 alignment(
Qt::AlignRight |
Qt::AlignBottom )
141 layout->setMaxColumns( 2 );
143 layout->setSpacing( 0 );
144 layout->setContentsMargins( 0, 0, 0, 0 );
165 QMap< const QwtPlotItem *, QList<QwtLegendLayoutItem *> >
map;
261 margin = qMax( margin, 0 );
262 if ( margin != this->
margin() )
265 margin, margin, margin, margin );
278 d_data->
layout->getContentsMargins( &left, NULL, NULL, NULL );
291 spacing = qMax( spacing, 0 );
316 margin = qMax( margin, 0 );
343 spacing = qMax( spacing, 0 );
426 radius = qMax( 0.0, radius );
556 const QRectF &canvasRect )
const 598 QPainter *painter,
const QRectF &rect )
const 606 painter->drawRoundedRect( rect, radius, radius );
625 int x = qRound( canvasRect.center().x() );
626 rect.moveCenter( QPoint( x, rect.center().y() ) );
630 rect.moveRight( qFloor( canvasRect.right() -
margin ) );
634 rect.moveLeft( qCeil( canvasRect.left() +
margin ) );
639 int y = qRound( canvasRect.center().y() );
640 rect.moveCenter( QPoint( rect.center().x(), y ) );
644 rect.moveBottom( qFloor( canvasRect.bottom() -
margin ) );
648 rect.moveTop( qCeil( canvasRect.top() +
margin ) );
662 const QList<QwtLegendData> &data )
664 if ( plotItem == NULL )
667 QList<QwtLegendLayoutItem *> layoutItems;
669 QMap<const QwtPlotItem *, QList<QwtLegendLayoutItem *> >::const_iterator it =
672 layoutItems = it.value();
674 bool changed =
false;
676 if ( data.size() != layoutItems.size() )
680 for (
int i = 0;
i < layoutItems.size();
i++ )
683 delete layoutItems[i];
690 if ( !data.isEmpty() )
692 #if QT_VERSION >= 0x040700 693 layoutItems.reserve( data.size() );
695 for (
int i = 0;
i < data.size();
i++ )
700 layoutItems += layoutItem;
703 d_data->
map.insert( plotItem, layoutItems );
707 for (
int i = 0;
i < data.size();
i++ )
709 if ( layoutItems[
i]->data().values() != data[
i].values() )
711 layoutItems[
i]->setData( data[
i] );
747 const QRectF &rect )
const 749 Q_UNUSED( plotItem );
752 const QRectF r = rect.toRect().adjusted( m, m, -m, -m );
754 painter->setClipRect( r, Qt::IntersectClip );
761 QRectF iconRect( r.topLeft(), graphic.
defaultSize() );
764 QPoint( iconRect.center().x(), rect.center().y() ) );
766 graphic.
render( painter, iconRect, Qt::KeepAspectRatio );
777 const QRectF textRect = r.adjusted( titleOff, 0, 0, 0 );
778 text.
draw( painter, textRect );
804 h = graphic.height();
811 w += qCeil( sz.width() );
812 h = qMax( h, qCeil( sz.height() ) );
815 if ( graphic.width() > 0 && !text.
isEmpty() )
818 size += QSize( w, h );
836 return graphic.height();
838 if ( graphic.width() > 0 )
844 return qMax( graphic.height(), h );
863 QList<QwtLegendLayoutItem *> layoutItems;
865 QMap<const QwtPlotItem *, QList<QwtLegendLayoutItem *> >::const_iterator it =
868 layoutItems = it.value();
870 QList<QRect> geometries;
871 #if QT_VERSION >= 0x040700 872 geometries.reserve(layoutItems.size());
875 for (
int i = 0;
i < layoutItems.size();
i++ )
876 geometries += layoutItems[
i]->
geometry();
void setSpacing(int)
Set the spacing between the legend items.
QwtDynGridLayout * layout
const QwtPlotItem * plotItem() const
virtual QSize maximumSize() const
BackgroundMode backgroundMode() const
void setBackgroundMode(BackgroundMode)
Set the background mode.
Each item has a background.
virtual bool isEmpty() const
virtual QSize minimumSize(const QwtLegendData &) const
The legend has a background.
void render(QPainter *) const
Replay all recorded painter commands.
void setFont(const QFont &)
virtual void setGeometry(const QRect &rect)
BackgroundMode
Background mode.
QMap< const QwtPlotItem *, QList< QwtLegendLayoutItem * > > map
virtual void addItem(QLayoutItem *)
Add an item to the next free position.
virtual void updateLegend(const QwtPlotItem *, const QList< QwtLegendData > &)
void setBackgroundBrush(const QBrush &)
Set the background brush.
virtual QRect geometry() const
void setData(const QwtLegendData &)
void setFont(const QFont &)
A class which draws a legend inside the plot canvas.
QSizeF defaultSize() const
Default size.
virtual void drawLegendData(QPainter *painter, const QwtPlotItem *, const QwtLegendData &, const QRectF &) const
virtual QRect geometry(const QRectF &canvasRect) const
void draw(QPainter *painter, const QRectF &rect) const
virtual void invalidate()
Invalidate all internal caches.
void clearLegend()
Remove all items from the legend.
virtual void draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &rect) const
virtual void drawBackground(QPainter *, const QRectF &rect) const
virtual bool isEmpty() const
void setTextPen(const QPen &)
Set the pen for drawing text labels.
void setMargin(int)
Set the margin around legend items.
TFSIMD_FORCE_INLINE const tfScalar & y() const
virtual QSize sizeHint() const
const QwtPlotItem * d_plotItem
int borderDistance() const
void setMaxColumns(uint maxCols)
virtual int heightForWidth(const QwtLegendData &, int w) const
virtual int count() const
virtual ~QwtPlotLegendItem()
Destructor.
virtual QLayoutItem * itemAt(int index) const
The QwtDynGridLayout class lays out widgets in a grid, adjusting the number of columns and rows to th...
virtual Qt::Orientations expandingDirections() const
void setAlignment(Qt::Alignment)
Set the alignmnet.
QList< const QwtPlotItem * > plotItems() const
QSizeF textSize(const QFont &=QFont()) const
virtual QSize minimumSize() const
QBrush backgroundBrush() const
void setBorderDistance(int numPixels)
Set the margin between the legend and the canvas border.
A class representing a text.
void setZ(double z)
Set the z value.
const QwtPlotLegendItem * d_legendItem
A paint device for scalable graphics.
TFSIMD_FORCE_INLINE const tfScalar & x() const
QwtPlotLegendItem::BackgroundMode backgroundMode
void setBorderRadius(double)
virtual void itemChanged()
void setBorderPen(const QPen &)
double borderRadius() const
TFSIMD_FORCE_INLINE const tfScalar & w() const
virtual bool hasHeightForWidth() const
virtual int minimumHeightForWidth(int w) const
virtual void setGeometry(const QRect &r)
QwtLegendLayoutItem(const QwtPlotLegendItem *, const QwtPlotItem *)
const QwtLegendData & data() const
QwtPlotLegendItem()
Constructor.
Base class for items on the plot canvas.
QList< QRect > legendGeometries(const QwtPlotItem *) const
virtual int heightForWidth(int w) const
void setItemInterest(ItemInterest, bool on=true)
virtual ~QwtLegendLayoutItem()
uint maxColumns() const
Return the upper limit for the number of columns.
Qt::Alignment alignment() const
double heightForWidth(double width, const QFont &=QFont()) const
Attributes of an entry on a legend.
virtual QLayoutItem * takeAt(int index)
virtual QSize sizeHint() const
void setMaxColumns(uint)
Limit the number of columns.