DAWorkbench 0.0.1
DAWorkbench API
载入中...
搜索中...
未找到
DAChartWidget.h
1#ifndef DACHARTWIDGET_H
2#define DACHARTWIDGET_H
3
4
5#include "DAFigureAPI.h"
6#include "DAChartDataInterface.h"
7#include "DAChartStyleInterface.h"
8#include "DAChartInteractionInterface.h"
9
10#include <QWidget>
11#include <memory>
12
13// QWT includes
14#include "qwt_plot.h"
15#include "qwt_plot_curve.h"
16#include "qwt_plot_barchart.h"
17#include "qwt_plot_marker.h"
18#include "qwt_plot_intervalcurve.h"
19#include "qwt_plot_spectrogram.h"
20
21class QwtDateScaleDraw;
22
23
24namespace DA
25{
26class DAFigureWidget;
27
36class DAFIGURE_API DAChartWidget : public QwtPlot,
40{
41 Q_OBJECT
42 DA_DECLARE_PRIVATE(DAChartWidget)
43public:
48 {
49 NoChange = 0x0,
50 ChartTitleChanged = 0x1,
51 BackgroundChanged = 0x2,
52 BorderColorChanged = 0x4,
53 // Axis
54 AxisLabelChanged = 0x10,
55 AxisColorChanged = 0x20,
56 AxisScaleChanged = 0x40,
57 // Grid & Legend
58 GridEnabledChanged = 0x100,
59 GridStyleChanged =
60 0x200,
63 LegendEnabledChanged = 0x400,
64 LegendPositionChanged = 0x800,
65 LegendBackgroundChanged = 0x1000,
66 LegendTextColorChanged = 0x2000,
67 LegendPanelEnabledChanged = 0x8000,
68 // scale
69 DateTimeScaleSetup = 0x10000,
70 // Interaction
71 ZoomStateChanged = 0x100000,
72 PanStateChanged = 0x200000,
73 CrosshairStateChanged = 0x400000,
74 DataPickingStateChanged =
75 0x800000,
76 MouseWheelZoomStateChanged = 0x1000000,
77 };
78 Q_ENUM(ChartPropertyChangeFlag)
79 Q_DECLARE_FLAGS(ChartPropertyChangeFlags, ChartPropertyChangeFlag)
80public:
81 explicit DAChartWidget(QWidget* parent = nullptr);
82 virtual ~DAChartWidget();
83
84 // ==================== DAChartDataInterface 实现 ====================
85 // 获取所有数据相关的rtti
86 virtual QList< int > dataRttis() const override;
87 // 曲线操作
88 QwtPlotCurve* addCurve(const QVector< double >& xData, const QVector< double >& yData, const QString& title = QString()) override;
89 QwtPlotCurve* addCurve(const QVector< QPointF >& points, const QString& title = QString()) override;
90 QList< QwtPlotCurve* > getCurves() const override;
91 void removeCurve(QwtPlotCurve* curve) override;
92
93 // 散点图
94 QwtPlotCurve* addScatter(const QVector< QPointF >& points, const QString& title = QString()) override;
95
96 // 柱状图
97 QwtPlotBarChart* addBarChart(const QVector< double >& values, const QString& title = QString()) override;
98 QwtPlotBarChart* addBarChart(const QVector< QPointF >& points, const QString& title = QString()) override;
99
100 // 误差图
101 QwtPlotIntervalCurve* addIntervalCurve(
102 const QVector< double >& values,
103 const QVector< double >& mins,
104 const QVector< double >& maxs,
105 const QString& title = QString()
106 ) override;
107
108 // 标记线
109 QwtPlotMarker* addVerticalLine(double x, const QString& title = QString()) override;
110 QwtPlotMarker* addHorizontalLine(double y, const QString& title = QString()) override;
111 QwtPlotMarker* addCrossLine(double x, double y, const QString& title = QString()) override;
112
113 // 高级图表
114 QwtPlotSpectrogram* addSpectrogram(QwtGridRasterData* gridData, const QString& title = QString()) override;
115
116 // 通用数据操作
117 void removePlotItem(QwtPlotItem* item) override;
118 // 删除所有数据相关的项目(保留网格、图例等显示元素)
119 void clearAllData() override;
120
121 // 数据工具函数
122 QRectF getDataBounds() const override;
123 bool hasData() const override;
124
125 // ==================== DAChartStyleInterface 实现 ====================
126 // 图表整体样式
127 void setChartTitle(const QString& title) override;
128 QString getChartTitle() const override;
129
130 void setBackgroundBrush(const QBrush& brush) override;
131 QBrush getBackgroundBrush() const override;
132
133 void setBorderColor(const QColor& color) override;
134 QColor getBorderColor() const override;
135
136 // 坐标轴样式
137 void setAxisLabel(int axisId, const QString& label) override;
138 QString getAxisLabel(int axisId) const override;
139
140 void setAxisColor(int axisId, const QColor& color) override;
141 QColor getAxisColor(int axisId) const override;
142
143 // 网格样式
144 void enableGrid(bool enable = true) override;
145 void enableGridX(bool enable = true);
146 void enableGridY(bool enable = true);
147 void enableGridXMin(bool enable = true);
148 void enableGridYMin(bool enable = true);
149 bool isGridEnabled() const override;
150 bool isGridXEnabled() const;
151 bool isGridYEnabled() const;
152 bool isGridXMinEnabled() const;
153 bool isGridYMinEnabled() const;
154
155 void setGridStyle(const QColor& color, qreal width = 1.0, Qt::PenStyle style = Qt::DotLine, bool isMajor = true) override;
156
157 void setGridMajorStyle(const QColor& color, qreal width = 1.0, Qt::PenStyle style = Qt::DotLine) override;
158
159 void setGridMinorStyle(const QColor& color, qreal width = 0.5, Qt::PenStyle style = Qt::DotLine) override;
160
161 // 图例样式
162 void enableLegend(bool enable = true) override;
163 bool isLegendEnabled() const override;
164
165 void setLegendPosition(Qt::Alignment alignment) override;
166 Qt::Alignment getLegendPosition() const override;
167
168 void setLegendBackground(const QBrush& brush) override;
169 QBrush getLegendBackground() const override;
170
171 void setLegendTextColor(const QColor& color) override;
172 QColor getLegendTextColor() const override;
173
174 // 时间坐标轴
175 void setupDateTimeAxis(int axisId, const QString& format = "yyyy-MM-dd hh:mm:ss") override;
176 bool isDateTimeAxis(int axisId) const override;
177
178 // ==================== DAChartInteractionInterface 实现 ====================
179 // 缩放控制
180 void enableZoom(bool enable = true) override;
181 bool isZoomEnabled() const override;
182
183 void zoomToOriginal() override;
184 void zoomIn() override;
185 void zoomOut() override;
186
187
188 QwtPlotCanvasZoomer* getZoomer() const override;
189
190 // 平移控制
191 void enablePan(bool enable = true) override;
192 bool isPanEnabled() const override;
193
194 QwtPlotPanner* getPanner() const override;
195
196 // 十字线控制
197 void enableCrosshair(bool enable = true) override;
198 bool isCrosshairEnabled() const override;
199
200 QwtPlotPicker* getCrosshair() const override;
201
202 // 数据拾取控制
203 bool isDataPickingEnabled() const;
204
205 void enableYValuePicking(bool enable = true) override;
206 bool isYValuePickingEnabled() const override;
207
208 void enableXYValuePicking(bool enable = true) override;
209 bool isXYValuePickingEnabled() const override;
210
211 QwtPlotSeriesDataPicker* getDataPicker() const override;
212
213 // 鼠标滚轮控制
214 void enableMouseWheelZoom(bool enable = true) override;
215 bool isMouseWheelZoomEnabled() const override;
216
217 QwtPlotMagnifier* getMagnifier() const override;
218
219 // 图例面板控制
220 void enableLegendPanel(bool enable = true) override;
221 bool isLegendPanelEnabled() const override;
222
223 QwtLegend* getLegendPanel() const override;
224
225
226 // 工厂函数注册
227 void registerPannerFactory(const PannerFactory& factory) override;
228 void registerPickerFactory(const PickerFactory& factory) override;
229 void registerDataPickerFactory(const DataPickerFactory& factory) override;
230
231 // ==================== 工具函数 ====================
232 DAFigureWidget* getFigure() const;
233
234 void notifyPropertiesChanged(ChartPropertyChangeFlags flag);
235
236public Q_SLOTS:
237 void onLegendItemToggled(const QVariant& itemInfo, bool checked);
238
239Q_SIGNALS:
240 // 通用信号
241 void chartPropertiesChanged(DA::DAChartWidget* chart, DA::DAChartWidget::ChartPropertyChangeFlags flag);
242
243protected:
244 void paintEvent(QPaintEvent* event) override;
245
246private:
247 // 初始化函数
248 void initializeChart();
249 void setupCanvas();
250 void initializeInteractions();
251
252 // 组件管理
253 void setupZoomer();
254 void setupPanner();
255 void setupMagnifier();
256 void setupCrosshair();
257 void setupDataPicker();
258 void setupLegendPanel();
259
260 // 显示元素管理
261 QwtPlotGrid* getOrCreateGrid();
262 QwtPlotLegendItem* getOrCreateLegend();
263};
264
265} // namespace DA
266
267
268#endif // DACHARTWIDGET_H
图表数据操作接口 - 负责数据的添加、删除和管理
Definition DAChartDataInterface.h:24
图表交互控制接口 - 负责缩放、平移、拾取等交互功能
Definition DAChartInteractionInterface.h:23
图表样式设置接口 - 负责颜色、字体、背景、显示元素等样式设置
Definition DAChartStyleInterface.h:19
增强的Qwt图表控件,提供完整的数据绘图、样式设置和交互控制功能
Definition DAChartWidget.h:40
ChartPropertyChangeFlag
The 图表属性
Definition DAChartWidget.h:48
绘图窗口
Definition DAFigureWidget.h:35
序列化类都是带异常的,使用中需要处理异常
Definition AppMainWindow.cpp:44