QWT API (中文) 7.0.1
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;
47
48template< typename T >
49class QList;
50
51// 6.1 compatibility definitions
52#define QWT_AXIS_COMPAT 1
53
137class QWT_EXPORT QwtPlot : public QFrame, public QwtPlotDict
138{
139 Q_OBJECT
140
141 Q_PROPERTY(QBrush canvasBackground READ canvasBackground WRITE setCanvasBackground)
142
143 Q_PROPERTY(bool autoReplot READ autoReplot WRITE setAutoReplot)
144
145 QWT_DECLARE_PRIVATE(QwtPlot)
146
147 friend class QwtFigure;
148
149public:
162 {
164 LeftLegend,
165
167 RightLegend,
168
170 BottomLegend,
171
173 TopLegend
174 };
175
192 {
195 TickOutside = 0,
196
199 TickInside = 1
200 };
201
202 // Constructor
203 explicit QwtPlot(QWidget* = nullptr);
204 // Constructor with title
205 explicit QwtPlot(const QwtText& title, QWidget* = nullptr);
206
207 // Destructor
208 virtual ~QwtPlot();
209
210 // Set auto replot
211 void setAutoReplot(bool = true);
212 // Check if auto replot is enabled
213 bool autoReplot() const;
214
215 // plot id
216 // Get plot id
217 QString plotId() const;
218 // Set plot id
219 void setPlotId(const QString& id);
220 // Layout
221
222 // Set plot layout
223 void setPlotLayout(QwtPlotLayout*);
224
225 // Get plot layout
226 QwtPlotLayout* plotLayout();
227 // Get plot layout (const)
228 const QwtPlotLayout* plotLayout() const;
229
230 // Title
231
232 // Set title from string
233 void setTitle(const QString&);
234 // Set title from QwtText
235 void setTitle(const QwtText&);
236 // Get title
237 QwtText title() const;
238
239 // Get title label
240 QwtTextLabel* titleLabel();
241 // Get title label (const)
242 const QwtTextLabel* titleLabel() const;
243
244 // Footer
245
246 // Set footer from string
247 void setFooter(const QString&);
248 // Set footer from QwtText
249 void setFooter(const QwtText&);
250 // Get footer
251 QwtText footer() const;
252
253 // Get footer label
254 QwtTextLabel* footerLabel();
255 // Get footer label (const)
256 const QwtTextLabel* footerLabel() const;
257
258 // Canvas
259
260 // Set canvas
261 void setCanvas(QWidget*);
262
263 // Get canvas
264 QWidget* canvas();
265 // Get canvas (const)
266 const QWidget* canvas() const;
267
268 // Set canvas background
269 void setCanvasBackground(const QBrush&);
270 // Get canvas background
271 QBrush canvasBackground() const;
272
273 // Get canvas map for axis
274 virtual QwtScaleMap canvasMap(QwtAxisId) const;
275
276 // Inverse transform from pixel position to value
277 double invTransform(QwtAxisId, double pos) const;
278 // Transform from value to pixel position
279 double transform(QwtAxisId, double value) const;
280
281 // Axes
282
283 // Check if axis is valid
284 bool isAxisValid(QwtAxisId) const;
285
286 // Set axis visible
287 void setAxisVisible(QwtAxisId, bool on = true);
288 // Check if axis is visible
289 bool isAxisVisible(QwtAxisId) const;
290
291 // Axes data
292
293 // Get axis scale engine
294 QwtScaleEngine* axisScaleEngine(QwtAxisId);
295 // Get axis scale engine (const)
296 const QwtScaleEngine* axisScaleEngine(QwtAxisId) const;
297 // Set axis scale engine
298 void setAxisScaleEngine(QwtAxisId, QwtScaleEngine*);
299
300 // Set axis auto scale
301 void setAxisAutoScale(QwtAxisId, bool on = true);
302 // Check if axis auto scale is enabled
303 bool axisAutoScale(QwtAxisId) const;
304
305 // Set axis font
306 void setAxisFont(QwtAxisId, const QFont&);
307 // Get axis font
308 QFont axisFont(QwtAxisId) const;
309
310 // Set axis scale
311 void setAxisScale(QwtAxisId, double min, double max, double stepSize = 0);
312 // Set axis scale division
313 void setAxisScaleDiv(QwtAxisId, const QwtScaleDiv&);
314 // Set axis scale draw
315 void setAxisScaleDraw(QwtAxisId, QwtScaleDraw*);
316
317 // Get axis step size
318 double axisStepSize(QwtAxisId) const;
319 // Get axis interval
320 QwtInterval axisInterval(QwtAxisId) const;
321 // Get axis scale division
322 const QwtScaleDiv& axisScaleDiv(QwtAxisId) const;
323
324 // Get axis scale draw (const)
325 const QwtScaleDraw* axisScaleDraw(QwtAxisId) const;
326 // Get axis scale draw
327 QwtScaleDraw* axisScaleDraw(QwtAxisId);
328
329 // Get axis widget (const)
330 const QwtScaleWidget* axisWidget(QwtAxisId) const;
331 // Get axis widget
332 QwtScaleWidget* axisWidget(QwtAxisId);
333
334 // Return the currently visible X/Y axis,XBottom/YLeft first
335 // Get visible X axis id
336 QwtAxisId visibleXAxisId() const;
337 // Get visible Y axis id
338 QwtAxisId visibleYAxisId() const;
339
340 // Set axis label alignment
341 void setAxisLabelAlignment(QwtAxisId, Qt::Alignment);
342 // Set axis label rotation
343 void setAxisLabelRotation(QwtAxisId, double rotation);
344
345 // Set axis title from string
346 void setAxisTitle(QwtAxisId, const QString&);
347 // Set axis title from QwtText
348 void setAxisTitle(QwtAxisId, const QwtText&);
349 // Get axis title
350 QwtText axisTitle(QwtAxisId) const;
351
352 // Set axis max minor ticks
353 void setAxisMaxMinor(QwtAxisId, int maxMinor);
354 // Get axis max minor ticks
355 int axisMaxMinor(QwtAxisId) const;
356
357 // Set axis max major ticks
358 void setAxisMaxMajor(QwtAxisId, int maxMajor);
359 // Get axis max major ticks
360 int axisMaxMajor(QwtAxisId) const;
361
362 // Tick Direction - NEW
363
386 void setAxisTickDirection(QwtAxisId axisId, TickDirection direction);
387
401 TickDirection axisTickDirection(QwtAxisId axisId) const;
402
403 // Legend
404
405 // Insert legend
406 void insertLegend(QwtAbstractLegend*, LegendPosition = QwtPlot::RightLegend, double ratio = -1.0);
407
408 // Get legend
409 QwtAbstractLegend* legend();
410 // Get legend (const)
411 const QwtAbstractLegend* legend() const;
412
413 // Update legend
414 void updateLegend();
415 // Update legend for specific item
416 void updateLegend(const QwtPlotItem*);
417
418 // Misc
419
420 // Get size hint
421 virtual QSize sizeHint() const override;
422 // Get minimum size hint
423 virtual QSize minimumSizeHint() const override;
424
425 // Update layout
426 virtual void updateLayout();
427 // Draw canvas
428 virtual void drawCanvas(QPainter*);
429
430 // Update axes
431 void updateAxes();
432 // Update canvas margins
433 void updateCanvasMargins();
434
435 // Get canvas margins hint
436 virtual void getCanvasMarginsHint(const QwtScaleMap maps[],
437 const QRectF& canvasRect,
438 double& left,
439 double& top,
440 double& right,
441 double& bottom) const;
442
443 // Handle events
444 virtual bool event(QEvent*) override;
445 // Event filter
446 virtual bool eventFilter(QObject*, QEvent*) override;
447
448 // Draw items
449 virtual void drawItems(QPainter*, const QRectF&, const QwtScaleMap maps[ QwtAxis::AxisPositions ]) const;
450
451 // Convert item to info
452 virtual QVariant itemToInfo(QwtPlotItem*) const;
453 // Convert info to item
454 virtual QwtPlotItem* infoToItem(const QVariant&) const;
455
456 // add since v7.1.0
457
458 // Create a parasite plot based on this axis as host
459 QwtPlot* createParasitePlot(QwtAxis::Position enableAxis);
460
461 // Set which axes of the host the parasite shares, only valid for parasite plots
462 void setParasiteShareAxis(QwtAxisId axisId, bool isShare = true);
463
464 // Get which axes of the host the parasite shares, only valid for parasite plots
465 bool isParasiteShareAxis(QwtAxisId axisId) const;
466 // Remove a parasite plot from this host plot
467 void removeParasitePlot(QwtPlot* parasite);
468
469 // Get all parasite plots associated with this host plot
470 QList< QwtPlot* > parasitePlots() const;
471 // Return all plots, including host plot, ascending order by default
472 QList< QwtPlot* > plotList(bool descending = false) const;
473 // Get the nth parasite plot
474 QwtPlot* parasitePlotAt(int index) const;
475
476 // Get parasite plot index (level), higher level means closer to plot boundary
477 int parasitePlotIndex(QwtPlot* parasite) const;
478
479 // Get the host plot for this parasite plot
480 QwtPlot* hostPlot() const;
481
482 // Check if this plot is a parasite plot
483 bool isParasitePlot() const;
484 // Check if this plot is the top parasite plot
485 bool isTopParasitePlot() const;
486
487 // Check if this plot is a host plot
488 bool isHostPlot() const;
489
490 // Set background color
491 void setBackgroundColor(const QColor& c);
492 // Get background color
493 QColor backgroundColor() const;
494
495 // Synchronize the axis ranges of the corresponding plot
496 void syncAxis(QwtAxisId axis, const QwtPlot* plot);
497 // Rescale the axes to encompass the full range of all data items
498 void rescaleAxes(bool onlyVisibleItems = true,
499 double marginPercent = 0.05,
500 QwtAxisId xAxis = QwtPlot::xBottom,
501 QwtAxisId yAxis = QwtPlot::yLeft);
502
503 // Set the specified axis to logarithmic scale
504 void setAxisToLogScale(QwtAxisId axisId);
505
506 // Set the specified axis to date-time scale
507 void setAxisToDateTime(QwtAxisId axisId, Qt::TimeSpec timeSpec = Qt::LocalTime);
508
509 // Restore the specified axis to linear scale
510 void setAxisToLinearScale(QwtAxisId axisId);
511
512 // Align parasite plot to host plot
513 void alignToHost();
514
515 // Get the number of parasite plots
516 int parasitePlotCount() const;
517
518 // Update axis edge margin
519 void updateAxisEdgeMargin(QwtAxisId axisId);
520 // Update all axis edge margins
521 void updateAllAxisEdgeMargin();
522 // Update items to fit scale division range
523 void updateItemsToScaleDiv();
524 // Enable/disable scale built-in actions
525 void setEnableScaleBuildinActions(bool on);
526 // Check if scale built-in actions are enabled
527 bool isEnableScaleBuildinActions() const;
528 // Set scale event dispatcher
529 void setupScaleEventDispatcher(QwtPlotScaleEventDispatcher* dispatcher);
530 // Save current auto replot state
531 void saveAutoReplotState();
532 // Restore auto replot state
533 void restoreAutoReplotState();
534 // Pan axis by pixels
535 void panAxis(QwtAxisId axisId, int deltaPixels);
536 // Pan canvas
537 void panCanvas(const QPoint& offset);
538 // Zoom axis
539 void zoomAxis(QwtAxisId axisId, double factor, const QPoint& centerPosPixels);
540#if QWT_AXIS_COMPAT
541 enum Axis
542 {
543 yLeft = QwtAxis::YLeft,
544 yRight = QwtAxis::YRight,
545 xBottom = QwtAxis::XBottom,
546 xTop = QwtAxis::XTop,
547
548 axisCnt = QwtAxis::AxisPositions
549 };
550
551 void enableAxis(int axisId, bool on = true)
552 {
553 setAxisVisible(axisId, on);
554 }
555
556 bool axisEnabled(int axisId) const
557 {
558 return isAxisVisible(axisId);
559 }
560#endif
561
562Q_SIGNALS:
576 void itemAttached(QwtPlotItem* plotItem, bool on);
577
595 void legendDataChanged(const QVariant& itemInfo, const QList< QwtLegendData >& data);
596
612 void parasitePlotAttached(QwtPlot* parasitePlot, bool on);
613public Q_SLOTS:
614 // Replot the plot
615 virtual void replot();
616 // Auto refresh
617 void autoRefresh();
618 // Replot all plots, including parasite or host plots
619 virtual void replotAll();
620 // Auto refresh all plots
621 void autoRefreshAll();
622
623protected:
624 // Handle resize event
625 virtual void resizeEvent(QResizeEvent*) override;
626 // Add a parasite plot to this host plot
627 void addParasitePlot(QwtPlot* parasite);
628 // Initialize parasite axes basic attributes
629 void initParasiteAxes(QwtPlot* parasitePlot) const;
630 // Implementation of updateLayout
631 void doLayout();
632
633 // NEW: Draw inside ticks for axes with TickInside direction
634 void drawInsideTicks(QPainter*, const QRectF& canvasRect,
635 const QwtScaleMap maps[QwtAxis::AxisPositions]) const;
636
637private Q_SLOTS:
638 // Update legend items
639 void updateLegendItems(const QVariant& itemInfo, const QList< QwtLegendData >& legendData);
640 // Handle yLeft scale range update request
641 void yLeftRequestScaleRangeUpdate(double min, double max);
642 // Handle yRight scale range update request
643 void yRightRequestScaleRangeUpdate(double min, double max);
644 // Handle xBottom scale range update request
645 void xBottomRequestScaleRangeUpdate(double min, double max);
646 // Handle xTop scale range update request
647 void xTopRequestScaleRangeUpdate(double min, double max);
648
649private:
650 friend class QwtPlotItem;
651 // Attach/detach item
652 void attachItem(QwtPlotItem*, bool);
653
654 // Initialize axes data
655 void initAxesData();
656 // Delete axes data
657 void deleteAxesData();
658
659 // Initialize plot
660 void initPlot(const QwtText& title);
661 // Top parasite plot triggers host to update all axis margins
662 void topParasiteTriggerHostUpdateAxisMargins();
663
664 // Helper: Draw a single inside tick
665 void drawSingleInsideTick(QPainter* painter,
666 double tickPixelPos,
667 double tickLength,
668 double backbonePos,
669 int axisPos) const;
670
671 class ScaleData;
672 ScaleData* m_scaleData;
673};
674
675#endif
Definition qwt_dyngrid_layout.h:33
图例控件的抽象基类
Definition qwt_abstract_legend.h:57
用于组织Qwt绘图的图形容器,提供灵活的布局选项
Definition qwt_figure.h:77
表示区间的类
Definition qwt_interval.h:45
绘图项的字典
Definition qwt_plot_dict.h:62
绘图画布上项目的基类
Definition qwt_plot_item.h:119
QwtPlot 的布局引擎
Definition qwt_plot_layout.h:53
针对寄生绘图的事件过滤器,主要处理坐标轴动作
Definition qwt_plot_scale_event_dispatcher.h:34
Definition qwt_plot_axis.cpp:99
二维绘图部件
Definition qwt_plot.h:138
void itemAttached(QwtPlotItem *plotItem, bool on)
LegendPosition
图例相对于画布的位置
Definition qwt_plot.h:162
@ RightLegend
The legend will be below the footer
Definition qwt_plot.h:167
TickDirection
刻度方向枚举
Definition qwt_plot.h:192
void parasitePlotAttached(QwtPlot *parasitePlot, bool on)
void legendDataChanged(const QVariant &itemInfo, const QList< QwtLegendData > &data)
A class representing a scale division/表示刻度划分的类
Definition qwt_scale_div.h:53
用于绘制刻度的类
Definition qwt_scale_draw.h:62
刻度引擎的基类
Definition qwt_scale_engine.h:76
刻度映射
Definition qwt_scale_map.h:52
包含刻度的控件
Definition qwt_scale_widget.h:95
显示 QwtText 的控件
Definition qwt_text_label.h:55
表示文本的类
Definition qwt_text.h:93
Position
坐标轴位置
Definition qwt_axis.h:53
@ YRight
Y axis right of the canvas
Definition qwt_axis.h:58
@ XTop
X axis above the canvas
Definition qwt_axis.h:64
@ XBottom
X axis below the canvas
Definition qwt_axis.h:61
@ YLeft
Y axis left of the canvas
Definition qwt_axis.h:55