QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 QgsDxfPaintDevice::QgsDxfPaintDevice( QgsDxfExport* dxf ): QPaintDevice(), mPaintEngine( 0 )
21 {
22  mPaintEngine = new QgsDxfPaintEngine( this, dxf );
23 }
24 
26 {
27  delete mPaintEngine;
28 }
29 
30 QPaintEngine* QgsDxfPaintDevice::paintEngine() const
31 {
32  return mPaintEngine;
33 }
34 
35 int QgsDxfPaintDevice::metric( PaintDeviceMetric metric ) const
36 {
37  switch ( metric )
38  {
39  case QPaintDevice::PdmWidth:
40  return mDrawingSize.width();
41  case QPaintDevice::PdmHeight:
42  return mDrawingSize.height();
43  case QPaintDevice::PdmWidthMM:
44  return mDrawingSize.width();
45  case QPaintDevice::PdmHeightMM:
46  return mDrawingSize.height();
47  case QPaintDevice::PdmNumColors:
48  return INT_MAX;
49  case QPaintDevice::PdmDepth:
50  return 32;
51  case QPaintDevice::PdmDpiX:
52  case QPaintDevice::PdmDpiY:
53  case QPaintDevice::PdmPhysicalDpiX:
54  case QPaintDevice::PdmPhysicalDpiY:
55  return 96;
56  }
57  return 0;
58 }
59 
61 {
62  if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
63  {
64  return 1.0;
65  }
66 
67  double widthFactor = mRectangle.width() / mDrawingSize.width();
68  double heightFactor = mRectangle.height() / mDrawingSize.height();
69  return ( widthFactor + heightFactor ) / 2.0;
70 }
71 
72 QPointF QgsDxfPaintDevice::dxfCoordinates( const QPointF& pt ) const
73 {
74  if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
75  {
76  return QPointF( pt.x(), pt.y() );
77  }
78 
79  double x = mRectangle.left() + pt.x() * ( mRectangle.width() / mDrawingSize.width() );
80  double y = mRectangle.bottom() - pt.y() * ( mRectangle.height() / mDrawingSize.height() );
81  return QPointF( x, y );
82 }
83 
84 void QgsDxfPaintDevice::setLayer( const QString& layer )
85 {
86  if ( mPaintEngine )
87  {
88  mPaintEngine->setLayer( layer );
89  }
90 }
91 
92 void QgsDxfPaintDevice::setShift( const QPointF& shift )
93 {
94  if ( mPaintEngine )
95  {
96  mPaintEngine->setShift( shift );
97  }
98 }
99 
100 
int metric(PaintDeviceMetric metric) const
QPointF dxfCoordinates(const QPointF &pt) const
Converts a point from device coordinates to dxf coordinates.
double widthScaleFactor() const
Returns scale factor for line width.
void setLayer(const QString &layer)
QgsDxfPaintEngine * mPaintEngine
void setShift(const QPointF &shift)
void setShift(const QPointF &shift)
QPaintEngine * paintEngine() const
void setLayer(const QString &layer)
QgsDxfPaintDevice(QgsDxfExport *dxf)