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 > RenderHints
  • typedef 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 () const
  • bool isEmpty () const
  • CommandTypes commandTypes () const
  • void 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 a QPixmap.
  • QPixmap toPixmap (const QSize &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio, qreal devicePixelRatio=0.0) const β€” Convert the graphic to a QPixmap.
  • QImage toImage (qreal devicePixelRatio=0.0) const β€” Convert the graphic to a QImage.
  • QImage toImage (const QSize &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio, qreal devicePixelRatio=0.0) const β€” Convert the graphic to a QImage.
  • QRectF scaledBoundingRect (qreal sx, qreal sy) const β€” Calculate the target rectangle for scaling the graphic.
  • QRectF boundingRect () const
  • QRectF controlPointRect () const
  • const QVector< QwtPainterCommand > & commands () const
  • void setCommands (const QVector< QwtPainterCommand > &) β€” Append paint commands.
  • void setDefaultSize (const QSizeF &) β€” Set a default size.
  • QSizeF defaultSize () const β€” Default size.
  • qreal heightForWidth (qreal width) const
  • qreal widthForHeight (qreal height) const
  • void setRenderHint (RenderHint, bool on=true)
  • bool testRenderHint (RenderHint) const
  • RenderHints renderHints () const

Public Member Functions inherited from QwtNullPaintDevice:

  • QwtNullPaintDevice () β€” Constructor.
  • virtual ~QwtNullPaintDevice () β€” Destructor.
  • void setMode (Mode)
  • Mode mode () const
  • virtual QPaintEngine * paintEngine () const override β€” See QPaintDevice::paintEngine().
  • virtual int metric (PaintDeviceMetric) const override
  • virtual void drawRects (const QRect *, int) β€” See QPaintEngine::drawRects().
  • virtual void drawRects (const QRectF *, int) β€” See QPaintEngine::drawRects().
  • virtual void drawLines (const QLine *, int) β€” See QPaintEngine::drawLines().
  • virtual void drawLines (const QLineF *, int) β€” See QPaintEngine::drawLines().
  • virtual void drawEllipse (const QRectF &) β€” See QPaintEngine::drawEllipse().
  • virtual void drawEllipse (const QRect &) β€” See QPaintEngine::drawEllipse().
  • virtual void drawPoints (const QPointF *, int) β€” See QPaintEngine::drawPoints().
  • virtual void drawPoints (const QPoint *, int) β€” See QPaintEngine::drawPoints().
  • virtual void drawPolygon (const QPointF *, int, QPaintEngine::PolygonDrawMode) β€” See QPaintEngine::drawPolygon().
  • virtual void drawPolygon (const QPoint *, int, QPaintEngine::PolygonDrawMode) β€” See QPaintEngine::drawPolygon().
  • virtual void drawTextItem (const QPointF &, const QTextItem &) β€” See QPaintEngine::drawTextItem().
  • virtual void drawTiledPixmap (const QRectF &, const QPixmap &, const QPointF &) β€” See QPaintEngine::drawTiledPixmap().

πŸ”’ Protected Member Functions

  • virtual QSize sizeMetrics () const override
  • virtual void drawPath (const QPainterPath &) override
  • virtual 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 β€” unfortunately QPicture had 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 β€” unfortunately QSvgRenderer hides too much information about its nodes in internal APIs that are necessary for proper layout calculations. Also it is derived from QObject and can't be copied like QImage/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 (QPixmap or QImage).
  • 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 a QwtGraphic a specific scaling between the controlPointRect() and the coordinates of the target rectangle is set up internally in render().

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 β€” the Image to be painted
  • subRect β€” 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 rectangle
  • pixmap β€” the pixmap being painted
  • subRect β€” 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 painter
  • pos β€” reference point, where to render
  • alignment β€” flags for how to align the target rectangle to pos.

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 painter
  • rect β€” rectangle for the scaled graphic
  • aspectRatioMode β€” mode for how to scale β€” see Qt::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 painter
  • size β€” size for the scaled graphic
  • aspectRatioMode β€” mode for how to scale β€” see Qt::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 factor
  • sy β€” 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 hint
  • on β€” 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 the devicePixelRatio)
  • aspectRatioMode β€” aspect ratio for how to scale the graphic
  • devicePixelRatio β€” device pixel ratio for the image. If devicePixelRatio <= 0.0 the 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. If devicePixelRatio <= 0.0 the 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 image
  • aspectRatioMode β€” aspect ratio for how to scale the graphic
  • devicePixelRatio β€” device pixel ratio for the pixmap. If devicePixelRatio <= 0.0 the 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. If devicePixelRatio <= 0.0 the 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