qwt_null_paintdevice.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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 <qpixmap.h>
13 
15 {
16 public:
19  {
20  }
21 
23 };
24 
25 class QwtNullPaintDevice::PaintEngine: public QPaintEngine
26 {
27 public:
28  PaintEngine();
29 
30  virtual bool begin( QPaintDevice * );
31  virtual bool end();
32 
33  virtual Type type () const;
34  virtual void updateState(const QPaintEngineState &);
35 
36  virtual void drawRects(const QRect *, int );
37  virtual void drawRects(const QRectF *, int );
38 
39  virtual void drawLines(const QLine *, int );
40  virtual void drawLines(const QLineF *, int );
41 
42  virtual void drawEllipse(const QRectF &);
43  virtual void drawEllipse(const QRect &);
44 
45  virtual void drawPath(const QPainterPath &);
46 
47  virtual void drawPoints(const QPointF *, int );
48  virtual void drawPoints(const QPoint *, int );
49 
50  virtual void drawPolygon(const QPointF *, int , PolygonDrawMode );
51  virtual void drawPolygon(const QPoint *, int , PolygonDrawMode );
52 
53  virtual void drawPixmap(const QRectF &,
54  const QPixmap &, const QRectF &);
55 
56  virtual void drawTextItem(const QPointF &, const QTextItem &);
57 
58  virtual void drawTiledPixmap(const QRectF &,
59  const QPixmap &, const QPointF &s);
60 
61  virtual void drawImage(const QRectF &,
62  const QImage &, const QRectF &, Qt::ImageConversionFlags );
63 
64 private:
65  QwtNullPaintDevice *nullDevice();
66 };
67 
69  QPaintEngine( QPaintEngine::AllFeatures )
70 {
71 }
72 
74 {
75  setActive( true );
76  return true;
77 }
78 
80 {
81  setActive( false );
82  return true;
83 }
84 
86 {
87  return QPaintEngine::User;
88 }
89 
91  const QRect *rects, int rectCount)
92 {
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 );
104 }
105 
107  const QRectF *rects, int rectCount)
108 {
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 );
120 }
121 
123  const QLine *lines, int lineCount)
124 {
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 );
136 }
137 
139  const QLineF *lines, int lineCount)
140 {
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 );
152 }
153 
155  const QRectF &rect)
156 {
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 );
168 }
169 
171  const QRect &rect)
172 {
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 );
184 }
185 
186 
188  const QPainterPath &path)
189 {
190  QwtNullPaintDevice *device = nullDevice();
191  if ( device == NULL )
192  return;
193 
194  device->drawPath( path );
195 }
196 
198  const QPointF *points, int pointCount)
199 {
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 );
211 }
212 
214  const QPoint *points, int pointCount)
215 {
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 );
227 }
228 
230  const QPointF *points, int pointCount, PolygonDrawMode mode)
231 {
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 );
255 }
256 
258  const QPoint *points, int pointCount, PolygonDrawMode mode)
259 {
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 );
283 }
284 
286  const QRectF &rect, const QPixmap &pm, const QRectF &subRect )
287 {
288  QwtNullPaintDevice *device = nullDevice();
289  if ( device == NULL )
290  return;
291 
292  device->drawPixmap( rect, pm, subRect );
293 }
294 
296  const QPointF &pos, const QTextItem &textItem)
297 {
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 );
309 }
310 
312  const QRectF &rect, const QPixmap &pixmap,
313  const QPointF &subRect)
314 {
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 );
326 }
327 
329  const QRectF &rect, const QImage &image,
330  const QRectF &subRect, Qt::ImageConversionFlags flags)
331 {
332  QwtNullPaintDevice *device = nullDevice();
333  if ( device == NULL )
334  return;
335 
336  device->drawImage( rect, image, subRect, flags );
337 }
338 
340  const QPaintEngineState &state)
341 {
342  QwtNullPaintDevice *device = nullDevice();
343  if ( device == NULL )
344  return;
345 
346  device->updateState( state );
347 }
348 
350 {
351  if ( !isActive() )
352  return NULL;
353 
354  return static_cast<QwtNullPaintDevice *>( paintDevice() );
355 }
356 
359  d_engine( NULL )
360 {
361  d_data = new PrivateData;
362 }
363 
366 {
367  delete d_engine;
368  delete d_data;
369 }
370 
378 {
379  d_data->mode = mode;
380 }
381 
387 {
388  return d_data->mode;
389 }
390 
392 QPaintEngine *QwtNullPaintDevice::paintEngine() const
393 {
394  if ( d_engine == NULL )
395  {
396  QwtNullPaintDevice *that =
397  const_cast< QwtNullPaintDevice * >( this );
398 
399  that->d_engine = new PaintEngine();
400  }
401 
402  return d_engine;
403 }
404 
413 int QwtNullPaintDevice::metric( PaintDeviceMetric deviceMetric ) const
414 {
415  int value;
416 
417  switch ( deviceMetric )
418  {
419  case PdmWidth:
420  {
421  value = sizeMetrics().width();
422  break;
423  }
424  case PdmHeight:
425  {
426  value = sizeMetrics().height();
427  break;
428  }
429  case PdmNumColors:
430  {
431  value = 0xffffffff;
432  break;
433  }
434  case PdmDepth:
435  {
436  value = 32;
437  break;
438  }
439  case PdmPhysicalDpiX:
440  case PdmPhysicalDpiY:
441  case PdmDpiY:
442  case PdmDpiX:
443  {
444  value = 72;
445  break;
446  }
447  case PdmWidthMM:
448  {
449  value = qRound( metric( PdmWidth ) * 25.4 / metric( PdmDpiX ) );
450  break;
451  }
452  case PdmHeightMM:
453  {
454  value = qRound( metric( PdmHeight ) * 25.4 / metric( PdmDpiY ) );
455  break;
456  }
457  default:
458  value = 0;
459  }
460  return value;
461 
462 }
463 
466  const QRect *rects, int rectCount)
467 {
468  Q_UNUSED(rects);
469  Q_UNUSED(rectCount);
470 }
471 
474  const QRectF *rects, int rectCount)
475 {
476  Q_UNUSED(rects);
477  Q_UNUSED(rectCount);
478 }
479 
482  const QLine *lines, int lineCount)
483 {
484  Q_UNUSED(lines);
485  Q_UNUSED(lineCount);
486 }
487 
490  const QLineF *lines, int lineCount)
491 {
492  Q_UNUSED(lines);
493  Q_UNUSED(lineCount);
494 }
495 
497 void QwtNullPaintDevice::drawEllipse( const QRectF &rect )
498 {
499  Q_UNUSED(rect);
500 }
501 
503 void QwtNullPaintDevice::drawEllipse( const QRect &rect )
504 {
505  Q_UNUSED(rect);
506 }
507 
509 void QwtNullPaintDevice::drawPath( const QPainterPath &path )
510 {
511  Q_UNUSED(path);
512 }
513 
516  const QPointF *points, int pointCount)
517 {
518  Q_UNUSED(points);
519  Q_UNUSED(pointCount);
520 }
521 
524  const QPoint *points, int pointCount)
525 {
526  Q_UNUSED(points);
527  Q_UNUSED(pointCount);
528 }
529 
532  const QPointF *points, int pointCount,
533  QPaintEngine::PolygonDrawMode mode)
534 {
535  Q_UNUSED(points);
536  Q_UNUSED(pointCount);
537  Q_UNUSED(mode);
538 }
539 
542  const QPoint *points, int pointCount,
543  QPaintEngine::PolygonDrawMode mode)
544 {
545  Q_UNUSED(points);
546  Q_UNUSED(pointCount);
547  Q_UNUSED(mode);
548 }
549 
551 void QwtNullPaintDevice::drawPixmap( const QRectF &rect,
552  const QPixmap &pm, const QRectF &subRect )
553 {
554  Q_UNUSED(rect);
555  Q_UNUSED(pm);
556  Q_UNUSED(subRect);
557 }
558 
561  const QPointF &pos, const QTextItem &textItem)
562 {
563  Q_UNUSED(pos);
564  Q_UNUSED(textItem);
565 }
566 
569  const QRectF &rect, const QPixmap &pixmap,
570  const QPointF &subRect)
571 {
572  Q_UNUSED(rect);
573  Q_UNUSED(pixmap);
574  Q_UNUSED(subRect);
575 }
576 
579  const QRectF &rect, const QImage &image,
580  const QRectF &subRect, Qt::ImageConversionFlags flags)
581 {
582  Q_UNUSED(rect);
583  Q_UNUSED(image);
584  Q_UNUSED(subRect);
585  Q_UNUSED(flags);
586 }
587 
590  const QPaintEngineState &state )
591 {
592  Q_UNUSED(state);
593 }
virtual bool begin(QPaintDevice *)
virtual ~QwtNullPaintDevice()
Destructor.
virtual void drawRects(const QRect *, int)
See QPaintEngine::drawRects()
QwtNullPaintDevice()
Constructor.
char * begin
virtual int metric(PaintDeviceMetric metric) const
virtual void drawLines(const QLine *, int)
See QPaintEngine::drawLines()
virtual QPaintEngine * paintEngine() const
See QPaintDevice::paintEngine()
XmlRpcServer s
A null paint device doing nothing.
virtual void drawTiledPixmap(const QRectF &, const QPixmap &, const QPointF &s)
See QPaintEngine::drawTiledPixmap()
virtual void drawTextItem(const QPointF &, const QTextItem &)
See QPaintEngine::drawTextItem()
virtual void drawEllipse(const QRectF &)
See QPaintEngine::drawEllipse()
virtual void drawRects(const QRect *, int)
char * end
virtual void drawTiledPixmap(const QRectF &, const QPixmap &, const QPointF &s)
virtual void drawPath(const QPainterPath &)
See QPaintEngine::drawPath()
GraphId path[kMaxDeadlockPathLen]
virtual void drawTextItem(const QPointF &, const QTextItem &)
virtual void updateState(const QPaintEngineState &state)
See QPaintEngine::updateState()
virtual void drawPath(const QPainterPath &)
T value
virtual void drawLines(const QLine *, int)
virtual void drawImage(const QRectF &, const QImage &, const QRectF &, Qt::ImageConversionFlags)
virtual void drawImage(const QRectF &, const QImage &, const QRectF &, Qt::ImageConversionFlags)
See QPaintEngine::drawImage()
virtual QSize sizeMetrics() const =0
virtual void updateState(const QPaintEngineState &)
virtual void drawPolygon(const QPointF *, int, QPaintEngine::PolygonDrawMode)
See QPaintEngine::drawPolygon()
virtual void drawPoints(const QPointF *, int)
virtual void drawPixmap(const QRectF &, const QPixmap &, const QRectF &)
virtual void drawPixmap(const QRectF &, const QPixmap &, const QRectF &)
See QPaintEngine::drawPixmap()
virtual void drawPoints(const QPointF *, int)
See QPaintEngine::drawPoints()
int i
virtual void drawPolygon(const QPointF *, int, PolygonDrawMode)
virtual void drawEllipse(const QRectF &)


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17