18
18
19
19
20
20
21
- static unsigned char * _getPoint (QPointF& pt, const QgsMapToPixel& mapToPixel , unsigned char * wkb)
21
+ static unsigned char * _getPoint ( QPointF& pt, QgsRenderContext& context , unsigned char * wkb )
22
22
{
23
23
wkb++; // jump over endian info
24
24
unsigned int wkbType = *(( int * ) wkb );
25
- wkb += sizeof (unsigned int );
26
-
27
- double x = *(( double * ) wkb ); wkb += sizeof (double );
28
- double y = *(( double * ) wkb ); wkb += sizeof (double );
29
-
25
+ wkb += sizeof ( unsigned int );
26
+
27
+ double x = *(( double * ) wkb ); wkb += sizeof ( double );
28
+ double y = *(( double * ) wkb ); wkb += sizeof ( double );
29
+
30
30
if ( wkbType == QGis::WKBPolygon25D )
31
- wkb += sizeof (double );
32
-
33
- mapToPixel.transformInPlace (x,y);
34
- // TODO: coordinate transform
35
- pt = QPointF (x,y);
31
+ wkb += sizeof ( double );
32
+
33
+ if ( context.coordinateTransform () )
34
+ {
35
+ double z = 0 ; // dummy variable for coordiante transform
36
+ context.coordinateTransform ()->transformInPlace ( x, y, z );
37
+ }
38
+
39
+ context.mapToPixel ().transformInPlace ( x, y );
40
+
41
+ pt = QPointF ( x, y );
36
42
return wkb;
37
43
}
38
44
39
- static unsigned char * _getLineString (QPolygonF& pts, const QgsMapToPixel& mapToPixel , unsigned char * wkb)
45
+ static unsigned char * _getLineString ( QPolygonF& pts, QgsRenderContext& context , unsigned char * wkb )
40
46
{
41
47
wkb++; // jump over endian info
42
48
unsigned int wkbType = *(( int * ) wkb );
43
- wkb += sizeof (unsigned int );
49
+ wkb += sizeof ( unsigned int );
44
50
unsigned int nPoints = *(( int * ) wkb );
45
- wkb += sizeof (unsigned int );
46
-
51
+ wkb += sizeof ( unsigned int );
52
+
47
53
bool hasZValue = ( wkbType == QGis::WKBLineString25D );
48
- double x,y;
54
+ double x, y;
55
+
56
+ pts.resize ( nPoints );
49
57
50
- pts.resize (nPoints);
58
+ const QgsCoordinateTransform* ct = context.coordinateTransform ();
59
+ const QgsMapToPixel& mtp = context.mapToPixel ();
60
+ double z = 0 ; // dummy variable for coordiante transform
51
61
52
62
for ( unsigned int i = 0 ; i < nPoints; ++i )
53
63
{
@@ -58,195 +68,203 @@ static unsigned char* _getLineString(QPolygonF& pts, const QgsMapToPixel& mapToP
58
68
59
69
if ( hasZValue ) // ignore Z value
60
70
wkb += sizeof ( double );
61
-
62
- mapToPixel.transformInPlace (x,y);
63
-
64
- pts[i] = QPointF (x,y);
65
-
66
- // TODO: coordinate transform
71
+
72
+ // TODO: maybe to the transform at once (faster?)
73
+ if ( ct )
74
+ ct->transformInPlace ( x, y, z );
75
+ mtp.transformInPlace ( x, y );
76
+
77
+ pts[i] = QPointF ( x, y );
78
+
67
79
}
68
-
80
+
69
81
return wkb;
70
82
}
71
83
72
- static unsigned char * _getPolygon (QPolygonF& pts, QList<QPolygonF>& holes, const QgsMapToPixel& mapToPixel , unsigned char * wkb)
84
+ static unsigned char * _getPolygon ( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context , unsigned char * wkb )
73
85
{
74
86
wkb++; // jump over endian info
75
87
unsigned int wkbType = *(( int * ) wkb );
76
- wkb += sizeof (unsigned int ); // jump over wkb type
88
+ wkb += sizeof ( unsigned int ); // jump over wkb type
77
89
unsigned int numRings = *(( int * ) wkb );
78
- wkb += sizeof (unsigned int );
79
-
90
+ wkb += sizeof ( unsigned int );
91
+
80
92
if ( numRings == 0 ) // sanity check for zero rings in polygon
81
93
return wkb;
82
94
83
95
bool hasZValue = ( wkbType == QGis::WKBPolygon25D );
84
- double x,y;
96
+ double x, y;
85
97
holes.clear ();
86
98
99
+ const QgsCoordinateTransform* ct = context.coordinateTransform ();
100
+ const QgsMapToPixel& mtp = context.mapToPixel ();
101
+ double z = 0 ; // dummy variable for coordiante transform
102
+
87
103
for ( unsigned int idx = 0 ; idx < numRings; idx++ )
88
104
{
89
105
unsigned int nPoints = *(( int * )wkb );
90
- wkb += sizeof (unsigned int );
106
+ wkb += sizeof ( unsigned int );
91
107
92
- QPolygonF poly (nPoints);
108
+ QPolygonF poly ( nPoints );
93
109
94
110
// Extract the points from the WKB and store in a pair of vectors.
95
111
for ( unsigned int jdx = 0 ; jdx < nPoints; jdx++ )
96
112
{
97
113
x = *(( double * ) wkb ); wkb += sizeof ( double );
98
114
y = *(( double * ) wkb ); wkb += sizeof ( double );
99
-
100
- mapToPixel.transformInPlace (x,y);
101
- // TODO: coordinate transform
102
115
103
- poly[jdx] = QPointF (x,y);
116
+ // TODO: maybe to the transform at once (faster?)
117
+ if ( ct )
118
+ ct->transformInPlace ( x, y, z );
119
+ mtp.transformInPlace ( x, y );
120
+
121
+ poly[jdx] = QPointF ( x, y );
104
122
105
123
if ( hasZValue )
106
124
wkb += sizeof ( double );
107
125
}
108
-
126
+
109
127
if ( nPoints < 1 )
110
128
continue ;
111
-
112
- if (idx == 0 )
129
+
130
+ if ( idx == 0 )
113
131
pts = poly;
114
132
else
115
- holes.append (poly);
133
+ holes.append ( poly );
116
134
}
117
-
135
+
118
136
return wkb;
119
137
}
120
138
121
139
122
- QgsFeatureRendererV2::QgsFeatureRendererV2 (QString type)
123
- : mType(type), mUsingSymbolLevels(false )
140
+ QgsFeatureRendererV2::QgsFeatureRendererV2 ( QString type )
141
+ : mType( type ), mUsingSymbolLevels( false )
124
142
{
125
143
}
126
144
127
- QgsFeatureRendererV2* QgsFeatureRendererV2::defaultRenderer (QGis::GeometryType geomType)
145
+ QgsFeatureRendererV2* QgsFeatureRendererV2::defaultRenderer ( QGis::GeometryType geomType )
128
146
{
129
- return new QgsSingleSymbolRendererV2 ( QgsSymbolV2::defaultSymbol (geomType) );
147
+ return new QgsSingleSymbolRendererV2 ( QgsSymbolV2::defaultSymbol ( geomType ) );
130
148
}
131
149
132
150
133
- void QgsFeatureRendererV2::renderFeature (QgsFeature& feature, QgsRenderContext& context, int layer)
151
+ void QgsFeatureRendererV2::renderFeature ( QgsFeature& feature, QgsRenderContext& context, int layer )
134
152
{
135
- QgsSymbolV2* symbol = symbolForFeature (feature);
136
- if (symbol == NULL )
153
+ QgsSymbolV2* symbol = symbolForFeature ( feature );
154
+ if ( symbol == NULL )
137
155
return ;
138
156
139
157
QgsSymbolV2::SymbolType symbolType = symbol->type ();
140
-
158
+
141
159
QgsGeometry* geom = feature.geometry ();
142
- switch (geom->wkbType ())
160
+ switch ( geom->wkbType () )
143
161
{
144
162
case QGis::WKBPoint:
163
+ {
164
+ if ( symbolType != QgsSymbolV2::Marker )
145
165
{
146
- if (symbolType != QgsSymbolV2::Marker)
147
- {
148
- QgsDebugMsg (" point can be drawn only with marker symbol!" );
149
- break ;
150
- }
151
- QPointF pt;
152
- _getPoint (pt, context.mapToPixel (), geom->asWkb ());
153
- ((QgsMarkerSymbolV2*)symbol)->renderPoint (pt, context, layer);
166
+ QgsDebugMsg ( " point can be drawn only with marker symbol!" );
167
+ break ;
154
168
}
155
- break ;
156
-
169
+ QPointF pt;
170
+ _getPoint ( pt, context, geom->asWkb () );
171
+ (( QgsMarkerSymbolV2* )symbol )->renderPoint ( pt, context, layer );
172
+ }
173
+ break ;
174
+
157
175
case QGis::WKBLineString:
176
+ {
177
+ if ( symbolType != QgsSymbolV2::Line )
158
178
{
159
- if (symbolType != QgsSymbolV2::Line)
160
- {
161
- QgsDebugMsg (" linestring can be drawn only with line symbol!" );
162
- break ;
163
- }
164
- QPolygonF pts;
165
- _getLineString (pts, context.mapToPixel (), geom->asWkb ());
166
- ((QgsLineSymbolV2*)symbol)->renderPolyline (pts, context, layer);
179
+ QgsDebugMsg ( " linestring can be drawn only with line symbol!" );
180
+ break ;
167
181
}
168
- break ;
169
-
182
+ QPolygonF pts;
183
+ _getLineString ( pts, context, geom->asWkb () );
184
+ (( QgsLineSymbolV2* )symbol )->renderPolyline ( pts, context, layer );
185
+ }
186
+ break ;
187
+
170
188
case QGis::WKBPolygon:
189
+ {
190
+ if ( symbolType != QgsSymbolV2::Fill )
171
191
{
172
- if (symbolType != QgsSymbolV2::Fill)
173
- {
174
- QgsDebugMsg (" polygon can be drawn only with fill symbol!" );
175
- break ;
176
- }
177
- QPolygonF pts;
178
- QList<QPolygonF> holes;
179
- _getPolygon (pts, holes, context.mapToPixel (), geom->asWkb ());
180
- ((QgsFillSymbolV2*)symbol)->renderPolygon (pts, (holes.count () ? &holes : NULL ), context, layer);
192
+ QgsDebugMsg ( " polygon can be drawn only with fill symbol!" );
193
+ break ;
181
194
}
182
- break ;
183
-
195
+ QPolygonF pts;
196
+ QList<QPolygonF> holes;
197
+ _getPolygon ( pts, holes, context, geom->asWkb () );
198
+ (( QgsFillSymbolV2* )symbol )->renderPolygon ( pts, ( holes.count () ? &holes : NULL ), context, layer );
199
+ }
200
+ break ;
201
+
184
202
case QGis::WKBMultiPoint:
203
+ {
204
+ if ( symbolType != QgsSymbolV2::Marker )
185
205
{
186
- if (symbolType != QgsSymbolV2::Marker)
187
- {
188
- QgsDebugMsg (" multi-point can be drawn only with marker symbol!" );
189
- break ;
190
- }
191
-
192
- unsigned char * wkb = geom->asWkb ();
193
- unsigned int num = *(( int * )(wkb + 5 ) );
194
- unsigned char * ptr = wkb + 9 ;
195
- QPointF pt;
196
-
197
- for (unsigned int i = 0 ; i < num; ++i)
198
- {
199
- ptr = _getPoint (pt, context.mapToPixel (), ptr);
200
- ((QgsMarkerSymbolV2*)symbol)->renderPoint (pt, context, layer);
201
- }
206
+ QgsDebugMsg ( " multi-point can be drawn only with marker symbol!" );
207
+ break ;
202
208
}
203
- break ;
204
-
209
+
210
+ unsigned char * wkb = geom->asWkb ();
211
+ unsigned int num = *(( int * )( wkb + 5 ) );
212
+ unsigned char * ptr = wkb + 9 ;
213
+ QPointF pt;
214
+
215
+ for ( unsigned int i = 0 ; i < num; ++i )
216
+ {
217
+ ptr = _getPoint ( pt, context, ptr );
218
+ (( QgsMarkerSymbolV2* )symbol )->renderPoint ( pt, context, layer );
219
+ }
220
+ }
221
+ break ;
222
+
205
223
case QGis::WKBMultiLineString:
224
+ {
225
+ if ( symbolType != QgsSymbolV2::Line )
206
226
{
207
- if (symbolType != QgsSymbolV2::Line)
208
- {
209
- QgsDebugMsg (" multi-linestring can be drawn only with line symbol!" );
210
- break ;
211
- }
212
-
213
- unsigned char * wkb = geom->asWkb ();
214
- unsigned int num = *(( int * )(wkb + 5 ) );
215
- unsigned char * ptr = wkb + 9 ;
216
- QPolygonF pts;
217
-
218
- for (unsigned int i = 0 ; i < num; ++i)
219
- {
220
- ptr = _getLineString (pts, context.mapToPixel (), ptr);
221
- ((QgsLineSymbolV2*)symbol)->renderPolyline (pts, context, layer);
222
- }
227
+ QgsDebugMsg ( " multi-linestring can be drawn only with line symbol!" );
228
+ break ;
223
229
}
224
- break ;
225
-
230
+
231
+ unsigned char * wkb = geom->asWkb ();
232
+ unsigned int num = *(( int * )( wkb + 5 ) );
233
+ unsigned char * ptr = wkb + 9 ;
234
+ QPolygonF pts;
235
+
236
+ for ( unsigned int i = 0 ; i < num; ++i )
237
+ {
238
+ ptr = _getLineString ( pts, context, ptr );
239
+ (( QgsLineSymbolV2* )symbol )->renderPolyline ( pts, context, layer );
240
+ }
241
+ }
242
+ break ;
243
+
226
244
case QGis::WKBMultiPolygon:
245
+ {
246
+ if ( symbolType != QgsSymbolV2::Fill )
227
247
{
228
- if (symbolType != QgsSymbolV2::Fill)
229
- {
230
- QgsDebugMsg (" multi-polygon can be drawn only with fill symbol!" );
231
- break ;
232
- }
233
-
234
- unsigned char * wkb = geom->asWkb ();
235
- unsigned int num = *(( int * )(wkb + 5 ) );
236
- unsigned char * ptr = wkb + 9 ;
237
- QPolygonF pts;
238
- QList<QPolygonF> holes;
239
-
240
- for (unsigned int i = 0 ; i < num; ++i)
241
- {
242
- ptr = _getPolygon (pts, holes, context.mapToPixel (), ptr);
243
- ((QgsFillSymbolV2*)symbol)->renderPolygon (pts, (holes.count () ? &holes : NULL ), context, layer);
244
- }
248
+ QgsDebugMsg ( " multi-polygon can be drawn only with fill symbol!" );
249
+ break ;
245
250
}
246
- break ;
247
-
251
+
252
+ unsigned char * wkb = geom->asWkb ();
253
+ unsigned int num = *(( int * )( wkb + 5 ) );
254
+ unsigned char * ptr = wkb + 9 ;
255
+ QPolygonF pts;
256
+ QList<QPolygonF> holes;
257
+
258
+ for ( unsigned int i = 0 ; i < num; ++i )
259
+ {
260
+ ptr = _getPolygon ( pts, holes, context, ptr );
261
+ (( QgsFillSymbolV2* )symbol )->renderPolygon ( pts, ( holes.count () ? &holes : NULL ), context, layer );
262
+ }
263
+ }
264
+ break ;
265
+
248
266
default :
249
- QgsDebugMsg (" unsupported wkb type for rendering" );
267
+ QgsDebugMsg ( " unsupported wkb type for rendering" );
250
268
}
251
269
}
252
270
@@ -256,32 +274,32 @@ QString QgsFeatureRendererV2::dump()
256
274
}
257
275
258
276
259
- QgsFeatureRendererV2* QgsFeatureRendererV2::load (QDomElement& element)
277
+ QgsFeatureRendererV2* QgsFeatureRendererV2::load ( QDomElement& element )
260
278
{
261
279
// <renderer-v2 type=""> ... </renderer-v2>
262
280
263
- if (element.isNull ())
281
+ if ( element.isNull () )
264
282
return NULL ;
265
283
266
284
// load renderer
267
- QString rendererType = element.attribute (" type" );
285
+ QString rendererType = element.attribute ( " type" );
268
286
269
- QgsRendererV2CreateFunc pfCreate = QgsRendererV2Registry::instance ()->rendererMetadata (rendererType).createFunction ();
287
+ QgsRendererV2CreateFunc pfCreate = QgsRendererV2Registry::instance ()->rendererMetadata ( rendererType ).createFunction ();
270
288
271
289
// unknown renderer type?
272
- if (pfCreate == NULL )
290
+ if ( pfCreate == NULL )
273
291
return NULL ;
274
292
275
- return pfCreate (element);
293
+ return pfCreate ( element );
276
294
}
277
295
278
- QDomElement QgsFeatureRendererV2::save (QDomDocument& doc)
296
+ QDomElement QgsFeatureRendererV2::save ( QDomDocument& doc )
279
297
{
280
298
// create empty renderer element
281
- return doc.createElement (RENDERER_TAG_NAME);
299
+ return doc.createElement ( RENDERER_TAG_NAME );
282
300
}
283
301
284
- QgsLegendSymbologyList QgsFeatureRendererV2::legendSymbologyItems (QSize iconSize)
302
+ QgsLegendSymbologyList QgsFeatureRendererV2::legendSymbologyItems ( QSize iconSize )
285
303
{
286
304
// empty list by default
287
305
return QgsLegendSymbologyList ();
0 commit comments