QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt_graphic.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_GRAPHIC_H
28#define QWT_GRAPHIC_H
29
30#include "qwt_global.h"
31#include "qwt_null_paintdevice.h"
32#include "qwt_painter_command.h"
33
34#include <qmetatype.h>
35
84class QWT_EXPORT QwtGraphic : public QwtNullPaintDevice
85{
86public:
92 {
104 RenderPensUnscaled = 0x1
105 };
106
107 Q_DECLARE_FLAGS(RenderHints, RenderHint)
108
109
114 {
116 VectorData = 1 << 0,
117
119 RasterData = 1 << 1,
120
122 Transformation = 1 << 2
123 };
124
125 Q_DECLARE_FLAGS(CommandTypes, CommandType)
126
127 // Constructor
128 QwtGraphic();
129 // Copy constructor
130 QwtGraphic(const QwtGraphic&);
131
132 // Destructor
133 ~QwtGraphic() override;
134
135 // Assignment operator
136 QwtGraphic& operator=(const QwtGraphic&);
137
138 // Clear all stored commands
139 void reset();
140
141 // Check if the graphic is null
142 bool isNull() const;
143 // Check if the graphic is empty
144 bool isEmpty() const;
145
146 // Get the types of painter commands being used
147 CommandTypes commandTypes() const;
148
149 // Replay all recorded painter commands
150 void render(QPainter*) const;
151
152 // Render graphic scaled to fit into given size
153 void render(QPainter*, const QSizeF&, Qt::AspectRatioMode = Qt::IgnoreAspectRatio) const;
154
155 // Render graphic aligned to a position
156 void render(QPainter*, const QPointF&, Qt::Alignment = Qt::AlignTop | Qt::AlignLeft) const;
157
158 // Render graphic scaled to fit into given rectangle
159 void render(QPainter*, const QRectF&, Qt::AspectRatioMode = Qt::IgnoreAspectRatio) const;
160
161 // Convert graphic to QPixmap in default size
162 QPixmap toPixmap(qreal devicePixelRatio = 0.0) const;
163
164 // Convert graphic to QPixmap with specified size
165 QPixmap toPixmap(const QSize&, Qt::AspectRatioMode = Qt::IgnoreAspectRatio, qreal devicePixelRatio = 0.0) const;
166
167 // Convert graphic to QImage in default size
168 QImage toImage(qreal devicePixelRatio = 0.0) const;
169
170 // Convert graphic to QImage with specified size
171 QImage toImage(const QSize&, Qt::AspectRatioMode = Qt::IgnoreAspectRatio, qreal devicePixelRatio = 0.0) const;
172
173 // Calculate the scaled bounding rectangle
174 QRectF scaledBoundingRect(qreal sx, qreal sy) const;
175
176 // Get the bounding rectangle
177 QRectF boundingRect() const;
178 // Get the control point rectangle
179 QRectF controlPointRect() const;
180
181 // Get the list of recorded paint commands
182 const QVector< QwtPainterCommand >& commands() const;
183 // Set the paint commands
184 void setCommands(const QVector< QwtPainterCommand >&);
185
186 // Set the default size
187 void setDefaultSize(const QSizeF&);
188 // Get the default size
189 QSizeF defaultSize() const;
190
191 // Get the height for a given width
192 qreal heightForWidth(qreal width) const;
193 // Get the width for a given height
194 qreal widthForHeight(qreal height) const;
195
196 // Set a render hint
197 void setRenderHint(RenderHint, bool on = true);
198 // Test a render hint
199 bool testRenderHint(RenderHint) const;
200
201 // Get the render hints
202 RenderHints renderHints() const;
203
204protected:
205 virtual QSize sizeMetrics() const override;
206
207 virtual void drawPath(const QPainterPath&) override;
208
209 virtual void drawPixmap(const QRectF&, const QPixmap&, const QRectF&) override;
210
211 virtual void drawImage(const QRectF&, const QImage&, const QRectF&, Qt::ImageConversionFlags) override;
212
213 virtual void updateState(const QPaintEngineState&) override;
214
215private:
216 void renderGraphic(QPainter*, QTransform*) const;
217
218 void updateBoundingRect(const QRectF&);
219 void updateControlPointRect(const QRectF&);
220
221 class PathInfo;
222
223 QWT_DECLARE_PRIVATE(QwtGraphic)
224};
225
226Q_DECLARE_OPERATORS_FOR_FLAGS(QwtGraphic::RenderHints)
227Q_DECLARE_OPERATORS_FOR_FLAGS(QwtGraphic::CommandTypes)
228Q_DECLARE_METATYPE(QwtGraphic)
229
230#endif
Definition qwt_clipper.h:41
A paint device for scalable graphics
Definition qwt_graphic.h:85
RenderHint
Hint how to render a graphic
Definition qwt_graphic.h:92
CommandType
Indicator if the graphic contains a specific type of painter command
Definition qwt_graphic.h:114
A null paint device that does nothing
Definition qwt_null_paintdevice.h:46
virtual void drawPixmap(const QRectF &, const QPixmap &, const QRectF &)
Draw a pixmap
Definition qwt_null_paintdevice.cpp:543
virtual void drawPath(const QPainterPath &)
Draw a painter path
Definition qwt_null_paintdevice.cpp:507
virtual void drawImage(const QRectF &, const QImage &, const QRectF &, Qt::ImageConversionFlags)
Draw an image
Definition qwt_null_paintdevice.cpp:566
virtual void updateState(const QPaintEngineState &)
Update the paint engine state
Definition qwt_null_paintdevice.cpp:575
virtual QSize sizeMetrics() const =0