@@ -47,29 +47,40 @@ QString QgsSimpleLineSymbolLayerV2::layerType() const
47
47
}
48
48
49
49
50
- void QgsSimpleLineSymbolLayerV2::startRender ( QgsRenderContext & context )
50
+ void QgsSimpleLineSymbolLayerV2::startRender ( QgsSymbolV2RenderContext & context )
51
51
{
52
52
mPen .setColor ( mColor );
53
- mPen .setWidth ( mWidth );
53
+ mPen .setWidthF ( mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor ( context. renderContext (), context. outputUnit () ) );
54
54
mPen .setStyle ( mPenStyle );
55
55
mPen .setJoinStyle ( mPenJoinStyle );
56
56
mPen .setCapStyle ( mPenCapStyle );
57
57
}
58
58
59
- void QgsSimpleLineSymbolLayerV2::stopRender ( QgsRenderContext & context )
59
+ void QgsSimpleLineSymbolLayerV2::stopRender ( QgsSymbolV2RenderContext & context )
60
60
{
61
61
}
62
62
63
- void QgsSimpleLineSymbolLayerV2::renderPolyline ( const QPolygonF& points, QgsRenderContext & context )
63
+ void QgsSimpleLineSymbolLayerV2::renderPolyline ( const QPolygonF& points, QgsSymbolV2RenderContext & context )
64
64
{
65
- context.painter ()->setPen ( mPen );
65
+ QgsRenderContext* rc = context.renderContext ();
66
+ if ( !rc )
67
+ {
68
+ return ;
69
+ }
70
+ QPainter* p = rc->painter ();
71
+ if ( !p )
72
+ {
73
+ return ;
74
+ }
75
+
76
+ p->setPen ( mPen );
66
77
if ( mOffset == 0 )
67
78
{
68
- context. painter () ->drawPolyline ( points );
79
+ p ->drawPolyline ( points );
69
80
}
70
81
else
71
82
{
72
- context. painter () ->drawPolyline ( ::offsetLine ( points, mOffset ) );
83
+ p ->drawPolyline ( ::offsetLine ( points, mOffset ) );
73
84
}
74
85
}
75
86
@@ -200,39 +211,59 @@ void QgsMarkerLineSymbolLayerV2::setColor( QColor color )
200
211
mColor = color;
201
212
}
202
213
203
- void QgsMarkerLineSymbolLayerV2::startRender ( QgsRenderContext & context )
214
+ void QgsMarkerLineSymbolLayerV2::startRender ( QgsSymbolV2RenderContext & context )
204
215
{
205
216
// if being rotated, it gets initialized with every line segment
206
217
if ( !mRotateMarker )
207
- mMarker ->startRender ( context );
218
+ {
219
+ QgsRenderContext* rc = context.renderContext ();
220
+ if ( rc )
221
+ {
222
+ mMarker ->startRender ( *rc );
223
+ }
224
+ }
208
225
}
209
226
210
- void QgsMarkerLineSymbolLayerV2::stopRender ( QgsRenderContext & context )
227
+ void QgsMarkerLineSymbolLayerV2::stopRender ( QgsSymbolV2RenderContext & context )
211
228
{
212
229
if ( !mRotateMarker )
213
- mMarker ->stopRender ( context );
230
+ {
231
+ QgsRenderContext* rc = context.renderContext ();
232
+ if ( rc )
233
+ {
234
+ mMarker ->stopRender ( *rc );
235
+ }
236
+ }
214
237
}
215
238
216
- void QgsMarkerLineSymbolLayerV2::renderPolyline ( const QPolygonF& points, QgsRenderContext & context )
239
+ void QgsMarkerLineSymbolLayerV2::renderPolyline ( const QPolygonF& points, QgsSymbolV2RenderContext & context )
217
240
{
218
241
if ( mOffset == 0 )
219
242
{
220
243
renderPolylineNoOffset ( points, context );
221
244
}
222
245
else
223
246
{
224
- QPolygonF points2 = ::offsetLine ( points, mOffset );
247
+ QPolygonF points2 = ::offsetLine ( points, mOffset * QgsSymbolLayerV2Utils::lineWidthScaleFactor ( context. renderContext (), context. outputUnit () ) );
225
248
renderPolylineNoOffset ( points2, context );
226
249
}
227
250
}
228
251
229
- void QgsMarkerLineSymbolLayerV2::renderPolylineNoOffset ( const QPolygonF& points, QgsRenderContext & context )
252
+ void QgsMarkerLineSymbolLayerV2::renderPolylineNoOffset ( const QPolygonF& points, QgsSymbolV2RenderContext & context )
230
253
{
231
254
QPointF lastPt = points[0 ];
232
255
double lengthLeft = 0 ; // how much is left until next marker
233
256
bool first = true ;
234
257
double origAngle = mMarker ->angle ();
235
258
259
+ double painterUnitInterval = mInterval * QgsSymbolLayerV2Utils::lineWidthScaleFactor ( context.renderContext (), context.outputUnit () );
260
+
261
+ QgsRenderContext* rc = context.renderContext ();
262
+ if ( !rc )
263
+ {
264
+ return ;
265
+ }
266
+
236
267
for ( int i = 1 ; i < points.count (); ++i )
237
268
{
238
269
const QPointF& pt = points[i];
@@ -242,42 +273,42 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineNoOffset( const QPolygonF& points
242
273
243
274
// for each line, find out dx and dy, and length
244
275
MyLine l ( lastPt, pt );
245
- QPointF diff = l.diffForInterval ( mInterval );
276
+ QPointF diff = l.diffForInterval ( painterUnitInterval );
246
277
247
278
// if there's some length left from previous line
248
279
// use only the rest for the first point in new line segment
249
- double c = 1 - lengthLeft / mInterval ;
280
+ double c = 1 - lengthLeft / painterUnitInterval ;
250
281
251
282
lengthLeft += l.length ();
252
283
253
284
// rotate marker (if desired)
254
285
if ( mRotateMarker )
255
286
{
256
287
mMarker ->setAngle ( origAngle + ( l.angle () * 180 / M_PI ) );
257
- mMarker ->startRender ( context );
288
+ mMarker ->startRender ( *rc );
258
289
}
259
290
260
291
// draw first marker
261
292
if ( first )
262
293
{
263
- mMarker ->renderPoint ( lastPt, context );
294
+ mMarker ->renderPoint ( lastPt, *rc );
264
295
first = false ;
265
296
}
266
297
267
298
// while we're not at the end of line segment, draw!
268
- while ( lengthLeft > mInterval )
299
+ while ( lengthLeft > painterUnitInterval )
269
300
{
270
301
// "c" is 1 for regular point or in interval (0,1] for begin of line segment
271
302
lastPt += c * diff;
272
- lengthLeft -= mInterval ;
273
- mMarker ->renderPoint ( lastPt, context );
303
+ lengthLeft -= painterUnitInterval ;
304
+ mMarker ->renderPoint ( lastPt, *rc );
274
305
c = 1 ; // reset c (if wasn't 1 already)
275
306
}
276
307
277
308
lastPt = pt;
278
309
279
310
if ( mRotateMarker )
280
- mMarker ->stopRender ( context );
311
+ mMarker ->stopRender ( *rc );
281
312
}
282
313
283
314
// restore original rotation
@@ -347,12 +378,12 @@ QString QgsLineDecorationSymbolLayerV2::layerType() const
347
378
return " LineDecoration" ;
348
379
}
349
380
350
- void QgsLineDecorationSymbolLayerV2::startRender ( QgsRenderContext & context )
381
+ void QgsLineDecorationSymbolLayerV2::startRender ( QgsSymbolV2RenderContext & context )
351
382
{
352
383
mPen .setColor ( mColor );
353
384
}
354
385
355
- void QgsLineDecorationSymbolLayerV2::stopRender ( QgsRenderContext & context )
386
+ void QgsLineDecorationSymbolLayerV2::stopRender ( QgsSymbolV2RenderContext & context )
356
387
{
357
388
}
358
389
@@ -369,10 +400,21 @@ static double _calculateAngle( double x1, double y1, double x2, double y2 )
369
400
return atan ( t ) + ( y2 >= y1 ? M_PI : 0 ); // atan is positive / negative
370
401
}
371
402
372
- void QgsLineDecorationSymbolLayerV2::renderPolyline ( const QPolygonF& points, QgsRenderContext & context )
403
+ void QgsLineDecorationSymbolLayerV2::renderPolyline ( const QPolygonF& points, QgsSymbolV2RenderContext & context )
373
404
{
374
405
// draw arrow at the end of line
375
406
407
+ QgsRenderContext* rc = context.renderContext ();
408
+ if ( !rc )
409
+ {
410
+ return ;
411
+ }
412
+ QPainter* p = rc->painter ();
413
+ if ( !p )
414
+ {
415
+ return ;
416
+ }
417
+
376
418
int cnt = points.count ();
377
419
QPointF p1 = points.at ( cnt - 2 );
378
420
QPointF p2 = points.at ( cnt - 1 );
@@ -385,9 +427,9 @@ void QgsLineDecorationSymbolLayerV2::renderPolyline( const QPolygonF& points, Qg
385
427
QPointF p2_1 = p2 - QPointF ( size * cos ( angle1 ), size * sin ( angle1 ) );
386
428
QPointF p2_2 = p2 - QPointF ( size * cos ( angle2 ), size * sin ( angle2 ) );
387
429
388
- context. painter () ->setPen ( mPen );
389
- context. painter () ->drawLine ( p2, p2_1 );
390
- context. painter () ->drawLine ( p2, p2_2 );
430
+ p ->setPen ( mPen );
431
+ p ->drawLine ( p2, p2_1 );
432
+ p ->drawLine ( p2, p2_2 );
391
433
}
392
434
393
435
QgsStringMap QgsLineDecorationSymbolLayerV2::properties () const
0 commit comments