QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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
30
31QPaintEngine *QgsDxfPaintDevice::paintEngine() const
32{
33 return mPaintEngine.get();
34}
35
36int QgsDxfPaintDevice::metric( PaintDeviceMetric metric ) const
37{
38 // NOLINTBEGIN(bugprone-branch-clone)
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#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 8, 0 ) )
63 case PdmDevicePixelRatioF_EncodedA:
64 return 1;
65 case PdmDevicePixelRatioF_EncodedB:
66 return 1;
67#endif
68 }
69 // NOLINTEND(bugprone-branch-clone)
70 return 0;
71}
72
74{
75 if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
76 {
77 return 1.0;
78 }
79
80 const double widthFactor = mRectangle.width() / mDrawingSize.width();
81 const double heightFactor = mRectangle.height() / mDrawingSize.height();
82 return ( widthFactor + heightFactor ) / 2.0;
83}
84
85QPointF QgsDxfPaintDevice::dxfCoordinates( QPointF pt ) const
86{
87 if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
88 {
89 return QPointF( pt.x(), pt.y() );
90 }
91
92 const double x = mRectangle.left() + pt.x() * ( mRectangle.width() / mDrawingSize.width() );
93 const double y = mRectangle.bottom() - pt.y() * ( mRectangle.height() / mDrawingSize.height() );
94 return QPointF( x, y );
95}
96
97void QgsDxfPaintDevice::setLayer( const QString &layer )
98{
99 if ( mPaintEngine )
100 {
101 mPaintEngine->setLayer( layer );
102 }
103}
104
105void QgsDxfPaintDevice::setShift( QPointF shift )
106{
107 if ( mPaintEngine )
108 {
109 mPaintEngine->setShift( shift );
110 }
111}
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)