17 #include <qlayoutitem.h> 24 class LayoutItem
QWT_FINAL :
public QLayoutItem
28 virtual ~LayoutItem();
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;
55 LayoutItem::LayoutItem(
57 : m_legendItem( legendItem )
58 , m_plotItem( plotItem)
62 LayoutItem::~LayoutItem()
81 Qt::Orientations LayoutItem::expandingDirections()
const 83 return Qt::Horizontal;
86 bool LayoutItem::hasHeightForWidth()
const 88 return !m_data.title().isEmpty();
91 int LayoutItem::minimumHeightForWidth(
int w )
const 93 return m_legendItem->heightForWidth( m_data, w );
96 int LayoutItem::heightForWidth(
int w )
const 98 return m_legendItem->heightForWidth( m_data, w );
101 bool LayoutItem::isEmpty()
const 106 QSize LayoutItem::maximumSize()
const 108 return QSize( QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX );
111 QSize LayoutItem::minimumSize()
const 113 return m_legendItem->minimumSize( m_data );
116 QSize LayoutItem::sizeHint()
const 118 return minimumSize();
121 void LayoutItem::setGeometry(
const QRect& rect )
126 QRect LayoutItem::geometry()
const 138 , borderRadius( 0.0 )
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 m_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 LayoutItem* 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 LayoutItem* layoutItem =
733 new LayoutItem(
this, plotItem );
735 layoutItems += layoutItem;
738 m_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
void setBackgroundMode(BackgroundMode)
Set the background mode.
Each item has a background.
The legend has a background.
void setFont(const QFont &)
BackgroundMode backgroundMode() const
BackgroundMode
Background mode.
double borderRadius() const
double heightForWidth(double width) const
QWT_CONSTEXPR float qwtMaxF(float a, float b)
void setBackgroundBrush(const QBrush &)
Set the background brush.
Qt::Alignment alignmentInCanvas() const
void setFont(const QFont &)
A class which draws a legend inside the plot canvas.
QList< QRect > legendGeometries(const QwtPlotItem *) const
virtual int heightForWidth(const QwtLegendData &, int width) const
void clearLegend()
Remove all items from the legend.
virtual QLayoutItem * takeAt(int index) QWT_OVERRIDE
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...
void draw(QPainter *painter, const QRectF &rect) const
QBrush backgroundBrush() 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
void setOffsetInCanvas(Qt::Orientations, int numPixels)
Set the distance between the legend and the canvas border.
A class representing a text.
virtual void drawLegendData(QPainter *, const QwtPlotItem *, const QwtLegendData &, const QRectF &) const
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()
QList< const QwtPlotItem *> plotItems() const
void setBorderPen(const QPen &)
virtual void addItem(QLayoutItem *) QWT_OVERRIDE
Add an item to the next free position.
void render(QPainter *) const
Replay all recorded painter commands.
virtual void drawBackground(QPainter *, const QRectF &rect) const
virtual QRect geometry(const QRectF &canvasRect) const
int offsetInCanvas(Qt::Orientation) const
Qt::Alignment canvasAlignment
span_constexpr std::size_t size(span< T, Extent > const &spn)
QMap< const QwtPlotItem *, QList< LayoutItem *> > map
QwtPlotLegendItem()
Constructor.
virtual QSize minimumSize(const QwtLegendData &) const
Base class for items on the plot canvas.
virtual void invalidate() QWT_OVERRIDE
Invalidate all internal caches.
void setItemInterest(ItemInterest, bool on=true)
QSizeF defaultSize() const
Default size.
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.
void setMaxColumns(uint)
Limit the number of columns.