Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_null_paintdevice.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_null_paintdevice.cpp
r4271 r8127 16 16 public: 17 17 PrivateData(): 18 size( 0, 0)19 { 20 } 21 22 Q Size size;18 mode( QwtNullPaintDevice::NormalMode ) 19 { 20 } 21 22 QwtNullPaintDevice::Mode mode; 23 23 }; 24 24 … … 26 26 { 27 27 public: 28 PaintEngine( QPaintEngine::PaintEngineFeatures);28 PaintEngine(); 29 29 30 30 virtual bool begin( QPaintDevice * ); … … 55 55 56 56 virtual void drawTextItem(const QPointF &, const QTextItem &); 57 57 58 virtual void drawTiledPixmap(const QRectF &, 58 59 const QPixmap &, const QPointF &s); 60 59 61 virtual void drawImage(const QRectF &, 60 62 const QImage &, const QRectF &, Qt::ImageConversionFlags ); 61 63 62 64 private: 63 QwtNullPaintDevice * d_device;65 QwtNullPaintDevice *nullDevice(); 64 66 }; 65 67 66 QwtNullPaintDevice::PaintEngine::PaintEngine( 67 QPaintEngine::PaintEngineFeatures features ): 68 QPaintEngine( features ), 69 d_device(NULL) 70 { 71 } 72 73 bool QwtNullPaintDevice::PaintEngine::begin( 74 QPaintDevice *device ) 75 { 76 d_device = static_cast<QwtNullPaintDevice *>( device ); 68 QwtNullPaintDevice::PaintEngine::PaintEngine(): 69 QPaintEngine( QPaintEngine::AllFeatures ) 70 { 71 } 72 73 bool QwtNullPaintDevice::PaintEngine::begin( QPaintDevice * ) 74 { 75 setActive( true ); 77 76 return true; 78 77 } … … 80 79 bool QwtNullPaintDevice::PaintEngine::end() 81 80 { 82 d_device = NULL;81 setActive( false ); 83 82 return true; 84 83 } 85 84 86 QPaintEngine::Type 87 QwtNullPaintDevice::PaintEngine::type () const 85 QPaintEngine::Type QwtNullPaintDevice::PaintEngine::type() const 88 86 { 89 87 return QPaintEngine::User; … … 93 91 const QRect *rects, int rectCount) 94 92 { 95 if ( d_device ) 96 d_device->drawRects( rects, rectCount ); 93 QwtNullPaintDevice *device = nullDevice(); 94 if ( device == NULL ) 95 return; 96 97 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 98 { 99 QPaintEngine::drawRects( rects, rectCount ); 100 return; 101 } 102 103 device->drawRects( rects, rectCount ); 97 104 } 98 105 … … 100 107 const QRectF *rects, int rectCount) 101 108 { 102 if ( d_device ) 103 d_device->drawRects( rects, rectCount ); 109 QwtNullPaintDevice *device = nullDevice(); 110 if ( device == NULL ) 111 return; 112 113 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 114 { 115 QPaintEngine::drawRects( rects, rectCount ); 116 return; 117 } 118 119 device->drawRects( rects, rectCount ); 104 120 } 105 121 … … 107 123 const QLine *lines, int lineCount) 108 124 { 109 if ( d_device ) 110 d_device->drawLines( lines, lineCount ); 125 QwtNullPaintDevice *device = nullDevice(); 126 if ( device == NULL ) 127 return; 128 129 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 130 { 131 QPaintEngine::drawLines( lines, lineCount ); 132 return; 133 } 134 135 device->drawLines( lines, lineCount ); 111 136 } 112 137 … … 114 139 const QLineF *lines, int lineCount) 115 140 { 116 if ( d_device ) 117 d_device->drawLines( lines, lineCount ); 141 QwtNullPaintDevice *device = nullDevice(); 142 if ( device == NULL ) 143 return; 144 145 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 146 { 147 QPaintEngine::drawLines( lines, lineCount ); 148 return; 149 } 150 151 device->drawLines( lines, lineCount ); 118 152 } 119 153 … … 121 155 const QRectF &rect) 122 156 { 123 if ( d_device ) 124 d_device->drawEllipse( rect ); 157 QwtNullPaintDevice *device = nullDevice(); 158 if ( device == NULL ) 159 return; 160 161 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 162 { 163 QPaintEngine::drawEllipse( rect ); 164 return; 165 } 166 167 device->drawEllipse( rect ); 125 168 } 126 169 … … 128 171 const QRect &rect) 129 172 { 130 if ( d_device ) 131 d_device->drawEllipse( rect ); 173 QwtNullPaintDevice *device = nullDevice(); 174 if ( device == NULL ) 175 return; 176 177 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 178 { 179 QPaintEngine::drawEllipse( rect ); 180 return; 181 } 182 183 device->drawEllipse( rect ); 132 184 } 133 185 … … 136 188 const QPainterPath &path) 137 189 { 138 if ( d_device ) 139 d_device->drawPath( path ); 190 QwtNullPaintDevice *device = nullDevice(); 191 if ( device == NULL ) 192 return; 193 194 device->drawPath( path ); 140 195 } 141 196 … … 143 198 const QPointF *points, int pointCount) 144 199 { 145 if ( d_device ) 146 d_device->drawPoints( points, pointCount ); 200 QwtNullPaintDevice *device = nullDevice(); 201 if ( device == NULL ) 202 return; 203 204 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 205 { 206 QPaintEngine::drawPoints( points, pointCount ); 207 return; 208 } 209 210 device->drawPoints( points, pointCount ); 147 211 } 148 212 … … 150 214 const QPoint *points, int pointCount) 151 215 { 152 if ( d_device ) 153 d_device->drawPoints( points, pointCount ); 216 QwtNullPaintDevice *device = nullDevice(); 217 if ( device == NULL ) 218 return; 219 220 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 221 { 222 QPaintEngine::drawPoints( points, pointCount ); 223 return; 224 } 225 226 device->drawPoints( points, pointCount ); 154 227 } 155 228 … … 157 230 const QPointF *points, int pointCount, PolygonDrawMode mode) 158 231 { 159 if ( d_device ) 160 d_device->drawPolygon( points, pointCount, mode ); 232 QwtNullPaintDevice *device = nullDevice(); 233 if ( device == NULL ) 234 return; 235 236 if ( device->mode() == QwtNullPaintDevice::PathMode ) 237 { 238 QPainterPath path; 239 240 if ( pointCount > 0 ) 241 { 242 path.moveTo( points[0] ); 243 for ( int i = 1; i < pointCount; i++ ) 244 path.lineTo( points[i] ); 245 246 if ( mode != PolylineMode ) 247 path.closeSubpath(); 248 } 249 250 device->drawPath( path ); 251 return; 252 } 253 254 device->drawPolygon( points, pointCount, mode ); 161 255 } 162 256 … … 164 258 const QPoint *points, int pointCount, PolygonDrawMode mode) 165 259 { 166 if ( d_device ) 167 d_device->drawPolygon( points, pointCount, mode ); 260 QwtNullPaintDevice *device = nullDevice(); 261 if ( device == NULL ) 262 return; 263 264 if ( device->mode() == QwtNullPaintDevice::PathMode ) 265 { 266 QPainterPath path; 267 268 if ( pointCount > 0 ) 269 { 270 path.moveTo( points[0] ); 271 for ( int i = 1; i < pointCount; i++ ) 272 path.lineTo( points[i] ); 273 274 if ( mode != PolylineMode ) 275 path.closeSubpath(); 276 } 277 278 device->drawPath( path ); 279 return; 280 } 281 282 device->drawPolygon( points, pointCount, mode ); 168 283 } 169 284 … … 171 286 const QRectF &rect, const QPixmap &pm, const QRectF &subRect ) 172 287 { 173 if ( d_device ) 174 d_device->drawPixmap( rect, pm, subRect ); 288 QwtNullPaintDevice *device = nullDevice(); 289 if ( device == NULL ) 290 return; 291 292 device->drawPixmap( rect, pm, subRect ); 175 293 } 176 294 … … 178 296 const QPointF &pos, const QTextItem &textItem) 179 297 { 180 if ( d_device ) 181 d_device->drawTextItem( pos, textItem ); 298 QwtNullPaintDevice *device = nullDevice(); 299 if ( device == NULL ) 300 return; 301 302 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 303 { 304 QPaintEngine::drawTextItem( pos, textItem ); 305 return; 306 } 307 308 device->drawTextItem( pos, textItem ); 182 309 } 183 310 … … 186 313 const QPointF &subRect) 187 314 { 188 if ( d_device ) 189 d_device->drawTiledPixmap( rect, pixmap, subRect ); 315 QwtNullPaintDevice *device = nullDevice(); 316 if ( device == NULL ) 317 return; 318 319 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 320 { 321 QPaintEngine::drawTiledPixmap( rect, pixmap, subRect ); 322 return; 323 } 324 325 device->drawTiledPixmap( rect, pixmap, subRect ); 190 326 } 191 327 … … 194 330 const QRectF &subRect, Qt::ImageConversionFlags flags) 195 331 { 196 if ( d_device ) 197 d_device->drawImage( rect, image, subRect, flags ); 332 QwtNullPaintDevice *device = nullDevice(); 333 if ( device == NULL ) 334 return; 335 336 device->drawImage( rect, image, subRect, flags ); 198 337 } 199 338 … … 201 340 const QPaintEngineState &state) 202 341 { 203 if ( d_device ) 204 d_device->updateState( state ); 342 QwtNullPaintDevice *device = nullDevice(); 343 if ( device == NULL ) 344 return; 345 346 device->updateState( state ); 347 } 348 349 inline QwtNullPaintDevice *QwtNullPaintDevice::PaintEngine::nullDevice() 350 { 351 if ( !isActive() ) 352 return NULL; 353 354 return static_cast<QwtNullPaintDevice *>( paintDevice() ); 205 355 } 206 356 207 357 //! Constructor 208 QwtNullPaintDevice::QwtNullPaintDevice( 209 QPaintEngine::PaintEngineFeatures features ) 210 { 211 init( features ); 212 } 213 214 //! Constructor 215 QwtNullPaintDevice::QwtNullPaintDevice( const QSize &size, 216 QPaintEngine::PaintEngineFeatures features ) 217 { 218 init( features ); 219 d_data->size = size; 220 } 221 222 void QwtNullPaintDevice::init( 223 QPaintEngine::PaintEngineFeatures features ) 224 { 225 d_engine = new PaintEngine( features ); 358 QwtNullPaintDevice::QwtNullPaintDevice(): 359 d_engine( NULL ) 360 { 226 361 d_data = new PrivateData; 227 362 } … … 235 370 236 371 /*! 237 Set the size of the paint device 238 239 \param size Size 240 \sa size() 372 Set the render mode 373 374 \param mode New mode 375 \sa mode() 376 */ 377 void QwtNullPaintDevice::setMode( Mode mode ) 378 { 379 d_data->mode = mode; 380 } 381 382 /*! 383 \return Render mode 384 \sa setMode() 241 385 */ 242 void QwtNullPaintDevice::setSize( const QSize & size ) 243 { 244 d_data->size = size; 245 } 246 247 /*! 248 \return Size of the paint device 249 \sa setSize() 250 */ 251 QSize QwtNullPaintDevice::size() const 252 { 253 return d_data->size; 386 QwtNullPaintDevice::Mode QwtNullPaintDevice::mode() const 387 { 388 return d_data->mode; 254 389 } 255 390 … … 257 392 QPaintEngine *QwtNullPaintDevice::paintEngine() const 258 393 { 394 if ( d_engine == NULL ) 395 { 396 QwtNullPaintDevice *that = 397 const_cast< QwtNullPaintDevice * >( this ); 398 399 that->d_engine = new PaintEngine(); 400 } 401 259 402 return d_engine; 260 403 } … … 262 405 /*! 263 406 See QPaintDevice::metric() 264 \sa setSize() 407 408 \param deviceMetric Type of metric 409 \return Metric information for the given paint device metric. 410 411 \sa sizeMetrics() 265 412 */ 266 int QwtNullPaintDevice::metric( PaintDeviceMetric metric ) const 267 { 268 static QPixmap pm; 269 413 int QwtNullPaintDevice::metric( PaintDeviceMetric deviceMetric ) const 414 { 270 415 int value; 271 416 272 switch ( metric )417 switch ( deviceMetric ) 273 418 { 274 419 case PdmWidth: 275 value = qMax( d_data->size.width(), 0 ); 276 break; 420 { 421 value = sizeMetrics().width(); 422 break; 423 } 277 424 case PdmHeight: 278 value = qMax( d_data->size.height(), 0 ); 279 break; 425 { 426 value = sizeMetrics().height(); 427 break; 428 } 280 429 case PdmNumColors: 281 value = 16777216; 282 break; 430 { 431 value = 0xffffffff; 432 break; 433 } 283 434 case PdmDepth: 284 value = 24; 285 break; 435 { 436 value = 32; 437 break; 438 } 286 439 case PdmPhysicalDpiX: 440 case PdmPhysicalDpiY: 287 441 case PdmDpiY: 288 case PdmPhysicalDpiY: 442 case PdmDpiX: 443 { 444 value = 72; 445 break; 446 } 289 447 case PdmWidthMM: 448 { 449 value = qRound( metric( PdmWidth ) * 25.4 / metric( PdmDpiX ) ); 450 break; 451 } 290 452 case PdmHeightMM: 291 case PdmDpiX: 453 { 454 value = qRound( metric( PdmHeight ) * 25.4 / metric( PdmDpiY ) ); 455 break; 456 } 292 457 default: 293 458 value = 0;
Note:
See TracChangeset
for help on using the changeset viewer.