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