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