|
29 | 29 | for tracking the mouse while drawing polylines or polygons.
|
30 | 30 | */
|
31 | 31 | 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 ) |
33 | 36 | {
|
34 | 37 | reset( isPolygon );
|
35 | 38 | setColor( QColor( Qt::lightGray ) );
|
36 | 39 | }
|
37 | 40 |
|
38 | 41 | QgsRubberBand::QgsRubberBand(): QgsMapCanvasItem( 0 )
|
39 |
| -{} |
| 42 | +{ |
| 43 | +} |
40 | 44 |
|
41 | 45 | QgsRubberBand::~QgsRubberBand()
|
42 |
| -{} |
| 46 | +{ |
| 47 | +} |
43 | 48 |
|
44 | 49 | /*!
|
45 | 50 | Set the outline and fill color.
|
@@ -88,15 +93,19 @@ void QgsRubberBand::addPoint( const QgsPoint & p, bool do_update /* = true */, i
|
88 | 93 |
|
89 | 94 | if ( geometryIndex == mPoints.size() )
|
90 | 95 | {
|
91 |
| - mPoints.push_back( QList<QgsPoint>() ); |
| 96 | + mPoints.push_back( QList<QgsPoint>() << p ); |
92 | 97 | }
|
93 | 98 |
|
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] ) |
96 | 101 | {
|
97 |
| - mPoints[geometryIndex].push_back( p ); |
| 102 | + mPoints[geometryIndex].last() = p; |
98 | 103 | }
|
99 |
| - mPoints[geometryIndex].push_back( p ); |
| 104 | + else |
| 105 | + { |
| 106 | + mPoints[geometryIndex] << p; |
| 107 | + } |
| 108 | + |
100 | 109 |
|
101 | 110 | if ( do_update )
|
102 | 111 | {
|
@@ -136,7 +145,7 @@ void QgsRubberBand::movePoint( const QgsPoint & p, int geometryIndex )
|
136 | 145 | return;
|
137 | 146 | }
|
138 | 147 |
|
139 |
| - mPoints[geometryIndex][mPoints.at( geometryIndex ).size() - 1] = p; |
| 148 | + mPoints[geometryIndex].last() = p; |
140 | 149 |
|
141 | 150 | updateRect();
|
142 | 151 | update();
|
@@ -349,7 +358,6 @@ void QgsRubberBand::paint( QPainter* p )
|
349 | 358 | QList<QgsPoint>::const_iterator it = mPoints.at( i ).constBegin();
|
350 | 359 | for ( ; it != mPoints.at( i ).constEnd(); ++it )
|
351 | 360 | {
|
352 |
| - //QgsDebugMsg("Drawing rubberband vertex: " + QString::number(it->x() + mTranslationOffsetX) + "//" + QString::number(it->y() + mTranslationOffsetY)); |
353 | 361 | pts.append( toCanvasCoordinates( QgsPoint( it->x() + mTranslationOffsetX, it->y() + mTranslationOffsetY ) ) - pos() );
|
354 | 362 | }
|
355 | 363 |
|
@@ -384,9 +392,7 @@ void QgsRubberBand::updateRect()
|
384 | 392 | for ( ; it != mPoints.at( i ).constEnd(); ++it )
|
385 | 393 | {
|
386 | 394 | r.combineExtentWith( it->x() + mTranslationOffsetX, it->y() + mTranslationOffsetY );
|
387 |
| - //QgsDebugMsg("Combining extent with: " + QString::number(it->x()) + "//" + QString::number(it->y())); |
388 | 395 | }
|
389 |
| - //QgsDebugMsg("r: " + r.toString()); |
390 | 396 | }
|
391 | 397 | setRect( r );
|
392 | 398 | }
|
|
0 commit comments