QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
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;
47class QwtColorCycle;
48
49template< typename T >
50class QList;
51
52// 6.1 compatibility definitions
53#define QWT_AXIS_COMPAT 1
54
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)
107
108 friend class QwtFigure;
109
110public:
116 {
118 LeftLegend,
119
121 RightLegend,
122
124 BottomLegend,
125
127 TopLegend
128 };
129
137 {
139 TickOutside = 0,
140
142 TickInside = 1
143 };
144
145 // Constructor
146 explicit QwtPlot(QWidget* = nullptr);
147 // Constructor with title
148 explicit QwtPlot(const QwtText& title, QWidget* = nullptr);
149
150 // Destructor
151 ~QwtPlot() override;
152
153 // Set auto replot
154 void setAutoReplot(bool = true);
155 // Check if auto replot is enabled
156 bool autoReplot() const;
157
158 // plot id
159 // Get plot id
160 QString plotId() const;
161 // Set plot id
162 void setPlotId(const QString& id);
163 // Layout
164
165 // Set plot layout
166 void setPlotLayout(QwtPlotLayout*);
167
168 // Get plot layout
169 QwtPlotLayout* plotLayout();
170 // Get plot layout (const)
171 const QwtPlotLayout* plotLayout() const;
172
173 // Title
174
175 // Set title from string
176 void setTitle(const QString&);
177 // Set title from QwtText
178 void setTitle(const QwtText&);
179 // Get title
180 QwtText title() const;
181
182 // Get title label
183 QwtTextLabel* titleLabel();
184 // Get title label (const)
185 const QwtTextLabel* titleLabel() const;
186
187 // Footer
188
189 // Set footer from string
190 void setFooter(const QString&);
191 // Set footer from QwtText
192 void setFooter(const QwtText&);
193 // Get footer
194 QwtText footer() const;
195
196 // Get footer label
197 QwtTextLabel* footerLabel();
198 // Get footer label (const)
199 const QwtTextLabel* footerLabel() const;
200
201 // Canvas
202
203 // Set canvas
204 void setCanvas(QWidget*);
205
206 // Get canvas
207 QWidget* canvas();
208 // Get canvas (const)
209 const QWidget* canvas() const;
210
211 // Set canvas background
212 void setCanvasBackground(const QBrush&);
213 // Get canvas background
214 QBrush canvasBackground() const;
215
216 // Color cycle
217
218 // Set color cycle for automatic item coloring
219 void setColorCycle(const QwtColorCycle&);
220 // Get the current color cycle
221 QwtColorCycle colorCycle() const;
222 // Get the next auto-assigned color for a plot item type
223 QColor nextColorForItem(int rtti);
224
225 // Get canvas map for axis
226 virtual QwtScaleMap canvasMap(QwtAxisId) const;
227
228 // Inverse transform from pixel position to value
229 double invTransform(QwtAxisId, double pos) const;
230 // Transform from value to pixel position
231 double transform(QwtAxisId, double value) const;
232
233 // Axes
234
235 // Check if axis is valid
236 bool isAxisValid(QwtAxisId) const;
237
238 // Set axis visible
239 void setAxisVisible(QwtAxisId, bool on = true);
240 // Check if axis is visible
241 bool isAxisVisible(QwtAxisId) const;
242
243 // Axes data
244
245 // Get axis scale engine
246 QwtScaleEngine* axisScaleEngine(QwtAxisId);
247 // Get axis scale engine (const)
248 const QwtScaleEngine* axisScaleEngine(QwtAxisId) const;
249 // Set axis scale engine
250 void setAxisScaleEngine(QwtAxisId, QwtScaleEngine*);
251
252 // Set axis auto scale
253 void setAxisAutoScale(QwtAxisId, bool on = true);
254 // Check if axis auto scale is enabled
255 bool axisAutoScale(QwtAxisId) const;
256
257 // Set axis font
258 void setAxisFont(QwtAxisId, const QFont&);
259 // Get axis font
260 QFont axisFont(QwtAxisId) const;
261
262 // Set axis scale
263 void setAxisScale(QwtAxisId, double min, double max, double stepSize = 0);
264 // Set axis scale division
265 void setAxisScaleDiv(QwtAxisId, const QwtScaleDiv&);
266 // Set axis scale draw
267 void setAxisScaleDraw(QwtAxisId, QwtScaleDraw*);
268
269 // Get axis step size
270 double axisStepSize(QwtAxisId) const;
271 // Get axis interval
272 QwtInterval axisInterval(QwtAxisId) const;
273 // Get axis scale division
274 const QwtScaleDiv& axisScaleDiv(QwtAxisId) const;
275
276 // Get axis scale draw (const)
277 const QwtScaleDraw* axisScaleDraw(QwtAxisId) const;
278 // Get axis scale draw
279 QwtScaleDraw* axisScaleDraw(QwtAxisId);
280
281 // Get axis widget (const)
282 const QwtScaleWidget* axisWidget(QwtAxisId) const;
283 // Get axis widget
284 QwtScaleWidget* axisWidget(QwtAxisId);
285
286 // Return the currently visible X/Y axis,XBottom/YLeft first
287 // Get visible X axis id
288 QwtAxisId visibleXAxisId() const;
289 // Get visible Y axis id
290 QwtAxisId visibleYAxisId() const;
291
292 // Set axis label alignment
293 void setAxisLabelAlignment(QwtAxisId, Qt::Alignment);
294 // Set axis label rotation
295 void setAxisLabelRotation(QwtAxisId, double rotation);
296
297 // Set axis title from string
298 void setAxisTitle(QwtAxisId, const QString&);
299 // Set axis title from QwtText
300 void setAxisTitle(QwtAxisId, const QwtText&);
301 // Get axis title
302 QwtText axisTitle(QwtAxisId) const;
303
304 // Set axis max minor ticks
305 void setAxisMaxMinor(QwtAxisId, int maxMinor);
306 // Get axis max minor ticks
307 int axisMaxMinor(QwtAxisId) const;
308
309 // Set axis max major ticks
310 void setAxisMaxMajor(QwtAxisId, int maxMajor);
311 // Get axis max major ticks
312 int axisMaxMajor(QwtAxisId) const;
313
314 // Tick Direction - NEW
315
316 // Set tick direction for an axis
317 void setAxisTickDirection(QwtAxisId axisId, TickDirection direction);
318
319 // Get tick direction for an axis
320 TickDirection axisTickDirection(QwtAxisId axisId) const;
321
322 // Legend
323
324 // Insert legend
325 void insertLegend(QwtAbstractLegend*, LegendPosition = QwtPlot::RightLegend, double ratio = -1.0);
326
327 // Get legend
328 QwtAbstractLegend* legend();
329 // Get legend (const)
330 const QwtAbstractLegend* legend() const;
331
332 // Update legend
333 void updateLegend();
334 // Update legend for specific item
335 void updateLegend(const QwtPlotItem*);
336
337 // Misc
338
339 // Get size hint
340 virtual QSize sizeHint() const override;
341 // Get minimum size hint
342 virtual QSize minimumSizeHint() const override;
343
344 // Update layout
345 virtual void updateLayout();
346 // Draw canvas
347 virtual void drawCanvas(QPainter*);
348
349 // Update axes
350 void updateAxes();
351 // Update canvas margins
352 void updateCanvasMargins();
353
354 // Get canvas margins hint
355 virtual void getCanvasMarginsHint(const QwtScaleMap maps[],
356 const QRectF& canvasRect,
357 double& left,
358 double& top,
359 double& right,
360 double& bottom) const;
361
362 // Handle events
363 virtual bool event(QEvent*) override;
364 // Event filter
365 virtual bool eventFilter(QObject*, QEvent*) override;
366
367 // Draw items
368 virtual void drawItems(QPainter*, const QRectF&, const QwtScaleMap maps[ QwtAxis::AxisPositions ]) const;
369
370 // Convert item to info
371 virtual QVariant itemToInfo(QwtPlotItem*) const;
372 // Convert info to item
373 virtual QwtPlotItem* infoToItem(const QVariant&) const;
374
375 // add since v7.1.0
376
377 // Create a parasite plot based on this axis as host
378 QwtPlot* createParasitePlot(QwtAxis::Position enableAxis);
379
380 // Set which axes of the host the parasite shares, only valid for parasite plots
381 void setParasiteShareAxis(QwtAxisId axisId, bool isShare = true);
382
383 // Get which axes of the host the parasite shares, only valid for parasite plots
384 bool isParasiteShareAxis(QwtAxisId axisId) const;
385 // Remove a parasite plot from this host plot
386 void removeParasitePlot(QwtPlot* parasite);
387
388 // Get all parasite plots associated with this host plot
389 QList< QwtPlot* > parasitePlots() const;
390 // Return all plots, including host plot, ascending order by default
391 QList< QwtPlot* > plotList(bool descending = false) const;
392 // Get the nth parasite plot
393 QwtPlot* parasitePlotAt(int index) const;
394
395 // Get parasite plot index (level), higher level means closer to plot boundary
396 int parasitePlotIndex(QwtPlot* parasite) const;
397
398 // Get the host plot for this parasite plot
399 QwtPlot* hostPlot() const;
400
401 // Check if this plot is a parasite plot
402 bool isParasitePlot() const;
403 // Check if this plot is the top parasite plot
404 bool isTopParasitePlot() const;
405
406 // Check if this plot is a host plot
407 bool isHostPlot() const;
408
409 // Set background color
410 void setBackgroundColor(const QColor& c);
411 // Get background color
412 QColor backgroundColor() const;
413
414 // Synchronize the axis ranges of the corresponding plot
415 void syncAxis(QwtAxisId axis, const QwtPlot* plot);
416 // Rescale the axes to encompass the full range of all data items
417 void rescaleAxes(bool onlyVisibleItems = true,
418 double marginPercent = 0.05,
419 QwtAxisId xAxis = QwtPlot::xBottom,
420 QwtAxisId yAxis = QwtPlot::yLeft);
421
422 // Set the specified axis to logarithmic scale
423 void setAxisToLogScale(QwtAxisId axisId);
424
425 // Set the specified axis to date-time scale
426 void setAxisToDateTime(QwtAxisId axisId, Qt::TimeSpec timeSpec = Qt::LocalTime);
427
428 // Restore the specified axis to linear scale
429 void setAxisToLinearScale(QwtAxisId axisId);
430
431 // Align parasite plot to host plot
432 void alignToHost();
433
434 // Get the number of parasite plots
435 int parasitePlotCount() const;
436
437 // Update axis edge margin
438 void updateAxisEdgeMargin(QwtAxisId axisId);
439 // Update all axis edge margins
440 void updateAllAxisEdgeMargin();
441 // Update items to fit scale division range
442 void updateItemsToScaleDiv();
443 // Enable/disable scale built-in actions
444 void setEnableScaleBuildinActions(bool on);
445 // Check if scale built-in actions are enabled
446 bool isEnableScaleBuildinActions() const;
447 // Set scale event dispatcher
448 void setupScaleEventDispatcher(QwtPlotScaleEventDispatcher* dispatcher);
449 // Save current auto replot state
450 void saveAutoReplotState();
451 // Restore auto replot state
452 void restoreAutoReplotState();
453 // Pan axis by pixels
454 void panAxis(QwtAxisId axisId, int deltaPixels);
455 // Pan canvas
456 void panCanvas(const QPoint& offset);
457 // Zoom axis
458 void zoomAxis(QwtAxisId axisId, double factor, const QPoint& centerPosPixels);
459#if QWT_AXIS_COMPAT
460 enum Axis
461 {
462 yLeft = QwtAxis::YLeft,
463 yRight = QwtAxis::YRight,
464 xBottom = QwtAxis::XBottom,
465 xTop = QwtAxis::XTop,
466
467 axisCnt = QwtAxis::AxisPositions
468 };
469
470 void enableAxis(int axisId, bool on = true)
471 {
472 setAxisVisible(axisId, on);
473 }
474
475 bool axisEnabled(int axisId) const
476 {
477 return isAxisVisible(axisId);
478 }
479#endif
480
481Q_SIGNALS:
487 void itemAttached(QwtPlotItem* plotItem, bool on);
488
497 void legendDataChanged(const QVariant& itemInfo, const QList< QwtLegendData >& data);
498
505 void parasitePlotAttached(QwtPlot* parasitePlot, bool on);
506public Q_SLOTS:
507 // Replot the plot
508 virtual void replot();
509 // Auto refresh
510 void autoRefresh();
511 // Replot all plots, including parasite or host plots
512 virtual void replotAll();
513 // Auto refresh all plots
514 void autoRefreshAll();
515
516protected:
517 // Handle resize event
518 virtual void resizeEvent(QResizeEvent*) override;
519 // Add a parasite plot to this host plot
520 void addParasitePlot(QwtPlot* parasite);
521 // Initialize parasite axes basic attributes
522 void initParasiteAxes(QwtPlot* parasitePlot) const;
523 // Implementation of updateLayout
524 void doLayout();
525
526 // NEW: Draw inside ticks for axes with TickInside direction
527 void drawInsideTicks(QPainter*, const QRectF& canvasRect, const QwtScaleMap maps[ QwtAxis::AxisPositions ]) const;
528
529private Q_SLOTS:
530 // Update legend items
531 void updateLegendItems(const QVariant& itemInfo, const QList< QwtLegendData >& legendData);
532 // Handle yLeft scale range update request
533 void yLeftRequestScaleRangeUpdate(double min, double max);
534 // Handle yRight scale range update request
535 void yRightRequestScaleRangeUpdate(double min, double max);
536 // Handle xBottom scale range update request
537 void xBottomRequestScaleRangeUpdate(double min, double max);
538 // Handle xTop scale range update request
539 void xTopRequestScaleRangeUpdate(double min, double max);
540
541private:
542 friend class QwtPlotItem;
543 // Attach/detach item
544 void attachItem(QwtPlotItem*, bool);
545
546 // Initialize axes data
547 void initAxesData();
548 // Delete axes data
549 void deleteAxesData();
550
551 // Initialize plot
552 void initPlot(const QwtText& title);
553 // Top parasite plot triggers host to update all axis margins
554 void topParasiteTriggerHostUpdateAxisMargins();
555
556 // Helper: Draw a single inside tick
557 void drawSingleInsideTick(QPainter* painter, double tickPixelPos, double tickLength, double backbonePos, int axisPos) const;
558
559 class ScaleData;
560 ScaleData* m_scaleData;
561};
562
563#endif
Definition qwt_raster_data.h:38
Abstract base class for legend widgets
Definition qwt_abstract_legend.h:47
Provides cyclic color selection from predefined palettes.
Definition qwt_color_cycle.h:46
A figure container for organizing Qwt plots with flexible layout options
Definition qwt_figure.h:47
A class representing an interval
Definition qwt_interval.h:39
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:43
Event filter for parasitic plots, handling axis interactions
Definition qwt_plot_scale_event_dispatcher.h:23
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:116
@ RightLegend
The legend will be below the footer
Definition qwt_plot.h:121
TickDirection
Tick direction enum
Definition qwt_plot.h:137
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:47
A class for drawing scales
Definition qwt_scale_draw.h:52
Base class for scale engines
Definition qwt_scale_engine.h:62
A scale map
Definition qwt_scale_map.h:44
A Widget which contains a scale
Definition qwt_scale_widget.h:73
A Widget which displays a QwtText
Definition qwt_text_label.h:47
A class representing a text
Definition qwt_text.h:70
Position
Axis position
Definition qwt_axis.h:43
@ YRight
Y axis right of the canvas
Definition qwt_axis.h:48
@ XTop
X axis above the canvas
Definition qwt_axis.h:54
@ XBottom
X axis below the canvas
Definition qwt_axis.h:51
@ YLeft
Y axis left of the canvas
Definition qwt_axis.h:45