qwt_null_paintdevice.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_null_paintdevice.h"
11 #include <qpaintengine.h>
12 #include <qpainterpath.h>
13 
15 {
16  public:
17  PrivateData():
19  {
20  }
21 
23 };
24 
25 class QwtNullPaintDevice::PaintEngine QWT_FINAL : public QPaintEngine
26 {
27  public:
28  PaintEngine();
29 
30  virtual bool begin( QPaintDevice* ) QWT_OVERRIDE;
31  virtual bool end() QWT_OVERRIDE;
32 
33  virtual Type type () const QWT_OVERRIDE;
34  virtual void updateState(const QPaintEngineState&) QWT_OVERRIDE;
35 
36  virtual void drawRects(const QRect*, int ) QWT_OVERRIDE;
37  virtual void drawRects(const QRectF*, int ) QWT_OVERRIDE;
38 
39  virtual void drawLines(const QLine*, int ) QWT_OVERRIDE;
40  virtual void drawLines(const QLineF*, int ) QWT_OVERRIDE;
41 
42  virtual void drawEllipse(const QRectF&) QWT_OVERRIDE;
43  virtual void drawEllipse(const QRect&) QWT_OVERRIDE;
44 
45  virtual void drawPath(const QPainterPath&) QWT_OVERRIDE;
46 
47  virtual void drawPoints(const QPointF*, int ) QWT_OVERRIDE;
48  virtual void drawPoints(const QPoint*, int ) QWT_OVERRIDE;
49 
50  virtual void drawPolygon(
51  const QPointF*, int, PolygonDrawMode ) QWT_OVERRIDE;
52 
53  virtual void drawPolygon(
54  const QPoint*, int, PolygonDrawMode ) QWT_OVERRIDE;
55 
56  virtual void drawPixmap(const QRectF&,
57  const QPixmap&, const QRectF&) QWT_OVERRIDE;
58 
59  virtual void drawTextItem(
60  const QPointF&, const QTextItem&) QWT_OVERRIDE;
61 
62  virtual void drawTiledPixmap(const QRectF&,
63  const QPixmap&, const QPointF& s) QWT_OVERRIDE;
64 
65  virtual void drawImage(const QRectF&, const QImage&,
66  const QRectF&, Qt::ImageConversionFlags ) QWT_OVERRIDE;
67 
68  private:
69  QwtNullPaintDevice* nullDevice();
70 };
71 
72 QwtNullPaintDevice::PaintEngine::PaintEngine()
73  : QPaintEngine( QPaintEngine::AllFeatures )
74 {
75 }
76 
77 bool QwtNullPaintDevice::PaintEngine::begin( QPaintDevice* )
78 {
79  setActive( true );
80  return true;
81 }
82 
83 bool QwtNullPaintDevice::PaintEngine::end()
84 {
85  setActive( false );
86  return true;
87 }
88 
90 {
91  /*
92  How to avoid conflicts with other 3rd party pain engines ?
93  At least we don't use QPaintEngine::User what is known to
94  be the value of some print engines
95  */
96  return static_cast< QPaintEngine::Type >( QPaintEngine::MaxUser - 2 );
97 }
98 
99 void QwtNullPaintDevice::PaintEngine::drawRects(
100  const QRect* rects, int rectCount)
101 {
102  QwtNullPaintDevice* device = nullDevice();
103  if ( device == NULL )
104  return;
105 
106  if ( device->mode() != QwtNullPaintDevice::NormalMode )
107  {
108  QPaintEngine::drawRects( rects, rectCount );
109  return;
110  }
111 
112  device->drawRects( rects, rectCount );
113 }
114 
115 void QwtNullPaintDevice::PaintEngine::drawRects(
116  const QRectF* rects, int rectCount)
117 {
118  QwtNullPaintDevice* device = nullDevice();
119  if ( device == NULL )
120  return;
121 
122  if ( device->mode() != QwtNullPaintDevice::NormalMode )
123  {
124  QPaintEngine::drawRects( rects, rectCount );
125  return;
126  }
127 
128  device->drawRects( rects, rectCount );
129 }
130 
131 void QwtNullPaintDevice::PaintEngine::drawLines(
132  const QLine* lines, int lineCount)
133 {
134  QwtNullPaintDevice* device = nullDevice();
135  if ( device == NULL )
136  return;
137 
138  if ( device->mode() != QwtNullPaintDevice::NormalMode )
139  {
140  QPaintEngine::drawLines( lines, lineCount );
141  return;
142  }
143 
144  device->drawLines( lines, lineCount );
145 }
146 
147 void QwtNullPaintDevice::PaintEngine::drawLines(
148  const QLineF* lines, int lineCount)
149 {
150  QwtNullPaintDevice* device = nullDevice();
151  if ( device == NULL )
152  return;
153 
154  if ( device->mode() != QwtNullPaintDevice::NormalMode )
155  {
156  QPaintEngine::drawLines( lines, lineCount );
157  return;
158  }
159 
160  device->drawLines( lines, lineCount );
161 }
162 
163 void QwtNullPaintDevice::PaintEngine::drawEllipse(
164  const QRectF& rect)
165 {
166  QwtNullPaintDevice* device = nullDevice();
167  if ( device == NULL )
168  return;
169 
170  if ( device->mode() != QwtNullPaintDevice::NormalMode )
171  {
172  QPaintEngine::drawEllipse( rect );
173  return;
174  }
175 
176  device->drawEllipse( rect );
177 }
178 
179 void QwtNullPaintDevice::PaintEngine::drawEllipse(
180  const QRect& rect)
181 {
182  QwtNullPaintDevice* device = nullDevice();
183  if ( device == NULL )
184  return;
185 
186  if ( device->mode() != QwtNullPaintDevice::NormalMode )
187  {
188  QPaintEngine::drawEllipse( rect );
189  return;
190  }
191 
192  device->drawEllipse( rect );
193 }
194 
195 
196 void QwtNullPaintDevice::PaintEngine::drawPath(
197  const QPainterPath& path)
198 {
199  QwtNullPaintDevice* device = nullDevice();
200  if ( device == NULL )
201  return;
202 
203  device->drawPath( path );
204 }
205 
206 void QwtNullPaintDevice::PaintEngine::drawPoints(
207  const QPointF* points, int pointCount)
208 {
209  QwtNullPaintDevice* device = nullDevice();
210  if ( device == NULL )
211  return;
212 
213  if ( device->mode() != QwtNullPaintDevice::NormalMode )
214  {
215  QPaintEngine::drawPoints( points, pointCount );
216  return;
217  }
218 
219  device->drawPoints( points, pointCount );
220 }
221 
222 void QwtNullPaintDevice::PaintEngine::drawPoints(
223  const QPoint* points, int pointCount)
224 {
225  QwtNullPaintDevice* device = nullDevice();
226  if ( device == NULL )
227  return;
228 
229  if ( device->mode() != QwtNullPaintDevice::NormalMode )
230  {
231  QPaintEngine::drawPoints( points, pointCount );
232  return;
233  }
234 
235  device->drawPoints( points, pointCount );
236 }
237 
238 void QwtNullPaintDevice::PaintEngine::drawPolygon(
239  const QPointF* points, int pointCount, PolygonDrawMode mode)
240 {
241  QwtNullPaintDevice* device = nullDevice();
242  if ( device == NULL )
243  return;
244 
245  if ( device->mode() == QwtNullPaintDevice::PathMode )
246  {
247  QPainterPath path;
248 
249  if ( pointCount > 0 )
250  {
251  path.moveTo( points[0] );
252  for ( int i = 1; i < pointCount; i++ )
253  path.lineTo( points[i] );
254 
255  if ( mode != PolylineMode )
256  path.closeSubpath();
257  }
258 
259  device->drawPath( path );
260  return;
261  }
262 
263  device->drawPolygon( points, pointCount, mode );
264 }
265 
266 void QwtNullPaintDevice::PaintEngine::drawPolygon(
267  const QPoint* points, int pointCount, PolygonDrawMode mode)
268 {
269  QwtNullPaintDevice* device = nullDevice();
270  if ( device == NULL )
271  return;
272 
273  if ( device->mode() == QwtNullPaintDevice::PathMode )
274  {
275  QPainterPath path;
276 
277  if ( pointCount > 0 )
278  {
279  path.moveTo( points[0] );
280  for ( int i = 1; i < pointCount; i++ )
281  path.lineTo( points[i] );
282 
283  if ( mode != PolylineMode )
284  path.closeSubpath();
285  }
286 
287  device->drawPath( path );
288  return;
289  }
290 
291  device->drawPolygon( points, pointCount, mode );
292 }
293 
294 void QwtNullPaintDevice::PaintEngine::drawPixmap(
295  const QRectF& rect, const QPixmap& pm, const QRectF& subRect )
296 {
297  QwtNullPaintDevice* device = nullDevice();
298  if ( device == NULL )
299  return;
300 
301  device->drawPixmap( rect, pm, subRect );
302 }
303 
304 void QwtNullPaintDevice::PaintEngine::drawTextItem(
305  const QPointF& pos, const QTextItem& textItem)
306 {
307  QwtNullPaintDevice* device = nullDevice();
308  if ( device == NULL )
309  return;
310 
311  if ( device->mode() != QwtNullPaintDevice::NormalMode )
312  {
313  QPaintEngine::drawTextItem( pos, textItem );
314  return;
315  }
316 
317  device->drawTextItem( pos, textItem );
318 }
319 
320 void QwtNullPaintDevice::PaintEngine::drawTiledPixmap(
321  const QRectF& rect, const QPixmap& pixmap,
322  const QPointF& subRect)
323 {
324  QwtNullPaintDevice* device = nullDevice();
325  if ( device == NULL )
326  return;
327 
328  if ( device->mode() != QwtNullPaintDevice::NormalMode )
329  {
330  QPaintEngine::drawTiledPixmap( rect, pixmap, subRect );
331  return;
332  }
333 
334  device->drawTiledPixmap( rect, pixmap, subRect );
335 }
336 
337 void QwtNullPaintDevice::PaintEngine::drawImage(
338  const QRectF& rect, const QImage& image,
339  const QRectF& subRect, Qt::ImageConversionFlags flags)
340 {
341  QwtNullPaintDevice* device = nullDevice();
342  if ( device == NULL )
343  return;
344 
345  device->drawImage( rect, image, subRect, flags );
346 }
347 
348 void QwtNullPaintDevice::PaintEngine::updateState(
349  const QPaintEngineState& engineState)
350 {
351  QwtNullPaintDevice* device = nullDevice();
352  if ( device == NULL )
353  return;
354 
355  device->updateState( engineState );
356 }
357 
358 inline QwtNullPaintDevice* QwtNullPaintDevice::PaintEngine::nullDevice()
359 {
360  if ( !isActive() )
361  return NULL;
362 
363  return static_cast< QwtNullPaintDevice* >( paintDevice() );
364 }
365 
368  m_engine( NULL )
369 {
370  m_data = new PrivateData;
371 }
372 
375 {
376  delete m_engine;
377  delete m_data;
378 }
379 
387 {
388  m_data->mode = mode;
389 }
390 
396 {
397  return m_data->mode;
398 }
399 
401 QPaintEngine* QwtNullPaintDevice::paintEngine() const
402 {
403  if ( m_engine == NULL )
404  {
405  QwtNullPaintDevice* that =
406  const_cast< QwtNullPaintDevice* >( this );
407 
408  that->m_engine = new PaintEngine();
409  }
410 
411  return m_engine;
412 }
413 
422 int QwtNullPaintDevice::metric( PaintDeviceMetric deviceMetric ) const
423 {
424  int value;
425 
426  switch ( deviceMetric )
427  {
428  case PdmWidth:
429  {
430  value = sizeMetrics().width();
431  break;
432  }
433  case PdmHeight:
434  {
435  value = sizeMetrics().height();
436  break;
437  }
438  case PdmNumColors:
439  {
440  value = 0xffffffff;
441  break;
442  }
443  case PdmDepth:
444  {
445  value = 32;
446  break;
447  }
448  case PdmPhysicalDpiX:
449  case PdmPhysicalDpiY:
450  case PdmDpiY:
451  case PdmDpiX:
452  {
453  value = 72;
454  break;
455  }
456  case PdmWidthMM:
457  {
458  value = qRound( metric( PdmWidth ) * 25.4 / metric( PdmDpiX ) );
459  break;
460  }
461  case PdmHeightMM:
462  {
463  value = qRound( metric( PdmHeight ) * 25.4 / metric( PdmDpiY ) );
464  break;
465  }
466  default:
467  value = 0;
468  }
469  return value;
470 
471 }
472 
475  const QRect* rects, int rectCount)
476 {
477  Q_UNUSED(rects);
478  Q_UNUSED(rectCount);
479 }
480 
483  const QRectF* rects, int rectCount)
484 {
485  Q_UNUSED(rects);
486  Q_UNUSED(rectCount);
487 }
488 
491  const QLine* lines, int lineCount)
492 {
493  Q_UNUSED(lines);
494  Q_UNUSED(lineCount);
495 }
496 
499  const QLineF* lines, int lineCount)
500 {
501  Q_UNUSED(lines);
502  Q_UNUSED(lineCount);
503 }
504 
506 void QwtNullPaintDevice::drawEllipse( const QRectF& rect )
507 {
508  Q_UNUSED(rect);
509 }
510 
512 void QwtNullPaintDevice::drawEllipse( const QRect& rect )
513 {
514  Q_UNUSED(rect);
515 }
516 
518 void QwtNullPaintDevice::drawPath( const QPainterPath& path )
519 {
520  Q_UNUSED(path);
521 }
522 
525  const QPointF* points, int pointCount)
526 {
527  Q_UNUSED(points);
528  Q_UNUSED(pointCount);
529 }
530 
533  const QPoint* points, int pointCount)
534 {
535  Q_UNUSED(points);
536  Q_UNUSED(pointCount);
537 }
538 
541  const QPointF* points, int pointCount,
542  QPaintEngine::PolygonDrawMode mode)
543 {
544  Q_UNUSED(points);
545  Q_UNUSED(pointCount);
546  Q_UNUSED(mode);
547 }
548 
551  const QPoint* points, int pointCount,
552  QPaintEngine::PolygonDrawMode mode)
553 {
554  Q_UNUSED(points);
555  Q_UNUSED(pointCount);
556  Q_UNUSED(mode);
557 }
558 
560 void QwtNullPaintDevice::drawPixmap( const QRectF& rect,
561  const QPixmap& pm, const QRectF& subRect )
562 {
563  Q_UNUSED(rect);
564  Q_UNUSED(pm);
565  Q_UNUSED(subRect);
566 }
567 
570  const QPointF& pos, const QTextItem& textItem)
571 {
572  Q_UNUSED(pos);
573  Q_UNUSED(textItem);
574 }
575 
578  const QRectF& rect, const QPixmap& pixmap,
579  const QPointF& subRect)
580 {
581  Q_UNUSED(rect);
582  Q_UNUSED(pixmap);
583  Q_UNUSED(subRect);
584 }
585 
588  const QRectF& rect, const QImage& image,
589  const QRectF& subRect, Qt::ImageConversionFlags flags)
590 {
591  Q_UNUSED(rect);
592  Q_UNUSED(image);
593  Q_UNUSED(subRect);
594  Q_UNUSED(flags);
595 }
596 
599  const QPaintEngineState& state )
600 {
601  Q_UNUSED(state);
602 }
QWT_FINAL
#define QWT_FINAL
Definition: qwt_global.h:57
QwtNullPaintDevice::m_data
PrivateData * m_data
Definition: qwt_null_paintdevice.h:130
detail::state
state
Definition: core.h:2305
backward::ColorMode::type
type
Definition: backward.hpp:3600
QwtNullPaintDevice::~QwtNullPaintDevice
virtual ~QwtNullPaintDevice()
Destructor.
Definition: qwt_null_paintdevice.cpp:374
QwtNullPaintDevice::Mode
Mode
Render mode.
Definition: qwt_null_paintdevice.h:47
QwtNullPaintDevice::PrivateData::mode
QwtNullPaintDevice::Mode mode
Definition: qwt_null_paintdevice.cpp:29
QwtNullPaintDevice::updateState
virtual void updateState(const QPaintEngineState &)
See QPaintEngine::updateState()
Definition: qwt_null_paintdevice.cpp:598
QwtNullPaintDevice::PrivateData
Definition: qwt_null_paintdevice.cpp:14
QwtNullPaintDevice::drawEllipse
virtual void drawEllipse(const QRectF &)
See QPaintEngine::drawEllipse()
Definition: qwt_null_paintdevice.cpp:506
QwtNullPaintDevice::PathMode
@ PathMode
Definition: qwt_null_paintdevice.h:83
QwtNullPaintDevice::m_engine
PaintEngine * m_engine
Definition: qwt_null_paintdevice.h:127
QwtNullPaintDevice::drawImage
virtual void drawImage(const QRectF &, const QImage &, const QRectF &, Qt::ImageConversionFlags)
See QPaintEngine::drawImage()
Definition: qwt_null_paintdevice.cpp:587
QwtNullPaintDevice::drawPixmap
virtual void drawPixmap(const QRectF &, const QPixmap &, const QRectF &)
See QPaintEngine::drawPixmap()
Definition: qwt_null_paintdevice.cpp:560
QwtNullPaintDevice::drawPoints
virtual void drawPoints(const QPointF *, int)
See QPaintEngine::drawPoints()
Definition: qwt_null_paintdevice.cpp:524
QwtNullPaintDevice::drawTiledPixmap
virtual void drawTiledPixmap(const QRectF &, const QPixmap &, const QPointF &)
See QPaintEngine::drawTiledPixmap()
Definition: qwt_null_paintdevice.cpp:577
QwtNullPaintDevice::paintEngine
virtual QPaintEngine * paintEngine() const QWT_OVERRIDE
See QPaintDevice::paintEngine()
Definition: qwt_null_paintdevice.cpp:401
QwtTriangle::Type
Type
Definition: qwt_symbol.cpp:32
QwtNullPaintDevice
A null paint device doing nothing.
Definition: qwt_null_paintdevice.h:32
QwtNullPaintDevice::metric
virtual int metric(PaintDeviceMetric) const QWT_OVERRIDE
Definition: qwt_null_paintdevice.cpp:422
QwtNullPaintDevice::drawPolygon
virtual void drawPolygon(const QPointF *, int, QPaintEngine::PolygonDrawMode)
See QPaintEngine::drawPolygon()
Definition: qwt_null_paintdevice.cpp:540
QwtNullPaintDevice::sizeMetrics
virtual QSize sizeMetrics() const =0
QwtNullPaintDevice::drawRects
virtual void drawRects(const QRect *, int)
See QPaintEngine::drawRects()
Definition: qwt_null_paintdevice.cpp:474
qwt_null_paintdevice.h
QwtNullPaintDevice::drawPath
virtual void drawPath(const QPainterPath &)
See QPaintEngine::drawPath()
Definition: qwt_null_paintdevice.cpp:518
QwtNullPaintDevice::drawTextItem
virtual void drawTextItem(const QPointF &, const QTextItem &)
See QPaintEngine::drawTextItem()
Definition: qwt_null_paintdevice.cpp:569
QwtNullPaintDevice::QwtNullPaintDevice
QwtNullPaintDevice()
Constructor.
Definition: qwt_null_paintdevice.cpp:367
QWT_OVERRIDE
#define QWT_OVERRIDE
Definition: qwt_global.h:53
QwtNullPaintDevice::setMode
void setMode(Mode)
Definition: qwt_null_paintdevice.cpp:386
QwtNullPaintDevice::drawLines
virtual void drawLines(const QLine *, int)
See QPaintEngine::drawLines()
Definition: qwt_null_paintdevice.cpp:490
QwtNullPaintDevice::mode
Mode mode() const
Definition: qwt_null_paintdevice.cpp:395
QwtNullPaintDevice::PrivateData::PrivateData
PrivateData()
Definition: qwt_null_paintdevice.cpp:24
QwtNullPaintDevice::NormalMode
@ NormalMode
Definition: qwt_null_paintdevice.h:60


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45