Skip to content

Commit

Permalink
Mesh selection actions (#58888)
Browse files Browse the repository at this point in the history
* add new actions

* icons for actions

* fix styling

* select by expression

* add tests
  • Loading branch information
JanCaha authored Nov 20, 2024
1 parent 1088325 commit 3d92b2b
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 2 deletions.
2 changes: 2 additions & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -938,11 +938,13 @@
<file>themes/default/mActionMeshDigitizing.svg</file>
<file>themes/default/mActionMeshSelectPolygon.svg</file>
<file>themes/default/mActionMeshSelectExpression.svg</file>
<file>themes/default/mActionMeshSelectIsolatedVertices.svg</file>
<file>themes/default/mActionNewMeshLayer.svg</file>
<file>themes/default/mActionMeshTransformByExpression.svg</file>
<file>themes/default/mIconVertexCoordinates.svg</file>
<file>themes/default/mActionMeshEditForceByVectorLines.svg</file>
<file>themes/default/mActionMeshReindex.svg</file>
<file>themes/default/mActionMeshSelectAll.svg</file>
<file>themes/default/mIconGeometryCollectionLayer.svg</file>
<file>themes/default/mIconGps.svg</file>
<file>themes/default/mActionNewGpx.svg</file>
Expand Down
1 change: 1 addition & 0 deletions images/themes/default/mActionMeshSelectAll.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 22 additions & 2 deletions src/app/mesh/qgsmaptooleditmeshframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,13 @@ QgsMapToolEditMeshFrame::QgsMapToolEditMeshFrame( QgsMapCanvas *canvas )

mSelectionHandler = std::make_unique<QgsMapToolSelectionHandler>( canvas, QgsMapToolSelectionHandler::SelectPolygon );

mActionSelectIsolatedVertices = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMeshSelectIsolatedVertices.svg" ) ), tr( "Select Isolated Vertices" ), this );
mActionSelectAllVertices = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMeshSelectAll.svg" ) ), tr( "Select All Vertices" ), this );

mSelectActions << mActionSelectByPolygon
<< mActionSelectByExpression;
<< mActionSelectByExpression
<< mActionSelectIsolatedVertices
<< mActionSelectAllVertices;

mActionTransformCoordinates = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMeshTransformByExpression.svg" ) ), tr( "Transform Vertices Coordinates" ), this );
mActionTransformCoordinates->setCheckable( true );
Expand Down Expand Up @@ -273,6 +278,19 @@ QgsMapToolEditMeshFrame::QgsMapToolEditMeshFrame( QgsMapCanvas *canvas )
mSelectionBand->reset( Qgis::GeometryType::Polygon );
} );

connect( mActionSelectIsolatedVertices, &QAction::triggered, this, [this]
{
onEditingStarted();
setSelectedVertices( mCurrentEditor->freeVerticesIndexes(), Qgis::SelectBehavior::SetSelection );
} );

connect( mActionSelectAllVertices, &QAction::triggered, this, [this]
{
onEditingStarted();
QList<int> verticesIndexes = mCurrentLayer->selectVerticesByExpression( QgsExpression( "true" ) );
setSelectedVertices( verticesIndexes, Qgis::SelectBehavior::SetSelection );
} );

connect( mActionSelectByExpression, &QAction::triggered, this, &QgsMapToolEditMeshFrame::showSelectByExpressionDialog );
connect( mActionTransformCoordinates, &QAction::triggered, this, &QgsMapToolEditMeshFrame::triggerTransformCoordinatesDockWidget );
connect( mActionReindexMesh, &QAction::triggered, this, &QgsMapToolEditMeshFrame::reindexMesh );
Expand Down Expand Up @@ -371,7 +389,9 @@ void QgsMapToolEditMeshFrame::setActionsEnable( bool enable )
<< mActionSelectByExpression
<< mActionTransformCoordinates
<< mActionForceByLines
<< mActionReindexMesh;
<< mActionReindexMesh
<< mActionSelectIsolatedVertices
<< mActionSelectAllVertices;

