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

Mesh selection actions #58888

Merged
merged 6 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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.
31 changes: 29 additions & 2 deletions src/app/mesh/qgsmaptooleditmeshframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,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 @@ -269,6 +274,26 @@ 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;
verticesIndexes.reserve( mCurrentLayer->meshVertexCount() );
for ( int i = 0; i < mCurrentLayer->meshVertexCount(); i++ )
{
verticesIndexes.append( i );
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meshVertexCount() says:

\note during mesh editing, some vertices can be void and are not included in this returned value

does that affect us?
Would it be better to maybe use mCurrentLayer->selectVerticesByExpression( true ) to get the indexes instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good point.

We could avoid evaluating the expression by using mCurrentLayer->nativeMesh()->vertexCount(). That would skip need to use QgsExpression and its evaluation. It is what the mCurrentLayer->selectVerticesByExpression() does internally anyways.


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 @@ -365,7 +390,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 @@ -350,6 +350,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
Loading