qwt_plot_opengl_canvas.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_opengl_canvas.h"
11 #include "qwt_plot.h"
12 #include <qevent.h>
13 #include <qopenglframebufferobject.h>
14 #include <qopenglpaintdevice.h>
15 
17 {
18 public:
20  isPolished( false ),
21  fboDirty( true ),
22  fbo( NULL )
23  {
24  }
25 
27  {
28  delete fbo;
29  }
30 
32 
33  bool isPolished;
34  bool fboDirty;
35  QOpenGLFramebufferObject* fbo;
36 };
37 
38 
46  QOpenGLWidget( plot ),
48 {
49  QSurfaceFormat fmt = format();
50  fmt.setSamples( 4 );
51 
52  init( fmt );
53 }
54 
55 QwtPlotOpenGLCanvas::QwtPlotOpenGLCanvas( const QSurfaceFormat &format, QwtPlot *plot ):
56  QOpenGLWidget( plot ),
58 {
59  init( format );
60 }
61 
62 void QwtPlotOpenGLCanvas::init( const QSurfaceFormat &format )
63 {
64  d_data = new PrivateData;
65  d_data->numSamples = format.samples();
66 
67  setFormat( format );
68 
69 #if 1
70  setAttribute( Qt::WA_OpaquePaintEvent, true );
71 #endif
72 }
73 
76 {
77  delete d_data;
78 }
79 
87 {
88  if ( d_data->isPolished )
89  QOpenGLWidget::paintEvent( event );
90 }
91 
98 {
99  const bool ok = QOpenGLWidget::event( event );
100 
101  if ( event->type() == QEvent::PolishRequest )
102  {
103  // In opposite to non OpenGL widgets receive pointless
104  // early repaints. As we always have a QEvent::PolishRequest
105  // followed by QEvent::Paint, we can ignore all thos repaints.
106 
107  d_data->isPolished = true;
108  }
109 
110  if ( event->type() == QEvent::PolishRequest ||
111  event->type() == QEvent::StyleChange )
112  {
113  // assuming, that we always have a styled background
114  // when we have a style sheet
115 
116  setAttribute( Qt::WA_StyledBackground,
117  testAttribute( Qt::WA_StyleSheet ) );
118  }
119 
120  return ok;
121 }
122 
124 {
126 }
127 
129 {
130  d_data->fboDirty = true;
131 }
132 
134 {
135  delete d_data->fbo;
136  d_data->fbo = NULL;
137 }
138 
139 QPainterPath QwtPlotOpenGLCanvas::borderPath( const QRect &rect ) const
140 {
141  return borderPath2( rect );
142 }
143 
145 {
146 }
147 
149 {
150  const bool hasFocusIndicator =
151  hasFocus() && focusIndicator() == CanvasFocusIndicator;
152 
153  QPainter painter;
154 
156  QOpenGLFramebufferObject::hasOpenGLFramebufferBlit() )
157  {
158  if ( hasFocusIndicator )
159  painter.begin( this );
160 
161  /*
162  QOpenGLWidget has its own internal FBO, that is used to restore
163  its content without having to repaint. This works fine when f.e
164  a rubberband is moving on top, but there are still situations,
165  where we can repaint without an potentially expensive replot:
166 
167  - when having the focus the top level window gets activated/deactivated
168  - ???
169  */
170 
171  if ( d_data->fbo && d_data->fbo->size() != size() )
172  {
173  delete d_data->fbo;
174  d_data->fbo = NULL;
175  }
176 
177  if ( d_data->fbo == NULL )
178  {
179  QOpenGLFramebufferObjectFormat fboFormat;
180  fboFormat.setSamples( d_data->numSamples );
181  fboFormat.setAttachment( QOpenGLFramebufferObject::CombinedDepthStencil );
182 
183  d_data->fbo = new QOpenGLFramebufferObject( size(), fboFormat );
184  d_data->fboDirty = true;
185  }
186 
187  if ( d_data->fboDirty )
188  {
189  d_data->fbo->bind();
190 
191  QOpenGLPaintDevice pd( size() );
192 
193  QPainter fboPainter( &pd );
194  draw( &fboPainter);
195  fboPainter.end();
196 
197  d_data->fboDirty = false;
198  }
199 
200  QOpenGLFramebufferObject::blitFramebuffer( NULL, d_data->fbo );
201  }
202  else
203  {
204  painter.begin( this );
205  draw( &painter );
206  }
207 
208  if ( hasFocusIndicator )
209  drawFocusIndicator( &painter );
210 }
211 
213 {
214  // nothing to do
215 }
Q_INVOKABLE QPainterPath borderPath(const QRect &) const
Paint double buffered reusing the content of the pixmap buffer when possible.
void init(const QSurfaceFormat &)
bool testPaintAttribute(PaintAttribute) const
FocusIndicator focusIndicator() const
A 2-D plotting widget.
Definition: qwt_plot.h:74
virtual ~QwtPlotOpenGLCanvas()
Destructor.
virtual Q_INVOKABLE void invalidateBackingStore()
virtual bool event(QEvent *)
std::string format(const std::string &, const time_point< seconds > &, const femtoseconds &, const time_zone &)
uintptr_t size
QPainterPath borderPath2(const QRect &rect) const
virtual void paintEvent(QPaintEvent *)
QwtPlot * plot()
Return parent plot widget.
virtual void drawFocusIndicator(QPainter *)
QwtPlotOpenGLCanvas(QwtPlot *=NULL)
Constructor.
virtual void resizeGL(int width, int height)


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17