Skip to content

Commit

Permalink
Fix QgsRubberBand visibility behavior
Browse files Browse the repository at this point in the history
Visibility behavior stays the same as in QGIS 2.6
Test included
  • Loading branch information
naihil committed Apr 2, 2015
1 parent f11fdb0 commit 6850ce6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/gui/qgsrubberband.cpp
Expand Up @@ -182,6 +182,7 @@ void QgsRubberBand::addPoint( const QgsPoint & p, bool doUpdate /* = true */, in

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

setVisible( true );
updateRect();
update();
}
Expand Down Expand Up @@ -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( isVisible() );
}

void QgsRubberBand::updatePosition( )
Expand Down
39 changes: 37 additions & 2 deletions tests/src/gui/testqgsrubberband.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -128,7 +129,6 @@ void TestQgsRubberband::testBoundingRect()
mRubberband->setIconSize( 5 ); // default, but better be explicit
mRubberband->setWidth( 1 ); // default, but better be explicit
mRubberband->addGeometry( geom.data(), mPolygonLayer );
mRubberband->setVisible( true );

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

// Check visibility after zoom
}

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 );
Expand Down

0 comments on commit 6850ce6

Please sign in to comment.