Fix incorrect draw stacking when drawing rubber bands with

secondary lines enabled
This commit is contained in:
Nyall Dawson 2017-09-29 10:58:45 +10:00
parent df71901a32
commit 4374c6e475
3 changed files with 34 additions and 22 deletions

View File

@ -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

View File

@ -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 )
{

View File

@ -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();