QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 #include "qgspoint.h"
21 
23 {
24  mPaintEngine = new QgsDxfPaintEngine( this, dxf );
25 }
26 
28 {
29  delete mPaintEngine;
30 }
31 
32 QPaintEngine *QgsDxfPaintDevice::paintEngine() const
33 {
34  return mPaintEngine;
35 }
36 
37 int QgsDxfPaintDevice::metric( PaintDeviceMetric metric ) const
38 {
39  switch ( metric )
40  {
41  case QPaintDevice::PdmWidth:
42  return mDrawingSize.width();
43  case QPaintDevice::PdmHeight:
44  return mDrawingSize.height();
45  case QPaintDevice::PdmWidthMM:
46  return mDrawingSize.width();
47  case QPaintDevice::PdmHeightMM:
48  return mDrawingSize.height();
49  case QPaintDevice::PdmNumColors:
50  return std::numeric_limits<int>::max();
51  case QPaintDevice::PdmDepth:
52  return 32;
53  case QPaintDevice::PdmDpiX:
54  case QPaintDevice::PdmDpiY:
55  case QPaintDevice::PdmPhysicalDpiX:
56  case QPaintDevice::PdmPhysicalDpiY:
57  return 96;
58  case QPaintDevice::PdmDevicePixelRatio:
59  return 1;
60 #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
61  case QPaintDevice::PdmDevicePixelRatioScaled:
62  return 1;
63 #endif
64  }
65  return 0;
66 }
67 
69 {
70  if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
71  {
72  return 1.0;
73  }
74 
75  double widthFactor = mRectangle.width() / mDrawingSize.width();
76  double heightFactor = mRectangle.height() / mDrawingSize.height();
77  return ( widthFactor + heightFactor ) / 2.0;
78 }
79 
80 QPointF QgsDxfPaintDevice::dxfCoordinates( QPointF pt ) const
81 {
82  if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
83  {
84  return QPointF( pt.x(), pt.y() );
85  }
86 
87  double x = mRectangle.left() + pt.x() * ( mRectangle.width() / mDrawingSize.width() );
88  double y = mRectangle.bottom() - pt.y() * ( mRectangle.height() / mDrawingSize.height() );
89  return QPointF( x, y );
90 }
91 
92 void QgsDxfPaintDevice::setLayer( const QString &layer )
93 {
94  if ( mPaintEngine )
95  {
96  mPaintEngine->setLayer( layer );
97  }
98 }
99 
100 void QgsDxfPaintDevice::setShift( QPointF shift )
101 {
102  if ( mPaintEngine )
103  {
104  mPaintEngine->setShift( shift );
105  }
106 }
107 
108 
QPointF dxfCoordinates(QPointF pt) const
Converts a point from device coordinates to dxf coordinates.
QPaintEngine * paintEngine() const override
~QgsDxfPaintDevice() override
double widthScaleFactor() const
Returns scale factor for line width.
void setLayer(const QString &layer)
void setShift(QPointF shift)
void setShift(QPointF shift)
void setLayer(const QString &layer)
QgsDxfPaintDevice(QgsDxfExport *dxf)
int metric(PaintDeviceMetric metric) const override