Skip to content
Permalink
Browse files

Fix QgsRubberBand visibility behavior (followup 37171dc)

Visibility behavior stays the same as in QGIS 2.6
Test included.

Fix #12486
Contributed via #1972
  • Loading branch information
naihil authored and Sandro Santilli committed Apr 7, 2015
1 parent d9245d7 commit 7210c4a639caa4ca321144718d238ff114b74e47
Showing with 43 additions and 1 deletion.
  1. +2 −1 src/gui/qgsrubberband.cpp
  2. +41 −0 tests/src/gui/testqgsrubberband.cpp
@@ -182,6 +182,7 @@ void QgsRubberBand::addPoint( const QgsPoint & p, bool doUpdate /* = true */, in

if ( doUpdate )
{
setVisible( true );
updateRect();
update();
}
@@ -418,6 +419,7 @@ void QgsRubberBand::addGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
return;
}

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

setRect( rect );
setVisible( true );
}

void QgsRubberBand::updatePosition( )
@@ -46,6 +46,7 @@ class TestQgsRubberband : public QObject

void testAddSingleMultiGeometries(); //test for #7728
void testBoundingRect(); //test for #12392
void testVisibility(); //test for #12486

private:
QgsMapCanvas* mCanvas;
@@ -153,6 +154,46 @@ void TestQgsRubberband::testBoundingRect()

}

void TestQgsRubberband::testVisibility()
{
mRubberband = new QgsRubberBand( mCanvas, mPolygonLayer->geometryType() );

// Visibility is set to false by default
QCOMPARE( mRubberband->isVisible(), false );

// Check visibility after setting to empty geometry
QSharedPointer<QgsGeometry> emptyGeom( new QgsGeometry );
mRubberband->setToGeometry( emptyGeom.data(), mPolygonLayer );
QCOMPARE( mRubberband->isVisible(), false );

// Check that visibility changes
mRubberband->setVisible( true );
mRubberband->setToGeometry( emptyGeom.data(), mPolygonLayer );
QCOMPARE( mRubberband->isVisible(), false );

// Check visibility after setting to valid geometry
QSharedPointer<QgsGeometry> geom( QgsGeometry::fromWkt(
"POLYGON((10 10,10 30,30 30,30 10,10 10))"
) );
mRubberband->setToGeometry( geom.data(), mPolygonLayer );
QCOMPARE( mRubberband->isVisible(), true );

// Add point without update
mRubberband->reset( true );
mRubberband->addPoint( QgsPoint( 10, 10 ), false );
QCOMPARE( mRubberband->isVisible(), false );

// Add point with update
mRubberband->addPoint( QgsPoint( 20, 20 ), true );
QCOMPARE( mRubberband->isVisible(), true );

// Check visibility after zoom (should not be changed)
mRubberband->setVisible( false );
mCanvas->zoomIn();
QCOMPARE( mRubberband->isVisible(), false );

}


QTEST_MAIN( TestQgsRubberband )
#include "testqgsrubberband.moc"

0 comments on commit 7210c4a

Please sign in to comment.
You can’t perform that action at this time.