QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
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:
25 // Default constructor
27
28 // Constructor with plot and axis intervals
30 const QwtInterval& yLeft,
31 const QwtInterval& yRight,
32 const QwtInterval& xBottom,
33 const QwtInterval& xTop);
34
35 // Create zoom state from current plot axis ranges
36 static QwtPlotCanvasZoomState fromPlot(QwtPlot* plot);
37
38 // Apply this zoom state to the associated plot
39 void apply() const;
40
41 // Check if two zoom states are equal
42 bool operator==(const QwtPlotCanvasZoomState& other) const;
43
44 // Check if two zoom states are not equal
45 bool operator!=(const QwtPlotCanvasZoomState& other) const;
46
47 // Check if this zoom state is valid (has an associated plot)
48 bool isValid() const;
49
50public:
51 QPointer< QwtPlot > plot;
52 QwtInterval axisInterval[ QwtAxis::AxisPositions ];
53};
54Q_DECLARE_METATYPE(QwtPlotCanvasZoomState)
55
56
81class QWT_EXPORT QwtPlotCanvasZoomer : public QwtCanvasPicker
82{
83 Q_OBJECT
84 QWT_DECLARE_PRIVATE(QwtPlotCanvasZoomer)
85public:
86 // Constructor
87 explicit QwtPlotCanvasZoomer(QWidget* canvas, bool doReplot = true);
88
89 // Destructor
90 ~QwtPlotCanvasZoomer() override;
91
92 // Set zoom base to current axis ranges, min zoom size is calculated based on this
93 virtual void setZoomBase(bool doReplot = true);
94
95 // Enable or disable automatic replot after zoom operations
96 void setAutoReplot(bool on = true);
97
98 // Check if automatic replot is enabled
99 bool isAutoReplot() const;
100
101 // Get the base zoom state (initial unzoomed state)
102 QList< QwtPlotCanvasZoomState > zoomBase() const;
103
104 // Get the current zoom state
105 QList< QwtPlotCanvasZoomState > zoomState() const;
106
107 // Set maximum number of zoom levels in the stack, -1 for unlimited
108 void setMaxStackDepth(int);
109
110 // Get maximum stack depth
111 int maxStackDepth() const;
112
113 // Get the zoom stack containing all zoom states
114 const QStack< QList< QwtPlotCanvasZoomState > >& zoomStack() const;
115
116 // Get the current zoom state index in the stack
117 uint zoomStateIndex() const;
118
119public Q_SLOTS:
120 // Navigate in the zoom stack by offset (negative = zoom out, positive = zoom in)
121 virtual void zoom(int offset);
122
123 // Append a new zoom state to the stack
124 virtual void appendZoom(const QList< QwtPlotCanvasZoomState >& rect);
125
126Q_SIGNALS:
132
133protected:
134 virtual void rescale();
135
136 virtual void widgetMouseReleaseEvent(QMouseEvent*) override;
137 virtual void widgetKeyPressEvent(QKeyEvent*) override;
138
139 virtual void begin() override;
140 virtual bool end(bool ok = true) override;
141 virtual bool accept(QPolygon&) const override;
142
143private:
144 void init(bool doReplot);
145
146 QList< QwtPlotCanvasZoomState > canvasRectToZoomStateList(const QRect& pixelRect) const;
147 QwtPlotCanvasZoomState canvasRectToZoomState(QwtPlot* plt, const QRect& pixelRect) const;
148 void moveCurrentState(double dx, double dy);
149};
150
151#endif // QWTCANVASZOOMER_H
Definition qwt_raster_data.h:38
Definition qwt_plot_axis_zoomer.h:35
Base picker class specifically for canvas
Definition qwt_canvas_picker.h:20
A class representing an interval
Definition qwt_interval.h:39
QwtPlotCanvasZoomer provides zooming for all axes of a plot canvas
Definition qwt_plot_canvas_zoomer.h:82
void zoomed(const QList< QwtPlotCanvasZoomState > &state)
Signal emitted when the plot has been zoomed in or out
A 2-D plotting widget
Definition qwt_plot.h:99
Struct that stores zoom states for all four axes
Definition qwt_plot_canvas_zoomer.h:23