Skip to content
Permalink
Browse files
Fix setting rubber band to point geometry, add tests
Fixes #44934
  • Loading branch information
nyalldawson committed Sep 5, 2021
1 parent 98a902b commit 6b78485e4cc7c16528b545c8e67220a55417a42a
Showing with 24 additions and 2 deletions.
  1. +0 −2 src/gui/qgsrubberband.cpp
  2. +24 −0 tests/src/gui/testqgsrubberband.cpp
@@ -335,15 +335,13 @@ void QgsRubberBand::addGeometry( const QgsGeometry &geometry, const QgsCoordinat
{
QgsPointXY pt = geom.asPoint();
addPoint( pt, false, idx );
removeLastPoint( idx, false );
}
else if ( QgsWkbTypes::geometryType( geomType ) == QgsWkbTypes::PointGeometry && QgsWkbTypes::isMultiType( geomType ) )
{
const QgsMultiPointXY mpt = geom.asMultiPoint();
for ( const QgsPointXY &pt : mpt )
{
addPoint( pt, false, idx );
removeLastPoint( idx, false );
idx++;
}
}
@@ -44,6 +44,7 @@ class TestQgsRubberband : public QObject

void testAddSingleMultiGeometries(); //test for #7728
void pointGeometryAddPoints();
void pointGeometrySetGeometry();
void lineGeometryAddPoints();
void copyPointsFrom();
void testBoundingRect(); //test for #12392
@@ -147,6 +148,29 @@ void TestQgsRubberband::pointGeometryAddPoints()
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "MultiPoint ((1 2))" ) );
}

void TestQgsRubberband::pointGeometrySetGeometry()
{
// point geometry, set using setToGeometry
std::unique_ptr< QgsMapCanvas > canvas = std::make_unique< QgsMapCanvas >();
QgsRubberBand r1( canvas.get(), QgsWkbTypes::PointGeometry );
QVERIFY( r1.asGeometry().isEmpty() );
r1.setToGeometry( QgsGeometry::fromPointXY( QgsPointXY( 1, 2 ) ) );
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "MultiPoint ((1 2))" ) );
r1.setToGeometry( QgsGeometry::fromPointXY( QgsPointXY( 2, 3 ) ) );
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "MultiPoint ((2 3))" ) );
r1.addGeometry( QgsGeometry::fromPointXY( QgsPointXY( 5, 6 ) ) );
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "MultiPoint ((2 3),(5 6))" ) );
r1.setToGeometry( QgsGeometry::fromMultiPointXY( {QgsPointXY( 1, 2 ), QgsPointXY( 3, 4 ) } ) );
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "MultiPoint ((1 2),(3 4))" ) );
r1.addGeometry( QgsGeometry::fromPointXY( QgsPointXY( 5, 7 ) ) );
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "MultiPoint ((1 2),(3 4),(5 7))" ) );
r1.addGeometry( QgsGeometry::fromMultiPointXY( { QgsPointXY( 7, 8 ), QgsPointXY( 9, 10 )} ) );
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "MultiPoint ((1 2),(3 4),(5 7),(7 8),(9 10))" ) );
r1.reset( QgsWkbTypes::PointGeometry );
r1.addGeometry( QgsGeometry::fromMultiPointXY( { QgsPointXY( 7, 8 ), QgsPointXY( 9, 10 )} ) );
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "MultiPoint ((7 8),(9 10))" ) );
}

void TestQgsRubberband::lineGeometryAddPoints()
{
std::unique_ptr< QgsMapCanvas > canvas = std::make_unique< QgsMapCanvas >();

0 comments on commit 6b78485

Please sign in to comment.