QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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  case QPaintDevice::PdmDevicePixelRatioScaled:
61  return 1;
62  }
63  return 0;
64 }
65 
67 {
68  if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
69  {
70  return 1.0;
71  }
72 
73  double widthFactor = mRectangle.width() / mDrawingSize.width();
74  double heightFactor = mRectangle.height() / mDrawingSize.height();
75  return ( widthFactor + heightFactor ) / 2.0;
76 }
77 
78 QPointF QgsDxfPaintDevice::dxfCoordinates( QPointF pt ) const
79 {
80  if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
81  {
82  return QPointF( pt.x(), pt.y() );
83  }
84 
85  double x = mRectangle.left() + pt.x() * ( mRectangle.width() / mDrawingSize.width() );
86  double y = mRectangle.bottom() - pt.y() * ( mRectangle.height() / mDrawingSize.height() );
87  return QPointF( x, y );
88 }
89 
90 void QgsDxfPaintDevice::setLayer( const QString &layer )
91 {
92  if ( mPaintEngine )
93  {
94  mPaintEngine->setLayer( layer );
95  }
96 }
97 
98 void QgsDxfPaintDevice::setShift( QPointF shift )
99 {
100  if ( mPaintEngine )
101  {
102  mPaintEngine->setShift( shift );
103  }
104 }
105 
106 
QgsDxfPaintDevice::paintEngine
QPaintEngine * paintEngine() const override
Definition: qgsdxfpaintdevice.cpp:32
QgsDxfExport
Definition: qgsdxfexport.h:63
QgsDxfPaintDevice::QgsDxfPaintDevice
QgsDxfPaintDevice(QgsDxfExport *dxf)
Definition: qgsdxfpaintdevice.cpp:22
QgsDxfPaintDevice::~QgsDxfPaintDevice
~QgsDxfPaintDevice() override
Definition: qgsdxfpaintdevice.cpp:27
qgsdxfpaintdevice.h
qgspoint.h
QgsDxfPaintDevice::setLayer
void setLayer(const QString &layer)
Definition: qgsdxfpaintdevice.cpp:90
QgsDxfPaintEngine::setShift
void setShift(QPointF shift)
Definition: qgsdxfpaintengine.h:58
QgsDxfPaintEngine
Definition: qgsdxfpaintengine.h:40
QgsDxfPaintDevice::dxfCoordinates
QPointF dxfCoordinates(QPointF pt) const
Converts a point from device coordinates to dxf coordinates.
Definition: qgsdxfpaintdevice.cpp:78
qgsdxfpaintengine.h
QgsDxfPaintDevice::metric
int metric(PaintDeviceMetric metric) const override
Definition: qgsdxfpaintdevice.cpp:37
QgsDxfPaintDevice::setShift
void setShift(QPointF shift)
Definition: qgsdxfpaintdevice.cpp:98
QgsDxfPaintDevice::widthScaleFactor
double widthScaleFactor() const
Returns scale factor for line width.
Definition: qgsdxfpaintdevice.cpp:66
QgsDxfPaintEngine::setLayer
void setLayer(const QString &layer)
Definition: qgsdxfpaintengine.h:55