QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 #include <memory>
27 
28 class QgsPointXY;
29 class QPoint;
30 
37 class CORE_EXPORT QgsMapToPixel
38 {
39  public:
40 
51  QgsMapToPixel( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation );
52 
57  QgsMapToPixel( double mapUnitsPerPixel );
58 
67  static QgsMapToPixel fromScale( double scale, QgsUnitTypes::DistanceUnit mapUnits, double dpi = 96 );
68 
74  QgsMapToPixel();
75 
81  QgsPointXY transform( const QgsPointXY &p ) const;
82 
83  void transform( QgsPointXY *p ) const;
84 
92  QgsPointXY transform( qreal x, qreal y ) const;
93 
99  void transformInPlace( double &x, double &y ) const;
100 
102  void transformInPlace( float &x, float &y ) const SIP_SKIP;
103 
104 #ifndef SIP_RUN
105 
112  template <class T> SIP_SKIP
113  void transformInPlace( QVector<T> &x, QVector<T> &y ) const
114  {
115  assert( x.size() == y.size() );
116  for ( int i = 0; i < x.size(); ++i )
117  transformInPlace( x[i], y[i] );
118  }
119 #endif
120 
122  QgsPointXY toMapCoordinates( int x, int y ) const;
123 
125  QgsPointXY toMapCoordinates( double x, double y ) const SIP_PYNAME( toMapCoordinatesF );
126 
132  QgsPointXY toMapCoordinates( QPoint p ) const;
133 
138  Q_DECL_DEPRECATED QgsPointXY toMapPoint( double x, double y ) const SIP_DEPRECATED;
139 
144  void setMapUnitsPerPixel( double mapUnitsPerPixel );
145 
147  double mapUnitsPerPixel() const;
148 
154  int mapWidth() const;
155 
160  int mapHeight() const;
161 
169  void setMapRotation( double degrees, double cx, double cy );
170 
175  double mapRotation() const;
176 
187  void setParameters( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation );
188 
190  QString showParameters() const;
191 
192  QTransform transform() const;
193 
199  double xCenter() const { return mXCenter; }
200 
206  double yCenter() const { return mYCenter; }
207 
208  private:
209  double mMapUnitsPerPixel = 1;
210  int mWidth = 1;
211  int mHeight = 1;
212  double mRotation = 0.0;
213  double mXCenter = 0.5;
214  double mYCenter = 0.5;
215  double xMin = 0;
216  double yMin = 0;
217  QTransform mMatrix;
218 
219  bool updateMatrix();
220 };
221 
222 
223 #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:37
#define SIP_SKIP
Definition: qgis_sip.h:119
#define SIP_DEPRECATED
Definition: qgis_sip.h:99
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:54
double yCenter() const
Returns the center y-coordinate for the transform.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:74