Skip to content

Commit f79961a

Browse files
author
jef
committedNov 15, 2010
fix starting point duplication in rubberband when using addPoint thought the API
git-svn-id: http://svn.osgeo.org/qgis/trunk@14679 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 3182ee4 commit f79961a

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed
 

‎src/gui/qgsrubberband.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,22 @@
2929
for tracking the mouse while drawing polylines or polygons.
3030
*/
3131
QgsRubberBand::QgsRubberBand( QgsMapCanvas* mapCanvas, bool isPolygon )
32-
: QgsMapCanvasItem( mapCanvas ), mIsPolygon( isPolygon ), mTranslationOffsetX( 0.0 ), mTranslationOffsetY( 0.0 )
32+
: QgsMapCanvasItem( mapCanvas )
33+
, mIsPolygon( isPolygon )
34+
, mTranslationOffsetX( 0.0 )
35+
, mTranslationOffsetY( 0.0 )
3336
{
3437
reset( isPolygon );
3538
setColor( QColor( Qt::lightGray ) );
3639
}
3740

3841
QgsRubberBand::QgsRubberBand(): QgsMapCanvasItem( 0 )
39-
{}
42+
{
43+
}
4044

4145
QgsRubberBand::~QgsRubberBand()
42-
{}
46+
{
47+
}
4348

4449
/*!
4550
Set the outline and fill color.
@@ -88,15 +93,19 @@ void QgsRubberBand::addPoint( const QgsPoint & p, bool do_update /* = true */, i
8893

8994
if ( geometryIndex == mPoints.size() )
9095
{
91-
mPoints.push_back( QList<QgsPoint>() );
96+
mPoints.push_back( QList<QgsPoint>() << p );
9297
}
9398

94-
//we need to set two points at the begin of the rubber band for operations that move the last point
95-
if ( mPoints[geometryIndex].size() == 0 )
99+
if ( mPoints[geometryIndex].size() == 2 &&
100+
mPoints[geometryIndex][0] == mPoints[geometryIndex][1] )
96101
{
97-
mPoints[geometryIndex].push_back( p );
102+
mPoints[geometryIndex].last() = p;
98103
}
99-
mPoints[geometryIndex].push_back( p );
104+
else
105+
{
106+
mPoints[geometryIndex] << p;
107+
}
108+
100109

101110
if ( do_update )
102111
{
@@ -136,7 +145,7 @@ void QgsRubberBand::movePoint( const QgsPoint & p, int geometryIndex )
136145
return;
137146
}
138147

139-
mPoints[geometryIndex][mPoints.at( geometryIndex ).size() - 1] = p;
148+
mPoints[geometryIndex].last() = p;
140149

141150
updateRect();
142151
update();
@@ -349,7 +358,6 @@ void QgsRubberBand::paint( QPainter* p )
349358
QList<QgsPoint>::const_iterator it = mPoints.at( i ).constBegin();
350359
for ( ; it != mPoints.at( i ).constEnd(); ++it )
351360
{
352-
//QgsDebugMsg("Drawing rubberband vertex: " + QString::number(it->x() + mTranslationOffsetX) + "//" + QString::number(it->y() + mTranslationOffsetY));
353361
pts.append( toCanvasCoordinates( QgsPoint( it->x() + mTranslationOffsetX, it->y() + mTranslationOffsetY ) ) - pos() );
354362
}
355363

@@ -384,9 +392,7 @@ void QgsRubberBand::updateRect()
384392
for ( ; it != mPoints.at( i ).constEnd(); ++it )
385393
{
386394
r.combineExtentWith( it->x() + mTranslationOffsetX, it->y() + mTranslationOffsetY );
387-
//QgsDebugMsg("Combining extent with: " + QString::number(it->x()) + "//" + QString::number(it->y()));
388395
}
389-
//QgsDebugMsg("r: " + r.toString());
390396
}
391397
setRect( r );
392398
}

0 commit comments

Comments
 (0)
Please sign in to comment.