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 
110 bool QwtPlotGLCanvas::event( QEvent* event )
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( this );
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
QwtPlotAbstractGLCanvas::draw
void draw(QPainter *)
Helper function for the derived plot canvas.
Definition: qwt_plot_abstract_canvas.cpp:1112
QwtPlotAbstractGLCanvas::replot
void replot()
Definition: qwt_plot_abstract_canvas.cpp:1093
QwtPlotGLCanvas::PrivateData::~PrivateData
~PrivateData()
Definition: qwt_plot_glcanvas.cpp:41
QwtPlotAbstractGLCanvas
Base class of QwtPlotOpenGLCanvas and QwtPlotGLCanvas.
Definition: qwt_plot_abstract_canvas.h:87
QwtPlotAbstractCanvas::CanvasFocusIndicator
@ CanvasFocusIndicator
Definition: qwt_plot_abstract_canvas.h:39
QwtPlot
A 2-D plotting widget.
Definition: qwt_plot.h:78
QwtPlotGLCanvas::PrivateData::PrivateData
PrivateData()
Definition: qwt_plot_glcanvas.cpp:35
QwtPlotGLCanvas::m_data
PrivateData * m_data
Definition: qwt_plot_glcanvas.h:82
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
ok
ROSCPP_DECL bool ok()
QwtPlotGLCanvas::PrivateData
Definition: qwt_plot_glcanvas.cpp:32
QwtPlotGLCanvas::resizeGL
virtual void resizeGL(int width, int height) QWT_OVERRIDE
No operation - reserved for some potential use in the future.
Definition: qwt_plot_glcanvas.cpp:233
QwtPlotGLCanvas::invalidateBackingStore
virtual Q_INVOKABLE void invalidateBackingStore() QWT_OVERRIDE
Invalidate the internal backing store.
Definition: qwt_plot_glcanvas.cpp:137
QwtPlotGLCanvas::borderPath
Q_INVOKABLE QPainterPath borderPath(const QRect &) const
Definition: qwt_plot_glcanvas.cpp:157
QwtPlotAbstractGLCanvas::testPaintAttribute
bool testPaintAttribute(PaintAttribute) const
Definition: qwt_plot_abstract_canvas.cpp:952
QwtPlotGLCanvas::initializeGL
virtual void initializeGL() QWT_OVERRIDE
No operation - reserved for some potential use in the future.
Definition: qwt_plot_glcanvas.cpp:163
QwtPlotAbstractGLCanvas::BackingStore
@ BackingStore
Paint double buffered reusing the content of the pixmap buffer when possible.
Definition: qwt_plot_abstract_canvas.h:110
qwt_plot_glcanvas.h
QwtPlotGLCanvas::paintEvent
virtual void paintEvent(QPaintEvent *) QWT_OVERRIDE
Definition: qwt_plot_glcanvas.cpp:100
QwtPlotAbstractCanvas::focusIndicator
FocusIndicator focusIndicator() const
Definition: qwt_plot_abstract_canvas.cpp:578
QwtPlotAbstractGLCanvas::setLineWidth
void setLineWidth(int)
Definition: qwt_plot_abstract_canvas.cpp:1033
QwtPlotGLCanvas::PrivateData::fbo
QGLFramebufferObject * fbo
Definition: qwt_plot_glcanvas.cpp:47
format
auto format(const text_style &ts, const S &format_str, const Args &... args) -> std::basic_string< Char >
Definition: color.h:543
QwtPlotAbstractGLCanvas::setFrameShadow
void setFrameShadow(QFrame::Shadow)
Definition: qwt_plot_abstract_canvas.cpp:991
qwt_painter.h
QwtPlotGLCanvas::event
virtual bool event(QEvent *) QWT_OVERRIDE
Definition: qwt_plot_glcanvas.cpp:110
QwtPlotGLCanvas::replot
void replot()
Definition: qwt_plot_glcanvas.cpp:131
QwtPlotGLCanvas::clearBackingStore
virtual void clearBackingStore() QWT_OVERRIDE
Definition: qwt_plot_glcanvas.cpp:142
QwtPlotGLCanvas::paintGL
virtual void paintGL() QWT_OVERRIDE
Paint the plot.
Definition: qwt_plot_glcanvas.cpp:168
QwtPlotAbstractGLCanvas::setFrameShape
void setFrameShape(QFrame::Shape)
Definition: qwt_plot_abstract_canvas.cpp:1011
QwtPlotGLCanvas::init
void init()
Definition: qwt_plot_glcanvas.cpp:82
QwtPlotGLCanvas::~QwtPlotGLCanvas
virtual ~QwtPlotGLCanvas()
Destructor.
Definition: qwt_plot_glcanvas.cpp:77
QwtPainter::devicePixelRatio
static qreal devicePixelRatio(const QPaintDevice *)
Definition: qwt_painter.cpp:1491
QwtPlotGLCanvas::QwtPlotGLCanvas
QwtPlotGLCanvas(QwtPlot *=NULL)
Constructor.
Definition: qwt_plot_glcanvas.cpp:56
qwt_plot.h
QwtPlotGLCanvas::PrivateData::fboDirty
bool fboDirty
Definition: qwt_plot_glcanvas.cpp:46


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Aug 11 2024 02:24:24