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 <qevent.h>
13 #include <qglframebufferobject.h>
14 
16 {
17 public:
19  fboDirty( true ),
20  fbo( NULL )
21  {
22  }
23 
25  {
26  delete fbo;
27  }
28 
29  bool fboDirty;
30  QGLFramebufferObject* fbo;
31 };
32 
33 class QwtPlotGLCanvasFormat: public QGLFormat
34 {
35 public:
37  QGLFormat( QGLFormat::defaultFormat() )
38  {
39  setSampleBuffers( true );
40  }
41 };
42 
50  QGLWidget( QwtPlotGLCanvasFormat(), plot ),
52 {
53  d_data = new PrivateData;
54 #if 1
55  setAttribute( Qt::WA_OpaquePaintEvent, true );
56 #endif
57 }
58 
59 QwtPlotGLCanvas::QwtPlotGLCanvas( const QGLFormat &format, QwtPlot *plot ):
60  QGLWidget( format, plot ),
62 {
63  d_data = new PrivateData;
64 #if 1
65  setAttribute( Qt::WA_OpaquePaintEvent, true );
66 #endif
67 }
68 
71 {
72  delete d_data;
73 }
74 
81 void QwtPlotGLCanvas::paintEvent( QPaintEvent *event )
82 {
83  QGLWidget::paintEvent( event );
84 }
85 
92 {
93  const bool ok = QGLWidget::event( event );
94 
95  if ( event->type() == QEvent::PolishRequest ||
96  event->type() == QEvent::StyleChange )
97  {
98  // assuming, that we always have a styled background
99  // when we have a style sheet
100 
101  setAttribute( Qt::WA_StyledBackground,
102  testAttribute( Qt::WA_StyleSheet ) );
103  }
104 
105  return ok;
106 }
107 
109 {
111 }
112 
114 {
115  d_data->fboDirty = true;
116 }
117 
119 {
120  delete d_data->fbo;
121  d_data->fbo = NULL;
122 }
123 
124 QPainterPath QwtPlotGLCanvas::borderPath( const QRect &rect ) const
125 {
126  return borderPath2( rect );
127 }
128 
130 {
131 }
132 
134 {
135  const bool hasFocusIndicator =
136  hasFocus() && focusIndicator() == CanvasFocusIndicator;
137 
138  QPainter painter;
139 
140 #if QT_VERSION < 0x040600
141  painter.begin( this );
142  draw( &painter );
143 #else
145  {
146  if ( hasFocusIndicator )
147  painter.begin( this );
148 
149  const QRect rect(0, 0, width(), height());
150 
151  if ( d_data->fbo && d_data->fbo->size() != size() )
152  {
153  delete d_data->fbo;
154  d_data->fbo = NULL;
155  }
156 
157  if ( d_data->fbo == NULL || d_data->fbo->size() != size() )
158  {
159  QGLFramebufferObjectFormat format;
160  format.setSamples( 4 );
161  format.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
162 
163  d_data->fbo = new QGLFramebufferObject( size(), format );
164  d_data->fboDirty = true;
165  }
166 
167  if ( d_data->fboDirty )
168  {
169  QPainter fboPainter( d_data->fbo );
170  draw( &fboPainter);
171  fboPainter.end();
172 
173  d_data->fboDirty = false;
174  }
175 
176  QGLFramebufferObject::blitFramebuffer( NULL, rect, d_data->fbo, rect );
177  }
178  else
179  {
180  painter.begin( this );
181  draw( &painter );
182  }
183 #endif
184 
185  if ( hasFocusIndicator )
186  drawFocusIndicator( &painter );
187 }
188 
190 {
191  // nothing to do
192 }
Paint double buffered reusing the content of the pixmap buffer when possible.
virtual ~QwtPlotGLCanvas()
Destructor.
bool testPaintAttribute(PaintAttribute) const
virtual void clearBackingStore()
virtual Q_INVOKABLE void invalidateBackingStore()
FocusIndicator focusIndicator() const
A 2-D plotting widget.
Definition: qwt_plot.h:74
virtual void initializeGL()
virtual void paintEvent(QPaintEvent *)
virtual void resizeGL(int width, int height)
virtual void paintGL()
Q_INVOKABLE QPainterPath borderPath(const QRect &) const
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 bool event(QEvent *)
QGLFramebufferObject * fbo
QwtPlot * plot()
Return parent plot widget.
QwtPlotGLCanvas(QwtPlot *=NULL)
Constructor.
virtual void drawFocusIndicator(QPainter *)
PrivateData * d_data


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