Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_directpainter.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_plot_directpainter.cpp (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_directpainter.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_plot_canvas.h" 14 14 #include "qwt_plot_seriesitem.h" 15 15 16 #include <qpainter.h> 16 17 #include <qevent.h> 17 #include <qapplication.h>18 18 #include <qpixmap.h> 19 19 20 20 static inline void qwtRenderItem( 21 QPainter *painter, const QRect&canvasRect,22 QwtPlotSeriesItem *seriesItem, int from, int to )21 QPainter* painter, const QRect& canvasRect, 22 QwtPlotSeriesItem* seriesItem, int from, int to ) 23 23 { 24 24 // A minor performance improvement is possible 25 25 // with caching the maps. TODO ... 26 26 27 QwtPlot *plot = seriesItem->plot();27 QwtPlot* plot = seriesItem->plot(); 28 28 const QwtScaleMap xMap = plot->canvasMap( seriesItem->xAxis() ); 29 29 const QwtScaleMap yMap = plot->canvasMap( seriesItem->yAxis() ); … … 34 34 } 35 35 36 static inline bool qwtHasBackingStore( const QwtPlotCanvas *canvas )36 static inline bool qwtHasBackingStore( const QwtPlotCanvas* canvas ) 37 37 { 38 38 return canvas->testPaintAttribute( QwtPlotCanvas::BackingStore ) 39 && canvas->backingStore() && !canvas->backingStore()->isNull(); 39 && canvas->backingStore() && !canvas->backingStore()->isNull(); 40 40 } 41 41 42 42 class QwtPlotDirectPainter::PrivateData 43 43 { 44 public: 45 PrivateData(): 46 attributes( 0 ), 47 hasClipping(false), 48 seriesItem( NULL ), 49 from( 0 ), 50 to( 0 ) 44 public: 45 PrivateData() 46 : hasClipping( false ) 47 , seriesItem( NULL ) 48 , from( 0 ) 49 , to( 0 ) 51 50 { 52 51 } … … 59 58 QPainter painter; 60 59 61 QwtPlotSeriesItem *seriesItem;60 QwtPlotSeriesItem* seriesItem; 62 61 int from; 63 62 int to; … … 65 64 66 65 //! Constructor 67 QwtPlotDirectPainter::QwtPlotDirectPainter( QObject *parent ):68 QObject( parent ) 69 { 70 d_data = new PrivateData;66 QwtPlotDirectPainter::QwtPlotDirectPainter( QObject* parent ) 67 : QObject( parent ) 68 { 69 m_data = new PrivateData; 71 70 } 72 71 … … 74 73 QwtPlotDirectPainter::~QwtPlotDirectPainter() 75 74 { 76 delete d_data;77 } 78 79 /*! 80 Change an attribute 81 82 \param attribute Attribute to change 83 \param on On/Off 84 85 \sa Attribute, testAttribute() 86 */ 75 delete m_data; 76 } 77 78 /*! 79 Change an attribute 80 81 \param attribute Attribute to change 82 \param on On/Off 83 84 \sa Attribute, testAttribute() 85 */ 87 86 void QwtPlotDirectPainter::setAttribute( Attribute attribute, bool on ) 88 87 { 89 if ( bool( d_data->attributes & attribute ) != on )88 if ( bool( m_data->attributes & attribute ) != on ) 90 89 { 91 90 if ( on ) 92 d_data->attributes |= attribute;91 m_data->attributes |= attribute; 93 92 else 94 d_data->attributes &= ~attribute;93 m_data->attributes &= ~attribute; 95 94 96 95 if ( ( attribute == AtomicPainter ) && on ) … … 100 99 101 100 /*! 102 \return True, when attribute is enabled 103 \param attribute Attribute to be tested 104 \sa Attribute, setAttribute() 105 */ 101 \return True, when attribute is enabled 102 \param attribute Attribute to be tested 103 \sa Attribute, setAttribute() 104 */ 106 105 bool QwtPlotDirectPainter::testAttribute( Attribute attribute ) const 107 106 { 108 return d_data->attributes & attribute;109 } 110 111 /*! 112 En/Disables clipping 113 114 \param enable Enables clipping is true, disable it otherwise 115 \sa hasClipping(), clipRegion(), setClipRegion() 116 */ 107 return m_data->attributes & attribute; 108 } 109 110 /*! 111 En/Disables clipping 112 113 \param enable Enables clipping is true, disable it otherwise 114 \sa hasClipping(), clipRegion(), setClipRegion() 115 */ 117 116 void QwtPlotDirectPainter::setClipping( bool enable ) 118 117 { 119 d_data->hasClipping = enable;120 } 121 122 /*! 123 \return true, when clipping is enabled 124 \sa setClipping(), clipRegion(), setClipRegion() 125 */ 118 m_data->hasClipping = enable; 119 } 120 121 /*! 122 \return true, when clipping is enabled 123 \sa setClipping(), clipRegion(), setClipRegion() 124 */ 126 125 bool QwtPlotDirectPainter::hasClipping() const 127 126 { 128 return d_data->hasClipping;127 return m_data->hasClipping; 129 128 } 130 129 … … 139 138 \param region Clip region 140 139 \sa clipRegion(), hasClipping(), setClipping() 141 */ 142 void QwtPlotDirectPainter::setClipRegion( const QRegion ®ion )143 { 144 d_data->clipRegion = region;145 d_data->hasClipping = true;140 */ 141 void QwtPlotDirectPainter::setClipRegion( const QRegion& region ) 142 { 143 m_data->clipRegion = region; 144 m_data->hasClipping = true; 146 145 } 147 146 … … 149 148 \return Currently set clip region. 150 149 \sa setClipRegion(), setClipping(), hasClipping() 151 */ 150 */ 152 151 QRegion QwtPlotDirectPainter::clipRegion() const 153 152 { 154 return d_data->clipRegion;155 } 156 157 /*! 158 \brief Draw a set of points of a seriesItem. 159 160 When observing an measurement while it is running, new points have to be 161 added to an existing seriesItem. drawSeries() can be used to display them avoiding 162 a complete redraw of the canvas. 163 164 Setting plot()->canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); 165 will result in faster painting, if the paint engine of the canvas widget 166 supports this feature. 167 168 \param seriesItem Item to be painted 169 \param from Index of the first point to be painted 170 \param to Index of the last point to be painted. If to < 0 the 153 return m_data->clipRegion; 154 } 155 156 /*! 157 \brief Draw a set of points of a seriesItem. 158 159 When observing an measurement while it is running, new points have to be 160 added to an existing seriesItem. drawSeries() can be used to display them avoiding 161 a complete redraw of the canvas. 162 163 Setting plot()->canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); 164 will result in faster painting, if the paint engine of the canvas widget 165 supports this feature. 166 167 \param seriesItem Item to be painted 168 \param from Index of the first point to be painted 169 \param to Index of the last point to be painted. If to < 0 the 171 170 series will be painted to its last point. 172 */ 171 */ 173 172 void QwtPlotDirectPainter::drawSeries( 174 QwtPlotSeriesItem *seriesItem, int from, int to )173 QwtPlotSeriesItem* seriesItem, int from, int to ) 175 174 { 176 175 if ( seriesItem == NULL || seriesItem->plot() == NULL ) 177 176 return; 178 177 179 QWidget *canvas = seriesItem->plot()->canvas();178 QWidget* canvas = seriesItem->plot()->canvas(); 180 179 const QRect canvasRect = canvas->contentsRect(); 181 180 182 QwtPlotCanvas *plotCanvas = qobject_cast<QwtPlotCanvas*>( canvas );181 QwtPlotCanvas* plotCanvas = qobject_cast< QwtPlotCanvas* >( canvas ); 183 182 184 183 if ( plotCanvas && qwtHasBackingStore( plotCanvas ) ) 185 184 { 186 QPainter painter( const_cast<QPixmap *>( plotCanvas->backingStore() ) );187 188 if ( d_data->hasClipping )189 painter.setClipRegion( d_data->clipRegion );185 QPainter painter( const_cast< QPixmap* >( plotCanvas->backingStore() ) ); 186 187 if ( m_data->hasClipping ) 188 painter.setClipRegion( m_data->clipRegion ); 190 189 191 190 qwtRenderItem( &painter, canvasRect, seriesItem, from, to ); … … 206 205 if ( !canvas->testAttribute( Qt::WA_PaintOutsidePaintEvent ) ) 207 206 #endif 208 immediatePaint = false;207 immediatePaint = false; 209 208 } 210 209 211 210 if ( immediatePaint ) 212 211 { 213 if ( ! d_data->painter.isActive() )212 if ( !m_data->painter.isActive() ) 214 213 { 215 214 reset(); 216 215 217 d_data->painter.begin( canvas );216 m_data->painter.begin( canvas ); 218 217 canvas->installEventFilter( this ); 219 218 } 220 219 221 if ( d_data->hasClipping )222 { 223 d_data->painter.setClipRegion(224 QRegion( canvasRect ) & d_data->clipRegion );220 if ( m_data->hasClipping ) 221 { 222 m_data->painter.setClipRegion( 223 QRegion( canvasRect ) & m_data->clipRegion ); 225 224 } 226 225 else 227 226 { 228 if ( ! d_data->painter.hasClipping() )229 d_data->painter.setClipRect( canvasRect );230 } 231 232 qwtRenderItem( & d_data->painter, canvasRect, seriesItem, from, to );233 234 if ( d_data->attributes & QwtPlotDirectPainter::AtomicPainter )227 if ( !m_data->painter.hasClipping() ) 228 m_data->painter.setClipRect( canvasRect ); 229 } 230 231 qwtRenderItem( &m_data->painter, canvasRect, seriesItem, from, to ); 232 233 if ( m_data->attributes & QwtPlotDirectPainter::AtomicPainter ) 235 234 { 236 235 reset(); … … 238 237 else 239 238 { 240 if ( d_data->hasClipping )241 d_data->painter.setClipping( false );239 if ( m_data->hasClipping ) 240 m_data->painter.setClipping( false ); 242 241 } 243 242 } … … 246 245 reset(); 247 246 248 d_data->seriesItem = seriesItem;249 d_data->from = from;250 d_data->to = to;247 m_data->seriesItem = seriesItem; 248 m_data->from = from; 249 m_data->to = to; 251 250 252 251 QRegion clipRegion = canvasRect; 253 if ( d_data->hasClipping )254 clipRegion &= d_data->clipRegion;252 if ( m_data->hasClipping ) 253 clipRegion &= m_data->clipRegion; 255 254 256 255 canvas->installEventFilter( this ); … … 258 257 canvas->removeEventFilter( this ); 259 258 260 d_data->seriesItem = NULL;259 m_data->seriesItem = NULL; 261 260 } 262 261 } … … 265 264 void QwtPlotDirectPainter::reset() 266 265 { 267 if ( d_data->painter.isActive() )268 { 269 QWidget *w = static_cast<QWidget*>( d_data->painter.device() );266 if ( m_data->painter.isActive() ) 267 { 268 QWidget* w = static_cast< QWidget* >( m_data->painter.device() ); 270 269 if ( w ) 271 270 w->removeEventFilter( this ); 272 271 273 d_data->painter.end();272 m_data->painter.end(); 274 273 } 275 274 } 276 275 277 276 //! Event filter 278 bool QwtPlotDirectPainter::eventFilter( QObject *, QEvent*event )277 bool QwtPlotDirectPainter::eventFilter( QObject*, QEvent* event ) 279 278 { 280 279 if ( event->type() == QEvent::Paint ) … … 282 281 reset(); 283 282 284 if ( d_data->seriesItem )285 { 286 const QPaintEvent *pe = static_cast< QPaintEvent*>( event );287 288 QWidget *canvas =d_data->seriesItem->plot()->canvas();283 if ( m_data->seriesItem ) 284 { 285 const QPaintEvent* pe = static_cast< QPaintEvent* >( event ); 286 287 QWidget* canvas = m_data->seriesItem->plot()->canvas(); 289 288 290 289 QPainter painter( canvas ); … … 295 294 if ( doCopyCache ) 296 295 { 297 QwtPlotCanvas *plotCanvas =298 qobject_cast<QwtPlotCanvas *>( canvas );296 QwtPlotCanvas* plotCanvas = 297 qobject_cast< QwtPlotCanvas* >( canvas ); 299 298 if ( plotCanvas ) 300 299 { … … 311 310 { 312 311 qwtRenderItem( &painter, canvas->contentsRect(), 313 d_data->seriesItem,d_data->from,d_data->to );312 m_data->seriesItem, m_data->from, m_data->to ); 314 313 } 315 314
Note:
See TracChangeset
for help on using the changeset viewer.
