Skip to content
Permalink
Browse files

Fix incorrect draw stacking when drawing rubber bands with

secondary lines enabled
  • Loading branch information
nyalldawson committed Oct 1, 2017
1 parent df71901 commit 4374c6e475620b7a90effdf726db03c48438d22d
Showing with 34 additions and 22 deletions.
  1. +1 −1 python/gui/qgsrubberband.sip
  2. +32 −20 src/gui/qgsrubberband.cpp
  3. +1 −1 src/gui/qgsrubberband.h
@@ -275,7 +275,7 @@ for tracking the mouse while drawing polylines or polygons.
\param p The QPainter object
%End

void drawShape( QPainter *p, QVector<QPointF> &pts );
void drawShape( QPainter *p, const QVector<QPointF> &pts );
%Docstring
Draws shape of the rubber band.
\param p The QPainter object
@@ -405,35 +405,47 @@ void QgsRubberBand::setToCanvasRectangle( QRect rect )

void QgsRubberBand::paint( QPainter *p )
{
if ( !mPoints.isEmpty() )
if ( mPoints.isEmpty() )
return;

QVector< QVector<QPointF> > shapes;
for ( const QList<QgsPointXY> &line : qgsAsConst( mPoints ) )
{
Q_FOREACH ( const QList<QgsPointXY> &line, mPoints )
QVector<QPointF> pts;
for ( const QgsPointXY &pt : line )
{
QVector<QPointF> pts;
Q_FOREACH ( const QgsPointXY &pt, line )
{
const QPointF cur = toCanvasCoordinates( QgsPointXY( pt.x() + mTranslationOffsetX, pt.y() + mTranslationOffsetY ) ) - pos();
if ( pts.empty() || std::abs( pts.back().x() - cur.x() ) > 1 || std::abs( pts.back().y() - cur.y() ) > 1 )
pts.append( cur );
}

if ( mSecondaryPen.color().isValid() )
{
mSecondaryPen.setWidth( mPen.width() + 2 );

p->setBrush( Qt::NoBrush );
p->setPen( mSecondaryPen );
drawShape( p, pts );
}
const QPointF cur = toCanvasCoordinates( QgsPointXY( pt.x() + mTranslationOffsetX, pt.y() + mTranslationOffsetY ) ) - pos();
if ( pts.empty() || std::abs( pts.back().x() - cur.x() ) > 1 || std::abs( pts.back().y() - cur.y() ) > 1 )
pts.append( cur );
}
shapes << pts;
}

int iterations = mSecondaryPen.color().isValid() ? 2 : 1;
for ( int i = 0; i < iterations; ++i )
{
if ( i == 0 && iterations > 1 )
{
// first iteration with multi-pen painting, so use secondary pen
mSecondaryPen.setWidth( mPen.width() + 2 );
p->setBrush( Qt::NoBrush );
p->setPen( mSecondaryPen );
}
else
{
// "top" layer, use primary pen/brush
p->setBrush( mBrush );
p->setPen( mPen );
drawShape( p, pts );
}

for ( const QVector<QPointF> &shape : qgsAsConst( shapes ) )
{
drawShape( p, shape );
}
}
}

void QgsRubberBand::drawShape( QPainter *p, QVector<QPointF> &pts )
void QgsRubberBand::drawShape( QPainter *p, const QVector<QPointF> &pts )
{
switch ( mGeometryType )
{
@@ -310,7 +310,7 @@ class GUI_EXPORT QgsRubberBand: public QgsMapCanvasItem
* \param p The QPainter object
* \param pts A list of points used to draw the shape
*/
void drawShape( QPainter *p, QVector<QPointF> &pts );
void drawShape( QPainter *p, const QVector<QPointF> &pts );

//! Recalculates needed rectangle
void updateRect();

0 comments on commit 4374c6e

Please sign in to comment.
You can’t perform that action at this time.