📄 qwt_plot_layout.cpp
字号:
{ 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(); int w = scaleData[QwtPlot::yLeft].w + scaleData[QwtPlot::yRight].w + QMAX(scaleData[QwtPlot::xBottom].w, scaleData[QwtPlot::xTop].w) + 2 * (canvas->frameWidth() + 1); int h = scaleData[QwtPlot::xBottom].h + scaleData[QwtPlot::xTop].h + QMAX(scaleData[QwtPlot::yLeft].h, scaleData[QwtPlot::yRight].h) + 2 * (canvas->frameWidth() + 1); const QLabel *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->axis(QwtPlot::yLeft) == 0 || plot->axis(QwtPlot::yRight) == 0; 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_spacing; } // Compute the legend contribution const QwtLegend *legend = plot->legend(); if ( legend && !legend->isEmpty() ) { if ( d_legendPos == Qwt::Left || d_legendPos == Qwt::Right ) { int legendW = legend->sizeHint().width(); int legendH = legend->heightForWidth(legendW); if ( legend->frameWidth() > 0 ) w += d_spacing; if ( legendH > h ) legendW += legend->verticalScrollBar()->sizeHint().height(); if ( d_legendRatio < 1.0 ) legendW = QMIN(legendW, int(w / (1.0 - d_legendRatio))); w += legendW; } else // Qwt::Top, Qwt::Bottom { int legendW = QMIN(legend->sizeHint().width(), w); int legendH = legend->heightForWidth(legendW); if ( legend->frameWidth() > 0 ) h += d_spacing; if ( d_legendRatio < 1.0 ) legendH = QMIN(legendH, int(h / (1.0 - d_legendRatio))); h += legendH; } } w += 2 * d_margin; h += 2 * d_margin; return QSize( w, h );}/*! Find the geometry for the legend \param options Options how to layout the legend \param rect Rectangle where to place the legend \return Geometry for the legend*/QRect QwtPlotLayout::layoutLegend(int options, const QRect &rect) const{ const QSize hint(d_layoutData->legend.hint); int dim; if ( d_legendPos == Qwt::Left || d_legendPos == Qwt::Right ) { // We don't allow vertical legends to take more than // half of the available space. dim = QMIN(hint.width(), int(rect.width() * d_legendRatio)); if ( !(options & IgnoreScrollbars) ) { if ( hint.height() > rect.height() ) { // The legend will need additional // space for the vertical scrollbar. dim += d_layoutData->legend.vScrollBarWidth; } } } else { dim = QMIN(hint.height(), int(rect.height() * d_legendRatio)); dim = QMAX(dim, d_layoutData->legend.hScrollBarHeight); } QRect legendRect = rect; switch(d_legendPos) { case Qwt::Left: legendRect.setWidth(dim); break; case Qwt::Right: legendRect.setX(rect.right() - dim + 1); legendRect.setWidth(dim); break; case Qwt::Top: legendRect.setHeight(dim); break; case Qwt::Bottom: legendRect.setY(rect.bottom() - dim + 1); legendRect.setHeight(dim); break; } return legendRect;}/*! Align the legend to the canvas \param canvasRect Geometry of the canvas \param legendRect Maximum geometry for the legend \return Geometry for the aligned legend*/QRect QwtPlotLayout::alignLegend(const QRect &canvasRect, const QRect &legendRect) const{ QRect alignedRect = legendRect; if ( d_legendPos == Qwt::Bottom || d_legendPos == Qwt::Top ) { if ( d_layoutData->legend.hint.width() < canvasRect.width() ) { alignedRect.setX(canvasRect.x()); alignedRect.setWidth(canvasRect.width()); } } else { if ( d_layoutData->legend.hint.height() < canvasRect.height() ) { alignedRect.setY(canvasRect.y()); alignedRect.setHeight(canvasRect.height()); } } return alignedRect;}/*! Expand all line breaks in text labels, and calculate the height of their widgets in orientation of the text. \param options Options how to layout the legend \param rect Bounding rect for title, axes and canvas. \param dimTitle Expanded height of the title widget \param dimAxis Expanded heights of the axis in axis orientation.*/void QwtPlotLayout::expandLineBreaks(int options, const QRect &rect, int &dimTitle, int dimAxis[QwtPlot::axisCnt]) const{ dimTitle = 0; for ( int i = 0; i < QwtPlot::axisCnt; i++ ) dimAxis[i] = 0; 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_layoutData->title.text) { int w = rect.width(); if ( d_layoutData->scale[QwtPlot::yLeft].isEnabled != d_layoutData->scale[QwtPlot::yRight].isEnabled ) { // center to the canvas w -= dimAxis[QwtPlot::yLeft] + dimAxis[QwtPlot::yRight]; } int d = d_layoutData->title.text->heightForWidth(w); if ( !(options & IgnoreFrames) ) d += 2 * d_layoutData->title.frameWidth; if ( d > dimTitle ) { dimTitle = d; done = FALSE; } } for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { int backboneOffset = d_canvasMargin[axis]; if ( !(options & IgnoreFrames) ) backboneOffset += d_layoutData->canvas.frameWidth; const struct QwtPlotLayoutData::t_scaleData &scaleData = d_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 += QMIN(dimAxis[QwtPlot::yLeft], scaleData.start - backboneOffset); length += QMIN(dimAxis[QwtPlot::yRight], scaleData.end - backboneOffset); } else // QwtPlot::yLeft, QwtPlot::yRight { length = rect.height() - dimAxis[QwtPlot::xTop] - dimAxis[QwtPlot::xBottom]; if ( dimAxis[QwtPlot::xBottom] > 0 ) { length += QMIN( d_layoutData->scale[QwtPlot::xBottom].tickOffset, scaleData.start - backboneOffset); } if ( dimAxis[QwtPlot::xTop] > 0 ) { length += QMIN( d_layoutData->scale[QwtPlot::xTop].tickOffset, scaleData.end - backboneOffset); } if ( dimTitle > 0 ) length -= dimTitle + d_spacing; } int d = scaleData.dimWithoutTitle; if ( !scaleData.scale->title().isEmpty() ) { d += scaleData.scale->titleHeightForWidth(length); } if ( options & AlignScales ) d -= scaleData.baseLineOffset; if ( d > dimAxis[axis] ) { dimAxis[axis] = d; done = FALSE; } } } }}/*! Align the ticks of the axis to the canvas borders using the empty corners.*/void QwtPlotLayout::alignScales(int options, QRect &canvasRect, QRect scaleRect[QwtPlot::axisCnt]) const{ int axis; int backboneOffset[QwtPlot::axisCnt]; for (axis = 0; axis < QwtPlot::axisCnt; axis++ ) { backboneOffset[axis] = 0; if ( !d_alignCanvasToScales ) backboneOffset[axis] += d_canvasMargin[axis]; if ( !(options & IgnoreFrames) ) backboneOffset[axis] += d_layoutData->canvas.frameWidth; } for (axis = 0; axis < QwtPlot::axisCnt; axis++ ) { if ( !scaleRect[axis].isValid() ) continue; const int startDist = d_layoutData->scale[axis].start; const int endDist = d_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(QMAX(left, minLeft)); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -