23
23
24
24
#include " qgslogger.h"
25
25
26
+ // @deprecated in 2.8
27
+ QgsMapToPixel::QgsMapToPixel ( double mapUnitsPerPixel,
28
+ double xc,
29
+ double yc,
30
+ int width,
31
+ int height,
32
+ double rotation )
33
+ : mMapUnitsPerPixel( mapUnitsPerPixel )
34
+ , mWidth( width )
35
+ , mHeight( height )
36
+ , mRotation( rotation )
37
+ , xCenter( xc )
38
+ , yCenter( yc )
39
+ , xMin ( xc - ( mWidth * mMapUnitsPerPixel / 2.0 ) )
40
+ , yMin ( yc - ( mHeight * mMapUnitsPerPixel / 2.0 ) )
41
+ {
42
+ updateMatrix ();
43
+ }
44
+
45
+ QgsMapToPixel::QgsMapToPixel ()
46
+ : mMapUnitsPerPixel( 1 )
47
+ , mWidth( 1 )
48
+ , mHeight( 1 )
49
+ , mRotation( 0.0 )
50
+ , xCenter( 0.5 )
51
+ , yCenter( 0.5 )
52
+ , xMin ( 0 )
53
+ , yMin ( 0 )
54
+ {
55
+ updateMatrix ();
56
+ }
57
+
26
58
QgsMapToPixel::QgsMapToPixel ( double mapUnitsPerPixel,
27
59
double height,
28
60
double ymin,
29
61
double xmin )
30
62
: mMapUnitsPerPixel( mapUnitsPerPixel )
63
+ , mWidth( -1 )
31
64
, mHeight( height )
32
- , yMin( ymin )
33
- , xMin( xmin )
34
- , mMapRotation( 0 )
65
+ , mRotation( 0.0 )
66
+ , xCenter( 0.0 )
67
+ , yCenter( 0.0 )
68
+ , xMin ( xmin )
69
+ , yMin ( ymin )
35
70
{
71
+ updateMatrix ();
36
72
}
37
73
38
74
QgsMapToPixel::~QgsMapToPixel ()
@@ -46,13 +82,11 @@ int QgsMapToPixel::mapHeight() const
46
82
47
83
int QgsMapToPixel::mapWidth () const
48
84
{
49
- return (( xCenter -xMin )* 2 ) / mMapUnitsPerPixel ;
85
+ return mWidth ;
50
86
}
51
87
52
- QTransform QgsMapToPixel::getMatrix () const
88
+ void QgsMapToPixel::updateMatrix ()
53
89
{
54
- double cy = mapHeight () / 2.0 ;
55
- double cx = mapWidth () / 2.0 ;
56
90
double rotation = mapRotation ();
57
91
58
92
#if 0 // debugging
@@ -71,17 +105,25 @@ QTransform QgsMapToPixel::getMatrix() const
71
105
// Returning a simplified matrix in hope it'll give expected
72
106
// results from an existing test, see
73
107
// https://travis-ci.org/qgis/QGIS/builds/42508945
74
- return QTransform::fromScale ( 1.0 / mMapUnitsPerPixel , -1.0 / mMapUnitsPerPixel )
108
+ mMatrix = QTransform::fromScale ( 1.0 / mMapUnitsPerPixel , -1.0 / mMapUnitsPerPixel )
75
109
.translate ( -xMin, - ( yMin + mHeight *mMapUnitsPerPixel ) );
110
+ return ;
76
111
}
77
112
78
- return QTransform::fromTranslate ( cx, cy )
113
+ double cy = mapHeight () / 2.0 ;
114
+ double cx = mapWidth () / 2.0 ;
115
+ mMatrix = QTransform::fromTranslate ( cx, cy )
79
116
.rotate ( rotation )
80
117
.scale ( 1 / mMapUnitsPerPixel , -1 / mMapUnitsPerPixel )
81
118
.translate ( -xCenter, -yCenter )
82
119
;
83
120
}
84
121
122
+ const QTransform& QgsMapToPixel::getMatrix () const
123
+ {
124
+ return mMatrix ;
125
+ }
126
+
85
127
QgsPoint QgsMapToPixel::toMapPoint ( double x, double y ) const
86
128
{
87
129
bool invertible;
@@ -115,6 +157,7 @@ QgsPoint QgsMapToPixel::toMapCoordinatesF( double x, double y ) const
115
157
void QgsMapToPixel::setMapUnitsPerPixel ( double mapUnitsPerPixel )
116
158
{
117
159
mMapUnitsPerPixel = mapUnitsPerPixel;
160
+ updateMatrix ();
118
161
}
119
162
120
163
double QgsMapToPixel::mapUnitsPerPixel () const
@@ -124,50 +167,75 @@ double QgsMapToPixel::mapUnitsPerPixel() const
124
167
125
168
void QgsMapToPixel::setMapRotation ( double degrees, double cx, double cy )
126
169
{
127
- mMapRotation = degrees;
170
+ mRotation = degrees;
128
171
xCenter = cx;
129
172
yCenter = cy;
130
- assert ( xCenter >= xMin );
131
- assert ( yCenter >= yMin );
132
- // assert(yCenter <= yMin + mHeight*mMapUnitsPerPixel;
173
+ if ( mWidth < 0 ) {
174
+ // set width not that we can compute it
175
+ mWidth = (( xCenter -xMin )*2 ) / mMapUnitsPerPixel ;
176
+ }
177
+ updateMatrix ();
133
178
}
134
179
135
180
double QgsMapToPixel::mapRotation () const
136
181
{
137
- return mMapRotation ;
138
- }
139
-
140
- void QgsMapToPixel::setViewportHeight ( double height )
141
- {
142
- mHeight = height;
182
+ return mRotation ;
143
183
}
144
184
185
+ // @deprecated in 2.8
145
186
void QgsMapToPixel::setYMinimum ( double ymin )
146
187
{
147
- yMin = ymin;
188
+ yCenter = ymin + mHeight * mMapUnitsPerPixel / 2.0 ;
189
+ mRotation = 0.0 ;
190
+ updateMatrix ();
148
191
}
149
192
193
+ // @deprecated in 2.8
150
194
void QgsMapToPixel::setXMinimum ( double xmin )
151
195
{
152
- xMin = xmin;
196
+ xCenter = xmin + mWidth * mMapUnitsPerPixel / 2.0 ;
197
+ mRotation = 0.0 ;
198
+ updateMatrix ();
153
199
}
154
200
201
+ // @deprecated in 2.8
155
202
void QgsMapToPixel::setParameters ( double mapUnitsPerPixel, double xmin, double ymin, double ymax )
156
203
{
157
204
mMapUnitsPerPixel = mapUnitsPerPixel;
158
205
xMin = xmin;
159
206
yMin = ymin;
160
207
mHeight = ymax;
208
+ xCenter = xmin + mWidth * mMapUnitsPerPixel / 2.0 ;
209
+ yCenter = ymin + mHeight * mMapUnitsPerPixel / 2.0 ;
210
+ mRotation = 0.0 ;
211
+ updateMatrix ();
212
+ }
161
213
214
+ void QgsMapToPixel::setParameters ( double mapUnitsPerPixel,
215
+ double xc,
216
+ double yc,
217
+ int width,
218
+ int height,
219
+ double rotation )
220
+ {
221
+ mMapUnitsPerPixel = mapUnitsPerPixel;
222
+ xCenter = xc;
223
+ yCenter = yc;
224
+ mWidth = width;
225
+ mHeight = height;
226
+ mRotation = rotation;
227
+ xMin = xc - ( mWidth * mMapUnitsPerPixel / 2.0 );
228
+ yMin = yc - ( mHeight * mMapUnitsPerPixel / 2.0 );
229
+ updateMatrix ();
162
230
}
163
231
164
232
QString QgsMapToPixel::showParameters ()
165
233
{
166
234
QString rep;
167
235
QTextStream ( &rep ) << " Map units/pixel: " << mMapUnitsPerPixel
168
- << " X minimum : " << xMin << " Y minimum: " << yMin
169
- << " Height : " << mHeight << " Rotation: " << mMapRotation
170
- << " X center : " << xCenter << " Y center: " << yCenter ;
236
+ << " center : " << xCenter << " , " << yCenter
237
+ << " rotation : " << mRotation
238
+ << " size : " << mWidth << " x " << mHeight ;
171
239
return rep;
172
240
173
241
}
0 commit comments