QGIS API Documentation  2.13.0-Master
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 "qgspoint.h"
21 #include <QTransform>
22 #include <vector>
23 
24 #include <cassert>
25 
26 class QgsPoint;
27 class QPoint;
28 
34 class CORE_EXPORT QgsMapToPixel
35 {
36  public:
45  Q_DECL_DEPRECATED QgsMapToPixel( double mapUnitsPerPixel, double height, double ymin = 0, double xmin = 0 );
46 
57  QgsMapToPixel( double mapUnitsPerPixel, double xc, double yc, int width, int height, double rotation );
58 
63  QgsMapToPixel( double mapUnitsPerPixel );
64 
70  QgsMapToPixel();
71 
77  QgsPoint transform( const QgsPoint& p ) const;
78 
79  void transform( QgsPoint* p ) const;
80 
88  QgsPoint transform( qreal x, qreal y ) const;
89 
102  void transformInPlace( double& x, double& y ) const;
103  void transformInPlace( float& x, float& y ) const;
104 
105 
112  template <class T>
114  {
115  assert( x.size() == y.size() );
116  for ( int i = 0; i < x.size(); ++i )
117  transformInPlace( x[i], y[i] );
118  }
119 
120  QgsPoint toMapCoordinates( int x, int y ) const;
121 
123  QgsPoint toMapCoordinatesF( double x, double y ) const;
124 
130  QgsPoint toMapCoordinates( QPoint p ) const;
131 
132  QgsPoint 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 
176  Q_DECL_DEPRECATED void setYMaximum( double yMax ) { mHeight = static_cast< int >( yMax ); }
177 
182  Q_DECL_DEPRECATED void setYMinimum( double ymin );
183 
188  Q_DECL_DEPRECATED void setXMinimum( double xmin );
189 
198  Q_DECL_DEPRECATED void setParameters( double mapUnitsPerPixel, double xmin, double ymin, double height );
199 
210  void setParameters( double mapUnitsPerPixel, double xc, double yc, int width, int height, double rotation );
211 
213  QString showParameters() const;
214 
215  QTransform transform() const;
216 
217  private:
218  double mMapUnitsPerPixel;
219  int mWidth;
220  int mHeight;
221  double mRotation;
222  double xCenter;
223  double yCenter;
224  double xMin;
225  double yMin;
226  QTransform mMatrix;
227 
228  bool updateMatrix();
229 };
230 
231 
232 #endif // QGSMAPTOPIXEL
void transformInPlace(QVector< T > &x, QVector< T > &y) const
Transform device coordinates to map coordinates.
Q_DECL_DEPRECATED void setYMaximum(double yMax)
Set maximum y value.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
A class to represent a point.
Definition: qgspoint.h:65
int size() const