QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt_picker.h
1/******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *
9 * Modified by ChenZongYan in 2024 <czy.t@163.com>
10 * Summary of major modifications (see ChangeLog.md for full history):
11 * 1. CMake build system & C++11 throughout.
12 * 2. Core panner/ zoomer refactored:
13 * - QwtPanner -> QwtCachePanner (pixmap-cache version)
14 * - New real-time QwtPlotPanner derived from QwtPicker.
15 * 3. Zoomer supports multi-axis.
16 * 4. Parasite-plot framework:
17 * - QwtFigure, QwtPlotParasiteLayout, QwtPlotTransparentCanvas,
18 * - QwtPlotScaleEventDispatcher, built-in pan/zoom on axis.
19 * 5. New picker: QwtPlotSeriesDataPicker (works with date axis).
20 * 6. Raster & color-map extensions:
21 * - QwtGridRasterData (2-D table + interpolation)
22 * - QwtLinearColorMap::stopColors(), stopPos() API rename.
23 * 7. Bar-chart: expose pen/brush control.
24 * 8. Amalgamated build: single QwtPlot.h / QwtPlot.cpp pair in src-amalgamate.
25 *****************************************************************************/
26
27#ifndef QWT_PICKER
28#define QWT_PICKER
29
30#include "qwt_global.h"
31#include "qwt_event_pattern.h"
32
33#include <qobject.h>
34#include <QPen>
35#include <QFont>
36#include <QPainterPath>
37#include <QPoint>
38#include <QPolygon>
39#include <QSize>
40#include <QRect>
41#include <QRegion>
44class QwtText;
45class QWidget;
46class QMouseEvent;
47class QWheelEvent;
48class QKeyEvent;
49class QPainter;
50
107class QWT_EXPORT QwtPicker : public QObject, public QwtEventPattern
108{
109 Q_OBJECT
110
112
113 Q_PROPERTY(bool isEnabled READ isEnabled WRITE setEnabled)
114 Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode)
115
116 Q_PROPERTY(DisplayMode trackerMode READ trackerMode WRITE setTrackerMode)
117 Q_PROPERTY(QPen trackerPen READ trackerPen WRITE setTrackerPen)
118 Q_PROPERTY(QFont trackerFont READ trackerFont WRITE setTrackerFont)
119
120 Q_PROPERTY(RubberBand rubberBand READ rubberBand WRITE setRubberBand)
121 Q_PROPERTY(QPen rubberBandPen READ rubberBandPen WRITE setRubberBandPen)
122 QWT_DECLARE_PRIVATE(QwtPicker)
123public:
130 {
132 NoRubberBand = 0,
133
136
139
142
145
148
151
155 UserRubberBand = 100
156 };
157
163 {
166
169
171 ActiveOnly
172 };
173
180 {
183
185 KeepSize
186 };
187
188 // Constructor
189 explicit QwtPicker(QWidget* parent);
190 // Constructor with rubber band and tracker mode
191 explicit QwtPicker(RubberBand rubberBand, DisplayMode trackerMode, QWidget*);
192
193 // Destructor
194 ~QwtPicker() override;
195
196 // Set the state machine
197 void setStateMachine(QwtPickerMachine*);
198 // Return the state machine (const)
199 const QwtPickerMachine* stateMachine() const;
200 // Return the state machine
201 QwtPickerMachine* stateMachine();
202
203 // Set the rubber band style
204 void setRubberBand(RubberBand);
205 // Return the rubber band style
206 RubberBand rubberBand() const;
207
208 // Set the tracker display mode
209 void setTrackerMode(DisplayMode);
210 // Return the tracker display mode
211 DisplayMode trackerMode() const;
212
213 // Set the resize mode
214 void setResizeMode(ResizeMode);
215 // Return the resize mode
216 ResizeMode resizeMode() const;
217
218 // Set the rubber band pen
219 void setRubberBandPen(const QPen&);
220 // Return the rubber band pen
221 QPen rubberBandPen() const;
222
223 // Set the tracker pen
224 void setTrackerPen(const QPen&);
225 // Return the tracker pen
226 QPen trackerPen() const;
227
228 // Set the tracker font
229 void setTrackerFont(const QFont&);
230 // Return the tracker font
231 QFont trackerFont() const;
232
233 // Return true when enabled
234 bool isEnabled() const;
235 // Return true if the selection is active
236 bool isActive() const;
237
238 // Event filter for handling events
239 virtual bool eventFilter(QObject*, QEvent*) override;
240
241 // Return the parent widget
242 QWidget* parentWidget();
243 // Return the parent widget (const)
244 const QWidget* parentWidget() const;
245
246 // Return the pick area
247 virtual QPainterPath pickArea() const;
248
249 // Draw the rubber band
250 virtual void drawRubberBand(QPainter*) const;
251 // Draw the tracker
252 virtual void drawTracker(QPainter*) const;
253
254 // Return the tracker mask
255 virtual QRegion trackerMask() const;
256 // Return the rubber band mask
257 virtual QRegion rubberBandMask() const;
258
259 // Return the tracker text for a position
260 virtual QwtText trackerText(const QPoint& pos) const;
261 // Return the tracker rectangle
262 virtual QRect trackerRect(const QFont&) const;
263 // Set the tracker position manually (for displaying picker without mouse)
264 virtual void setTrackerPosition(const QPoint& pos);
265 // Return the tracker position
266 QPoint trackerPosition() const;
267 // Return the selected points
268 QPolygon selection() const;
269 // Update the display
270 void update();
271 // Set the picker active manually
272 void setActive(bool on);
273public Q_SLOTS:
274 // Enable or disable the picker
275 void setEnabled(bool);
276
277Q_SIGNALS:
284 void activated(bool on);
285
290 void selected(const QPolygon& polygon);
291
297 void appended(const QPoint& pos);
298
304 void moved(const QPoint& pos);
305
311 void removed(const QPoint& pos);
312
319 void changed(const QPolygon& selection);
320
321protected:
322 virtual QPolygon adjustedPoints(const QPolygon&) const;
323
324 virtual void transition(const QEvent*);
325
326 virtual void begin();
327 virtual void append(const QPoint&);
328 virtual void move(const QPoint&);
329 virtual void remove();
330 virtual bool end(bool ok = true);
331
332 virtual bool accept(QPolygon&) const;
333 virtual void reset();
334
335 virtual void widgetMousePressEvent(QMouseEvent*);
336 virtual void widgetMouseReleaseEvent(QMouseEvent*);
337 virtual void widgetMouseDoubleClickEvent(QMouseEvent*);
338 virtual void widgetMouseMoveEvent(QMouseEvent*);
339 virtual void widgetWheelEvent(QWheelEvent*);
340 virtual void widgetKeyPressEvent(QKeyEvent*);
341 virtual void widgetKeyReleaseEvent(QKeyEvent*);
342 virtual void widgetEnterEvent(QEvent*);
343 virtual void widgetLeaveEvent(QEvent*);
344
345 virtual void stretchSelection(const QSize& oldSize, const QSize& newSize);
346
347 virtual void updateDisplay();
348
349 const QwtWidgetOverlay* rubberBandOverlay() const;
350 const QwtWidgetOverlay* trackerOverlay() const;
351
352 const QPolygon& pickedPoints() const;
353
354private:
355 void init(QWidget*, RubberBand rubberBand, DisplayMode trackerMode);
356
357 void setMouseTracking(bool);
358};
359
360#endif
A collection of event patterns
Definition qwt_event_pattern.h:46
A state machine for QwtPicker selections
Definition qwt_picker_machine.h:45
QwtPicker provides selections on a widget
Definition qwt_picker.h:108
DisplayMode
Display mode
Definition qwt_picker.h:163
@ AlwaysOn
Display always
Definition qwt_picker.h:168
@ AlwaysOff
Display never
Definition qwt_picker.h:165
void selected(const QPolygon &polygon)
Signal emitting the selected points at the end of a selection
void activated(bool on)
Signal indicating when the picker has been activated
RubberBand
Rubber band style
Definition qwt_picker.h:130
@ VLineRubberBand
A vertical line ( only for QwtPickerMachine::PointSelection )
Definition qwt_picker.h:138
@ CrossRubberBand
A crosshair ( only for QwtPickerMachine::PointSelection )
Definition qwt_picker.h:141
@ EllipseRubberBand
An ellipse ( only for QwtPickerMachine::RectSelection )
Definition qwt_picker.h:147
@ PolygonRubberBand
A polygon ( only for QwtPickerMachine::PolygonSelection )
Definition qwt_picker.h:150
@ HLineRubberBand
A horizontal line ( only for QwtPickerMachine::PointSelection )
Definition qwt_picker.h:135
@ RectRubberBand
A rectangle ( only for QwtPickerMachine::RectSelection )
Definition qwt_picker.h:144
ResizeMode
Controls what to do with the selected points when the observed widget is resized
Definition qwt_picker.h:180
@ Stretch
All points are scaled according to the new size,
Definition qwt_picker.h:182
void appended(const QPoint &pos)
Signal emitted when a point has been appended to the selection
void moved(const QPoint &pos)
Signal emitted whenever the last appended point of the selection has been moved
void removed(const QPoint &pos)
Signal emitted whenever the last appended point of the selection has been removed
void changed(const QPolygon &selection)
Signal emitted when the active selection has been changed
A class representing a text
Definition qwt_text.h:70
An overlay for a widget
Definition qwt_widget_overlay.h:59