for ( QAction *action : std::as_const( actions ) )
action->setEnabled( enable );
Expand Down
3 changes: 3 additions & 0 deletions src/app/mesh/qgsmaptooleditmeshframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ class APP_EXPORT QgsMapToolEditMeshFrame : public QgsMapToolAdvancedDigitizing
QAction *mActionSelectByExpression = nullptr;
QAction *mActionForceByLines = nullptr;

QAction *mActionSelectIsolatedVertices = nullptr;
QAction *mActionSelectAllVertices = nullptr;

QgsMeshEditForceByLineAction *mWidgetActionForceByLine = nullptr;
QAction *mActionReindexMesh = nullptr;

Expand Down
50 changes: 50 additions & 0 deletions tests/src/app/testqgsmaptooleditmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class TestQgsMapToolEditMesh : public QObject

void editMesh();

void selectElements();

private:
QgisApp *mQgisApp = nullptr;
std::unique_ptr<QgsMeshLayer> meshLayerQuadFlower;
Expand Down Expand Up @@ -388,5 +390,53 @@ void TestQgsMapToolEditMesh::editMesh()
QCOMPARE( mEditMeshMapTool->mSelectedFaces.count(), 0 );
}

void TestQgsMapToolEditMesh::selectElements()
{
QString uri = QString( mDataDir + "/quad_and_triangle_with_free_vertices.2dm" );
std::unique_ptr<QgsMeshLayer> layer = std::make_unique<QgsMeshLayer>( uri, "quad and triangle", "mdal" );
QVERIFY( layer->isValid() );

const QgsCoordinateTransform transform;
QgsMeshEditingError error;
layer->startFrameEditing( transform, error, false );
QVERIFY( error == QgsMeshEditingError() );

mCanvas->setLayers( QList<QgsMapLayer *>() << layer.get() );

QVERIFY( layer->meshEditor() );

TestQgsMapToolAdvancedDigitizingUtils tool( mEditMeshMapTool );
mCanvas->setCurrentLayer( layer.get() );
mEditMeshMapTool->mActionDigitizing->trigger();

// select all vertices
QCOMPARE( mEditMeshMapTool->mSelectedVertices.count(), 0 );
mEditMeshMapTool->mActionSelectAllVertices->trigger();
QCOMPARE( mEditMeshMapTool->mSelectedVertices.count(), 10 );

// reset selection
tool.mouseClick( 0, 0, Qt::LeftButton );

// select isolated vertices
QCOMPARE( mEditMeshMapTool->mSelectedVertices.count(), 0 );
mEditMeshMapTool->mActionSelectIsolatedVertices->trigger();
QCOMPARE( mEditMeshMapTool->mSelectedVertices.count(), 5 );

// reset selection
tool.mouseClick( 0, 0, Qt::LeftButton );

// select by polygon
QCOMPARE( mEditMeshMapTool->mSelectedVertices.count(), 0 );
mEditMeshMapTool->mActionSelectByPolygon->trigger();

// polygon definition
tool.mouseClick( 2100, 3000, Qt::LeftButton );
tool.mouseClick( 2900, 2300, Qt::LeftButton );
tool.mouseClick( 3100, 3000, Qt::LeftButton );
tool.mouseClick( 2500, 3000, Qt::RightButton );

QCOMPARE( mEditMeshMapTool->mSelectedVertices.count(), 3 );
}

QGSTEST_MAIN( TestQgsMapToolEditMesh )
#include "testqgsmaptooleditmesh.moc"
13 changes: 13 additions & 0 deletions tests/testdata/mesh/quad_and_triangle_with_free_vertices.2dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
MESH2D
ND 1 1000 2000 20
ND 2 2000 2000 30
ND 3 3000 2000 40
ND 4 2000 3000 50
ND 5 1000 3000 10
ND 6 2453.85 2920.15 0
ND 7 2915.19 2965.09 0
ND 8 2783.38 2656.53 0
ND 9 964.98 1799.75 0
ND 10 1555.14 1781.78 0
E4Q 1 1 2 4 5
E3T 2 2 3 4

0 comments on commit 3d92b2b

Please sign in to comment.