QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
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
20#include "qgsdxfpaintengine.h"
21#include "qgspoint.h"
22
24{
25 mPaintEngine = std::make_unique<QgsDxfPaintEngine>( this, dxf );
26}
27
32
33QPaintEngine *QgsDxfPaintDevice::paintEngine() const
34{
35 return mPaintEngine.get();
36}
37
38int QgsDxfPaintDevice::metric( PaintDeviceMetric metric ) const
39{
40 // NOLINTBEGIN(bugprone-branch-clone)
41 switch ( metric )
42 {
43 case QPaintDevice::PdmWidth:
44 return mDrawingSize.width();
45 case QPaintDevice::PdmHeight:
46 return mDrawingSize.height();
47 case QPaintDevice::PdmWidthMM:
48 return mDrawingSize.width();
49 case QPaintDevice::PdmHeightMM:
50 return mDrawingSize.height();
51 case QPaintDevice::PdmNumColors:
52 return std::numeric_limits<int>::max();
53 case QPaintDevice::PdmDepth:
54 return 32;
55 case QPaintDevice::PdmDpiX:
56 case QPaintDevice::PdmDpiY:
57 case QPaintDevice::PdmPhysicalDpiX:
58 case QPaintDevice::PdmPhysicalDpiY:
59 return 96;
60 case QPaintDevice::PdmDevicePixelRatio:
61 return 1;
62 case QPaintDevice::PdmDevicePixelRatioScaled:
63 return 1;
64#if (QT_VERSION >= QT_VERSION_CHECK(6, 8, 0))
65 case PdmDevicePixelRatioF_EncodedA:
66 return 1;
67 case PdmDevicePixelRatioF_EncodedB:
68 return 1;
69#endif
70 }
71 // NOLINTEND(bugprone-branch-clone)
72 return 0;
73}
74
76{
77 if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
78 {
79 return 1.0;
80 }
81
82 const double widthFactor = mRectangle.width() / mDrawingSize.width();
83 const double heightFactor = mRectangle.height() / mDrawingSize.height();
84 return ( widthFactor + heightFactor ) / 2.0;
85}
86
87QPointF QgsDxfPaintDevice::dxfCoordinates( QPointF pt ) const
88{
89 if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
90 {
91 return QPointF( pt.x(), pt.y() );
92 }
93
94 const double x = mRectangle.left() + pt.x() * ( mRectangle.width() / mDrawingSize.width() );
95 const double y = mRectangle.bottom() - pt.y() * ( mRectangle.height() / mDrawingSize.height() );
96 return QPointF( x, y );
97}
98
99void QgsDxfPaintDevice::setLayer( const QString &layer )
100{
101 if ( mPaintEngine )
102 {
103 mPaintEngine->setLayer( layer );
104 }
105}
106
107void QgsDxfPaintDevice::setShift( QPointF shift )
108{
109 if ( mPaintEngine )
110 {
111 mPaintEngine->setShift( shift );
112 }
113}
114
115
Exports QGIS layers to the DXF format.
double widthScaleFactor() const
Returns scale factor for line width.
QPaintEngine * paintEngine() const override
void setShift(QPointF shift)
QPointF dxfCoordinates(QPointF pt) const
Converts a point from device coordinates to dxf coordinates.
void setLayer(const QString &layer)
int metric(PaintDeviceMetric metric) const override
QgsDxfPaintDevice(QgsDxfExport *dxf)