Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of Allow undo del vertex for shape tools #34302

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/app/qgsmaptooladdcircle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ void QgsMapToolAddCircle::keyPressEvent( QKeyEvent *e )
if ( mParentTool )
mParentTool->keyPressEvent( e );
}

if ( e && e->key() == Qt::Key_Backspace )
{
if ( mPoints.size() == 1 )
{

if ( mTempRubberBand )
{
delete mTempRubberBand;
mTempRubberBand = nullptr;
}

mPoints.clear();
}
else if ( mPoints.size() > 1 )
{
mPoints.removeLast();

}
if ( mParentTool )
mParentTool->keyPressEvent( e );
}
}

void QgsMapToolAddCircle::keyReleaseEvent( QKeyEvent *e )
Expand Down
22 changes: 22 additions & 0 deletions src/app/qgsmaptooladdellipse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ void QgsMapToolAddEllipse::keyPressEvent( QKeyEvent *e )
if ( mParentTool )
mParentTool->keyPressEvent( e );
}

if ( e && e->key() == Qt::Key_Backspace )
{
if ( mPoints.size() == 1 )
{

if ( mTempRubberBand )
{
delete mTempRubberBand;
mTempRubberBand = nullptr;
}

mPoints.clear();
}
else if ( mPoints.size() > 1 )
{
mPoints.removeLast();

}
if ( mParentTool )
mParentTool->keyPressEvent( e );
}
}

void QgsMapToolAddEllipse::keyReleaseEvent( QKeyEvent *e )
Expand Down
22 changes: 22 additions & 0 deletions src/app/qgsmaptooladdrectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ void QgsMapToolAddRectangle::keyPressEvent( QKeyEvent *e )
if ( mParentTool )
mParentTool->keyPressEvent( e );
}

if ( e && e->key() == Qt::Key_Backspace )
{
if ( mPoints.size() == 1 )
{

if ( mTempRubberBand )
{
delete mTempRubberBand;
mTempRubberBand = nullptr;
}

mPoints.clear();
}
else if ( mPoints.size() > 1 )
{
mPoints.removeLast();

}
if ( mParentTool )
mParentTool->keyPressEvent( e );
}
}

void QgsMapToolAddRectangle::keyReleaseEvent( QKeyEvent *e )
Expand Down
23 changes: 22 additions & 1 deletion src/app/qgsmaptooladdregularpolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ void QgsMapToolAddRegularPolygon::createNumberSidesSpinBox()
mNumberSidesSpinBox->setPrefix( tr( "Number of sides: " ) );
mNumberSidesSpinBox->setValue( mNumberSides );
QgisApp::instance()->addUserInputWidget( mNumberSidesSpinBox.get() );
mNumberSidesSpinBox->setFocus( Qt::TabFocusReason );
}

void QgsMapToolAddRegularPolygon::deleteNumberSidesSpinBox()
Expand All @@ -72,6 +71,28 @@ void QgsMapToolAddRegularPolygon::keyPressEvent( QKeyEvent *e )
if ( mParentTool )
mParentTool->keyPressEvent( e );
}

if ( e && e->key() == Qt::Key_Backspace )
{
if ( mPoints.size() == 1 )
{

if ( mTempRubberBand )
{
delete mTempRubberBand;
mTempRubberBand = nullptr;
}

mPoints.clear();
}
else if ( mPoints.size() > 1 )
{
mPoints.removeLast();

}
if ( mParentTool )
mParentTool->keyPressEvent( e );
}
}

void QgsMapToolAddRegularPolygon::keyReleaseEvent( QKeyEvent *e )
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgsmaptoolcircle2points.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ void QgsMapToolCircle2Points::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

if ( e->button() == Qt::LeftButton )
{
mPoints.append( point );
if ( mPoints.isEmpty() )
mPoints.append( point );

if ( !mPoints.isEmpty() && !mTempRubberBand )
if ( !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( mLayerType, true );
mTempRubberBand->show();
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgsmaptoolcirclecenterpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ void QgsMapToolCircleCenterPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

if ( e->button() == Qt::LeftButton )
{
mPoints.append( point );
if ( mPoints.empty() )
mPoints.append( point );

if ( !mPoints.isEmpty() && !mTempRubberBand )
if ( !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( mLayerType, true );
mTempRubberBand->show();
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgsmaptoolellipsecenterpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ void QgsMapToolEllipseCenterPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

if ( e->button() == Qt::LeftButton )
{
mPoints.append( point );
if ( mPoints.empty() )
mPoints.append( point );

if ( !mPoints.isEmpty() && !mTempRubberBand )
if ( !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( mLayerType, true );
mTempRubberBand->show();
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgsmaptoolellipseextent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ void QgsMapToolEllipseExtent::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

if ( e->button() == Qt::LeftButton )
{
mPoints.append( point );
if ( mPoints.empty() )
mPoints.append( point );

if ( !mPoints.isEmpty() && !mTempRubberBand )
if ( !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( mLayerType, true );
mTempRubberBand->show();
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgsmaptoolellipsefoci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ void QgsMapToolEllipseFoci::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

if ( e->button() == Qt::LeftButton )
{
mPoints.append( point );
if ( mPoints.size() < 2 )
mPoints.append( point );

if ( !mPoints.isEmpty() && !mTempRubberBand )
if ( !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( mLayerType, true );
mTempRubberBand->show();
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgsmaptoolrectanglecenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ void QgsMapToolRectangleCenter::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

if ( e->button() == Qt::LeftButton )
{
mPoints.append( point );
if ( mPoints.empty() )
mPoints.append( point );

if ( !mPoints.isEmpty() && !mTempRubberBand )
if ( !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( mLayerType, true );
mTempRubberBand->show();
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgsmaptoolrectangleextent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ void QgsMapToolRectangleExtent::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

if ( e->button() == Qt::LeftButton )
{
mPoints.append( point );
if ( mPoints.empty() )
mPoints.append( point );

if ( !mPoints.isEmpty() && !mTempRubberBand )
if ( !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( mLayerType, true );
mTempRubberBand->show();
Expand Down
14 changes: 6 additions & 8 deletions src/app/qgsmaptoolregularpolygon2points.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,15 @@ void QgsMapToolRegularPolygon2Points::cadCanvasReleaseEvent( QgsMapMouseEvent *e

if ( e->button() == Qt::LeftButton )
{
mPoints.append( point );
if ( mPoints.empty() )
mPoints.append( point );

if ( !mPoints.isEmpty() )
if ( !mTempRubberBand )
{
if ( !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( mLayerType, true );
mTempRubberBand->show();
mTempRubberBand = createGeometryRubberBand( mLayerType, true );
mTempRubberBand->show();

createNumberSidesSpinBox();
}
createNumberSidesSpinBox();
}
}
else if ( e->button() == Qt::RightButton )
Expand Down
14 changes: 6 additions & 8 deletions src/app/qgsmaptoolregularpolygoncentercorner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@ void QgsMapToolRegularPolygonCenterCorner::cadCanvasReleaseEvent( QgsMapMouseEve

if ( e->button() == Qt::LeftButton )
{
mPoints.append( point );
if ( mPoints.empty() )
mPoints.append( point );

if ( !mPoints.isEmpty() )
if ( !mTempRubberBand )
{
if ( !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( mLayerType, true );
mTempRubberBand->show();
mTempRubberBand = createGeometryRubberBand( mLayerType, true );
mTempRubberBand->show();

createNumberSidesSpinBox();
}
createNumberSidesSpinBox();
}
}
else if ( e->button() == Qt::RightButton )
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsmaptoolregularpolygoncenterpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ void QgsMapToolRegularPolygonCenterPoint::cadCanvasReleaseEvent( QgsMapMouseEven

if ( e->button() == Qt::LeftButton )
{
mPoints.append( point );
if ( mPoints.size() < 1 )
mPoints.append( point );

if ( !mPoints.isEmpty() )
{
Expand Down
84 changes: 84 additions & 0 deletions tests/src/app/testqgsmaptoolcircle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ class TestQgsMapToolCircle : public QObject
void cleanupTestCase();

void testCircleFrom2Points();
void testCircleFrom2PointsWithDeletedVertex();
void testCircleFrom3Points();
void testCircleFrom3PointsWithDeletedVertex();
void testCircleFromCenterPoint();
void testCircleFromCenterPointWithDeletedVertex();

private:
QgisApp *mQgisApp = nullptr;
Expand Down Expand Up @@ -105,6 +108,33 @@ void TestQgsMapToolCircle::testCircleFrom2Points()
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolCircle::testCircleFrom2PointsWithDeletedVertex()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 333 );
mLayer->startEditing();

QgsMapToolCircle2Points mapTool( mParentTool, mCanvas );
mCanvas->setMapTool( &mapTool );

TestQgsMapToolAdvancedDigitizingUtils utils( &mapTool );

utils.mouseClick( 4, 1, Qt::LeftButton );
utils.keyClick( Qt::Key_Backspace );
utils.mouseClick( 0, 0, Qt::LeftButton );
utils.mouseMove( 0, 2 );
utils.mouseClick( 0, 2, Qt::RightButton );
QgsFeatureId newFid = utils.newFeatureId();

QCOMPARE( mLayer->featureCount(), ( long )1 );
QgsFeature f = mLayer->getFeature( newFid );

QString wkt = "CompoundCurveZ (CircularStringZ (0 2 333, 1 1 333, 0 0 333, -1 1 333, 0 2 333))";
QCOMPARE( f.geometry().asWkt(), wkt );

mLayer->rollBack();
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolCircle::testCircleFrom3Points()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 111 );
Expand All @@ -130,6 +160,33 @@ void TestQgsMapToolCircle::testCircleFrom3Points()
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolCircle::testCircleFrom3PointsWithDeletedVertex()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 111 );
mLayer->startEditing();

QgsMapToolCircle3Points mapTool( mParentTool, mCanvas );
mCanvas->setMapTool( &mapTool );

TestQgsMapToolAdvancedDigitizingUtils utils( &mapTool );
utils.mouseClick( 0, 0, Qt::LeftButton );
utils.mouseClick( 4, 1, Qt::LeftButton );
utils.keyClick( Qt::Key_Backspace );
utils.mouseClick( 0, 2, Qt::LeftButton );
utils.mouseMove( 1, 1 );
utils.mouseClick( 1, 1, Qt::RightButton );
QgsFeatureId newFid = utils.newFeatureId();

QCOMPARE( mLayer->featureCount(), ( long )1 );
QgsFeature f = mLayer->getFeature( newFid );

QString wkt = "CompoundCurveZ (CircularStringZ (0 2 111, 1 1 111, 0 0 111, -1 1 111, 0 2 111))";
QCOMPARE( f.geometry().asWkt(), wkt );

mLayer->rollBack();
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolCircle::testCircleFromCenterPoint()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 222 );
Expand All @@ -154,5 +211,32 @@ void TestQgsMapToolCircle::testCircleFromCenterPoint()
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolCircle::testCircleFromCenterPointWithDeletedVertex()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 222 );
mLayer->startEditing();

QgsMapToolCircleCenterPoint mapTool( mParentTool, mCanvas );
mCanvas->setMapTool( &mapTool );

TestQgsMapToolAdvancedDigitizingUtils utils( &mapTool );

utils.mouseClick( 4, 1, Qt::LeftButton );
utils.keyClick( Qt::Key_Backspace );
utils.mouseClick( 0, 0, Qt::LeftButton );
utils.mouseMove( 0, 2 );
utils.mouseClick( 0, 2, Qt::RightButton );
QgsFeatureId newFid = utils.newFeatureId();

QCOMPARE( mLayer->featureCount(), ( long )1 );
QgsFeature f = mLayer->getFeature( newFid );

QString wkt = "CompoundCurveZ (CircularStringZ (0 2 222, 2 0 222, 0 -2 222, -2 0 222, 0 2 222))";
QCOMPARE( f.geometry().asWkt(), wkt );

mLayer->rollBack();
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

QGSTEST_MAIN( TestQgsMapToolCircle )
#include "testqgsmaptoolcircle.moc"
Loading