QWT 7.0.1
Loading...
Searching...
No Matches
qwt_plot.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_PLOT_H
28#define QWT_PLOT_H
29
30#include "qwt_global.h"
31#include "qwt_axis_id.h"
32#include "qwt_plot_dict.h"
33
34#include <qframe.h>
35
36class QwtPlotLayout;
38class QwtScaleWidget;
39class QwtScaleEngine;
40class QwtScaleDiv;
41class QwtScaleMap;
42class QwtScaleDraw;
43class QwtTextLabel;
44class QwtInterval;
45class QwtText;
47
48template< typename T >
49class QList;
50
51// 6.1 compatibility definitions
52#define QWT_AXIS_COMPAT 1
53
98class QWT_EXPORT QwtPlot : public QFrame, public QwtPlotDict
99{
100 Q_OBJECT
101
102 Q_PROPERTY(QBrush canvasBackground READ canvasBackground WRITE setCanvasBackground)
103
104 Q_PROPERTY(bool autoReplot READ autoReplot WRITE setAutoReplot)
105
106 QWT_DECLARE_PRIVATE(QwtPlot)
107public:
114 {
117
120
123
125 TopLegend
126 };
127
128 explicit QwtPlot(QWidget* = NULL);
129 explicit QwtPlot(const QwtText& title, QWidget* = NULL);
130
131 virtual ~QwtPlot();
132
133 void setAutoReplot(bool = true);
134 bool autoReplot() const;
135
136 // Layout
137
138 void setPlotLayout(QwtPlotLayout*);
139
140 QwtPlotLayout* plotLayout();
141 const QwtPlotLayout* plotLayout() const;
142
143 // Title
144
145 void setTitle(const QString&);
146 void setTitle(const QwtText&);
147 QwtText title() const;
148
149 QwtTextLabel* titleLabel();
150 const QwtTextLabel* titleLabel() const;
151
152 // Footer
153
154 void setFooter(const QString&);
155 void setFooter(const QwtText&);
156 QwtText footer() const;
157
158 QwtTextLabel* footerLabel();
159 const QwtTextLabel* footerLabel() const;
160
161 // Canvas
162
163 void setCanvas(QWidget*);
164
165 QWidget* canvas();
166 const QWidget* canvas() const;
167
168 void setCanvasBackground(const QBrush&);
169 QBrush canvasBackground() const;
170
171 virtual QwtScaleMap canvasMap(QwtAxisId) const;
172
173 double invTransform(QwtAxisId, double pos) const;
174 double transform(QwtAxisId, double value) const;
175
176 // Axes
177
178 bool isAxisValid(QwtAxisId) const;
179
180 void setAxisVisible(QwtAxisId, bool on = true);
181 bool isAxisVisible(QwtAxisId) const;
182
183 // Axes data
184
185 QwtScaleEngine* axisScaleEngine(QwtAxisId);
186 const QwtScaleEngine* axisScaleEngine(QwtAxisId) const;
187 void setAxisScaleEngine(QwtAxisId, QwtScaleEngine*);
188
189 void setAxisAutoScale(QwtAxisId, bool on = true);
190 bool axisAutoScale(QwtAxisId) const;
191
192 void setAxisFont(QwtAxisId, const QFont&);
193 QFont axisFont(QwtAxisId) const;
194
195 void setAxisScale(QwtAxisId, double min, double max, double stepSize = 0);
196 void setAxisScaleDiv(QwtAxisId, const QwtScaleDiv&);
197 void setAxisScaleDraw(QwtAxisId, QwtScaleDraw*);
198
199 double axisStepSize(QwtAxisId) const;
200 QwtInterval axisInterval(QwtAxisId) const;
201 const QwtScaleDiv& axisScaleDiv(QwtAxisId) const;
202
203 const QwtScaleDraw* axisScaleDraw(QwtAxisId) const;
204 QwtScaleDraw* axisScaleDraw(QwtAxisId);
205
206 const QwtScaleWidget* axisWidget(QwtAxisId) const;
207 QwtScaleWidget* axisWidget(QwtAxisId);
208
209 // 获取一个有效的x轴,有效的定义顺序:1.可见、2.XBottom优先、3.指针有效,因此如果xBotton和xTop都可见时,先放回xBottom
210 QwtAxisId visibleXAxisId() const;
211 QwtAxisId visibleYAxisId() const;
212
213 void setAxisLabelAlignment(QwtAxisId, Qt::Alignment);
214 void setAxisLabelRotation(QwtAxisId, double rotation);
215
216 void setAxisTitle(QwtAxisId, const QString&);
217 void setAxisTitle(QwtAxisId, const QwtText&);
218 QwtText axisTitle(QwtAxisId) const;
219
220 void setAxisMaxMinor(QwtAxisId, int maxMinor);
221 int axisMaxMinor(QwtAxisId) const;
222
223 void setAxisMaxMajor(QwtAxisId, int maxMajor);
224 int axisMaxMajor(QwtAxisId) const;
225
226 // Legend
227
228 void insertLegend(QwtAbstractLegend*, LegendPosition = QwtPlot::RightLegend, double ratio = -1.0);
229
230 QwtAbstractLegend* legend();
231 const QwtAbstractLegend* legend() const;
232
233 void updateLegend();
234 void updateLegend(const QwtPlotItem*);
235
236 // Misc
237
238 virtual QSize sizeHint() const QWT_OVERRIDE;
239 virtual QSize minimumSizeHint() const QWT_OVERRIDE;
240
241 virtual void updateLayout();
242 virtual void drawCanvas(QPainter*);
243
244 void updateAxes();
245 void updateCanvasMargins();
246
247 virtual void getCanvasMarginsHint(const QwtScaleMap maps[],
248 const QRectF& canvasRect,
249 double& left,
250 double& top,
251 double& right,
252 double& bottom) const;
253
254 virtual bool event(QEvent*) QWT_OVERRIDE;
255 virtual bool eventFilter(QObject*, QEvent*) QWT_OVERRIDE;
256
257 virtual void drawItems(QPainter*, const QRectF&, const QwtScaleMap maps[ QwtAxis::AxisPositions ]) const;
258
259 virtual QVariant itemToInfo(QwtPlotItem*) const;
260 virtual QwtPlotItem* infoToItem(const QVariant&) const;
261
262 // add since v7.1.0
263
264 // 创建一个基于此轴为宿主的寄生轴
265 QwtPlot* createParasitePlot(QwtAxis::Position enableAxis);
266
267 // 设置寄生轴共享宿主的轴是哪些,此函数仅针对寄生轴有效
268 void setParasiteShareAxis(QwtAxisId axisId, bool isShare = true);
269
270 // 获取寄生轴是和宿主轴的哪些轴共享,此函数仅针对寄生轴有效
271 bool isParasiteShareAxis(QwtAxisId axisId) const;
272 // Remove a parasite plot from this host plot/从此宿主绘图移除寄生绘图
273 void removeParasitePlot(QwtPlot* parasite);
274
275 // Get all parasite plots associated with this host plot/获取与此宿主绘图关联的所有寄生绘图
276 QList< QwtPlot* > parasitePlots() const;
277 // 返回所有绘图,包含宿主绘图,descending=false,增序返回,宿主绘图在第一个,层级越低越靠前,如果descending=true,那么降序返回,宿主在最末端
278 QList< QwtPlot* > plotList(bool descending = false) const;
279 // 获取第n个宿主轴
280 QwtPlot* parasitePlotAt(int index) const;
281
282 // 寄生轴的索引(层级),所谓寄生轴层级,默认是寄生轴的添加顺序,第一个添加的寄生轴为0层,第二个添加的寄生轴为1层,寄生轴层级越高,轴越靠绘图的边界
283 int parasitePlotIndex(QwtPlot* parasite) const;
284
285 // Get the host plot for this parasite plot/获取此寄生绘图的宿主绘图
286 QwtPlot* hostPlot() const;
287
288 // Check if this plot is a parasite plot/检查此绘图是否为寄生绘图
289 bool isParasitePlot() const;
290 // 是否是最顶部的宿主绘图,最顶部的宿主绘图坐标轴处于最外围,且一般是最后进行更新
291 bool isTopParasitePlot() const;
292
293 // Check if this plot is a host plot/检查此绘图是否为宿主绘图
294 bool isHostPlot() const;
295
296 // set Background Color/设置背景颜色
297 void setBackgroundColor(const QColor& c);
298 QColor backgroundColor() const;
299
300 // Synchronize the axis ranges of the corresponding plot/同步plot对应的坐标轴范围
301 void syncAxis(QwtAxisId axis, const QwtPlot* plot);
302 // Rescale the axes to encompass the full range of all data items./重新缩放坐标轴以适应所有数据项的范围
303 void rescaleAxes(bool onlyVisibleItems = true,
304 double marginPercent = 0.05,
305 QwtAxisId xAxis = QwtPlot::xBottom,
306 QwtAxisId yAxis = QwtPlot::yLeft);
307
308 // Set the specified axis to logarithmic scale / 将指定坐标轴设置为对数刻度
309 void setAxisToLogScale(QwtAxisId axisId);
310
311 // Set the specified axis to date-time scale / 将指定坐标轴设置为日期-时间刻度
312 void setAxisToDateTime(QwtAxisId axisId, Qt::TimeSpec timeSpec = Qt::LocalTime);
313
314 // Restore the specified axis to linear scale / 将指定坐标轴恢复为线性刻度
315 void setAxisToLinearScale(QwtAxisId axisId);
316
317 // 让寄生轴和宿主轴对齐
318 void alignToHost();
319
320 // 获取宿主轴的个数
321 int parasitePlotCount() const;
322
323 // 更新宿主轴和寄生轴的偏移
324 void updateAxisEdgeMargin(QwtAxisId axisId);
325 // 更新寄生轴的坐标
326 void updateAllAxisEdgeMargin();
327 // 更新绘图上的items,让其适配scaleDiv的范围
328 void updateItemsToScaleDiv();
329 // 坐标轴事件使能
330 void setEnableScaleBuildinActions(bool on);
331 bool isEnableScaleBuildinActions() const;
332 // 设置坐标轴事件转发器,这个是实现坐标轴事件的主要管理类
333 void setupScaleEventDispatcher(QwtPlotScaleEventDispatcher* dispatcher);
334 // 保存/恢复当前自动绘图设置的状态
335 void saveAutoReplotState();
336 void restoreAutoReplotState();
337 // 按像素平移指定坐标轴,注意,需要手动replot
338 void panAxis(QwtAxisId axisId, int deltaPixels);
339 // 移动canvas,移动canvas会导致所有轴都进行偏移,注意,需要手动replot
340 void panCanvas(const QPoint& offset);
341 // 对坐标轴进行缩放,注意,需要手动replot
342 void zoomAxis(QwtAxisId axisId, double factor, const QPoint& centerPosPixels);
343#if QWT_AXIS_COMPAT
344 enum Axis
345 {
346 yLeft = QwtAxis::YLeft,
347 yRight = QwtAxis::YRight,
348 xBottom = QwtAxis::XBottom,
349 xTop = QwtAxis::XTop,
350
351 axisCnt = QwtAxis::AxisPositions
352 };
353
354 void enableAxis(int axisId, bool on = true)
355 {
356 setAxisVisible(axisId, on);
357 }
358
359 bool axisEnabled(int axisId) const
360 {
361 return isAxisVisible(axisId);
362 }
363#endif
364
365Q_SIGNALS:
372 void itemAttached(QwtPlotItem* plotItem, bool on);
373
384 void legendDataChanged(const QVariant& itemInfo, const QList< QwtLegendData >& data);
385
391 void parasitePlotAttached(QwtPlot* parasitePlot, bool on);
392public Q_SLOTS:
393 virtual void replot();
394 void autoRefresh();
395 // 重绘所有绘图,包括寄生绘图或者宿主绘图
396 virtual void replotAll();
397 void autoRefreshAll();
398
399protected:
400 virtual void resizeEvent(QResizeEvent*) QWT_OVERRIDE;
401 // Add a parasite plot to this host plot/向此宿主绘图添加寄生绘图
402 void addParasitePlot(QwtPlot* parasite);
403 // 初始化寄生轴的基本属性
404 void initParasiteAxes(QwtPlot* parasitePlot) const;
405 // updateLayout的具体实现
406 void doLayout();
407private Q_SLOTS:
408 void updateLegendItems(const QVariant& itemInfo, const QList< QwtLegendData >& legendData);
409 void yLeftRequestScaleRangeUpdate(double min, double max);
410 void yRightRequestScaleRangeUpdate(double min, double max);
411 void xBottomRequestScaleRangeUpdate(double min, double max);
412 void xTopRequestScaleRangeUpdate(double min, double max);
413
414private:
415 friend class QwtPlotItem;
416 void attachItem(QwtPlotItem*, bool);
417
418 void initAxesData();
419 void deleteAxesData();
420
421 void initPlot(const QwtText& title);
422 // 最顶部的寄生绘图对宿主绘图调用updateAllAxisEdgeMargin
423 void topParasiteTriggerHostUpdateAxisMargins();
424
425 class ScaleData;
426 ScaleData* m_scaleData;
427};
428
429#endif
Definition qwt_dyngrid_layout.h:33
Abstract base class for legend widgets.
Definition qwt_abstract_legend.h:50
A class representing an interval.
Definition qwt_interval.h:40
A dictionary for plot items.
Definition qwt_plot_dict.h:50
Base class for items on the plot canvas.
Definition qwt_plot_item.h:85
Layout engine for QwtPlot.
Definition qwt_plot_layout.h:45
针对寄生绘图的事件过滤器,主要处理坐标轴动作
Definition qwt_plot_scale_event_dispatcher.h:24
Definition qwt_plot_axis.cpp:99
A 2-D plotting widget.
Definition qwt_plot.h:99
void itemAttached(QwtPlotItem *plotItem, bool on)
A signal indicating, that an item has been attached/detached.
LegendPosition
Position of the legend, relative to the canvas.
Definition qwt_plot.h:114
@ LeftLegend
The legend will be left from the QwtAxis::YLeft axis.
Definition qwt_plot.h:116
@ RightLegend
The legend will be right from the QwtAxis::YRight axis.
Definition qwt_plot.h:119
@ BottomLegend
The legend will be below the footer.
Definition qwt_plot.h:122
void parasitePlotAttached(QwtPlot *parasitePlot, bool on)
Identify the relationship between the parasitic plot and its host plot.
void legendDataChanged(const QVariant &itemInfo, const QList< QwtLegendData > &data)
A signal with the attributes how to update the legend entries for a plot item.
A class representing a scale division/表示刻度划分的类
Definition qwt_scale_div.h:53
A class for drawing scales.
Definition qwt_scale_draw.h:53
Base class for scale engines./刻度引擎的基类
Definition qwt_scale_engine.h:67
A scale map.
Definition qwt_scale_map.h:44
A Widget which contains a scale.
Definition qwt_scale_widget.h:74
A Widget which displays a QwtText.
Definition qwt_text_label.h:44
A class representing a text.
Definition qwt_text.h:69
Enums and methods for axes.
Definition qwt_axis.h:36
@ YRight
Y axis right of the canvas.
Definition qwt_axis.h:44
@ XTop
X axis above the canvas.
Definition qwt_axis.h:50
@ XBottom
X axis below the canvas.
Definition qwt_axis.h:47
@ YLeft
Y axis left of the canvas.
Definition qwt_axis.h:41