三、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 (QwtEventPattern, QwtPickerMachine). 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 指与当前索引的偏移量