Skip to content

Commit 6850ce6

Browse files
committed
Fix QgsRubberBand visibility behavior
Visibility behavior stays the same as in QGIS 2.6 Test included
1 parent f11fdb0 commit 6850ce6

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/gui/qgsrubberband.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ void QgsRubberBand::addPoint( const QgsPoint & p, bool doUpdate /* = true */, in
182182

183183
if ( doUpdate )
184184
{
185+
setVisible( true );
185186
updateRect();
186187
update();
187188
}
@@ -418,6 +419,7 @@ void QgsRubberBand::addGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
418419
return;
419420
}
420421

422+
setVisible( true );
421423
updateRect();
422424
update();
423425
}
@@ -567,7 +569,6 @@ void QgsRubberBand::updateRect()
567569
QgsRectangle rect( topLeft.x(), topLeft.y(), topLeft.x() + r.width()*res, topLeft.y() - r.height()*res );
568570

569571
setRect( rect );
570-
setVisible( isVisible() );
571572
}
572573

573574
void QgsRubberBand::updatePosition( )

tests/src/gui/testqgsrubberband.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class TestQgsRubberband : public QObject
4646

4747
void testAddSingleMultiGeometries(); //test for #7728
4848
void testBoundingRect(); //test for #12392
49+
void testVisibility(); //test for 12486
4950

5051
private:
5152
QgsMapCanvas* mCanvas;
@@ -128,7 +129,6 @@ void TestQgsRubberband::testBoundingRect()
128129
mRubberband->setIconSize( 5 ); // default, but better be explicit
129130
mRubberband->setWidth( 1 ); // default, but better be explicit
130131
mRubberband->addGeometry( geom.data(), mPolygonLayer );
131-
mRubberband->setVisible( true );
132132

133133
// 20 pixels for the extent + 3 for pen & icon per side + 2 of padding
134134
QCOMPARE( mRubberband->boundingRect(), QRectF(QPointF(-1,-1),QSizeF(28,28)) );
@@ -152,7 +152,42 @@ void TestQgsRubberband::testBoundingRect()
152152
mapSize.height() - ( 30 + 3 ) * 2
153153
) );
154154

155-
// Check visibility after zoom
155+
}
156+
157+
void TestQgsRubberband::testVisibility()
158+
{
159+
mRubberband = new QgsRubberBand( mCanvas, mPolygonLayer->geometryType() );
160+
161+
// Visibility is set to false by default
162+
QCOMPARE( mRubberband->isVisible(), false );
163+
164+
// Check visibility after setting to empty geometry
165+
QSharedPointer<QgsGeometry> emptyGeom( new QgsGeometry );
166+
mRubberband->setToGeometry( emptyGeom.data(), mPolygonLayer );
167+
QCOMPARE( mRubberband->isVisible(), false );
168+
169+
// Check that visibility changes
170+
mRubberband->setVisible( true );
171+
mRubberband->setToGeometry( emptyGeom.data(), mPolygonLayer );
172+
QCOMPARE( mRubberband->isVisible(), false );
173+
174+
// Check visibility after setting to valid geometry
175+
QSharedPointer<QgsGeometry> geom( QgsGeometry::fromWkt(
176+
"POLYGON((10 10,10 30,30 30,30 10,10 10))"
177+
) );
178+
mRubberband->setToGeometry( geom.data(), mPolygonLayer );
179+
QCOMPARE( mRubberband->isVisible(), true );
180+
181+
// Add point without update
182+
mRubberband->reset( true );
183+
mRubberband->addPoint( QgsPoint( 10, 10 ), false );
184+
QCOMPARE( mRubberband->isVisible(), false );
185+
186+
// Add point with update
187+
mRubberband->addPoint( QgsPoint( 20, 20 ), true );
188+
QCOMPARE( mRubberband->isVisible(), true );
189+
190+
// Check visibility after zoom (should not be changed)
156191
mRubberband->setVisible( false );
157192
mCanvas->zoomIn();
158193
QCOMPARE( mRubberband->isVisible(), false );

0 commit comments

Comments
 (0)