📄 qwt_plot_layout.cpp
字号:
else { if ( d_alignCanvasToScales ) { canvasRect.setLeft(QMAX(canvasRect.left(), axisRect.left() - leftOffset)); } else { if ( leftOffset > 0 ) axisRect.setLeft(axisRect.left() + leftOffset); } } const int rightOffset = backboneOffset[QwtPlot::yRight] - endDist; if ( scaleRect[QwtPlot::yRight].isValid() ) { int maxRight = scaleRect[QwtPlot::yRight].right(); int right = axisRect.right() - rightOffset; axisRect.setRight(QMIN(right, maxRight)); } else { if ( d_alignCanvasToScales ) { canvasRect.setRight( QMIN(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] - startDist; if ( scaleRect[QwtPlot::xBottom].isValid() ) { int maxBottom = scaleRect[QwtPlot::xBottom].top() + d_layoutData->scale[QwtPlot::xBottom].tickOffset; int bottom = axisRect.bottom() - bottomOffset; axisRect.setBottom(QMIN(bottom, maxBottom)); } else { if ( d_alignCanvasToScales ) { canvasRect.setBottom(QMIN(canvasRect.bottom(), axisRect.bottom() + bottomOffset)); } else { if ( bottomOffset > 0 ) axisRect.setBottom(axisRect.bottom() - bottomOffset); } } const int topOffset = backboneOffset[QwtPlot::xTop] - endDist; if ( scaleRect[QwtPlot::xTop].isValid() ) { int minTop = scaleRect[QwtPlot::xTop].bottom() - d_layoutData->scale[QwtPlot::xTop].tickOffset; int top = axisRect.top() + topOffset; axisRect.setTop(QMAX(top, minTop)); } else { if ( d_alignCanvasToScales ) { canvasRect.setTop(QMAX(canvasRect.top(), axisRect.top() + - topOffset)); } else { if ( topOffset > 0 ) axisRect.setTop(axisRect.top() + topOffset); } } } }}/*! \brief Recalculate the geometry of all components. \param plot Plot to be layout \param plotRect Rect where to place the components \param options Options \sa QwtPlotLayout::invalidate(), QwtPlotLayout::titleRect(), QwtPlotLayout::legendRect(), QwtPlotLayout::scaleRect(), QwtPlotLayout::canvasRect()*/void QwtPlotLayout::activate(const QwtPlot *plot, const QRect &plotRect, int options) { invalidate(); QRect rect(plotRect); // undistributed rest of the plot rect if ( !(options & IgnoreMargin) ) { // subtract the margin rect.setRect( rect.x() + d_margin, rect.y() + d_margin, rect.width() - 2 * d_margin, rect.height() - 2 * d_margin ); } // We extract all layout relevant data from the widgets, // filter them through pfilter and save them to d_layoutData. d_layoutData->init(plot, rect); if (!(options & IgnoreLegend) && plot->legend() && !plot->legend()->isEmpty() ) { d_legendRect = layoutLegend(options, rect); // subtract d_legendRect from rect const QRegion region(rect); rect = region.subtract(d_legendRect).boundingRect(); if ( d_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_legendPos) { case Qwt::Left: rect.setLeft(rect.left() + d_spacing); break; case Qwt::Right: rect.setRight(rect.right() - d_spacing); break; case Qwt::Top: rect.setTop(rect.top() + d_spacing); break; case Qwt::Bottom: rect.setBottom(rect.bottom() - d_spacing); break; } } } /* +---+-----------+---+ | 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_titleRect = QRect(rect.x(), rect.y(), rect.width(), dimTitle); if ( d_layoutData->scale[QwtPlot::yLeft].isEnabled != d_layoutData->scale[QwtPlot::yRight].isEnabled ) { // if only one of the y axes is missing we align // the title centered to the canvas d_titleRect.setX(rect.x() + dimAxes[QwtPlot::yLeft]); d_titleRect.setWidth(rect.width() - dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight]); } // subtract title rect.setTop(rect.top() + dimTitle + d_spacing); } d_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_scaleRect[axis]; scaleRect = d_canvasRect; switch(axis) { case QwtPlot::yLeft: scaleRect.setX(d_canvasRect.left() - dim); scaleRect.setWidth(dim); break; case QwtPlot::yRight: scaleRect.setX(d_canvasRect.right() + 1); scaleRect.setWidth(dim); break; case QwtPlot::xBottom: scaleRect.setY(d_canvasRect.bottom() + 1); scaleRect.setHeight(dim); break; case QwtPlot::xTop: scaleRect.setY(d_canvasRect.top() - dim); scaleRect.setHeight(dim); break; } scaleRect = scaleRect.normalize(); } } // +---+-----------+---+ // | <- 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_canvasRect, d_scaleRect); if (!d_legendRect.isEmpty() ) { // We prefer to align the legend to the canvas - not to // the complete plot - if possible. d_legendRect = alignLegend(d_canvasRect, d_legendRect); }}QwtPlotLayoutData::QwtPlotLayoutData(){ title.text = NULL;}QwtPlotLayoutData::~QwtPlotLayoutData(){ delete title.text;}/* Extract all layout relevant data from the plot components*/void QwtPlotLayoutData::init(const QwtPlot *plot, const QRect &rect){ // legend legend.frameWidth = plot->legend()->frameWidth(); legend.vScrollBarWidth = plot->legend()->verticalScrollBar()->sizeHint().width(); legend.hScrollBarHeight = plot->legend()->horizontalScrollBar()->sizeHint().height(); const QSize hint = plot->legend()->sizeHint(); int w = QMIN(hint.width(), rect.width()); int h = plot->legend()->heightForWidth(w); if ( h == 0 ) h = hint.height(); if ( h > rect.height() ) w += legend.vScrollBarWidth; legend.hint = QSize(w, h); // title title.frameWidth = 0; title.text = NULL; if (plot->titleLabel() && !plot->titleLabel()->text().isEmpty()) { const QLabel *label = plot->titleLabel(); title.text = QwtText::makeText(label->text(), label->textFormat(), label->alignment(), label->font()); title.frameWidth = plot->titleLabel()->frameWidth(); } // scales for (int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { const QwtScale *sd = plot->axis(axis); if ( sd ) { scale[axis].isEnabled = TRUE; scale[axis].scale = sd; scale[axis].scaleFont = sd->font(); scale[axis].start = sd->startBorderDist(); scale[axis].end = sd->endBorderDist(); scale[axis].baseLineOffset = sd->baseLineDist(); scale[axis].tickOffset = sd->baseLineDist() + (int)sd->scaleDraw()->majTickLength(); scale[axis].dimWithoutTitle = sd->dimForLength( QCOORD_MAX, scale[axis].scaleFont); if ( !sd->title().isEmpty() ) { scale[axis].dimWithoutTitle -= sd->titleHeightForWidth(QCOORD_MAX); } } else { scale[axis].isEnabled = FALSE; scale[axis].start = 0; scale[axis].end = 0; scale[axis].baseLineOffset = 0; scale[axis].tickOffset = 0; scale[axis].dimWithoutTitle = 0; } } // canvas canvas.frameWidth = plot->canvas()->frameWidth();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -