Qwt源码解读之拾取操作类(二)

三、QwtPlotPicker类:

QwtPlotPicker provides selections on a plot canvas.

QwtPlotPicker is a QwtPicker tailored for selections on a plot canvas.It is set to a x-Axis and y-Axis and translates all pixel coordinates into this coodinate system.

1、构造函数:

/*!
  \brief Create a plot picker

  The picker is set to those x- and y-axis of the plot
  that are enabled. If both or no x-axis are enabled, the picker
  is set to QwtPlot::xBottom. If both or no y-axis are
  enabled, it is set to QwtPlot::yLeft.

  \param canvas Plot canvas to observe, also the parent object

  \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect()
*/

QwtPlotPicker::QwtPlotPicker( QwtPlotCanvas *canvas ):
    QwtPicker( canvas ),
    d_xAxis( -1 ),
    d_yAxis( -1 )
{
    if ( !canvas )
        return;

    // attach axes

    int xAxis = QwtPlot::xBottom;
    const QwtPlot *plot = QwtPlotPicker::plot();
    if ( !plot->axisEnabled( QwtPlot::xBottom ) &&
        plot->axisEnabled( QwtPlot::xTop ) )
    {
        xAxis = QwtPlot::xTop;
    }

    int yAxis = QwtPlot::yLeft;
    if ( !plot->axisEnabled( QwtPlot::yLeft ) &&
        plot->axisEnabled( QwtPlot::yRight ) )
    {
        yAxis = QwtPlot::yRight;
    }

    setAxis( xAxis, yAxis );
}
说明:

1)QwtPlotPicker只是依附于两个轴(x轴和y轴),并且其依附的轴必须是可用的(enabled),否则QwtPlotPicker则默认依附于QwtPlot::xBottom 和 QwtPlot::yLeft轴。

2)C++构造函数没有返回值!

    if ( !canvas )
        return;

上面这句代码让人惊愕?!

四、QwtPlotZoomer类

QwtPlotZoomer providesstacked zooming for a plot widget.

QwtPlotZoomer offers rubberband selections on the plot canvas, translating the selected rectangles into plot coordinates and adjusting the axes to them. Zooming can repeated as often as possible, limited only by maxStackDepth() or minZoomSize().Each rectangle is pushed on a stack.

Zoom rectangles can be selected depending on selectionFlags() using the mouse or keyboard (QwtEventPatternQwtPickerMachine). QwtEventPattern::MouseSelect3,QwtEventPattern::KeyUndo, or QwtEventPattern::MouseSelect6,QwtEventPattern::KeyRedo walk up and down the zoom stack. QwtEventPattern::MouseSelect2 or QwtEventPattern::KeyHome unzoom to the initial size.

QwtPlotZoomer is tailored for plots with one x and y axis, but it is allowed to attach a second QwtPlotZoomer for the other axes.

Note:
The realtime example includes an derived zoomer class that adds scrollbars to the plot canvas.

QwtPlotZoomer类对一个Plot部件提供了缩放功能,并将每一个缩放状态保存至栈中,因此还可以随时撤销与恢复。QwtPlotZoomer也只能对一组x-y轴进行缩放,当然,你可以用第二个QwtPlotZoomer对另一组x-y轴进行缩放操作。

1、属性数据:

class QwtPlotZoomer::PrivateData
{
public:
    uint zoomRectIndex;
    QStack<QRectF> zoomStack;

    int maxStackDepth;
};
2、原始(基础)大小设置:

    virtual void setZoomBase( bool doReplot = true );
    virtual void setZoomBase( const QRectF & );
3、缩放至某矩形大小或某个栈索引对应的大小:

    virtual void zoom( const QRectF & );
    virtual void zoom( int offset ); // offset 指与当前索引的偏移量




  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值