A paint device for scalable graphics. More...
#include <qwt_graphic.h>
Classes | |
class | PathInfo |
class | PrivateData |
Public Types | |
enum | RenderHint { RenderPensUnscaled = 0x1 } |
typedef QFlags< RenderHint > | RenderHints |
Render hints. More... | |
Public Types inherited from QwtNullPaintDevice | |
enum | Mode { NormalMode, PolygonPathMode, PathMode } |
Render mode. More... | |
Public Member Functions | |
QRectF | boundingRect () const |
const QVector< QwtPainterCommand > & | commands () const |
QRectF | controlPointRect () const |
QSizeF | defaultSize () const |
Default size. More... | |
bool | isEmpty () const |
bool | isNull () const |
QwtGraphic & | operator= (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 QSizeF &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio) 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 QPointF &, Qt::Alignment=Qt::AlignTop|Qt::AlignLeft) const |
Replay all recorded painter commands. More... | |
void | reset () |
Clear all stored commands. More... | |
QRectF | scaledBoundingRect (double sx, double sy) const |
Calculate the target rectangle for scaling the graphic. More... | |
void | setCommands (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 |
Convert the graphic to a QImage. More... | |
QImage | toImage (const QSize &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio) const |
Convert the graphic to a QImage. More... | |
QPixmap | toPixmap () const |
Convert the graphic to a QPixmap. More... | |
QPixmap | toPixmap (const QSize &, Qt::AspectRatioMode=Qt::IgnoreAspectRatio) const |
Convert the graphic to a QPixmap. More... | |
virtual | ~QwtGraphic () |
Destructor. More... | |
Public Member Functions inherited from QwtNullPaintDevice | |
virtual void | drawEllipse (const QRectF &) |
See QPaintEngine::drawEllipse() More... | |
virtual void | drawEllipse (const QRect &) |
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 QPointF *, int) |
See QPaintEngine::drawPoints() More... | |
virtual void | drawPoints (const QPoint *, int) |
See QPaintEngine::drawPoints() More... | |
virtual void | drawPolygon (const QPointF *, int, QPaintEngine::PolygonDrawMode) |
See QPaintEngine::drawPolygon() More... | |
virtual void | drawPolygon (const QPoint *, 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 &s) |
See QPaintEngine::drawTiledPixmap() More... | |
virtual int | metric (PaintDeviceMetric metric) const |
Mode | mode () const |
virtual QPaintEngine * | paintEngine () const |
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) |
Store a image command in the command list. More... | |
virtual void | drawPath (const QPainterPath &) |
virtual void | drawPixmap (const QRectF &, const QPixmap &, const QRectF &) |
Store a pixmap command in the command list. More... | |
virtual QSize | sizeMetrics () const |
virtual void | updateState (const QPaintEngineState &state) |
Store a state command in the command list. More... | |
Private Member Functions | |
void | updateBoundingRect (const QRectF &) |
void | updateControlPointRect (const QRectF &) |
Private Attributes | |
PrivateData * | d_data |
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.
Definition at line 74 of file qwt_graphic.h.
typedef QFlags<RenderHint> QwtGraphic::RenderHints |
Render hints.
The default setting is to disable all hints
Definition at line 103 of file qwt_graphic.h.
Hint how to render a graphic
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.
|
Definition at line 81 of file qwt_graphic.h.
QwtGraphic::QwtGraphic | ( | ) |
Constructor.
Initializes a null graphic
Definition at line 344 of file qwt_graphic.cpp.
QwtGraphic::QwtGraphic | ( | const QwtGraphic & | other | ) |
Copy constructor.
other | Source |
Definition at line 357 of file qwt_graphic.cpp.
|
virtual |
Destructor.
Definition at line 365 of file qwt_graphic.cpp.
QRectF QwtGraphic::boundingRect | ( | ) | const |
The bounding rectangle is the controlPointRect() extended by the areas needed for rendering the outlines with unscaled pens.
Definition at line 453 of file qwt_graphic.cpp.
const QVector< QwtPainterCommand > & QwtGraphic::commands | ( | ) | const |
Definition at line 980 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.
Definition at line 469 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.
Definition at line 551 of file qwt_graphic.cpp.
|
protectedvirtual |
Store a image command in the command list.
rect | traget rectangle |
image | Image to be painted |
subRect | Reactangle of the pixmap to be painted |
flags | Image conversion flags |
Reimplemented from QwtNullPaintDevice.
Definition at line 923 of file qwt_graphic.cpp.
|
protectedvirtual |
Store a path command in the command list
path | Painter path |
Reimplemented from QwtNullPaintDevice.
Definition at line 861 of file qwt_graphic.cpp.
|
protectedvirtual |
Store a pixmap command in the command list.
rect | target rectangle |
pixmap | Pixmap to be painted |
subRect | Reactangle of the pixmap to be painted |
Reimplemented from QwtNullPaintDevice.
Definition at line 899 of file qwt_graphic.cpp.
bool QwtGraphic::isEmpty | ( | ) | const |
Definition at line 412 of file qwt_graphic.cpp.
bool QwtGraphic::isNull | ( | ) | const |
Definition at line 403 of file qwt_graphic.cpp.
QwtGraphic & QwtGraphic::operator= | ( | const QwtGraphic & | other | ) |
Assignment operator.
other | Source |
Definition at line 376 of file qwt_graphic.cpp.
void QwtGraphic::render | ( | QPainter * | painter | ) | const |
Replay all recorded painter commands.
painter | Qt painter |
Definition at line 563 of file qwt_graphic.cpp.
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 ).
painter | Qt painter |
size | Size for the scaled graphic |
aspectRatioMode | Mode how to scale - See Qt::AspectRatioMode |
Definition at line 594 of file qwt_graphic.cpp.
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
painter | Qt painter |
rect | Rectangle for the scaled graphic |
aspectRatioMode | Mode how to scale - See Qt::AspectRatioMode |
Definition at line 610 of file qwt_graphic.cpp.
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.
painter | Qt painter |
pos | Reference point, where to render |
alignment | Flags how to align the target rectangle to pos. |
Definition at line 695 of file qwt_graphic.cpp.
void QwtGraphic::reset | ( | ) |
QRectF QwtGraphic::scaledBoundingRect | ( | double | sx, |
double | sy | ||
) | const |
Calculate the target rectangle for scaling the graphic.
sx | Horizontal scaling factor |
sy | Vertical scaling factor |
Definition at line 490 of file qwt_graphic.cpp.
void QwtGraphic::setCommands | ( | QVector< QwtPainterCommand > & | commands | ) |
Append paint commands.
commands | Paint commands |
Definition at line 991 of file qwt_graphic.cpp.
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.
size | Default size |
Definition at line 530 of file qwt_graphic.cpp.
void QwtGraphic::setRenderHint | ( | RenderHint | hint, |
bool | on = true |
||
) |
Toggle an render hint
hint | Render hint |
on | true/false |
Definition at line 425 of file qwt_graphic.cpp.
|
protectedvirtual |
Implements QwtNullPaintDevice.
Definition at line 510 of file qwt_graphic.cpp.
bool QwtGraphic::testRenderHint | ( | RenderHint | hint | ) | const |
Test a render hint
hint | Render hint |
Definition at line 440 of file qwt_graphic.cpp.
QImage QwtGraphic::toImage | ( | ) | 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.
Definition at line 833 of file qwt_graphic.cpp.
QImage QwtGraphic::toImage | ( | const QSize & | size, |
Qt::AspectRatioMode | aspectRatioMode = Qt::IgnoreAspectRatio |
||
) | 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.
size | Size of the image |
aspectRatioMode | Aspect ratio how to scale the graphic |
Definition at line 804 of file qwt_graphic.cpp.
QPixmap QwtGraphic::toPixmap | ( | ) | 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.
Definition at line 741 of file qwt_graphic.cpp.
QPixmap QwtGraphic::toPixmap | ( | const QSize & | size, |
Qt::AspectRatioMode | aspectRatioMode = Qt::IgnoreAspectRatio |
||
) | 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.
size | Size of the image |
aspectRatioMode | Aspect ratio how to scale the graphic |
Definition at line 775 of file qwt_graphic.cpp.
|
private |
Definition at line 949 of file qwt_graphic.cpp.
|
private |
Definition at line 968 of file qwt_graphic.cpp.
|
protectedvirtual |
Store a state command in the command list.
state | State to be stored |
Reimplemented from QwtNullPaintDevice.
Definition at line 944 of file qwt_graphic.cpp.
|
private |
Definition at line 169 of file qwt_graphic.h.