Qwt User's Guide 6.3.0
Loading...
Searching...
No Matches
qwt_plot_graphicitem.cpp
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
10#include "qwt_plot_graphicitem.h"
11#include "qwt_scale_map.h"
12#include "qwt_painter.h"
13#include "qwt_text.h"
14#include "qwt_graphic.h"
15
16class QwtPlotGraphicItem::PrivateData
17{
18 public:
19 QRectF boundingRect;
20 QwtGraphic graphic;
21};
22
33 : QwtPlotItem( QwtText( title ) )
34{
35 init();
36}
37
48 : QwtPlotItem( title )
49{
50 init();
51}
52
55{
56 delete m_data;
57}
58
59void QwtPlotGraphicItem::init()
60{
61 m_data = new PrivateData();
62 m_data->boundingRect = QwtPlotItem::boundingRect();
63
66
67 setZ( 8.0 );
68}
69
75
83 const QRectF& rect, const QwtGraphic& graphic )
84{
85 m_data->boundingRect = rect;
86 m_data->graphic = graphic;
87
90}
91
97{
98 return m_data->graphic;
99}
100
103{
104 return m_data->boundingRect;
105}
106
115void QwtPlotGraphicItem::draw( QPainter* painter,
116 const QwtScaleMap& xMap, const QwtScaleMap& yMap,
117 const QRectF& canvasRect ) const
118{
119 if ( m_data->graphic.isEmpty() )
120 return;
121
122 QRectF r = QwtScaleMap::transform( xMap, yMap, boundingRect() );
123
124 if ( !r.intersects( canvasRect ) )
125 return;
126
127 if ( QwtPainter::roundingAlignment( painter ) )
128 {
129 r.setLeft ( qRound( r.left() ) );
130 r.setRight ( qRound( r.right() ) );
131 r.setTop ( qRound( r.top() ) );
132 r.setBottom ( qRound( r.bottom() ) );
133 }
134
135 m_data->graphic.render( painter, r );
136}
A paint device for scalable graphics.
Definition qwt_graphic.h:76
bool isEmpty() const
void render(QPainter *) const
Replay all recorded painter commands.
static bool roundingAlignment()
void setGraphic(const QRectF &rect, const QwtGraphic &)
virtual ~QwtPlotGraphicItem()
Destructor.
QwtGraphic graphic() const
virtual QRectF boundingRect() const override
Bounding rectangle of the item.
QwtPlotGraphicItem(const QString &title=QString())
Constructor.
virtual void draw(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const override
virtual int rtti() const override
Base class for items on the plot canvas.
virtual void legendChanged()
void setZ(double z)
Set the z value.
void setItemAttribute(ItemAttribute, bool on=true)
@ Rtti_PlotGraphic
For QwtPlotGraphicItem, QwtPlotSvgItem.
virtual void itemChanged()
@ Legend
The item is represented on the legend.
virtual QRectF boundingRect() const
A scale map.
double transform(double s) const
A class representing a text.
Definition qwt_text.h:52