QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt_plot_series_data_picker.h
1/******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 2024 ChenZongYan <czy.t@163.com>
4 *****************************************************************************/
5#ifndef QWT_PLOT_SERIES_DATA_PICKER_H
6#define QWT_PLOT_SERIES_DATA_PICKER_H
7#include <QList>
8#include <QPointF>
9#include <QVariant>
10#include "qwt_canvas_picker.h"
11#include "qwt_text.h"
12class QwtPlot;
13class QwtPlotItem;
14
21{
22 Q_OBJECT
23 QWT_DECLARE_PRIVATE(QwtPlotSeriesDataPicker)
24public:
29 {
31 PickNearestPoint
32 };
33
50
55 {
57 LinearInterpolation
58 };
59
64 {
65 QwtPlotItem* item { nullptr };
66 QPointF feature { 0, 0 };
67 QVariant sampleData;
68 size_t index { 0 };
69 };
70
71public:
73 explicit QwtPlotSeriesDataPicker(QWidget* canvas);
76
78 void setPickMode(PickSeriesMode mode);
80 PickSeriesMode pickMode() const;
81
83 void setTextArea(TextPlacement t);
85 TextPlacement textArea() const;
86
88 void setInterpolationMode(InterpolationMode mode);
90 InterpolationMode interpolationMode() const;
92 bool isInterpolation() const;
93
95 void setNearestSearchWindowSize(int windowSize);
97 int nearestSearchWindowSize() const;
98
100 void setEnableDrawFeaturePoint(bool on = true);
102 bool isEnableDrawFeaturePoint() const;
103
105 void setDrawFeaturePointSize(int px);
107 int drawFeaturePointSize() const;
108
109 // Returns the list of feature points currently picked by the tracker
110 QList< FeaturePoint > featurePoints() const;
111
113 void setTextBackgroundBrush(const QBrush& br);
115 QBrush textBackgroundBrush() const;
116
118 void setTextAlignment(Qt::Alignment al);
120 Qt::Alignment textAlignment() const;
121
123 void setEnableShowXValue(bool on);
124 bool isEnableShowXValue() const;
125
127 void setTextTrackerOffset(const QPoint& offset);
128 QPoint textTrackerOffset() const;
129
131 QwtText trackerText(const QPoint& pos) const override;
132
134 QRect trackerRect(const QFont& f) const override;
135
137 virtual void drawRubberBand(QPainter* painter) const override;
138
140 virtual void setTrackerPosition(const QPoint& pos) override;
141
142protected:
144 virtual int pickYValue(const QwtPlot* p, const QPoint& pos, bool interpolate = false);
146 virtual int pickNearestPoint(const QwtPlot* plot, const QPoint& pos, int windowSize = -5);
147
148 virtual void widgetMousePressEvent(QMouseEvent* event) override;
149 virtual void widgetMouseDoubleClickEvent(QMouseEvent* event) override;
150Q_SIGNALS:
159 void clicked(QwtPlotSeriesDataPicker* picker, const QPoint& pos);
160
167 void doubleClicked(QwtPlotSeriesDataPicker* picker, const QPoint& pos);
168
169private Q_SLOTS:
170 // Slot for item detachment, used to update records
171 void onPlotItemDetached(QwtPlotItem* item, bool on);
172 void onParasitePlotAttached(QwtPlot* parasiteplot, bool on);
173
174protected:
175 // Generate text content for an item
176 virtual QString valueString(const QList< FeaturePoint >& fps) const;
177 // Draw a feature point
178 virtual void
179 drawFeaturePoint(QPainter* painter, const QwtPlot* plot, const QwtPlotItem* item, const QPointF& itemPoint) const;
180 // Mouse move
181 virtual void move(const QPoint& pos) override;
182 // Format value according to axis type; for date axes the value is a large float but users need to see a format like 2024-10-01
183 QString formatAxisValue(double value, int axisId, QwtPlot* plot) const;
184
185private:
186 // Draw feature points (captured points)
187 void drawAllFeaturePoints(QPainter* painter) const;
188 // Update feature points
189 void updateFeaturePoint(const QPoint& pos);
190 //
191 QRect ensureRectInBounds(const QRect& rect, const QRect& bounds) const;
192};
193
194#endif // QWT_PLOT_SERIES_DATA_PICKER_H
Definition qwt_raster_data.h:38
Base picker class specifically for canvas
Definition qwt_canvas_picker.h:20
virtual void drawRubberBand(QPainter *) const
Draw a rubber band, depending on rubberBand()
Definition qwt_picker.cpp:607
virtual void setTrackerPosition(const QPoint &pos)
Set the tracker position manually
Definition qwt_picker.cpp:809
virtual void widgetMousePressEvent(QMouseEvent *)
Handle a mouse press event for the observed widget.
Definition qwt_picker.cpp:905
virtual void move(const QPoint &)
Move the last point of the selection The moved() signal is emitted.
Definition qwt_picker.cpp:1241
virtual QwtText trackerText(const QPoint &pos) const
Return the label for a position
Definition qwt_picker.cpp:485
virtual QRect trackerRect(const QFont &) const
Calculate the bounding rectangle for the tracker text from the current position of the tracker
Definition qwt_picker.cpp:748
virtual void widgetMouseDoubleClickEvent(QMouseEvent *)
Handle mouse double click event for the observed widget.
Definition qwt_picker.cpp:987
Base class for items on the plot canvas
Definition qwt_plot_item.h:85
A plot data picker class for displaying current y-values or nearest points
Definition qwt_plot_series_data_picker.h:21
void doubleClicked(QwtPlotSeriesDataPicker *picker, const QPoint &pos)
Emitted when the user double-left-clicks on the plot canvas
InterpolationMode
Interpolation modes
Definition qwt_plot_series_data_picker.h:55
@ NoInterpolation
No interpolation, use nearest data point
Definition qwt_plot_series_data_picker.h:56
TextPlacement
Text placement options
Definition qwt_plot_series_data_picker.h:38
@ TextOnCanvasTopRight
Text on canvas top right
Definition qwt_plot_series_data_picker.h:43
@ TextOnCanvasTopAuto
Text on canvas top, left or right auto-detected based on mouse position
Definition qwt_plot_series_data_picker.h:47
@ TextOnCanvasBottomRight
Text on canvas bottom right
Definition qwt_plot_series_data_picker.h:45
@ TextOnCanvasBottomLeft
Text on canvas bottom left
Definition qwt_plot_series_data_picker.h:46
@ TextPlaceAuto
Auto placement (top for pick y, follow mouse for pick nearest)
Definition qwt_plot_series_data_picker.h:39
@ TextFollowOnTop
On top of the plot area (default)
Definition qwt_plot_series_data_picker.h:40
@ TextFollowOnBottom
On bottom of the plot area
Definition qwt_plot_series_data_picker.h:41
@ TextOnCanvasTopLeft
Text on canvas top left
Definition qwt_plot_series_data_picker.h:44
@ TextFollowMouse
Follow mouse pointer
Definition qwt_plot_series_data_picker.h:42
PickSeriesMode
Pick modes
Definition qwt_plot_series_data_picker.h:29
@ PickYValue
Pick y-value (default)
Definition qwt_plot_series_data_picker.h:30
void clicked(QwtPlotSeriesDataPicker *picker, const QPoint &pos)
Emitted when the user left-clicks on the plot canvas
~QwtPlotSeriesDataPicker() override
Destructor
A 2-D plotting widget
Definition qwt_plot.h:99
A class representing a text
Definition qwt_text.h:70
Feature point structure
Definition qwt_plot_series_data_picker.h:64
QVariant sampleData
Full sample data (QwtOHLCSample, QwtIntervalSample, etc.)
Definition qwt_plot_series_data_picker.h:67