⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qwt_plot_layout.cpp

📁 软件无线电的平台
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** * Qwt Widget Library * Copyright (C) 1997   Josef Wilgen * Copyright (C) 2002   Uwe Rathmann * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/// vim: expandtab#include <qlabel.h>#include "qwt_rect.h"#include "qwt_text.h"#include "qwt_plot_canvas.h"#include "qwt_scale.h"#include "qwt_legend.h"#include "qwt_plot_layout.h"class QwtPlotLayoutData{    friend class QwtPlotLayout;protected:    QwtPlotLayoutData();    ~QwtPlotLayoutData();    void init(const QwtPlot *, const QRect &rect);    struct t_legendData    {        int frameWidth;        int vScrollBarWidth;        int hScrollBarHeight;        QSize hint;    } legend;        struct t_titleData    {        const QwtText *text;        int frameWidth;    } title;    struct t_scaleData    {        bool isEnabled;        const QwtScale *scale;        QFont scaleFont;        int start;        int end;        int baseLineOffset;        int tickOffset;         int dimWithoutTitle;    } scale[QwtPlot::axisCnt];    struct t_canvasData    {        int frameWidth;    } canvas;};/*!  \brief Constructor */QwtPlotLayout::QwtPlotLayout():    d_margin(0),    d_spacing(5),    d_alignCanvasToScales(FALSE){    setLegendPos(Qwt::Bottom);    setCanvasMargin(4);    d_layoutData = new QwtPlotLayoutData;    invalidate();}//! DestructorQwtPlotLayout::~QwtPlotLayout(){    delete d_layoutData;}/*!  Change the margin of the plot. The margin is the space  around all components.   \param margin new margin  \sa QwtPlotLayout::margin(), QwtPlotLayout::setSpacing(),      QwtPlot::setMargin()*/void QwtPlotLayout::setMargin(int margin){    if ( margin < 0 )        margin = 0;    d_margin = margin;}/*!    \return margin    \sa QwtPlotLayout::setMargin(), QwtPlotLayout::spacing(),         QwtPlot::margin()*/int QwtPlotLayout::margin() const{    return d_margin;}/*!  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.   \param margin New margin  \param axis One of QwtPlot::Axis. Specifies where the position of the margin.               -1 means margin at all borders.  \sa QwtPlotLayout::canvasMargin()   \warning The canvas will have no effect when alignCanvasToScales is TRUE*/void QwtPlotLayout::setCanvasMargin(int margin, int axis){    if ( margin < -1 )        margin = -1;    if ( axis == -1 )    {        for (axis = 0; axis < QwtPlot::axisCnt; axis++)            d_canvasMargin[axis] = margin;    }    else if ( axis >= 0 || axis < QwtPlot::axisCnt )        d_canvasMargin[axis] = margin;}/*!    \return Margin around the scale tick borders    \sa QwtPlotLayout::setCanvasMargin()*/int QwtPlotLayout::canvasMargin(int axis) const{    if ( axis < 0 || axis >= QwtPlot::axisCnt )        return 0;    return d_canvasMargin[axis];}/*!  Change the align-canvas-to-axis-scales setting. The canvas may:  - extend beyond the axis scale ends to maximize its size,  - align with the axis scale ends to control its size.  \param alignCanvasToScales New align-canvas-to-axis-scales setting  \sa QwtPlotLayout::alignCanvasToTicks, QwtPlotLayout::setCanvasMargin()   \note In this context the term 'scale' means the backbone of a scale.  \warning In case of alignCanvasToScales == TRUE canvasMargin will have            no effect*/void QwtPlotLayout::setAlignCanvasToScales(bool alignCanvasToScales){    d_alignCanvasToScales = alignCanvasToScales;}/*!  Return the align-canvas-to-axis-scales setting. The canvas may:  - extend beyond the axis scale ends to maximize its size  - align with the axis scale ends to control its size.  \return align-canvas-to-axis-scales setting  \sa QwtPlotLayout::setAlignCanvasToScales, QwtPlotLayout::setCanvasMargin()   \note In this context the term 'scale' means the backbone of a scale.*/bool QwtPlotLayout::alignCanvasToScales() const{    return d_alignCanvasToScales;}/*!  Change the spacing of the plot. The spacing is the distance  between the plot components.   \param spacing new spacing  \sa QwtPlotLayout::setMargin(), QwtPlotLayout::spacing() */void QwtPlotLayout::setSpacing(int spacing){    d_spacing = QMAX(0, spacing);}/*!  \return spacing  \sa QwtPlotLayout::margin(), QwtPlotLayout::setSpacing() */int QwtPlotLayout::spacing() const{    return d_spacing;}/*!  \brief Specify the position of the legend  \param pos The legend's position. Valid values are \c Qwt::Left,           \c Qwt::Right, \c Qwt::Top, \c QwtBottom.  \param 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.                  \sa QwtPlot::setLegendPos()*/void QwtPlotLayout::setLegendPos(int pos, double ratio){    if ( ratio > 1.0 )        ratio = 1.0;    switch(pos)    {        case Qwt::Top:        case Qwt::Bottom:            if ( ratio <= 0.0 )                ratio = 0.33;            d_legendRatio = ratio;            d_legendPos = pos;            break;        case Qwt::Left:        case Qwt::Right:            if ( ratio <= 0.0 )                ratio = 0.5;            d_legendRatio = ratio;            d_legendPos = pos;            break;        default:            break;    }}/*!  \return Position of the legend  \sa QwtPlotLayout::setLegendPos(), QwtPlot::setLegendPos(),      QwtPlot::legendPos()*/int QwtPlotLayout::legendPos() const{    return d_legendPos;}/*!  \return Position of the legend  \sa QwtPlotLayout::setLegendPos(), QwtPlot::setLegendPos()*/double QwtPlotLayout::legendRatio() const{    return d_legendRatio;}/*!  \return Geometry for the title  \sa QwtPlotLayout::activate(), QwtPlotLayout::invalidate()*/const QRect &QwtPlotLayout::titleRect() const{    return d_titleRect;}/*!  \return Geometry for the legend  \sa QwtPlotLayout::activate(), QwtPlotLayout::invalidate()*/const QRect &QwtPlotLayout::legendRect() const{    return d_legendRect;}/*!  \param axis Axis index  \return Geometry for the scale  \sa QwtPlotLayout::activate(), QwtPlotLayout::invalidate()*/const QRect &QwtPlotLayout::scaleRect(int axis) const{    if ( axis < 0 || axis >= QwtPlot::axisCnt )    {        static QRect dummyRect;        return dummyRect;    }    return d_scaleRect[axis];}/*!  \return Geometry for the canvas  \sa QwtPlotLayout::activate(), QwtPlotLayout::invalidate()*/const QRect &QwtPlotLayout::canvasRect() const{    return d_canvasRect;}/*!  Invalidate the geometry of all components.   \sa QwtPlotLayout::activate()*/void QwtPlotLayout::invalidate(){    d_titleRect = d_legendRect = d_canvasRect = QRect();    for (int axis = 0; axis < QwtPlot::axisCnt; axis++ )        d_scaleRect[axis] = QRect();}/*!    \brief Return a minimum size hint  \sa QwtPlot::minimumSizeHint()*/QSize QwtPlotLayout::minimumSizeHint(const QwtPlot *plot) const{    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++ )    {        const QwtScale *scl = plot->axis(axis);        if ( scl )        {            ScaleData &sd = scaleData[axis];            const QSize hint = scl->minimumSizeHint();            sd.w = hint.width();             sd.h = hint.height();             scl->minBorderDist(sd.minLeft, sd.minRight);            sd.tickOffset = scl->baseLineDist() +                scl->scaleDraw()->majTickLength();        }        canvasBorder[axis] = plot->canvas()->frameWidth() +            d_canvasMargin[axis] + 1;                }    for ( axis = 0; axis < QwtPlot::axisCnt; axis++ )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -