Skip to content
Permalink
Browse files
Fix QgsRubberBand adds two points for first point added to a point
geometry rubber band
  • Loading branch information
nyalldawson committed Sep 1, 2021
1 parent f19f554 commit 08d0e9846b85584de5c94d6eb62554e9c0e3db97
Showing with 38 additions and 1 deletion.
  1. +2 −1 src/gui/qgsrubberband.cpp
  2. +36 −0 tests/src/gui/testqgsrubberband.cpp
@@ -149,7 +149,8 @@ void QgsRubberBand::addPoint( const QgsPointXY &p, bool doUpdate /* = true */, i
if ( ringIndex == mPoints.at( geometryIndex ).size() )
{
mPoints[geometryIndex].append( QgsPolylineXY() );
mPoints[geometryIndex][ringIndex].append( p );
if ( mGeometryType != QgsWkbTypes::PointGeometry )
mPoints[geometryIndex][ringIndex].append( p );
}

if ( mPoints.at( geometryIndex ).at( ringIndex ).size() == 2 &&
@@ -43,6 +43,8 @@ class TestQgsRubberband : public QObject
void cleanup(); // will be called after every testfunction.

void testAddSingleMultiGeometries(); //test for #7728
void pointGeometryAddPoints();
void lineGeometryAddPoints();
void testBoundingRect(); //test for #12392
void testVisibility(); //test for 12486
void testClose(); //test closing geometry
@@ -126,6 +128,40 @@ void TestQgsRubberband::testAddSingleMultiGeometries()
QVERIFY( mRubberband->numberOfVertices() == 15 );
}

void TestQgsRubberband::pointGeometryAddPoints()
{
// point geometry
std::unique_ptr< QgsMapCanvas > canvas = std::make_unique< QgsMapCanvas >();
QgsRubberBand r1( canvas.get(), QgsWkbTypes::PointGeometry );
QVERIFY( r1.asGeometry().isEmpty() );
r1.addPoint( QgsPointXY( 1, 2 ) );
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "MultiPoint ((1 2))" ) );
r1.addPoint( QgsPointXY( 2, 3 ) );
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "MultiPoint ((1 2),(2 3))" ) );
r1.addPoint( QgsPointXY( 3, 4 ) );
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "MultiPoint ((1 2),(2 3),(3 4))" ) );
r1.reset( QgsWkbTypes::PointGeometry );
QVERIFY( r1.asGeometry().isEmpty() );
r1.addPoint( QgsPointXY( 1, 2 ) );
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "MultiPoint ((1 2))" ) );
}

void TestQgsRubberband::lineGeometryAddPoints()
{
std::unique_ptr< QgsMapCanvas > canvas = std::make_unique< QgsMapCanvas >();
QgsRubberBand r1( canvas.get(), QgsWkbTypes::LineGeometry );
QVERIFY( r1.asGeometry().isEmpty() );
r1.addPoint( QgsPointXY( 1, 2 ) );
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "LineString (1 2, 1 2)" ) );
r1.addPoint( QgsPointXY( 2, 3 ) );
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "LineString (1 2, 2 3)" ) );
r1.addPoint( QgsPointXY( 3, 4 ) );
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "LineString (1 2, 2 3, 3 4)" ) );
r1.reset( QgsWkbTypes::LineGeometry );
QVERIFY( r1.asGeometry().isEmpty() );
r1.addPoint( QgsPointXY( 1, 2 ) );
QCOMPARE( r1.asGeometry().asWkt(), QStringLiteral( "LineString (1 2, 1 2)" ) );
}

void TestQgsRubberband::testBoundingRect()
{

0 comments on commit 08d0e98

Please sign in to comment.