Classes | Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
QwtGraphic Class Reference

A paint device for scalable graphics. More...

#include <qwt_graphic.h>

Inheritance diagram for QwtGraphic:
Inheritance graph
[legend]

Classes

class  PathInfo
 
class  PrivateData
 

Public Types

enum  CommandType { VectorData = 1 << 0, RasterData = 1 << 1, Transformation = 1 << 2 }
 
enum  RenderHint { RenderPensUnscaled = 0x1 }
 
- Public Types inherited from QwtNullPaintDevice
enum  Mode { NormalMode, PolygonPathMode, PathMode }
 Render mode. More...
 

Public Member Functions

QRectF boundingRect () const
 
const QVector< QwtPainterCommand > & commands () const
 
CommandTypes commandTypes () const
 
QRectF controlPointRect () const
 
QSizeF defaultSize () const
 Default size. More...
 
qreal heightForWidth (qreal width) const
 
bool isEmpty () const
 
bool isNull () const
 
QwtGraphicoperator= (const QwtGraphic &)
 Assignment operator. More...
 
 QwtGraphic ()
 Constructor. More...
 
 QwtGraphic (const QwtGraphic &)
 Copy constructor. More...
 
void render (QPainter *) const
 Replay all recorded painter commands. More...
 
void render (QPainter *, const QPointF &, Qt::Alignment=Qt::AlignTop|Qt::AlignLeft) const
 Replay all recorded painter commands. More...
 
void render (QPainter *, const QRectF &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio) const
 Replay all recorded painter commands. More...
 
void render (QPainter *, const QSizeF &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio) const
 Replay all recorded painter commands. More...
 
RenderHints renderHints () const
 
void reset ()
 Clear all stored commands. More...
 
QRectF scaledBoundingRect (qreal sx, qreal sy) const
 Calculate the target rectangle for scaling the graphic. More...
 
void setCommands (const QVector< QwtPainterCommand > &)
 Append paint commands. More...
 
void setDefaultSize (const QSizeF &)
 Set a default size. More...
 
void setRenderHint (RenderHint, bool on=true)
 
bool testRenderHint (RenderHint) const
 
QImage toImage (const QSize &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio, qreal devicePixelRatio=0.0) const
 Convert the graphic to a QImage. More...
 
QImage toImage (qreal devicePixelRatio=0.0) const
 Convert the graphic to a QImage. More...
 
QPixmap toPixmap (const QSize &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio, qreal devicePixelRatio=0.0) const
 Convert the graphic to a QPixmap. More...
 
QPixmap toPixmap (qreal devicePixelRatio=0.0) const
 Convert the graphic to a QPixmap. More...
 
qreal widthForHeight (qreal height) const
 
virtual ~QwtGraphic ()
 Destructor. More...
 
- Public Member Functions inherited from QwtNullPaintDevice
virtual void drawEllipse (const QRect &)
 See QPaintEngine::drawEllipse() More...
 
virtual void drawEllipse (const QRectF &)
 See QPaintEngine::drawEllipse() More...
 
virtual void drawLines (const QLine *, int)
 See QPaintEngine::drawLines() More...
 
virtual void drawLines (const QLineF *, int)
 See QPaintEngine::drawLines() More...
 
virtual void drawPoints (const QPoint *, int)
 See QPaintEngine::drawPoints() More...
 
virtual void drawPoints (const QPointF *, int)
 See QPaintEngine::drawPoints() More...
 
virtual void drawPolygon (const QPoint *, int, QPaintEngine::PolygonDrawMode)
 See QPaintEngine::drawPolygon() More...
 
virtual void drawPolygon (const QPointF *, int, QPaintEngine::PolygonDrawMode)
 See QPaintEngine::drawPolygon() More...
 
virtual void drawRects (const QRect *, int)
 See QPaintEngine::drawRects() More...
 
virtual void drawRects (const QRectF *, int)
 See QPaintEngine::drawRects() More...
 
virtual void drawTextItem (const QPointF &, const QTextItem &)
 See QPaintEngine::drawTextItem() More...
 
virtual void drawTiledPixmap (const QRectF &, const QPixmap &, const QPointF &)
 See QPaintEngine::drawTiledPixmap() More...
 
virtual int metric (PaintDeviceMetric) const QWT_OVERRIDE
 
Mode mode () const
 
virtual QPaintEngine * paintEngine () const QWT_OVERRIDE
 See QPaintDevice::paintEngine() More...
 
 QwtNullPaintDevice ()
 Constructor. More...
 
void setMode (Mode)
 
virtual ~QwtNullPaintDevice ()
 Destructor. More...
 

Protected Member Functions

virtual void drawImage (const QRectF &, const QImage &, const QRectF &, Qt::ImageConversionFlags) QWT_OVERRIDE
 Store a image command in the command list. More...
 
virtual void drawPath (const QPainterPath &) QWT_OVERRIDE
 
virtual void drawPixmap (const QRectF &, const QPixmap &, const QRectF &) QWT_OVERRIDE
 Store a pixmap command in the command list. More...
 
virtual QSize sizeMetrics () const QWT_OVERRIDE
 
virtual void updateState (const QPaintEngineState &) QWT_OVERRIDE
 Store a state command in the command list. More...
 

Private Member Functions

void renderGraphic (QPainter *, QTransform *) const
 
void updateBoundingRect (const QRectF &)
 
void updateControlPointRect (const QRectF &)
 

Private Attributes

PrivateDatam_data
 

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:

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.

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:

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 Enumeration Documentation

◆ 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.

◆ 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() [1/2]

QwtGraphic::QwtGraphic ( )

Constructor.

Initializes a null graphic

See also
isNull()

Definition at line 355 of file qwt_graphic.cpp.

◆ QwtGraphic() [2/2]

QwtGraphic::QwtGraphic ( const QwtGraphic other)

Copy constructor.

Parameters
otherSource
See also
operator=()

Definition at line 367 of file qwt_graphic.cpp.

◆ ~QwtGraphic()

QwtGraphic::~QwtGraphic ( )
virtual

Destructor.

Definition at line 374 of file qwt_graphic.cpp.

Member Function Documentation

◆ boundingRect()

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.

◆ commands()

const QVector< QwtPainterCommand > & QwtGraphic::commands ( ) const
Returns
List of recorded paint commands
See also
setCommands()

Definition at line 1131 of file qwt_graphic.cpp.

◆ commandTypes()

QwtGraphic::CommandTypes QwtGraphic::commandTypes ( ) const
Returns
Types of painter commands being used

Definition at line 430 of file qwt_graphic.cpp.

◆ controlPointRect()

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.

◆ defaultSize()

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()

void QwtGraphic::drawImage ( const QRectF &  rect,
const QImage &  image,
const QRectF &  subRect,
Qt::ImageConversionFlags  flags 
)
protectedvirtual

Store a image command in the command list.

Parameters
recttarget rectangle
imageImage to be painted
subRectReactangle of the pixmap to be painted
flagsImage conversion flags
See also
QPaintEngine::drawImage()

Reimplemented from QwtNullPaintDevice.

Definition at line 1059 of file qwt_graphic.cpp.

◆ drawPath()

void QwtGraphic::drawPath ( const QPainterPath &  path)
protectedvirtual

Store a path command in the command list

Parameters
pathPainter path
See also
QPaintEngine::drawPath()

Reimplemented from QwtNullPaintDevice.

Definition at line 995 of file qwt_graphic.cpp.

◆ drawPixmap()

void QwtGraphic::drawPixmap ( const QRectF &  rect,
const QPixmap &  pixmap,
const QRectF &  subRect 
)
protectedvirtual

Store a pixmap command in the command list.

Parameters
recttarget rectangle
pixmapPixmap to be painted
subRectReactangle of the pixmap to be painted
See also
QPaintEngine::drawPixmap()

Reimplemented from QwtNullPaintDevice.

Definition at line 1034 of file qwt_graphic.cpp.

◆ heightForWidth()

qreal QwtGraphic::heightForWidth ( qreal  width) const

Find the height for a given width

The height is calculated using the aspect ratio of defaultSize().

Parameters
widthWidth
Returns
Calculated height
See also
defaultSize()

Definition at line 592 of file qwt_graphic.cpp.

◆ isEmpty()

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.

◆ isNull()

bool QwtGraphic::isNull ( ) const
Returns
True, when no painter commands have been stored
See also
isEmpty(), commands()

Definition at line 413 of file qwt_graphic.cpp.

◆ operator=()

QwtGraphic & QwtGraphic::operator= ( const QwtGraphic other)

Assignment operator.

Parameters
otherSource
Returns
A reference of this object

Definition at line 385 of file qwt_graphic.cpp.

◆ render() [1/4]

void QwtGraphic::render ( QPainter *  painter) const

Replay all recorded painter commands.

Parameters
painterQt painter

Definition at line 624 of file qwt_graphic.cpp.

◆ render() [2/4]

void QwtGraphic::render ( QPainter *  painter,
const QPointF &  pos,
Qt::Alignment  alignment = Qt::AlignTop | Qt::AlignLeft 
) const

Replay all recorded painter commands.

The graphic is scaled to the defaultSize() and aligned to a position.

Parameters
painterQt painter
posReference point, where to render
alignmentFlags how to align the target rectangle to pos.

Definition at line 762 of file qwt_graphic.cpp.

◆ render() [3/4]

void QwtGraphic::render ( QPainter *  painter,
const QRectF &  rect,
Qt::AspectRatioMode  aspectRatioMode = Qt::IgnoreAspectRatio 
) const

Replay all recorded painter commands.

The graphic is scaled to fit into the given rectangle

Parameters
painterQt painter
rectRectangle for the scaled graphic
aspectRatioModeMode how to scale - See Qt::AspectRatioMode

Definition at line 676 of file qwt_graphic.cpp.

◆ render() [4/4]

void QwtGraphic::render ( QPainter *  painter,
const QSizeF &  size,
Qt::AspectRatioMode  aspectRatioMode = Qt::IgnoreAspectRatio 
) const

Replay all recorded painter commands.

The graphic is scaled to fit into the rectangle of the given size starting at ( 0, 0 ).

Parameters
painterQt painter
sizeSize for the scaled graphic
aspectRatioModeMode how to scale - See Qt::AspectRatioMode

Definition at line 660 of file qwt_graphic.cpp.

◆ renderGraphic()

void QwtGraphic::renderGraphic ( QPainter *  painter,
QTransform *  initialTransform 
) const
private

Definition at line 629 of file qwt_graphic.cpp.

◆ renderHints()

QwtGraphic::RenderHints QwtGraphic::renderHints ( ) const
Returns
Render hints

Definition at line 464 of file qwt_graphic.cpp.

◆ reset()

void QwtGraphic::reset ( )

Clear all stored commands.

See also
isNull()

Definition at line 397 of file qwt_graphic.cpp.

◆ scaledBoundingRect()

QRectF QwtGraphic::scaledBoundingRect ( qreal  sx,
qreal  sy 
) const

Calculate the target rectangle for scaling the graphic.

Parameters
sxHorizontal scaling factor
syVertical scaling factor
Note
In case of paths that are painted with a cosmetic pen ( see QPen::isCosmetic() ) the target rectangle is different to multiplying the bounding rectangle.
Returns
Scaled bounding rectangle
See also
boundingRect(), controlPointRect()

Definition at line 514 of file qwt_graphic.cpp.

◆ setCommands()

void QwtGraphic::setCommands ( const QVector< QwtPainterCommand > &  commands)

Append paint commands.

