qwt_plot_glcanvas.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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_glcanvas.h"
11 #include "qwt_plot.h"
12 #include "qwt_painter.h"
13 
14 #include <qcoreevent.h>
15 #include <qpainter.h>
16 #include <qpainterpath.h>
17 #include <qglframebufferobject.h>
18 
19 namespace
20 {
21  class QwtPlotGLCanvasFormat: public QGLFormat
22  {
23  public:
24  QwtPlotGLCanvasFormat():
25  QGLFormat( QGLFormat::defaultFormat() )
26  {
27  setSampleBuffers( true );
28  }
29  };
30 }
31 
33 {
34 public:
36  fboDirty( true ),
37  fbo( NULL )
38  {
39  }
40 
42  {
43  delete fbo;
44  }
45 
46  bool fboDirty;
47  QGLFramebufferObject* fbo;
48 };
49 
57  QGLWidget( QwtPlotGLCanvasFormat(), plot ),
59 {
60  d_data = new PrivateData;
61 #if 1
62  setAttribute( Qt::WA_OpaquePaintEvent, true );
63 #endif
64 }
65 
67  QGLWidget( format, plot ),
69 {
70  d_data = new PrivateData;
71 #if 1
72  setAttribute( Qt::WA_OpaquePaintEvent, true );
73 #endif
74 }
75 
78 {
79  delete d_data;
80 }
81 
88 void QwtPlotGLCanvas::paintEvent( QPaintEvent *event )
89 {
90  QGLWidget::paintEvent( event );
91 }
92 
99 {
100  const bool ok = QGLWidget::event( event );
101 
102  if ( event->type() == QEvent::PolishRequest ||
103  event->type() == QEvent::StyleChange )
104  {
105  // assuming, that we always have a styled background
106  // when we have a style sheet
107 
108  setAttribute( Qt::WA_StyledBackground,
109  testAttribute( Qt::WA_StyleSheet ) );
110  }
111 
112  return ok;
113 }
114 
116 {
118 }
119 
121 {
122  d_data->fboDirty = true;
123 }
124 
126 {
127  delete d_data->fbo;
128  d_data->fbo = NULL;
129 }
130 
131 QPainterPath QwtPlotGLCanvas::borderPath( const QRect &rect ) const
132 {
133  return borderPath2( rect );
134 }
135 
137 {
138 }
139 
141 {
142  const bool hasFocusIndicator =
143  hasFocus() && focusIndicator() == CanvasFocusIndicator;
144 
145  QPainter painter;
146 
148  {
149  const qreal pixelRatio = QwtPainter::devicePixelRatio( NULL );
150  const QRect rect( 0, 0, width() * pixelRatio, height() * pixelRatio );
151 
152  if ( hasFocusIndicator )
153  painter.begin( this );
154 
155  if ( d_data->fbo )
156  {
157  if ( d_data->fbo->size() != rect.size() )
158  {
159  delete d_data->fbo;
160  d_data->fbo = NULL;
161  }
162  }
163 
164  if ( d_data->fbo == NULL )
165  {
166  QGLFramebufferObjectFormat format;
167  format.setSamples( 4 );
168  format.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
169 
170  d_data->fbo = new QGLFramebufferObject( rect.size(), format );
171  d_data->fboDirty = true;
172  }
173 
174  if ( d_data->fboDirty )
175  {
176  QPainter fboPainter( d_data->fbo );
177  fboPainter.scale( pixelRatio, pixelRatio );
178  draw( &fboPainter );
179  fboPainter.end();
180 
181  d_data->fboDirty = false;
182  }
183 
184  /*
185  Why do we have this strange translation - but, anyway
186  QwtPlotGLCanvas in combination with scaling factor
187  is not very likely to happen as using QwtPlotOpenGLCanvas
188  usually makes more sense then.
189  */
190 
191  QGLFramebufferObject::blitFramebuffer( NULL,
192  rect.translated( 0, height() - rect.height() ), d_data->fbo, rect );
193  }
194  else
195  {
196  painter.begin( this );
197  draw( &painter );
198  }
199 
200  if ( hasFocusIndicator )
201  drawFocusIndicator( &painter );
202 }
203 
205 {
206  // nothing to do
207 }
208 
209 #if QWT_MOC_INCLUDE
210 #include "moc_qwt_plot_glcanvas.cpp"
211 #endif
Paint double buffered reusing the content of the pixmap buffer when possible.
virtual void clearBackingStore() QWT_OVERRIDE
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
Definition: core.h:2081
virtual ~QwtPlotGLCanvas()
Destructor.
bool testPaintAttribute(PaintAttribute) const
FocusIndicator focusIndicator() const
A 2-D plotting widget.
Definition: qwt_plot.h:75
virtual void resizeGL(int width, int height) QWT_OVERRIDE
virtual Q_INVOKABLE void invalidateBackingStore() QWT_OVERRIDE
virtual void paintEvent(QPaintEvent *) QWT_OVERRIDE
static qreal devicePixelRatio(const QPaintDevice *)
Q_INVOKABLE QPainterPath borderPath(const QRect &) const
virtual void paintGL() QWT_OVERRIDE
QPainterPath borderPath2(const QRect &rect) const
QGLFramebufferObject * fbo
QwtPlot * plot()
Return parent plot widget.
virtual bool event(QEvent *) QWT_OVERRIDE
QwtPlotGLCanvas(QwtPlot *=NULL)
Constructor.
virtual void drawFocusIndicator(QPainter *)
virtual void initializeGL() QWT_OVERRIDE
PrivateData * d_data


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10