QWT 7.0.1
Loading...
Searching...
No Matches
qwt_plot_canvas_zoomer.h
1/******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 2024 ChenZongYan <czy.t@163.com>
4 *****************************************************************************/
5#ifndef QWT_PLOT_CANVAS_ZOOMER_H
6#define QWT_PLOT_CANVAS_ZOOMER_H
7#include "qwt_global.h"
8#include "qwt_canvas_picker.h"
9#include "qwt_axis_id.h"
10#include "qwt_interval.h"
11#include <QPointer>
12// Qt
13class QSizeF;
14template< typename T >
15class QStack;
16// Qwt
17class QwtPlot;
18
22struct QWT_EXPORT QwtPlotCanvasZoomState
23{
24public:
27 const QwtInterval& yLeft,
28 const QwtInterval& yRight,
29 const QwtInterval& xBottom,
30 const QwtInterval& xTop);
31 // 从plot获取当前所有坐标轴的状态
32 static QwtPlotCanvasZoomState fromPlot(QwtPlot* plot);
33
34 // 将状态应用到plot
35 void apply() const;
36
37 // 判断两个状态是否相等
38 bool operator==(const QwtPlotCanvasZoomState& other) const;
39 bool operator!=(const QwtPlotCanvasZoomState& other) const;
40
41 // 检查状态是否有效
42 bool isValid() const;
43
44public:
45 QPointer< QwtPlot > plot;
46 QwtInterval axisInterval[ QwtAxis::AxisPositions ];
47};
48Q_DECLARE_METATYPE(QwtPlotCanvasZoomState)
49
50
76class QWT_EXPORT QwtPlotCanvasZoomer : public QwtCanvasPicker
77{
78 Q_OBJECT
79 QWT_DECLARE_PRIVATE(QwtPlotCanvasZoomer)
80public:
81 explicit QwtPlotCanvasZoomer(QWidget* canvas, bool doReplot = true);
82 virtual ~QwtPlotCanvasZoomer();
83
84 // 设置缩放基准状态(当前所有坐标轴的范围),最小缩放范围会基于此基准进行计算
85 virtual void setZoomBase(bool doReplot = true);
86
87 // 设置是否自动replot,默认为true
88 void setAutoReplot(bool on = true);
89 bool isAutoReplot() const;
90 // 获取基准缩放状态
91 QList< QwtPlotCanvasZoomState > zoomBase() const;
92 // 获取当前缩放状态
93 QList< QwtPlotCanvasZoomState > zoomState() const;
94 // zoomer记录的最大的缩放次数,如果超过这个次数,不会再让缩放,-1为不限制次数
95 void setMaxStackDepth(int);
96 int maxStackDepth() const;
97 // 缩放栈
98 const QStack< QList< QwtPlotCanvasZoomState > >& zoomStack() const;
99
100 uint zoomStateIndex() const;
101
102public Q_SLOTS:
103 // 通过索引在缩放栈中导航
104 virtual void zoom(int offset);
105 virtual void appendZoom(const QList< QwtPlotCanvasZoomState >& rect);
106Q_SIGNALS:
112
113protected:
114 virtual void rescale();
115
116 virtual void widgetMouseReleaseEvent(QMouseEvent*) QWT_OVERRIDE;
117 virtual void widgetKeyPressEvent(QKeyEvent*) QWT_OVERRIDE;
118
119 virtual void begin() QWT_OVERRIDE;
120 virtual bool end(bool ok = true) QWT_OVERRIDE;
121 virtual bool accept(QPolygon&) const QWT_OVERRIDE;
122
123private:
124 void init(bool doReplot);
125
126 // 将画布上的像素矩形转换为四个坐标轴的缩放状态
127 QList< QwtPlotCanvasZoomState > canvasRectToZoomStateList(const QRect& pixelRect) const;
128 // 将画布上的像素矩形转换为四个坐标轴的缩放状态
129 QwtPlotCanvasZoomState canvasRectToZoomState(QwtPlot* plt, const QRect& pixelRect) const;
130 // 移动当前缩放状态
131 void moveCurrentState(double dx, double dy);
132};
133
134#endif // QWTCANVASZOOMER_H
Definition qwt_dyngrid_layout.h:33
Definition qwt_plot_axis_zoomer.h:35
专门针对 canvas 的 picker 基类 / Base picker class specifically for canvas
Definition qwt_canvas_picker.h:21
A class representing an interval.
Definition qwt_interval.h:40
QwtCanvasZoomer provides zooming for all axes of a plot canvas.
Definition qwt_plot_canvas_zoomer.h:77
void zoomed(const QList< QwtPlotCanvasZoomState > &state)
A signal emitted when the plot has been zoomed in or out.
A 2-D plotting widget.
Definition qwt_plot.h:99
存储所有四个坐标轴缩放状态的结构体
Definition qwt_plot_canvas_zoomer.h:23