10 #include "qwt_plot_directpainter.h"
11 #include "qwt_scale_map.h"
13 #include "qwt_plot_canvas.h"
14 #include "qwt_plot_seriesitem.h"
20 static inline void qwtRenderItem(
21 QPainter* painter,
const QRect& canvasRect,
31 painter->setRenderHint( QPainter::Antialiasing,
33 seriesItem->
drawSeries( painter, xMap, yMap, canvasRect, from, to );
36 static inline bool qwtHasBackingStore(
const QwtPlotCanvas* canvas )
42 class QwtPlotDirectPainter::PrivateData
69 m_data =
new PrivateData;
88 if (
bool( m_data->attributes & attribute ) != on )
91 m_data->attributes |= attribute;
93 m_data->attributes &= ~attribute;
107 return m_data->attributes & attribute;
118 m_data->hasClipping = enable;
127 return m_data->hasClipping;
143 m_data->clipRegion = region;
144 m_data->hasClipping =
true;
153 return m_data->clipRegion;
175 if ( seriesItem == NULL || seriesItem->
plot() == NULL )
178 QWidget* canvas = seriesItem->
plot()->
canvas();
179 const QRect canvasRect = canvas->contentsRect();
181 QwtPlotCanvas* plotCanvas = qobject_cast< QwtPlotCanvas* >( canvas );
183 if ( plotCanvas && qwtHasBackingStore( plotCanvas ) )
185 QPainter painter(
const_cast< QPixmap*
>( plotCanvas->
backingStore() ) );
187 if ( m_data->hasClipping )
188 painter.setClipRegion( m_data->clipRegion );
190 qwtRenderItem( &painter, canvasRect, seriesItem, from, to );
196 plotCanvas->repaint();
201 bool immediatePaint =
true;
202 if ( !canvas->testAttribute( Qt::WA_WState_InPaintEvent ) )
204 #if QT_VERSION < 0x050000
205 if ( !canvas->testAttribute( Qt::WA_PaintOutsidePaintEvent ) )
207 immediatePaint =
false;
210 if ( immediatePaint )
212 if ( !m_data->painter.isActive() )
216 m_data->painter.begin( canvas );
217 canvas->installEventFilter(
this );
220 if ( m_data->hasClipping )
222 m_data->painter.setClipRegion(
223 QRegion( canvasRect ) & m_data->clipRegion );
227 if ( !m_data->painter.hasClipping() )
228 m_data->painter.setClipRect( canvasRect );
231 qwtRenderItem( &m_data->painter, canvasRect, seriesItem, from, to );
239 if ( m_data->hasClipping )
240 m_data->painter.setClipping(
false );
247 m_data->seriesItem = seriesItem;
252 if ( m_data->hasClipping )
255 canvas->installEventFilter(
this );
257 canvas->removeEventFilter(
this );
259 m_data->seriesItem = NULL;
266 if ( m_data->painter.isActive() )
268 QWidget* w =
static_cast< QWidget*
>( m_data->painter.device() );
270 w->removeEventFilter(
this );
272 m_data->painter.end();
279 if ( event->type() == QEvent::Paint )
283 if ( m_data->seriesItem )
285 const QPaintEvent* pe =
static_cast< QPaintEvent*
>( event );
287 QWidget* canvas = m_data->seriesItem->plot()->canvas();
289 QPainter painter( canvas );
290 painter.setClipRegion( pe->region() );
297 qobject_cast< QwtPlotCanvas* >( canvas );
300 doCopyCache = qwtHasBackingStore( plotCanvas );
303 painter.drawPixmap( plotCanvas->rect().topLeft(),
311 qwtRenderItem( &painter, canvas->contentsRect(),
312 m_data->seriesItem, m_data->from, m_data->to );
bool testPaintAttribute(PaintAttribute) const
@ BackingStore
Paint double buffered reusing the content of the pixmap buffer when possible.
const QPixmap * backingStore() const
void setClipRegion(const QRegion &)
Assign a clip region and enable clipping.
Attribute
Paint attributes.
void setAttribute(Attribute, bool on)
QFlags< Attribute > Attributes
bool testAttribute(Attribute) const
QRegion clipRegion() const
void reset()
Close the internal QPainter.
virtual ~QwtPlotDirectPainter()
Destructor.
void drawSeries(QwtPlotSeriesItem *, int from, int to)
Draw a set of points of a seriesItem.
virtual bool eventFilter(QObject *, QEvent *) override
Event filter.
QwtPlotDirectPainter(QObject *parent=NULL)
Constructor.
virtual QwtScaleMap canvasMap(QwtAxisId) const
QwtAxisId yAxis() const
Return yAxis.
QwtPlot * plot() const
Return attached plot.
QwtAxisId xAxis() const
Return xAxis.
@ RenderAntialiased
Enable antialiasing.
bool testRenderHint(RenderHint) const
Base class for plot items representing a series of samples.
virtual void drawSeries(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const =0