QGIS API Documentation  3.0.2-Girona (307d082)
qgsmaptopixel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaptopixel.h - description
3  -------------------
4  begin : Sat Jun 22 2002
5  copyright : (C) 2002 by Gary E.Sherman
6  email : sherman at mrcc.com
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 #ifndef QGSMAPTOPIXEL
18 #define QGSMAPTOPIXEL
19 
20 #include "qgis_core.h"
21 #include "qgis_sip.h"
22 #include <QTransform>
23 #include <vector>
24 #include "qgsunittypes.h"
25 #include <cassert>
26 
27 class QgsPointXY;
28 class QPoint;
29 
36 class CORE_EXPORT QgsMapToPixel
37 {
38  public:
39 
50  QgsMapToPixel( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation );
51 
56  QgsMapToPixel( double mapUnitsPerPixel );
57 
66  static QgsMapToPixel fromScale( double scale, QgsUnitTypes::DistanceUnit mapUnits, double dpi = 96 );
67 
73  QgsMapToPixel();
74 
80  QgsPointXY transform( const QgsPointXY &p ) const;
81 
82  void transform( QgsPointXY *p ) const;
83 
91  QgsPointXY transform( qreal x, qreal y ) const;
92 
98  void transformInPlace( double &x, double &y ) const;
99 
101  void transformInPlace( float &x, float &y ) const SIP_SKIP;
102 
103 #ifndef SIP_RUN
104 
111  template <class T> SIP_SKIP
112  void transformInPlace( QVector<T> &x, QVector<T> &y ) const
113  {
114  assert( x.size() == y.size() );
115  for ( int i = 0; i < x.size(); ++i )
116  transformInPlace( x[i], y[i] );
117  }
118 #endif
119 
120  QgsPointXY toMapCoordinates( int x, int y ) const;
121 
123  QgsPointXY toMapCoordinatesF( double x, double y ) const;
124 
130  QgsPointXY toMapCoordinates( QPoint p ) const;
131 
132  QgsPointXY toMapPoint( double x, double y ) const;
133 
138  void setMapUnitsPerPixel( double mapUnitsPerPixel );
139 
141  double mapUnitsPerPixel() const;
142 
148  int mapWidth() const;
149 
154  int mapHeight() const;
155 
163  void setMapRotation( double degrees, double cx, double cy );
164 
169  double mapRotation() const;
170 
181  void setParameters( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation );
182 
184  QString showParameters() const;
185 
186  QTransform transform() const;
187 
193  double xCenter() const { return mXCenter; }
194 
200  double yCenter() const { return mYCenter; }
201 
202  private:
203  double mMapUnitsPerPixel = 1;
204  int mWidth = 1;
205  int mHeight = 1;
206  double mRotation = 0.0;
207  double mXCenter = 0.5;
208  double mYCenter = 0.5;
209  double xMin = 0;
210  double yMin = 0;
211  QTransform mMatrix;
212 
213  bool updateMatrix();
214 };
215 
216 
217 #endif // QGSMAPTOPIXEL
double xCenter() const
Returns the center x-coordinate for the transform.
void transformInPlace(QVector< T > &x, QVector< T > &y) const
Transform device coordinates to map coordinates.
A class to represent a 2D point.
Definition: qgspointxy.h:43
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:36
#define SIP_SKIP
Definition: qgis_sip.h:119
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:43
double yCenter() const
Returns the center y-coordinate for the transform.