Parameters
commandsPaint commands
See also
commands()

Definition at line 1142 of file qwt_graphic.cpp.

◆ setDefaultSize()

void QwtGraphic::setDefaultSize ( const QSizeF &  size)

Set a default size.

The default size is used in all methods rendering the graphic, where no size is explicitly specified. Assigning an empty size means, that the default size will be calculated from the bounding rectangle.

The default setting is an empty size.

Parameters
sizeDefault size
See also
defaultSize(), boundingRect()

Definition at line 553 of file qwt_graphic.cpp.

◆ setRenderHint()

void QwtGraphic::setRenderHint ( RenderHint  hint,
bool  on = true 
)

Toggle an render hint

Parameters
hintRender hint
ontrue/false
See also
testRenderHint(), RenderHint

Definition at line 443 of file qwt_graphic.cpp.

◆ sizeMetrics()

QSize QwtGraphic::sizeMetrics ( ) const
protectedvirtual
Returns
Ceiled defaultSize()

Implements QwtNullPaintDevice.

Definition at line 533 of file qwt_graphic.cpp.

◆ testRenderHint()

bool QwtGraphic::testRenderHint ( RenderHint  hint) const

Test a render hint

Parameters
hintRender hint
Returns
true/false
See also
setRenderHint(), RenderHint

Definition at line 458 of file qwt_graphic.cpp.

◆ toImage() [1/2]

QImage QwtGraphic::toImage ( const QSize &  size,
Qt::AspectRatioMode  aspectRatioMode = Qt::IgnoreAspectRatio,
qreal  devicePixelRatio = 0.0 
) const

Convert 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.

Parameters
sizeSize of the image ( will be multiplied by the devicePixelRatio )
aspectRatioModeAspect ratio how to scale the graphic
devicePixelRatioDevice 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.

◆ toImage() [2/2]

QImage QwtGraphic::toImage ( qreal  devicePixelRatio = 0.0) const

Convert 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.

Parameters
devicePixelRatioDevice 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.

◆ toPixmap() [1/2]

QPixmap QwtGraphic::toPixmap ( const QSize &  size,
Qt::AspectRatioMode  aspectRatioMode = Qt::IgnoreAspectRatio,
qreal  devicePixelRatio = 0.0 
) const

Convert the graphic to a QPixmap.

All pixels of the pixmap get initialized by Qt::transparent before the graphic is scaled and rendered on it.

Parameters
sizeSize of the image
aspectRatioModeAspect ratio how to scale the graphic
devicePixelRatioDevice 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.

◆ toPixmap() [2/2]

QPixmap QwtGraphic::toPixmap ( qreal  devicePixelRatio = 0.0) const

Convert 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.

Parameters
devicePixelRatioDevice 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.

◆ updateBoundingRect()

void QwtGraphic::updateBoundingRect ( const QRectF &  rect)
private

Definition at line 1100 of file qwt_graphic.cpp.

◆ updateControlPointRect()

void QwtGraphic::updateControlPointRect ( const QRectF &  rect)
private

Definition at line 1119 of file qwt_graphic.cpp.

◆ updateState()

void QwtGraphic::updateState ( const QPaintEngineState &  state)
protectedvirtual

Store a state command in the command list.

Parameters
stateState to be stored
See also
QPaintEngine::updateState()

Reimplemented from QwtNullPaintDevice.

Definition at line 1081 of file qwt_graphic.cpp.

◆ widthForHeight()

qreal QwtGraphic::widthForHeight ( qreal  height) const

Find the width for a given height

The width is calculated using the aspect ratio of defaultSize().

Parameters
heightHeight
Returns
Calculated width
See also
defaultSize()

Definition at line 611 of file qwt_graphic.cpp.

Member Data Documentation

◆ m_data

PrivateData* QwtGraphic::m_data
private

Definition at line 196 of file qwt_graphic.h.


The documentation for this class was generated from the following files:


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Aug 11 2024 02:24:29