@@ -405,35 +405,47 @@ void QgsRubberBand::setToCanvasRectangle( QRect rect )
405
405
406
406
void QgsRubberBand::paint ( QPainter *p )
407
407
{
408
- if ( !mPoints .isEmpty () )
408
+ if ( mPoints .isEmpty () )
409
+ return ;
410
+
411
+ QVector< QVector<QPointF> > shapes;
412
+ for ( const QList<QgsPointXY> &line : qgsAsConst ( mPoints ) )
409
413
{
410
- Q_FOREACH ( const QList<QgsPointXY> &line, mPoints )
414
+ QVector<QPointF> pts;
415
+ for ( const QgsPointXY &pt : line )
411
416
{
412
- QVector<QPointF> pts;
413
- Q_FOREACH ( const QgsPointXY &pt, line )
414
- {
415
- const QPointF cur = toCanvasCoordinates ( QgsPointXY ( pt.x () + mTranslationOffsetX , pt.y () + mTranslationOffsetY ) ) - pos ();
416
- if ( pts.empty () || std::abs ( pts.back ().x () - cur.x () ) > 1 || std::abs ( pts.back ().y () - cur.y () ) > 1 )
417
- pts.append ( cur );
418
- }
419
-
420
- if ( mSecondaryPen .color ().isValid () )
421
- {
422
- mSecondaryPen .setWidth ( mPen .width () + 2 );
423
-
424
- p->setBrush ( Qt::NoBrush );
425
- p->setPen ( mSecondaryPen );
426
- drawShape ( p, pts );
427
- }
417
+ const QPointF cur = toCanvasCoordinates ( QgsPointXY ( pt.x () + mTranslationOffsetX , pt.y () + mTranslationOffsetY ) ) - pos ();
418
+ if ( pts.empty () || std::abs ( pts.back ().x () - cur.x () ) > 1 || std::abs ( pts.back ().y () - cur.y () ) > 1 )
419
+ pts.append ( cur );
420
+ }
421
+ shapes << pts;
422
+ }
428
423
424
+ int iterations = mSecondaryPen .color ().isValid () ? 2 : 1 ;
425
+ for ( int i = 0 ; i < iterations; ++i )
426
+ {
427
+ if ( i == 0 && iterations > 1 )
428
+ {
429
+ // first iteration with multi-pen painting, so use secondary pen
430
+ mSecondaryPen .setWidth ( mPen .width () + 2 );
431
+ p->setBrush ( Qt::NoBrush );
432
+ p->setPen ( mSecondaryPen );
433
+ }
434
+ else
435
+ {
436
+ // "top" layer, use primary pen/brush
429
437
p->setBrush ( mBrush );
430
438
p->setPen ( mPen );
431
- drawShape ( p, pts );
439
+ }
440
+
441
+ for ( const QVector<QPointF> &shape : qgsAsConst ( shapes ) )
442
+ {
443
+ drawShape ( p, shape );
432
444
}
433
445
}
434
446
}
435
447
436
- void QgsRubberBand::drawShape ( QPainter *p, QVector<QPointF> &pts )
448
+ void QgsRubberBand::drawShape ( QPainter *p, const QVector<QPointF> &pts )
437
449
{
438
450
switch ( mGeometryType )
439
451
{
0 commit comments