qwt_plot_canvas.cpp
Go to the documentation of this file.
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_canvas.h"
11 #include "qwt_painter.h"
12 #include "qwt_plot.h"
13 
14 #include <qpainter.h>
15 #include <qpainterpath.h>
16 #include <qevent.h>
17 
19 {
20  public:
21  PrivateData()
22  : backingStore( NULL )
23  {
24  }
25 
26  ~PrivateData()
27  {
28  delete backingStore;
29  }
30 
31  QwtPlotCanvas::PaintAttributes paintAttributes;
32  QPixmap* backingStore;
33 };
34 
42  : QFrame( plot )
43  , QwtPlotAbstractCanvas( this )
44 {
45  m_data = new PrivateData;
46 
50 
51  setLineWidth( 2 );
52  setFrameShadow( QFrame::Sunken );
53  setFrameShape( QFrame::Panel );
54 }
55 
58 {
59  delete m_data;
60 }
61 
71 {
72  if ( bool( m_data->paintAttributes & attribute ) == on )
73  return;
74 
75  if ( on )
76  m_data->paintAttributes |= attribute;
77  else
78  m_data->paintAttributes &= ~attribute;
79 
80  switch ( attribute )
81  {
82  case BackingStore:
83  {
84  if ( on )
85  {
86  if ( m_data->backingStore == NULL )
87  m_data->backingStore = new QPixmap();
88 
89  if ( isVisible() )
90  {
91 #if QT_VERSION >= 0x050000
92  *m_data->backingStore = grab( rect() );
93 #else
95  QPixmap::grabWidget( this, rect() );
96 #endif
97  }
98  }
99  else
100  {
101  delete m_data->backingStore;
102  m_data->backingStore = NULL;
103  }
104  break;
105  }
106  case Opaque:
107  {
108  if ( on )
109  setAttribute( Qt::WA_OpaquePaintEvent, true );
110 
111  break;
112  }
113  default:
114  {
115  break;
116  }
117  }
118 }
119 
128 {
129  return m_data->paintAttributes & attribute;
130 }
131 
133 const QPixmap* QwtPlotCanvas::backingStore() const
134 {
135  return m_data->backingStore;
136 }
137 
140 {
141  if ( m_data->backingStore )
142  *m_data->backingStore = QPixmap();
143 }
144 
151 bool QwtPlotCanvas::event( QEvent* event )
152 {
153  if ( event->type() == QEvent::PolishRequest )
154  {
156  {
157  // Setting a style sheet changes the
158  // Qt::WA_OpaquePaintEvent attribute, but we insist
159  // on painting the background.
160 
161  setAttribute( Qt::WA_OpaquePaintEvent, true );
162  }
163  }
164 
165  if ( event->type() == QEvent::PolishRequest ||
166  event->type() == QEvent::StyleChange )
167  {
169  }
170 
171  return QFrame::event( event );
172 }
173 
178 void QwtPlotCanvas::paintEvent( QPaintEvent* event )
179 {
180  QPainter painter( this );
181  painter.setClipRegion( event->region() );
182 
184  m_data->backingStore != NULL )
185  {
186  QPixmap& bs = *m_data->backingStore;
187  if ( bs.size() != size() * QwtPainter::devicePixelRatio( &bs ) )
188  {
189  bs = QwtPainter::backingStore( this, size() );
190 
191  if ( testAttribute(Qt::WA_StyledBackground) )
192  {
193  QPainter p( &bs );
195  }
196  else
197  {
198  QPainter p;
199  if ( borderRadius() <= 0.0 )
200  {
201  QwtPainter::fillPixmap( this, bs );
202  p.begin( &bs );
203  drawCanvas( &p );
204  }
205  else
206  {
207  p.begin( &bs );
208  drawUnstyled( &p );
209  }
210 
211  if ( frameWidth() > 0 )
212  drawBorder( &p );
213  }
214  }
215 
216  painter.drawPixmap( 0, 0, *m_data->backingStore );
217  }
218  else
219  {
220  if ( testAttribute(Qt::WA_StyledBackground ) )
221  {
222  if ( testAttribute( Qt::WA_OpaquePaintEvent ) )
223  {
225  }
226  else
227  {
228  drawCanvas( &painter );
229  }
230  }
231  else
232  {
233  if ( testAttribute( Qt::WA_OpaquePaintEvent ) )
234  {
235  if ( autoFillBackground() )
236  {
237  fillBackground( &painter );
238  drawBackground( &painter );
239  }
240  }
241  else
242  {
243  if ( borderRadius() > 0.0 )
244  {
245  QPainterPath clipPath;
246  clipPath.addRect( rect() );
247  clipPath = clipPath.subtracted( borderPath( rect() ) );
248 
249  painter.save();
250 
251  painter.setClipPath( clipPath, Qt::IntersectClip );
252  fillBackground( &painter );
253  drawBackground( &painter );
254 
255  painter.restore();
256  }
257  }
258 
259  drawCanvas( &painter );
260 
261  if ( frameWidth() > 0 )
262  drawBorder( &painter );
263  }
264  }
265 
266  if ( hasFocus() && focusIndicator() == CanvasFocusIndicator )
267  drawFocusIndicator( &painter );
268 }
269 
276 void QwtPlotCanvas::drawBorder( QPainter* painter )
277 {
278  if ( borderRadius() <= 0 )
279  {
280  drawFrame( painter );
281  return;
282  }
283 
285 }
286 
291 void QwtPlotCanvas::resizeEvent( QResizeEvent* event )
292 {
293  QFrame::resizeEvent( event );
295 }
296 
302 {
304 
306  repaint( contentsRect() );
307  else
308  update( contentsRect() );
309 }
310 
320 QPainterPath QwtPlotCanvas::borderPath( const QRect& rect ) const
321 {
322  return canvasBorderPath( rect );
323 }
324 
325 #if QWT_MOC_INCLUDE
326 #include "moc_qwt_plot_canvas.cpp"
327 #endif
QwtPlotCanvas::HackStyledBackground
@ HackStyledBackground
Try to improve painting of styled backgrounds.
Definition: qwt_plot_canvas.h:91
QwtPlotAbstractCanvas::updateStyleSheetInfo
void updateStyleSheetInfo()
Update the cached information about the current style sheet.
Definition: qwt_plot_abstract_canvas.cpp:835
QwtPlotCanvas::PrivateData::~PrivateData
~PrivateData()
Definition: qwt_plot_canvas.cpp:33
QwtPlotCanvas::event
virtual bool event(QEvent *) QWT_OVERRIDE
Definition: qwt_plot_canvas.cpp:151
QwtPlotCanvas::invalidateBackingStore
Q_INVOKABLE void invalidateBackingStore()
Invalidate the internal backing store.
Definition: qwt_plot_canvas.cpp:139
QwtPlotCanvas::QwtPlotCanvas
QwtPlotCanvas(QwtPlot *=NULL)
Constructor.
Definition: qwt_plot_canvas.cpp:41
QwtPlotAbstractCanvas::drawBorder
virtual void drawBorder(QPainter *)
Definition: qwt_plot_abstract_canvas.cpp:628
QwtPlotAbstractCanvas::CanvasFocusIndicator
@ CanvasFocusIndicator
Definition: qwt_plot_abstract_canvas.h:39
QwtPlotCanvas::drawBorder
virtual void drawBorder(QPainter *) QWT_OVERRIDE
Definition: qwt_plot_canvas.cpp:276
QwtPlot
A 2-D plotting widget.
Definition: qwt_plot.h:78
QwtPlotCanvas::BackingStore
@ BackingStore
Paint double buffered reusing the content of the pixmap buffer when possible.
Definition: qwt_plot_canvas.h:57
QwtPlotAbstractCanvas::canvasBorderPath
QPainterPath canvasBorderPath(const QRect &rect) const
Definition: qwt_plot_abstract_canvas.cpp:619
QwtPlotAbstractCanvas::drawFocusIndicator
virtual void drawFocusIndicator(QPainter *)
Definition: qwt_plot_abstract_canvas.cpp:587
QwtPlotCanvas::setPaintAttribute
void setPaintAttribute(PaintAttribute, bool on=true)
Changing the paint attributes.
Definition: qwt_plot_canvas.cpp:70
QwtPainter::fillPixmap
static void fillPixmap(const QWidget *, QPixmap &, const QPoint &offset=QPoint())
Definition: qwt_painter.cpp:1311
nonstd::span_lite::size
span_constexpr std::size_t size(span< T, Extent > const &spn)
Definition: span.hpp:1554
QwtPlotCanvas::m_data
PrivateData * m_data
Definition: qwt_plot_canvas.h:127
QwtPlotCanvas::replot
void replot()
Definition: qwt_plot_canvas.cpp:301
QwtPlotCanvas::~QwtPlotCanvas
virtual ~QwtPlotCanvas()
Destructor.
Definition: qwt_plot_canvas.cpp:57
update
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
QwtPlotAbstractCanvas::fillBackground
void fillBackground(QPainter *)
Helper function for the derived plot canvas.
Definition: qwt_plot_abstract_canvas.cpp:696
QwtPlotAbstractCanvas::drawUnstyled
void drawUnstyled(QPainter *)
Helper function for the derived plot canvas.
Definition: qwt_plot_abstract_canvas.cpp:702
QwtPainter::backingStore
static QPixmap backingStore(QWidget *, const QSize &)
Definition: qwt_painter.cpp:1525
QwtPlotAbstractCanvas::drawCanvas
void drawCanvas(QPainter *)
Draw the plot to the canvas.
Definition: qwt_plot_abstract_canvas.cpp:803
QwtPlotCanvas::borderPath
Q_INVOKABLE QPainterPath borderPath(const QRect &) const
Definition: qwt_plot_canvas.cpp:320
QwtPlotAbstractCanvas::focusIndicator
FocusIndicator focusIndicator() const
Definition: qwt_plot_abstract_canvas.cpp:578
QwtPlotCanvas::resizeEvent
virtual void resizeEvent(QResizeEvent *) QWT_OVERRIDE
Definition: qwt_plot_canvas.cpp:291
QwtPlotAbstractCanvas::drawStyled
void drawStyled(QPainter *, bool)
Helper function for the derived plot canvas.
Definition: qwt_plot_abstract_canvas.cpp:744
QwtPlotCanvas::PaintAttribute
PaintAttribute
Paint attributes.
Definition: qwt_plot_canvas.h:44
qwt_painter.h
QwtPlotCanvas::backingStore
const QPixmap * backingStore() const
Definition: qwt_plot_canvas.cpp:133
QwtPlotAbstractCanvas::drawBackground
virtual void drawBackground(QPainter *)
Helper function for the derived plot canvas.
Definition: qwt_plot_abstract_canvas.cpp:690
qwt_plot_canvas.h
QwtPlotCanvas::PrivateData::paintAttributes
QwtPlotCanvas::PaintAttributes paintAttributes
Definition: qwt_plot_canvas.cpp:38
QwtPlotCanvas::PrivateData::PrivateData
PrivateData()
Definition: qwt_plot_canvas.cpp:28
QwtPlotCanvas::ImmediatePaint
@ ImmediatePaint
Definition: qwt_plot_canvas.h:99
QwtPlotCanvas::PrivateData
Definition: qwt_plot_canvas.cpp:18
QwtPainter::devicePixelRatio
static qreal devicePixelRatio(const QPaintDevice *)
Definition: qwt_painter.cpp:1491
QwtPlotCanvas::PrivateData::backingStore
QPixmap * backingStore
Definition: qwt_plot_canvas.cpp:39
QwtPlotCanvas::paintEvent
virtual void paintEvent(QPaintEvent *) QWT_OVERRIDE
Definition: qwt_plot_canvas.cpp:178
QwtPlotCanvas::Opaque
@ Opaque
Try to fill the complete contents rectangle of the plot canvas.
Definition: qwt_plot_canvas.h:74
QwtPlotCanvas::borderRadius
double borderRadius
Definition: qwt_plot_canvas.h:33
QwtPlotAbstractCanvas
Base class for all type of plot canvases.
Definition: qwt_plot_abstract_canvas.h:21
qwt_plot.h
QwtPlotCanvas::testPaintAttribute
bool testPaintAttribute(PaintAttribute) const
Definition: qwt_plot_canvas.cpp:127


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45