Skip to content

Commit

Permalink
Make Delete ring map tool respect selected features
Browse files Browse the repository at this point in the history
  • Loading branch information
uclaros authored and nyalldawson committed Oct 25, 2023
1 parent f465ef4 commit 4178ace
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/app/qgsmaptooldeletering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void QgsMapToolDeleteRing::canvasPressEvent( QgsMapMouseEvent *e )

const QgsGeometry ringGeom = ringUnderPoint( p, mPressedFid, mPressedPartNum, mPressedRingNum );

if ( mPressedFid != -1 )
if ( mPressedRingNum != -1 )
{
QgsFeature f;
vlayer->getFeatures( QgsFeatureRequest().setFilterFid( mPressedFid ) ).nextFeature( f );
Expand All @@ -89,6 +89,12 @@ void QgsMapToolDeleteRing::canvasPressEvent( QgsMapMouseEvent *e )
mRubberBand->setToGeometry( ringGeom, vlayer );
mRubberBand->show();
}
else if ( vlayer->selectedFeatureCount() > 0 )
{
emit messageEmitted(
tr( "If there are selected features, the delete ring tool only applies to those. Clear the selection and try again." ),
Qgis::MessageLevel::Warning );
}
}

void QgsMapToolDeleteRing::canvasReleaseEvent( QgsMapMouseEvent *e )
Expand Down Expand Up @@ -129,8 +135,13 @@ QgsGeometry QgsMapToolDeleteRing::ringUnderPoint( const QgsPointXY &p, QgsFeatur
QgsPolygonXY tempPol;
QgsGeometry tempGeom;
double area = std::numeric_limits<double>::max();
const QgsFeatureIds selectedFeatureIds = vlayer->selectedFeatureIds();
while ( fit.nextFeature( f ) )
{
if ( !selectedFeatureIds.isEmpty() &&
!selectedFeatureIds.contains( f.id() ) )
continue;

g = f.geometry();
if ( g.isNull() || QgsWkbTypes::geometryType( g.wkbType() ) != Qgis::GeometryType::Polygon )
continue;
Expand Down

0 comments on commit 4178ace

Please sign in to comment.