QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 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 const double widthFactor = mRectangle.width() / mDrawingSize.width();
74 const double heightFactor = mRectangle.height() / mDrawingSize.height();
75 return ( widthFactor + heightFactor ) / 2.0;
76}
77
78QPointF QgsDxfPaintDevice::dxfCoordinates( QPointF pt ) const
79{
80 if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
81 {
82 return QPointF( pt.x(), pt.y() );
83 }
84
85 const double x = mRectangle.left() + pt.x() * ( mRectangle.width() / mDrawingSize.width() );
86 const double y = mRectangle.bottom() - pt.y() * ( mRectangle.height() / mDrawingSize.height() );
87 return QPointF( x, y );
88}
89
90void QgsDxfPaintDevice::setLayer( const QString &layer )
91{
92 if ( mPaintEngine )
93 {
94 mPaintEngine->setLayer( layer );
95 }
96}
97
98void QgsDxfPaintDevice::setShift( QPointF shift )
99{
100 if ( mPaintEngine )
101 {
102 mPaintEngine->setShift( shift );
103 }
104}
105
106
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)