QwtGraphic(3)
π¦ QwtGraphic β scalable-graphics royalty π¦
okay bestie, this is the QwtGraphic(3) page from the Library Functions Manual, part 1 of 2. We're talking about the QwtGraphic class, and it is literally giving paint-device-for-scalable-graphics energy. No cap, we're keeping every flag, signature, default, enum, line number and warning. β¨
β¨ NAME β¨
QwtGraphic β a paint device for scalable graphics. π
πΈ SYNOPSIS πΈ
#include <qwt_graphic.h>
Inherits QwtNullPaintDevice.
π Public Types
enum RenderHint { RenderPensUnscaled = 0x1 }enum CommandType { VectorData = 1 << 0, RasterData = 1 << 1, Transformation = 1 << 2 }typedef QFlags< RenderHint > RenderHintstypedef QFlags< CommandType > CommandTypes
Public Types inherited from QwtNullPaintDevice:
enum Mode { NormalMode, PolygonPathMode, PathMode }β Render mode.
π Public Member Functions
QwtGraphic ()β Constructor.QwtGraphic (const QwtGraphic &)β Copy constructor.virtual ~QwtGraphic ()β Destructor.QwtGraphic & operator= (const QwtGraphic &)β Assignment operator.void reset ()β Clear all stored commands.bool isNull () constbool isEmpty () constCommandTypes commandTypes () constvoid render (QPainter *) constβ Replay all recorded painter commands.void render (QPainter *, const QSizeF &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio) constβ Replay all recorded painter commands.void render (QPainter *, const QPointF &, Qt::Alignment=Qt::AlignTop|Qt::AlignLeft) constβ Replay all recorded painter commands.void render (QPainter *, const QRectF &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio) constβ Replay all recorded painter commands.QPixmap toPixmap (qreal devicePixelRatio=0.0) constβ Convert the graphic to aQPixmap.QPixmap toPixmap (const QSize &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio, qreal devicePixelRatio=0.0) constβ Convert the graphic to aQPixmap.QImage toImage (qreal devicePixelRatio=0.0) constβ Convert the graphic to aQImage.QImage toImage (const QSize &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio, qreal devicePixelRatio=0.0) constβ Convert the graphic to aQImage.QRectF scaledBoundingRect (qreal sx, qreal sy) constβ Calculate the target rectangle for scaling the graphic.QRectF boundingRect () constQRectF controlPointRect () constconst QVector< QwtPainterCommand > & commands () constvoid setCommands (const QVector< QwtPainterCommand > &)β Append paint commands.void setDefaultSize (const QSizeF &)β Set a default size.QSizeF defaultSize () constβ Default size.qreal heightForWidth (qreal width) constqreal widthForHeight (qreal height) constvoid setRenderHint (RenderHint, bool on=true)bool testRenderHint (RenderHint) constRenderHints renderHints () const
Public Member Functions inherited from QwtNullPaintDevice:
QwtNullPaintDevice ()β Constructor.virtual ~QwtNullPaintDevice ()β Destructor.void setMode (Mode)Mode mode () constvirtual QPaintEngine * paintEngine () const overrideβ SeeQPaintDevice::paintEngine().virtual int metric (PaintDeviceMetric) const overridevirtual void drawRects (const QRect *, int)β SeeQPaintEngine::drawRects().virtual void drawRects (const QRectF *, int)β SeeQPaintEngine::drawRects().virtual void drawLines (const QLine *, int)β SeeQPaintEngine::drawLines().virtual void drawLines (const QLineF *, int)β SeeQPaintEngine::drawLines().virtual void drawEllipse (const QRectF &)β SeeQPaintEngine::drawEllipse().virtual void drawEllipse (const QRect &)β SeeQPaintEngine::drawEllipse().virtual void drawPoints (const QPointF *, int)β SeeQPaintEngine::drawPoints().virtual void drawPoints (const QPoint *, int)β SeeQPaintEngine::drawPoints().virtual void drawPolygon (const QPointF *, int, QPaintEngine::PolygonDrawMode)β SeeQPaintEngine::drawPolygon().virtual void drawPolygon (const QPoint *, int, QPaintEngine::PolygonDrawMode)β SeeQPaintEngine::drawPolygon().virtual void drawTextItem (const QPointF &, const QTextItem &)β SeeQPaintEngine::drawTextItem().virtual void drawTiledPixmap (const QRectF &, const QPixmap &, const QPointF &)β SeeQPaintEngine::drawTiledPixmap().
π Protected Member Functions
virtual QSize sizeMetrics () const overridevirtual void drawPath (const QPainterPath &) overridevirtual void drawPixmap (const QRectF &, const QPixmap &, const QRectF &) overrideβ Store a pixmap command in the command list.virtual void drawImage (const QRectF &, const QImage &, const QRectF &, Qt::ImageConversionFlags) overrideβ Store a image command in the command list.virtual void updateState (const QPaintEngineState &) overrideβ Store a state command in the command list.
π Detailed Description π
A paint device for scalable graphics. π
QwtGraphic is the representation of a graphic that is tailored for scalability. Like QPicture, it will be initialized by QPainter operations and can be replayed later to any target paint device. π¨
While the usual image representations QImage and QPixmap are not scalable, Qt offers two paint devices that might be candidates for representing a vector graphic:
QPictureβ unfortunatelyQPicturehad been forgotten when Qt4 introduced floating point based render engines. Its API is still on integers, what make it unusable for proper scaling. πQSvgRenderer/QSvgGeneratorβ unfortunatelyQSvgRendererhides too much information about its nodes in internal APIs that are necessary for proper layout calculations. Also it is derived fromQObjectand can't be copied likeQImage/QPixmap.
QwtGraphic maps all scalable drawing primitives to a QPainterPath and stores them together with the painter state changes (pen, brush, transformation ...) in a list of QwtPaintCommands. For being a complete QPaintDevice, it also stores pixmaps or images, what is somehow against the idea of the class, because these objects can't be scaled without a loss in quality. lowkey tragic, but facts.
The main issue about scaling a QwtGraphic object are the pens used for drawing the outlines of the painter paths. While non cosmetic pens (QPen::isCosmetic()) are scaled with the same ratio as the path, cosmetic pens have a fixed width. A graphic might have paths with different pens β cosmetic and non-cosmetic. ποΈ
QwtGraphic caches 2 different rectangles:
- control point rectangle β The control point rectangle is the bounding rectangle of all control point rectangles of the painter paths, or the target rectangle of the pixmaps/images.
- bounding rectangle β The bounding rectangle extends the control point rectangle by what is needed for rendering the outline with an unscaled pen.
Because the offset for drawing the outline depends on the shape of the painter path (the peak of a triangle is different than the flat side), scaling with a fixed aspect ratio always needs to be calculated from the control point rectangle. π
See also: QwtPainterCommand
π Definition at line 75 of file qwt_graphic.h.
π Member Typedef Documentation π
typedef QFlags<CommandType > QwtGraphic::CommandTypes
An ORed combination of CommandType values. π«Ά
Definition at line 117 of file qwt_graphic.h.
typedef QFlags<RenderHint > QwtGraphic::RenderHints
An ORed combination of RenderHint values. β¨
Definition at line 99 of file qwt_graphic.h.
π§ Member Enumeration Documentation π§
enum QwtGraphic::CommandType
Indicator if the graphic contains a specific type of painter command. π
See also: CommandTypes, commandTypes();
Enumerator:
VectorDataβ The graphic contains scalable vector data.RasterDataβ The graphic contains raster data (QPixmaporQImage).Transformationβ The graphic contains transformations beyond simple translations.
Definition at line 105 of file qwt_graphic.h.
enum QwtGraphic::RenderHint
Hint how to render a graphic. π¨
See also: setRenderHint(), testRenderHint()
Enumerator:
RenderPensUnscaledβ When rendering aQwtGraphica specific scaling between thecontrolPointRect()and the coordinates of the target rectangle is set up internally inrender().
When RenderPensUnscaled is set this specific scaling is applied for the control points only, but not for the pens. All other painter transformations (set up by application code) are supposed to work like usual. π
See also: render();
Definition at line 82 of file qwt_graphic.h.
πΈ Constructor & Destructor Documentation πΈ
QwtGraphic::QwtGraphic ()
Constructor. Initializes a null graphic. π£
See also: isNull()
Definition at line 355 of file qwt_graphic.cpp.
QwtGraphic::QwtGraphic (const QwtGraphic & other)
Copy constructor. π
Parameters:
- other β Source
See also: operator=()
Definition at line 367 of file qwt_graphic.cpp.
QwtGraphic::~QwtGraphic () [virtual]
Destructor. π
Definition at line 374 of file qwt_graphic.cpp.
π Member Function Documentation π
QRectF QwtGraphic::boundingRect () const
The bounding rectangle is the controlPointRect() extended by the areas needed for rendering the outlines with unscaled pens. πΌοΈ
Returns: Bounding rectangle of the graphic
See also: controlPointRect(), scaledBoundingRect()
Definition at line 477 of file qwt_graphic.cpp.
const QVector< QwtPainterCommand > & QwtGraphic::commands () const
Returns: List of recorded paint commands
See also: setCommands()
Definition at line 1131 of file qwt_graphic.cpp.
QwtGraphic::CommandTypes QwtGraphic::commandTypes () const
Returns: Types of painter commands being used
Definition at line 430 of file qwt_graphic.cpp.
QRectF QwtGraphic::controlPointRect () const
The control point rectangle is the bounding rectangle of all control points of the paths and the target rectangles of the images/pixmaps. π―
Returns: Control point rectangle
See also: boundingRect(), scaledBoundingRect()
Definition at line 493 of file qwt_graphic.cpp.
QSizeF QwtGraphic::defaultSize () const
Default size. When a non empty size has been assigned by setDefaultSize() this size will be returned. Otherwise the default size is the size of the bounding rectangle. π
The default size is used in all methods rendering the graphic, where no size is explicitly specified.
Returns: Default size
See also: setDefaultSize(), boundingRect()
Definition at line 574 of file qwt_graphic.cpp.
πΌοΈ drawImage β image command time
void QwtGraphic::drawImage (const QRectF & rect, const QImage & image, const QRectF & subRect, Qt::ImageConversionFlags flags) [override], [protected], [virtual]
Store a image command in the command list. π«Ά
rectβ the target rectangle (where it lands)imageβ theImageto be paintedsubRectβ the Reactangle of the pixmap to be painted πflagsβ image conversion flags
See also QPaintEngine::drawImage()
Reimplemented from QwtNullPaintDevice.
Definition at line 1059 of file qwt_graphic.cpp.
void QwtGraphic::drawPath (const QPainterPath & path) β [override], [protected], [virtual]
Stores a path command straight into the command list β¨
pathβ the painter path
See also QPaintEngine::drawPath()
Reimplemented from QwtNullPaintDevice.
Definition at line 995 of file qwt_graphic.cpp.
void QwtGraphic::drawPixmap (const QRectF & rect, const QPixmap & pixmap, const QRectF & subRect) β [override], [protected], [virtual]
Stores a pixmap command in the command list π
rectβ target rectanglepixmapβ the pixmap being paintedsubRectβ Reactangle of the pixmap to be painted
See also QPaintEngine::drawPixmap()
Reimplemented from QwtNullPaintDevice.
Definition at line 1034 of file qwt_graphic.cpp.
qreal QwtGraphic::heightForWidth (qreal width) const
Finds the height for a given width π₯
The height gets calculated using the aspect ratio of defaultSize().
widthβ the width
Returns the calculated height
See also defaultSize()
Definition at line 592 of file qwt_graphic.cpp.
bool QwtGraphic::isEmpty () const
Returns True when the bounding rectangle is empty π«Ά
See also boundingRect(), isNull()
Definition at line 422 of file qwt_graphic.cpp.
bool QwtGraphic::isNull () const
Returns True when no painter commands have been stored β like, nothing at all, bestie π
See also isEmpty(), commands()
Definition at line 413 of file qwt_graphic.cpp.
QwtGraphic & QwtGraphic::operator= (const QwtGraphic & other)
The assignment operator π¦
otherβ the source
Returns a reference to this object
Definition at line 385 of file qwt_graphic.cpp.
void QwtGraphic::render (QPainter * painter) const
Replays all the recorded painter commands π¬
painterβ Qt painter
Definition at line 624 of file qwt_graphic.cpp.
void QwtGraphic::render (QPainter * painter, const QPointF & pos, Qt::Alignment alignment = Qt::AlignTop | Qt::AlignLeft) const
Replays all recorded painter commands. The graphic gets scaled to the defaultSize() and aligned to a position πΈ
painterβ Qt painterposβ reference point, where to renderalignmentβ flags for how to align the target rectangle topos.
Definition at line 762 of file qwt_graphic.cpp.
void QwtGraphic::render (QPainter * painter, const QRectF & rect, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio) const
Replays all recorded painter commands. The graphic is scaled to fit into the given rectangle β¨
painterβ Qt painterrectβ rectangle for the scaled graphicaspectRatioModeβ mode for how to scale β seeQt::AspectRatioMode
Definition at line 676 of file qwt_graphic.cpp.
void QwtGraphic::render (QPainter * painter, const QSizeF & size, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio) const
Replays all recorded painter commands. The graphic is scaled to fit into the rectangle of the given size, starting at ( 0, 0 ) π
painterβ Qt paintersizeβ size for the scaled graphicaspectRatioModeβ mode for how to scale β seeQt::AspectRatioMode
Definition at line 660 of file qwt_graphic.cpp.
QwtGraphic::RenderHints QwtGraphic::renderHints () const
Returns the render hints π
Definition at line 464 of file qwt_graphic.cpp.
void QwtGraphic::reset ()
Clears all stored commands β poof, gone, no cap π§Ή
See also isNull()
Definition at line 397 of file qwt_graphic.cpp.
QRectF QwtGraphic::scaledBoundingRect (qreal sx, qreal sy) const
Calculates the target rectangle for scaling the graphic π―
sxβ horizontal scaling factorsyβ vertical scaling factor
Note: for paths that are painted with a cosmetic pen (see QPen::isCosmetic()) the target rectangle is different from just multiplying the bounding rectangle. little heads up, bestie π
Returns the scaled bounding rectangle
See also boundingRect(), controlPointRect()
Definition at line 514 of file qwt_graphic.cpp.
void QwtGraphic::setCommands (const QVector< QwtPainterCommand > & commands)
Appends paint commands π₯
commandsβ paint commands
See also commands()
Definition at line 1142 of file qwt_graphic.cpp.
void QwtGraphic::setDefaultSize (const QSizeF & size)
Sets a default size. The default size is used in every method that renders the graphic where no size is explicitly specified. Assigning an empty size means the default size will be calculated from the bounding rectangle π
The default setting is an empty size.
sizeβ default size
See also defaultSize(), boundingRect()
Definition at line 553 of file qwt_graphic.cpp.
void QwtGraphic::setRenderHint (RenderHint hint, bool on = true)
Toggles a render hint π
hintβ render hintonβtrue/false
See also testRenderHint(), RenderHint
Definition at line 443 of file qwt_graphic.cpp.
QSize QwtGraphic::sizeMetrics () const β [override], [protected], [virtual]
Returns the ceiled defaultSize() π
Implements QwtNullPaintDevice.
Definition at line 533 of file qwt_graphic.cpp.
bool QwtGraphic::testRenderHint (RenderHint hint) const
Tests a render hint π
hintβ render hint
Returns true/false
See also setRenderHint(), RenderHint
Definition at line 458 of file qwt_graphic.cpp.
QImage QwtGraphic::toImage (const QSize & size, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio, qreal devicePixelRatio = 0.0) const
Converts the graphic to a QImage πΌοΈ All pixels of the image get initialized by 0 (transparent) before the graphic is scaled and rendered on it.
The format of the image is QImage::Format_ARGB32_Premultiplied.
sizeβ size of the image (will be multiplied by thedevicePixelRatio)aspectRatioModeβ aspect ratio for how to scale the graphicdevicePixelRatioβ device pixel ratio for the image. IfdevicePixelRatio <= 0.0the pixmap is initialized with the system default.
Returns the graphic as image
See also toPixmap(), render()
Definition at line 907 of file qwt_graphic.cpp.
QImage QwtGraphic::toImage (qreal devicePixelRatio = 0.0) const
Converts the graphic to a QImage. All pixels of the image get initialized by 0 (transparent) before the graphic is scaled and rendered on it π
The format of the image is QImage::Format_ARGB32_Premultiplied.
The size of the image is the default size (ceiled to integers) of the graphic multiplied by the devicePixelRatio.
devicePixelRatioβ device pixel ratio for the image. IfdevicePixelRatio <= 0.0the pixmap is initialized with the system default.
Returns the graphic as image in default size
See also defaultSize(), toPixmap(), render()
Definition at line 953 of file qwt_graphic.cpp.
QPixmap QwtGraphic::toPixmap (const QSize & size, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio, qreal devicePixelRatio = 0.0) const
Converts the graphic to a QPixmap π All pixels of the pixmap get initialized by Qt::transparent before the graphic is scaled and rendered on it.
sizeβ size of the imageaspectRatioModeβ aspect ratio for how to scale the graphicdevicePixelRatioβ device pixel ratio for the pixmap. IfdevicePixelRatio <= 0.0the pixmap is initialized with the system default.
Returns the graphic as pixmap
See also toImage(), render()
Definition at line 863 of file qwt_graphic.cpp.
QPixmap QwtGraphic::toPixmap (qreal devicePixelRatio = 0.0) const
Converts the graphic to a QPixmap π All pixels of the pixmap get initialized by Qt::transparent before the graphic is scaled and rendered on it.
The size of the pixmap is the default size (ceiled to integers) of the graphic.
devicePixelRatioβ device pixel ratio for the pixmap. IfdevicePixelRatio <= 0.0the pixmap is initialized with the system default.
Returns the graphic as pixmap in default size
See also defaultSize(), toImage(), render()
Definition at line 812 of file qwt_graphic.cpp.
void QwtGraphic::updateState (const QPaintEngineState & state) β [override], [protected], [virtual]
Stores a state command in the command list πΎ
stateβ state to be stored
See also QPaintEngine::updateState()
Reimplemented from QwtNullPaintDevice.
Definition at line 1081 of file qwt_graphic.cpp.
qreal QwtGraphic::widthForHeight (qreal height) const
Finds the width for a given height β¨
The width gets calculated using the aspect ratio of defaultSize().
heightβ height
Returns the calculated width
See also defaultSize()
Definition at line 611 of file qwt_graphic.cpp.
π AUTHOR π
Generated automatically by Doxygen for Qwt User's Guide from the source code. yeah, our girl Doxygen wrote this entire thing for us, absolutely iconic of her π«Ά
and that's the whole page bestie, we did it π the guide comes from the Qwt User's Guide and it's dated QwtGraphic(3) β go forth and render, mwah π
π
π¦ where this page comes from
- alpine 3.24: qwt-doc 6.3.0-r0 Β· custom
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms