Skip to content

Commit 892f142

Browse files
author
Sandro Santilli
committedApr 7, 2015
Merge pull request #1972 from naihil/rubberband-visibility-fix
Don`t change current visibility flag of rubberband on updates
2 parents f055db1 + 6850ce6 commit 892f142

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
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( true );
571572
}
572573

573574
void QgsRubberBand::updatePosition( )

‎tests/src/gui/testqgsrubberband.cpp

Lines changed: 41 additions & 0 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;
@@ -153,6 +154,46 @@ void TestQgsRubberband::testBoundingRect()
153154

154155
}
155156

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)
191+
mRubberband->setVisible( false );
192+
mCanvas->zoomIn();
193+
QCOMPARE( mRubberband->isVisible(), false );
194+
195+
}
196+
156197

157198
QTEST_MAIN( TestQgsRubberband )
158199
#include "testqgsrubberband.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.