Layout engine for QwtPlot. More...
#include <qwt_plot_layout.h>
Classes | |
class | LayoutData |
class | PrivateData |
Public Types | |
enum | Options { AlignScales = 1, IgnoreScrollbars = 2, IgnoreFrames = 4, IgnoreMargin = 8, IgnoreLegend = 16 } |
Public Member Functions | |
QwtPlotLayout () | |
Constructor. | |
virtual | ~QwtPlotLayout () |
Destructor. | |
void | setMargin (int) |
int | margin () const |
void | setCanvasMargin (int margin, int axis=-1) |
int | canvasMargin (int axis) const |
void | setAlignCanvasToScales (bool) |
bool | alignCanvasToScales () const |
void | setSpacing (int) |
int | spacing () const |
void | setLegendPosition (QwtPlot::LegendPosition pos, double ratio) |
Specify the position of the legend. | |
void | setLegendPosition (QwtPlot::LegendPosition pos) |
Specify the position of the legend. | |
QwtPlot::LegendPosition | legendPosition () const |
void | setLegendRatio (double ratio) |
double | legendRatio () const |
virtual QSize | minimumSizeHint (const QwtPlot *) const |
Return a minimum size hint. | |
virtual void | activate (const QwtPlot *, const QRect &rect, int options=0) |
Recalculate the geometry of all components. | |
virtual void | invalidate () |
const QRect & | titleRect () const |
const QRect & | legendRect () const |
const QRect & | scaleRect (int axis) const |
const QRect & | canvasRect () const |
Protected Member Functions | |
QRect | layoutLegend (int options, const QRect &) const |
QRect | alignLegend (const QRect &canvasRect, const QRect &legendRect) const |
void | expandLineBreaks (int options, const QRect &rect, int &dimTitle, int dimAxes[QwtPlot::axisCnt]) const |
void | alignScales (int options, QRect &canvasRect, QRect scaleRect[QwtPlot::axisCnt]) const |
Layout engine for QwtPlot.
It is used by the QwtPlot widget to organize its internal widgets or by QwtPlot::print() to render its content to a QPaintDevice like a QPrinter, QPixmap/QImage or QSvgRenderer.
Definition at line 24 of file qwt_plot_layout.h.
Options to configure the plot layout engine
Definition at line 35 of file qwt_plot_layout.h.
{
QwtPlotLayout::QwtPlotLayout | ( | ) | [explicit] |
Constructor.
Definition at line 182 of file qwt_plot_layout.cpp.
References QwtPlot::BottomLegend, invalidate(), setCanvasMargin(), and setLegendPosition().
{ d_data = new PrivateData; setLegendPosition(QwtPlot::BottomLegend); setCanvasMargin(4); invalidate(); }
QwtPlotLayout::~QwtPlotLayout | ( | ) | [virtual] |
void QwtPlotLayout::activate | ( | const QwtPlot * | plot, |
const QRect & | plotRect, | ||
int | options = 0 |
||
) | [virtual] |
Recalculate the geometry of all components.
plot | Plot to be layout |
plotRect | Rect where to place the components |
options | Options |
Definition at line 1046 of file qwt_plot_layout.cpp.
References alignLegend(), alignScales(), QwtPlot::axisCnt, QwtPlot::BottomLegend, QwtPlotLayout::PrivateData::canvasRect, expandLineBreaks(), QwtPlot::ExternalLegend, QwtPlotLayout::LayoutData::t_legendData::frameWidth, IgnoreFrames, IgnoreLegend, IgnoreMargin, QwtPlotLayout::LayoutData::init(), invalidate(), QwtLegend::isEmpty(), QwtPlotLayout::LayoutData::t_scaleData::isEnabled, QwtPlotLayout::PrivateData::layoutData, layoutLegend(), QwtPlot::LeftLegend, QwtPlotLayout::LayoutData::legend, QwtPlot::legend(), QwtPlotLayout::PrivateData::legendPos, QwtPlotLayout::PrivateData::legendRect, QwtPlotLayout::PrivateData::margin, QwtPlot::RightLegend, QwtPlotLayout::LayoutData::scale, QwtPlotLayout::PrivateData::scaleRect, scaleRect(), QwtPlotLayout::PrivateData::spacing, QwtPlotLayout::PrivateData::titleRect, QwtPlot::TopLegend, QwtPlot::xBottom, QwtPlot::xTop, QwtPlot::yLeft, and QwtPlot::yRight.
Referenced by QwtPlot::updateLayout().
{ invalidate(); QRect rect(plotRect); // undistributed rest of the plot rect if ( !(options & IgnoreMargin) ) { // subtract the margin rect.setRect( rect.x() + d_data->margin, rect.y() + d_data->margin, rect.width() - 2 * d_data->margin, rect.height() - 2 * d_data->margin ); } // We extract all layout relevant data from the widgets, // filter them through pfilter and save them to d_data->layoutData. d_data->layoutData.init(plot, rect); if (!(options & IgnoreLegend) && d_data->legendPos != QwtPlot::ExternalLegend && plot->legend() && !plot->legend()->isEmpty() ) { d_data->legendRect = layoutLegend(options, rect); // subtract d_data->legendRect from rect const QRegion region(rect); rect = region.subtract(d_data->legendRect).boundingRect(); if ( d_data->layoutData.legend.frameWidth && !(options & IgnoreFrames ) ) { // In case of a frame we have to insert a spacing. // Otherwise the leading of the font separates // legend and scale/canvas switch(d_data->legendPos) { case QwtPlot::LeftLegend: rect.setLeft(rect.left() + d_data->spacing); break; case QwtPlot::RightLegend: rect.setRight(rect.right() - d_data->spacing); break; case QwtPlot::TopLegend: rect.setTop(rect.top() + d_data->spacing); break; case QwtPlot::BottomLegend: rect.setBottom(rect.bottom() - d_data->spacing); break; case QwtPlot::ExternalLegend: break; // suppress compiler warning } } } #ifdef __GNUC__ #endif /* +---+-----------+---+ | Title | +---+-----------+---+ | | Axis | | +---+-----------+---+ | A | | A | | x | Canvas | x | | i | | i | | s | | s | +---+-----------+---+ | | Axis | | +---+-----------+---+ */ // axes and title include text labels. The height of each // label depends on its line breaks, that depend on the width // for the label. A line break in a horizontal text will reduce // the available width for vertical texts and vice versa. // expandLineBreaks finds the height/width for title and axes // including all line breaks. int dimTitle, dimAxes[QwtPlot::axisCnt]; expandLineBreaks(options, rect, dimTitle, dimAxes); if (dimTitle > 0 ) { d_data->titleRect = QRect(rect.x(), rect.y(), rect.width(), dimTitle); if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled != d_data->layoutData.scale[QwtPlot::yRight].isEnabled ) { // if only one of the y axes is missing we align // the title centered to the canvas d_data->titleRect.setX(rect.x() + dimAxes[QwtPlot::yLeft]); d_data->titleRect.setWidth(rect.width() - dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight]); } // subtract title rect.setTop(rect.top() + dimTitle + d_data->spacing); } d_data->canvasRect.setRect( rect.x() + dimAxes[QwtPlot::yLeft], rect.y() + dimAxes[QwtPlot::xTop], rect.width() - dimAxes[QwtPlot::yRight] - dimAxes[QwtPlot::yLeft], rect.height() - dimAxes[QwtPlot::xBottom] - dimAxes[QwtPlot::xTop]); for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { // set the rects for the axes if ( dimAxes[axis] ) { int dim = dimAxes[axis]; QRect &scaleRect = d_data->scaleRect[axis]; scaleRect = d_data->canvasRect; switch(axis) { case QwtPlot::yLeft: scaleRect.setX(d_data->canvasRect.left() - dim); scaleRect.setWidth(dim); break; case QwtPlot::yRight: scaleRect.setX(d_data->canvasRect.right() + 1); scaleRect.setWidth(dim); break; case QwtPlot::xBottom: scaleRect.setY(d_data->canvasRect.bottom() + 1); scaleRect.setHeight(dim); break; case QwtPlot::xTop: scaleRect.setY(d_data->canvasRect.top() - dim); scaleRect.setHeight(dim); break; } #if QT_VERSION < 0x040000 scaleRect = scaleRect.normalize(); #else scaleRect = scaleRect.normalized(); #endif } } // +---+-----------+---+ // | <- Axis -> | // +-^-+-----------+-^-+ // | | | | | | // | | | | // | A | | A | // | x | Canvas | x | // | i | | i | // | s | | s | // | | | | // | | | | | | // +-V-+-----------+-V-+ // | <- Axis -> | // +---+-----------+---+ // The ticks of the axes - not the labels above - should // be aligned to the canvas. So we try to use the empty // corners to extend the axes, so that the label texts // left/right of the min/max ticks are moved into them. alignScales(options, d_data->canvasRect, d_data->scaleRect); if (!d_data->legendRect.isEmpty() ) { // We prefer to align the legend to the canvas - not to // the complete plot - if possible. d_data->legendRect = alignLegend(d_data->canvasRect, d_data->legendRect); } }
bool QwtPlotLayout::alignCanvasToScales | ( | ) | const |
Return the align-canvas-to-axis-scales setting. The canvas may:
Definition at line 287 of file qwt_plot_layout.cpp.
References QwtPlotLayout::PrivateData::alignCanvasToScales.
Referenced by setAlignCanvasToScales().
{ return d_data->alignCanvasToScales; }
QRect QwtPlotLayout::alignLegend | ( | const QRect & | canvasRect, |
const QRect & | legendRect | ||
) | const [protected] |
Align the legend to the canvas
canvasRect | Geometry of the canvas |
legendRect | Maximum geometry for the legend |
Definition at line 709 of file qwt_plot_layout.cpp.
References QwtPlot::BottomLegend, QwtPlotLayout::LayoutData::t_legendData::hint, QwtPlotLayout::PrivateData::layoutData, QwtPlotLayout::LayoutData::legend, QwtPlotLayout::PrivateData::legendPos, legendRect(), and QwtPlot::TopLegend.
Referenced by activate().
{ QRect alignedRect = legendRect; if ( d_data->legendPos == QwtPlot::BottomLegend || d_data->legendPos == QwtPlot::TopLegend ) { if ( d_data->layoutData.legend.hint.width() < canvasRect.width() ) { alignedRect.setX(canvasRect.x()); alignedRect.setWidth(canvasRect.width()); } } else { if ( d_data->layoutData.legend.hint.height() < canvasRect.height() ) { alignedRect.setY(canvasRect.y()); alignedRect.setHeight(canvasRect.height()); } } return alignedRect; }
void QwtPlotLayout::alignScales | ( | int | options, |
QRect & | canvasRect, | ||
QRect | scaleRect[QwtPlot::axisCnt] | ||
) | const [protected] |
Align the ticks of the axis to the canvas borders using the empty corners.
Definition at line 873 of file qwt_plot_layout.cpp.
References QwtPlotLayout::PrivateData::alignCanvasToScales, QwtPlotLayout::LayoutData::canvas, QwtPlotLayout::PrivateData::canvasMargin, QwtPlotLayout::LayoutData::t_scaleData::end, QwtPlotLayout::LayoutData::t_canvasData::frameWidth, IgnoreFrames, QwtPlotLayout::PrivateData::layoutData, qwtMax, qwtMin, QwtPlotLayout::LayoutData::scale, scaleRect(), QwtPlotLayout::LayoutData::t_scaleData::start, QwtPlotLayout::LayoutData::t_scaleData::tickOffset, QwtPlot::xBottom, QwtPlot::xTop, QwtPlot::yLeft, and QwtPlot::yRight.
Referenced by activate().
{ int axis; int backboneOffset[QwtPlot::axisCnt]; for (axis = 0; axis < QwtPlot::axisCnt; axis++ ) { backboneOffset[axis] = 0; if ( !d_data->alignCanvasToScales ) backboneOffset[axis] += d_data->canvasMargin[axis]; if ( !(options & IgnoreFrames) ) backboneOffset[axis] += d_data->layoutData.canvas.frameWidth; } for (axis = 0; axis < QwtPlot::axisCnt; axis++ ) { if ( !scaleRect[axis].isValid() ) continue; const int startDist = d_data->layoutData.scale[axis].start; const int endDist = d_data->layoutData.scale[axis].end; QRect &axisRect = scaleRect[axis]; if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom ) { const int leftOffset = backboneOffset[QwtPlot::yLeft] - startDist; if ( scaleRect[QwtPlot::yLeft].isValid() ) { int minLeft = scaleRect[QwtPlot::yLeft].left(); int left = axisRect.left() + leftOffset; axisRect.setLeft(qwtMax(left, minLeft)); } else { if ( d_data->alignCanvasToScales && leftOffset < 0 ) { canvasRect.setLeft(qwtMax(canvasRect.left(), axisRect.left() - leftOffset)); } else { if ( leftOffset > 0 ) axisRect.setLeft(axisRect.left() + leftOffset); } } const int rightOffset = backboneOffset[QwtPlot::yRight] - endDist + 1; if ( scaleRect[QwtPlot::yRight].isValid() ) { int maxRight = scaleRect[QwtPlot::yRight].right(); int right = axisRect.right() - rightOffset; axisRect.setRight(qwtMin(right, maxRight)); } else { if ( d_data->alignCanvasToScales && rightOffset < 0 ) { canvasRect.setRight( qwtMin(canvasRect.right(), axisRect.right() + rightOffset) ); } else { if ( rightOffset > 0 ) axisRect.setRight(axisRect.right() - rightOffset); } } } else // QwtPlot::yLeft, QwtPlot::yRight { const int bottomOffset = backboneOffset[QwtPlot::xBottom] - endDist + 1; if ( scaleRect[QwtPlot::xBottom].isValid() ) { int maxBottom = scaleRect[QwtPlot::xBottom].top() + d_data->layoutData.scale[QwtPlot::xBottom].tickOffset; int bottom = axisRect.bottom() - bottomOffset; axisRect.setBottom(qwtMin(bottom, maxBottom)); } else { if ( d_data->alignCanvasToScales && bottomOffset < 0 ) { canvasRect.setBottom(qwtMin(canvasRect.bottom(), axisRect.bottom() + bottomOffset)); } else { if ( bottomOffset > 0 ) axisRect.setBottom(axisRect.bottom() - bottomOffset); } } const int topOffset = backboneOffset[QwtPlot::xTop] - startDist; if ( scaleRect[QwtPlot::xTop].isValid() ) { int minTop = scaleRect[QwtPlot::xTop].bottom() - d_data->layoutData.scale[QwtPlot::xTop].tickOffset; int top = axisRect.top() + topOffset; axisRect.setTop(qwtMax(top, minTop)); } else { if ( d_data->alignCanvasToScales && topOffset < 0 ) { canvasRect.setTop(qwtMax(canvasRect.top(), axisRect.top() - topOffset)); } else { if ( topOffset > 0 ) axisRect.setTop(axisRect.top() + topOffset); } } } } if ( d_data->alignCanvasToScales ) { /* The canvas has been aligned to the scale with largest border distances. Now we have to realign the other scale. */ int fw = 0; if ( !(options & IgnoreFrames) ) fw = d_data->layoutData.canvas.frameWidth; if ( scaleRect[QwtPlot::xBottom].isValid() && scaleRect[QwtPlot::xTop].isValid() ) { for ( int axis = QwtPlot::xBottom; axis <= QwtPlot::xTop; axis++ ) { scaleRect[axis].setLeft(canvasRect.left() + fw - d_data->layoutData.scale[axis].start); scaleRect[axis].setRight(canvasRect.right() - fw - 1 + d_data->layoutData.scale[axis].end); } } if ( scaleRect[QwtPlot::yLeft].isValid() && scaleRect[QwtPlot::yRight].isValid() ) { for ( int axis = QwtPlot::yLeft; axis <= QwtPlot::yRight; axis++ ) { scaleRect[axis].setTop(canvasRect.top() + fw - d_data->layoutData.scale[axis].start); scaleRect[axis].setBottom(canvasRect.bottom() - fw - 1 + d_data->layoutData.scale[axis].end); } } } }
int QwtPlotLayout::canvasMargin | ( | int | axis ) | const |
Definition at line 253 of file qwt_plot_layout.cpp.
References QwtPlot::axisCnt, and QwtPlotLayout::PrivateData::canvasMargin.
Referenced by QwtPlot::canvasMap(), and QwtPlot::print().
{ if ( axis < 0 || axis >= QwtPlot::axisCnt ) return 0; return d_data->canvasMargin[axis]; }
const QRect & QwtPlotLayout::canvasRect | ( | ) | const |
Definition at line 442 of file qwt_plot_layout.cpp.
References QwtPlotLayout::PrivateData::canvasRect.
Referenced by QwtPlot::print(), and QwtPlot::updateLayout().
{ return d_data->canvasRect; }
void QwtPlotLayout::expandLineBreaks | ( | int | options, |
const QRect & | rect, | ||
int & | dimTitle, | ||
int | dimAxis[QwtPlot::axisCnt] | ||
) | const [protected] |
Expand all line breaks in text labels, and calculate the height of their widgets in orientation of the text.
options | Options how to layout the legend |
rect | Bounding rect for title, axes and canvas. |
dimTitle | Expanded height of the title widget |
dimAxis | Expanded heights of the axis in axis orientation. |
Definition at line 746 of file qwt_plot_layout.cpp.
References QwtPlotLayout::PrivateData::alignCanvasToScales, QwtPlotLayout::LayoutData::canvas, QwtPlotLayout::PrivateData::canvasMargin, QwtPlotLayout::LayoutData::t_scaleData::dimWithoutTitle, QwtPlotLayout::LayoutData::t_scaleData::end, QwtPlotLayout::LayoutData::t_titleData::frameWidth, QwtPlotLayout::LayoutData::t_canvasData::frameWidth, QwtText::heightForWidth(), IgnoreFrames, QwtText::isEmpty(), QwtPlotLayout::LayoutData::t_scaleData::isEnabled, QwtPlotLayout::PrivateData::layoutData, qwtMin, QwtPlotLayout::LayoutData::scale, QwtPlotLayout::LayoutData::t_scaleData::scaleWidget, QwtPlotLayout::PrivateData::spacing, QwtPlotLayout::LayoutData::t_scaleData::start, QwtPlotLayout::LayoutData::t_titleData::text, QwtPlotLayout::LayoutData::t_scaleData::tickOffset, QwtScaleWidget::title(), QwtPlotLayout::LayoutData::title, QwtScaleWidget::titleHeightForWidth(), QwtPlot::xBottom, QwtPlot::xTop, QwtPlot::yLeft, and QwtPlot::yRight.
Referenced by activate().
{ dimTitle = 0; for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) dimAxis[axis] = 0; int backboneOffset[QwtPlot::axisCnt]; for (int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { backboneOffset[axis] = 0; if ( !d_data->alignCanvasToScales ) backboneOffset[axis] += d_data->canvasMargin[axis]; if ( !(options & IgnoreFrames) ) backboneOffset[axis] += d_data->layoutData.canvas.frameWidth; } bool done = false; while (!done) { done = true; // the size for the 4 axis depend on each other. Expanding // the height of a horizontal axis will shrink the height // for the vertical axis, shrinking the height of a vertical // axis will result in a line break what will expand the // width and results in shrinking the width of a horizontal // axis what might result in a line break of a horizontal // axis ... . So we loop as long until no size changes. if ( !d_data->layoutData.title.text.isEmpty() ) { int w = rect.width(); if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled != d_data->layoutData.scale[QwtPlot::yRight].isEnabled ) { // center to the canvas w -= dimAxis[QwtPlot::yLeft] + dimAxis[QwtPlot::yRight]; } int d = d_data->layoutData.title.text.heightForWidth(w); if ( !(options & IgnoreFrames) ) d += 2 * d_data->layoutData.title.frameWidth; if ( d > dimTitle ) { dimTitle = d; done = false; } } for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { const struct LayoutData::t_scaleData &scaleData = d_data->layoutData.scale[axis]; if (scaleData.isEnabled) { int length; if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom ) { length = rect.width() - dimAxis[QwtPlot::yLeft] - dimAxis[QwtPlot::yRight]; length -= scaleData.start + scaleData.end; if ( dimAxis[QwtPlot::yRight] > 0 ) length -= 1; length += qwtMin(dimAxis[QwtPlot::yLeft], scaleData.start - backboneOffset[QwtPlot::yLeft]); length += qwtMin(dimAxis[QwtPlot::yRight], scaleData.end - backboneOffset[QwtPlot::yRight]); } else // QwtPlot::yLeft, QwtPlot::yRight { length = rect.height() - dimAxis[QwtPlot::xTop] - dimAxis[QwtPlot::xBottom]; length -= scaleData.start + scaleData.end; length -= 1; if ( dimAxis[QwtPlot::xBottom] <= 0 ) length -= 1; if ( dimAxis[QwtPlot::xTop] <= 0 ) length -= 1; if ( dimAxis[QwtPlot::xBottom] > 0 ) { length += qwtMin( d_data->layoutData.scale[QwtPlot::xBottom].tickOffset, scaleData.start - backboneOffset[QwtPlot::xBottom]); } if ( dimAxis[QwtPlot::xTop] > 0 ) { length += qwtMin( d_data->layoutData.scale[QwtPlot::xTop].tickOffset, scaleData.end - backboneOffset[QwtPlot::xTop]); } if ( dimTitle > 0 ) length -= dimTitle + d_data->spacing; } int d = scaleData.dimWithoutTitle; if ( !scaleData.scaleWidget->title().isEmpty() ) { d += scaleData.scaleWidget->titleHeightForWidth(length); } if ( d > dimAxis[axis] ) { dimAxis[axis] = d; done = false; } } } } }
void QwtPlotLayout::invalidate | ( | ) | [virtual] |
Invalidate the geometry of all components.
Definition at line 451 of file qwt_plot_layout.cpp.
References QwtPlot::axisCnt, QwtPlotLayout::PrivateData::canvasRect, QwtPlotLayout::PrivateData::legendRect, QwtPlotLayout::PrivateData::scaleRect, and QwtPlotLayout::PrivateData::titleRect.
Referenced by activate(), and QwtPlotLayout().
{ d_data->titleRect = d_data->legendRect = d_data->canvasRect = QRect(); for (int axis = 0; axis < QwtPlot::axisCnt; axis++ ) d_data->scaleRect[axis] = QRect(); }
QRect QwtPlotLayout::layoutLegend | ( | int | options, |
const QRect & | rect | ||
) | const [protected] |
Find the geometry for the legend
options | Options how to layout the legend |
rect | Rectangle where to place the legend |
Definition at line 648 of file qwt_plot_layout.cpp.
References QwtPlot::BottomLegend, QwtPlot::ExternalLegend, QwtPlotLayout::LayoutData::t_legendData::hint, QwtPlotLayout::LayoutData::t_legendData::hScrollBarHeight, IgnoreScrollbars, int(), QwtPlotLayout::PrivateData::layoutData, QwtPlot::LeftLegend, QwtPlotLayout::LayoutData::legend, QwtPlotLayout::PrivateData::legendPos, QwtPlotLayout::PrivateData::legendRatio, legendRect(), qwtMax, qwtMin, QwtPlot::RightLegend, QwtPlot::TopLegend, and QwtPlotLayout::LayoutData::t_legendData::vScrollBarWidth.
Referenced by activate().
{ const QSize hint(d_data->layoutData.legend.hint); int dim; if ( d_data->legendPos == QwtPlot::LeftLegend || d_data->legendPos == QwtPlot::RightLegend ) { // We don't allow vertical legends to take more than // half of the available space. dim = qwtMin(hint.width(), int(rect.width() * d_data->legendRatio)); if ( !(options & IgnoreScrollbars) ) { if ( hint.height() > rect.height() ) { // The legend will need additional // space for the vertical scrollbar. dim += d_data->layoutData.legend.vScrollBarWidth; } } } else { dim = qwtMin(hint.height(), int(rect.height() * d_data->legendRatio)); dim = qwtMax(dim, d_data->layoutData.legend.hScrollBarHeight); } QRect legendRect = rect; switch(d_data->legendPos) { case QwtPlot::LeftLegend: legendRect.setWidth(dim); break; case QwtPlot::RightLegend: legendRect.setX(rect.right() - dim + 1); legendRect.setWidth(dim); break; case QwtPlot::TopLegend: legendRect.setHeight(dim); break; case QwtPlot::BottomLegend: legendRect.setY(rect.bottom() - dim + 1); legendRect.setHeight(dim); break; case QwtPlot::ExternalLegend: break; } return legendRect; }
QwtPlot::LegendPosition QwtPlotLayout::legendPosition | ( | ) | const |
Definition at line 373 of file qwt_plot_layout.cpp.
References QwtPlotLayout::PrivateData::legendPos.
Referenced by QwtPlotLayout::LayoutData::init(), QwtPlot::insertLegend(), setLegendRatio(), and QwtPlot::updateLayout().
{ return d_data->legendPos; }
double QwtPlotLayout::legendRatio | ( | ) | const |
Definition at line 396 of file qwt_plot_layout.cpp.
References QwtPlotLayout::PrivateData::legendRatio.
{ return d_data->legendRatio; }
const QRect & QwtPlotLayout::legendRect | ( | ) | const |
Definition at line 416 of file qwt_plot_layout.cpp.
References QwtPlotLayout::PrivateData::legendRect.
Referenced by alignLegend(), layoutLegend(), and QwtPlot::updateLayout().
{ return d_data->legendRect; }
int QwtPlotLayout::margin | ( | ) | const |
Definition at line 217 of file qwt_plot_layout.cpp.
References QwtPlotLayout::PrivateData::margin.
Referenced by QwtPlot::margin(), setCanvasMargin(), setMargin(), and QwtPlot::setMargin().
{ return d_data->margin; }
QSize QwtPlotLayout::minimumSizeHint | ( | const QwtPlot * | plot ) | const [virtual] |
Return a minimum size hint.
Definition at line 463 of file qwt_plot_layout.cpp.
References QwtPlot::axisCnt, QwtPlot::axisEnabled(), QwtPlot::axisWidget(), QwtPlot::canvas(), QwtPlotLayout::PrivateData::canvasMargin, QwtPlot::ExternalLegend, QwtScaleWidget::getBorderDistHint(), QwtAbstractScaleDraw::hasComponent(), QwtLegend::heightForWidth(), QwtTextLabel::heightForWidth(), QwtLegend::isEmpty(), QwtPlot::LeftLegend, QwtPlot::legend(), QwtPlotLayout::PrivateData::legendPos, QwtPlotLayout::PrivateData::legendRatio, QwtAbstractScaleDraw::majTickLength(), QwtPlotLayout::PrivateData::margin, QwtScaleWidget::margin(), QwtScaleWidget::minimumSizeHint(), qwtMax, qwtMin, QwtPlot::RightLegend, QwtScaleWidget::scaleDraw(), QwtLegend::sizeHint(), QwtPlotLayout::PrivateData::spacing, QwtAbstractScaleDraw::Ticks, QwtPlot::titleLabel(), QwtLegend::verticalScrollBar(), QwtPlot::xBottom, QwtPlot::xTop, QwtPlot::yLeft, and QwtPlot::yRight.
Referenced by QwtPlot::minimumSizeHint().
{ class ScaleData { public: ScaleData() { w = h = minLeft = minRight = tickOffset = 0; } int w; int h; int minLeft; int minRight; int tickOffset; } scaleData[QwtPlot::axisCnt]; int canvasBorder[QwtPlot::axisCnt]; int axis; for ( axis = 0; axis < QwtPlot::axisCnt; axis++ ) { if ( plot->axisEnabled(axis) ) { const QwtScaleWidget *scl = plot->axisWidget(axis); ScaleData &sd = scaleData[axis]; const QSize hint = scl->minimumSizeHint(); sd.w = hint.width(); sd.h = hint.height(); scl->getBorderDistHint(sd.minLeft, sd.minRight); sd.tickOffset = scl->margin(); if ( scl->scaleDraw()->hasComponent(QwtAbstractScaleDraw::Ticks) ) sd.tickOffset += scl->scaleDraw()->majTickLength(); } canvasBorder[axis] = plot->canvas()->frameWidth() + d_data->canvasMargin[axis] + 1; } for ( axis = 0; axis < QwtPlot::axisCnt; axis++ ) { ScaleData &sd = scaleData[axis]; if ( sd.w && (axis == QwtPlot::xBottom || axis == QwtPlot::xTop) ) { if ( (sd.minLeft > canvasBorder[QwtPlot::yLeft]) && scaleData[QwtPlot::yLeft].w ) { int shiftLeft = sd.minLeft - canvasBorder[QwtPlot::yLeft]; if ( shiftLeft > scaleData[QwtPlot::yLeft].w ) shiftLeft = scaleData[QwtPlot::yLeft].w; sd.w -= shiftLeft; } if ( (sd.minRight > canvasBorder[QwtPlot::yRight]) && scaleData[QwtPlot::yRight].w ) { int shiftRight = sd.minRight - canvasBorder[QwtPlot::yRight]; if ( shiftRight > scaleData[QwtPlot::yRight].w ) shiftRight = scaleData[QwtPlot::yRight].w; sd.w -= shiftRight; } } if ( sd.h && (axis == QwtPlot::yLeft || axis == QwtPlot::yRight) ) { if ( (sd.minLeft > canvasBorder[QwtPlot::xBottom]) && scaleData[QwtPlot::xBottom].h ) { int shiftBottom = sd.minLeft - canvasBorder[QwtPlot::xBottom]; if ( shiftBottom > scaleData[QwtPlot::xBottom].tickOffset ) shiftBottom = scaleData[QwtPlot::xBottom].tickOffset; sd.h -= shiftBottom; } if ( (sd.minLeft > canvasBorder[QwtPlot::xTop]) && scaleData[QwtPlot::xTop].h ) { int shiftTop = sd.minRight - canvasBorder[QwtPlot::xTop]; if ( shiftTop > scaleData[QwtPlot::xTop].tickOffset ) shiftTop = scaleData[QwtPlot::xTop].tickOffset; sd.h -= shiftTop; } } } const QwtPlotCanvas *canvas = plot->canvas(); const QSize minCanvasSize = canvas->minimumSize(); int w = scaleData[QwtPlot::yLeft].w + scaleData[QwtPlot::yRight].w; int cw = qwtMax(scaleData[QwtPlot::xBottom].w, scaleData[QwtPlot::xTop].w) + 2 * (canvas->frameWidth() + 1); w += qwtMax(cw, minCanvasSize.width()); int h = scaleData[QwtPlot::xBottom].h + scaleData[QwtPlot::xTop].h; int ch = qwtMax(scaleData[QwtPlot::yLeft].h, scaleData[QwtPlot::yRight].h) + 2 * (canvas->frameWidth() + 1); h += qwtMax(ch, minCanvasSize.height()); const QwtTextLabel *title = plot->titleLabel(); if (title && !title->text().isEmpty()) { // If only QwtPlot::yLeft or QwtPlot::yRight is showing, // we center on the plot canvas. const bool centerOnCanvas = !(plot->axisEnabled(QwtPlot::yLeft) && plot->axisEnabled(QwtPlot::yRight)); int titleW = w; if ( centerOnCanvas ) { titleW -= scaleData[QwtPlot::yLeft].w + scaleData[QwtPlot::yRight].w; } int titleH = title->heightForWidth(titleW); if ( titleH > titleW ) // Compensate for a long title { w = titleW = titleH; if ( centerOnCanvas ) { w += scaleData[QwtPlot::yLeft].w + scaleData[QwtPlot::yRight].w; } titleH = title->heightForWidth(titleW); } h += titleH + d_data->spacing; } // Compute the legend contribution const QwtLegend *legend = plot->legend(); if ( d_data->legendPos != QwtPlot::ExternalLegend && legend && !legend->isEmpty() ) { if ( d_data->legendPos == QwtPlot::LeftLegend || d_data->legendPos == QwtPlot::RightLegend ) { int legendW = legend->sizeHint().width(); int legendH = legend->heightForWidth(legendW); if ( legend->frameWidth() > 0 ) w += d_data->spacing; if ( legendH > h ) legendW += legend->verticalScrollBar()->sizeHint().height(); if ( d_data->legendRatio < 1.0 ) legendW = qwtMin(legendW, int(w / (1.0 - d_data->legendRatio))); w += legendW; } else // QwtPlot::Top, QwtPlot::Bottom { int legendW = qwtMin(legend->sizeHint().width(), w); int legendH = legend->heightForWidth(legendW); if ( legend->frameWidth() > 0 ) h += d_data->spacing; if ( d_data->legendRatio < 1.0 ) legendH = qwtMin(legendH, int(h / (1.0 - d_data->legendRatio))); h += legendH; } } w += 2 * d_data->margin; h += 2 * d_data->margin; return QSize( w, h ); }
const QRect & QwtPlotLayout::scaleRect | ( | int | axis ) | const |
axis | Axis index |
Definition at line 427 of file qwt_plot_layout.cpp.
References QwtPlot::axisCnt, and QwtPlotLayout::PrivateData::scaleRect.
Referenced by activate(), alignScales(), QwtPlot::print(), and QwtPlot::updateLayout().
{ if ( axis < 0 || axis >= QwtPlot::axisCnt ) { static QRect dummyRect; return dummyRect; } return d_data->scaleRect[axis]; }
void QwtPlotLayout::setAlignCanvasToScales | ( | bool | alignCanvasToScales ) |
Change the align-canvas-to-axis-scales setting. The canvas may:
alignCanvasToScales | New align-canvas-to-axis-scales setting |
Definition at line 273 of file qwt_plot_layout.cpp.
References alignCanvasToScales(), and QwtPlotLayout::PrivateData::alignCanvasToScales.
{ d_data->alignCanvasToScales = alignCanvasToScales; }
void QwtPlotLayout::setCanvasMargin | ( | int | margin, |
int | axis = -1 |
||
) |
Change a margin of the canvas. The margin is the space above/below the scale ticks. A negative margin will be set to -1, excluding the borders of the scales.
margin | New margin |
axis | One of QwtPlot::Axis. Specifies where the position of the margin. -1 means margin at all borders. |
Definition at line 235 of file qwt_plot_layout.cpp.
References QwtPlot::axisCnt, QwtPlotLayout::PrivateData::canvasMargin, and margin().
Referenced by QwtPlotLayout().
{ if ( margin < -1 ) margin = -1; if ( axis == -1 ) { for (axis = 0; axis < QwtPlot::axisCnt; axis++) d_data->canvasMargin[axis] = margin; } else if ( axis >= 0 && axis < QwtPlot::axisCnt ) d_data->canvasMargin[axis] = margin; }
void QwtPlotLayout::setLegendPosition | ( | QwtPlot::LegendPosition | pos, |
double | ratio | ||
) |
Specify the position of the legend.
pos | The legend's position. |
ratio | Ratio between legend and the bounding rect of title, canvas and axes. The legend will be shrinked if it would need more space than the given ratio. The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0 it will be reset to the default ratio. The default vertical/horizontal ratio is 0.33/0.5. |
Definition at line 326 of file qwt_plot_layout.cpp.
References QwtPlot::BottomLegend, QwtPlot::ExternalLegend, QwtPlot::LeftLegend, QwtPlotLayout::PrivateData::legendPos, QwtPlotLayout::PrivateData::legendRatio, QwtPlot::RightLegend, and QwtPlot::TopLegend.
Referenced by QwtPlot::insertLegend(), QwtPlotLayout(), setLegendPosition(), and setLegendRatio().
{ if ( ratio > 1.0 ) ratio = 1.0; switch(pos) { case QwtPlot::TopLegend: case QwtPlot::BottomLegend: if ( ratio <= 0.0 ) ratio = 0.33; d_data->legendRatio = ratio; d_data->legendPos = pos; break; case QwtPlot::LeftLegend: case QwtPlot::RightLegend: if ( ratio <= 0.0 ) ratio = 0.5; d_data->legendRatio = ratio; d_data->legendPos = pos; break; case QwtPlot::ExternalLegend: d_data->legendRatio = ratio; // meaningless d_data->legendPos = pos; default: break; } }
void QwtPlotLayout::setLegendPosition | ( | QwtPlot::LegendPosition | pos ) |
Specify the position of the legend.
pos | The legend's position. Valid values are QwtPlot::LeftLegend , QwtPlot::RightLegend , QwtPlot::TopLegend , QwtPlot::BottomLegend . |
Definition at line 363 of file qwt_plot_layout.cpp.
References setLegendPosition().
{ setLegendPosition(pos, 0.0); }
void QwtPlotLayout::setLegendRatio | ( | double | ratio ) |
Specify the relative size of the legend in the plot
ratio | Ratio between legend and the bounding rect of title, canvas and axes. The legend will be shrinked if it would need more space than the given ratio. The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0 it will be reset to the default ratio. The default vertical/horizontal ratio is 0.33/0.5. |
Definition at line 387 of file qwt_plot_layout.cpp.
References legendPosition(), and setLegendPosition().
{ setLegendPosition(legendPosition(), ratio); }
void QwtPlotLayout::setMargin | ( | int | margin ) |
Change the margin of the plot. The margin is the space around all components.
margin | new margin |
Definition at line 206 of file qwt_plot_layout.cpp.
References margin(), and QwtPlotLayout::PrivateData::margin.
Referenced by QwtPlot::setMargin().
void QwtPlotLayout::setSpacing | ( | int | spacing ) |
Change the spacing of the plot. The spacing is the distance between the plot components.
spacing | new spacing |
Definition at line 299 of file qwt_plot_layout.cpp.
References qwtMax, and QwtPlotLayout::PrivateData::spacing.
int QwtPlotLayout::spacing | ( | ) | const |
Definition at line 308 of file qwt_plot_layout.cpp.
References QwtPlotLayout::PrivateData::spacing.
{ return d_data->spacing; }
const QRect & QwtPlotLayout::titleRect | ( | ) | const |
Definition at line 406 of file qwt_plot_layout.cpp.
References QwtPlotLayout::PrivateData::titleRect.
Referenced by QwtPlot::updateLayout().
{ return d_data->titleRect; }