QGIS API Documentation  3.0.2-Girona (307d082)
qgsdxfpaintdevice.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdxpaintdevice.cpp
3  --------------------
4  begin : November 2013
5  copyright : (C) 2013 by Marco Hugentobler
6  email : marco at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgsdxfpaintdevice.h"
19 #include "qgsdxfpaintengine.h"
20 
22 {
23  mPaintEngine = new QgsDxfPaintEngine( this, dxf );
24 }
25 
27 {
28  delete mPaintEngine;
29 }
30 
31 QPaintEngine *QgsDxfPaintDevice::paintEngine() const
32 {
33  return mPaintEngine;
34 }
35 
36 int QgsDxfPaintDevice::metric( PaintDeviceMetric metric ) const
37 {
38  switch ( metric )
39  {
40  case QPaintDevice::PdmWidth:
41  return mDrawingSize.width();
42  case QPaintDevice::PdmHeight:
43  return mDrawingSize.height();
44  case QPaintDevice::PdmWidthMM:
45  return mDrawingSize.width();
46  case QPaintDevice::PdmHeightMM:
47  return mDrawingSize.height();
48  case QPaintDevice::PdmNumColors:
49  return INT_MAX;
50  case QPaintDevice::PdmDepth:
51  return 32;
52  case QPaintDevice::PdmDpiX:
53  case QPaintDevice::PdmDpiY:
54  case QPaintDevice::PdmPhysicalDpiX:
55  case QPaintDevice::PdmPhysicalDpiY:
56  return 96;
57  case QPaintDevice::PdmDevicePixelRatio:
58  return 1;
59 #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
60  case QPaintDevice::PdmDevicePixelRatioScaled:
61  return 1;
62 #endif
63  }
64  return 0;
65 }
66 
68 {
69  if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
70  {
71  return 1.0;
72  }
73 
74  double widthFactor = mRectangle.width() / mDrawingSize.width();
75  double heightFactor = mRectangle.height() / mDrawingSize.height();
76  return ( widthFactor + heightFactor ) / 2.0;
77 }
78 
79 QPointF QgsDxfPaintDevice::dxfCoordinates( QPointF pt ) const
80 {
81  if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
82  {
83  return QPointF( pt.x(), pt.y() );
84  }
85 
86  double x = mRectangle.left() + pt.x() * ( mRectangle.width() / mDrawingSize.width() );
87  double y = mRectangle.bottom() - pt.y() * ( mRectangle.height() / mDrawingSize.height() );
88  return QPointF( x, y );
89 }
90 
91 void QgsDxfPaintDevice::setLayer( const QString &layer )
92 {
93  if ( mPaintEngine )
94  {
95  mPaintEngine->setLayer( layer );
96  }
97 }
98 
99 void QgsDxfPaintDevice::setShift( QPointF shift )
100 {
101  if ( mPaintEngine )
102  {
103  mPaintEngine->setShift( shift );
104  }
105 }
106 
107 
QPaintEngine * paintEngine() const override
~QgsDxfPaintDevice() override
void setLayer(const QString &layer)
void setShift(QPointF shift)
void setShift(QPointF shift)
QPointF dxfCoordinates(QPointF pt) const
Converts a point from device coordinates to dxf coordinates.
double widthScaleFactor() const
Returns scale factor for line width.
void setLayer(const QString &layer)
QgsDxfPaintDevice(QgsDxfExport *dxf)
int metric(PaintDeviceMetric metric) const override