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