qwt_plot_glcanvas.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_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 )
58  , QwtPlotAbstractGLCanvas( this )
59 {
60  init();
61 }
70  : QGLWidget( format, plot )
71  , QwtPlotAbstractGLCanvas( this )
72 {
73  init();
74 }
75 
78 {
79  delete m_data;
80 }
81 
83 {
84  m_data = new PrivateData;
85 
86 #if 1
87  setAttribute( Qt::WA_OpaquePaintEvent, true );
88 #endif
89  setLineWidth( 2 );
90  setFrameShadow( QFrame::Sunken );
91  setFrameShape( QFrame::Panel );
92 }
93 
100 void QwtPlotGLCanvas::paintEvent( QPaintEvent* event )
101 {
102  QGLWidget::paintEvent( event );
103 }
104 
111 {
112  const bool ok = QGLWidget::event( event );
113 
114  if ( event->type() == QEvent::PolishRequest ||
115  event->type() == QEvent::StyleChange )
116  {
117  // assuming, that we always have a styled background
118  // when we have a style sheet
119 
120  setAttribute( Qt::WA_StyledBackground,
121  testAttribute( Qt::WA_StyleSheet ) );
122  }
123 
124  return ok;
125 }
126 
132 {
134 }
135 
138 {
139  m_data->fboDirty = true;
140 }
141 
143 {
144  delete m_data->fbo;
145  m_data->fbo = NULL;
146 }
147 
157 QPainterPath QwtPlotGLCanvas::borderPath( const QRect& rect ) const
158 {
159  return canvasBorderPath( rect );
160 }
161 
164 {
165 }
166 
169 {
170  const bool hasFocusIndicator =
171  hasFocus() && focusIndicator() == CanvasFocusIndicator;
172 
173  QPainter painter;
174 
176  {
177  const qreal pixelRatio = QwtPainter::devicePixelRatio( NULL );
178  const QRect rect( 0, 0, width() * pixelRatio, height() * pixelRatio );
179 
180  if ( hasFocusIndicator )
181  painter.begin( this );
182 
183  if ( m_data->fbo )
184  {
185  if ( m_data->fbo->size() != rect.size() )
186  {
187  delete m_data->fbo;
188  m_data->fbo = NULL;
189  }
190  }
191 
192  if ( m_data->fbo == NULL )
193  {
194  QGLFramebufferObjectFormat format;
195  format.setSamples( 4 );
196  format.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
197 
198  m_data->fbo = new QGLFramebufferObject( rect.size(), format );
199  m_data->fboDirty = true;
200  }
201 
202  if ( m_data->fboDirty )
203  {
204  QPainter fboPainter( m_data->fbo );
205  fboPainter.scale( pixelRatio, pixelRatio );
206  draw( &fboPainter );
207  fboPainter.end();
208 
209  m_data->fboDirty = false;
210  }
211 
212  /*
213  Why do we have this strange translation - but, anyway
214  QwtPlotGLCanvas in combination with scaling factor
215  is not very likely to happen as using QwtPlotOpenGLCanvas
216  usually makes more sense then.
217  */
218 
219  QGLFramebufferObject::blitFramebuffer( NULL,
220  rect.translated( 0, height() - rect.height() ), m_data->fbo, rect );
221  }
222  else
223  {
224  painter.begin( this );
225  draw( &painter );
226  }
227 
228  if ( hasFocusIndicator )
229  drawFocusIndicator( &painter );
230 }
231 
234 {
235  // nothing to do
236 }
237 
238 #if QWT_MOC_INCLUDE
239 #include "moc_qwt_plot_glcanvas.cpp"
240 #endif
Paint double buffered reusing the content of the pixmap buffer when possible.
QPainterPath canvasBorderPath(const QRect &rect) const
virtual void clearBackingStore() QWT_OVERRIDE
void draw(QPainter *)
Helper function for the derived plot canvas.
virtual ~QwtPlotGLCanvas()
Destructor.
A 2-D plotting widget.
Definition: qwt_plot.h:78
virtual void resizeGL(int width, int height) QWT_OVERRIDE
No operation - reserved for some potential use in the future.
bool testPaintAttribute(PaintAttribute) const
virtual Q_INVOKABLE void invalidateBackingStore() QWT_OVERRIDE
Invalidate the internal backing store.
PrivateData * m_data
Base class of QwtPlotOpenGLCanvas and QwtPlotGLCanvas.
Definition: lz4.c:1706
virtual void paintEvent(QPaintEvent *) QWT_OVERRIDE
static qreal devicePixelRatio(const QPaintDevice *)
FocusIndicator focusIndicator() const
virtual void paintGL() QWT_OVERRIDE
Paint the plot.
QGLFramebufferObject * fbo
QwtPlot * plot()
Return parent plot widget.
virtual bool event(QEvent *) QWT_OVERRIDE
QwtPlotGLCanvas(QwtPlot *=NULL)
Constructor.
virtual void drawFocusIndicator(QPainter *)
Q_INVOKABLE QPainterPath borderPath(const QRect &) const
virtual void initializeGL() QWT_OVERRIDE
No operation - reserved for some potential use in the future.
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)
Definition: color.h:583


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:01:38