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

Make avoid overlap work with more digitizing tools (fixes #50433) #56873

Merged
merged 16 commits into from Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/app/qgsmaptoolmovefeature.cpp
Expand Up @@ -15,6 +15,7 @@

#include "qgisapp.h"
#include "qgsadvanceddigitizingdockwidget.h"
#include "qgsavoidintersectionsoperation.h"
#include "qgsfeatureiterator.h"
#include "qgsgeometry.h"
#include "qgslogger.h"
Expand Down Expand Up @@ -217,6 +218,20 @@ void QgsMapToolMoveFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
request.setFilterFids( mMovedFeatures ).setNoAttributes();
QgsFeatureIterator fi = vlayer->getFeatures( request );
QgsFeature f;

QgsAvoidIntersectionsOperation avoidIntersections;
connect( &avoidIntersections, &QgsAvoidIntersectionsOperation::messageEmitted, this, &QgsMapTool::messageEmitted );

// when removing intersections don't check for intersections with selected features
QSet<QgsFeatureId> ignoreFeatureIds;
for ( const auto &feat : mMovedFeatures )
{
ignoreFeatureIds.insert( feat );
}

QHash<QgsVectorLayer *, QSet<QgsFeatureId> > ignoreFeatures;
ignoreFeatures.insert( vlayer, ignoreFeatureIds );
JuhoErvasti marked this conversation as resolved.
Show resolved Hide resolved

while ( fi.nextFeature( f ) )
{
if ( !f.hasGeometry() )
Expand All @@ -227,6 +242,23 @@ void QgsMapToolMoveFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
continue;

const QgsFeatureId id = f.id();

if ( vlayer->geometryType() == Qgis::GeometryType::Polygon )
{
const QgsAvoidIntersectionsOperation::Result res = avoidIntersections.apply( vlayer, id, geom, ignoreFeatures );

if ( res.operationResult == Qgis::GeometryOperationResult::InvalidInputGeometryType || geom.isEmpty() )
{
QString errorMessage = ( geom.isEmpty() ) ?
JuhoErvasti marked this conversation as resolved.
Show resolved Hide resolved
tr( "Resulting geometry would be empty" ) :
JuhoErvasti marked this conversation as resolved.
Show resolved Hide resolved
tr( "An error was reported during intersection removal" );

emit messageEmitted( errorMessage, Qgis::MessageLevel::Warning );
vlayer->destroyEditCommand();
return;
}
}

vlayer->changeGeometry( id, geom );

if ( QgsProject::instance()->topologicalEditing() )
Expand Down
23 changes: 23 additions & 0 deletions src/app/qgsmaptooloffsetcurve.cpp
Expand Up @@ -17,6 +17,7 @@
#include <QGridLayout>
#include <QLabel>

#include "qgsavoidintersectionsoperation.h"
#include "qgsdoublespinbox.h"
#include "qgsfeatureiterator.h"
#include "qgsmaptooloffsetcurve.h"
Expand Down Expand Up @@ -346,6 +347,28 @@ void QgsMapToolOffsetCurve::applyOffset( double offset, Qt::KeyboardModifiers mo

destLayer->beginEditCommand( tr( "Offset curve" ) );

QgsAvoidIntersectionsOperation avoidIntersections;

connect( &avoidIntersections, &QgsAvoidIntersectionsOperation::messageEmitted, this, &QgsMapTool::messageEmitted );

QHash<QgsVectorLayer *, QSet<QgsFeatureId> > ignoreFeatures;
ignoreFeatures.insert( destLayer, QSet<QgsFeatureId> { mModifiedFeature } );
JuhoErvasti marked this conversation as resolved.
Show resolved Hide resolved

const QgsAvoidIntersectionsOperation::Result res = avoidIntersections.apply( destLayer, mModifiedFeature, mModifiedGeometry, ignoreFeatures );

if ( res.operationResult == Qgis::GeometryOperationResult::InvalidInputGeometryType || mModifiedGeometry.isEmpty() )
{
QString errorMessage = ( mModifiedGeometry.isEmpty() ) ?
JuhoErvasti marked this conversation as resolved.
Show resolved Hide resolved
tr( "Resulting geometry would be empty" ) :
JuhoErvasti marked this conversation as resolved.
Show resolved Hide resolved
tr( "An error was reported during intersection removal" );

emit messageEmitted( errorMessage, Qgis::MessageLevel::Warning );
destLayer->destroyEditCommand();
deleteRubberBandAndGeometry();
deleteUserInputWidget();
return;
}

bool editOk = true;
if ( !mCtrlHeldOnFirstClick && !( modifiers & Qt::ControlModifier ) )
{
Expand Down
34 changes: 34 additions & 0 deletions src/app/qgsmaptoolrotatefeature.cpp
Expand Up @@ -23,6 +23,7 @@
#include <cmath>

#include "qgsadvanceddigitizingdockwidget.h"
#include "qgsavoidintersectionsoperation.h"
#include "qgsmaptoolrotatefeature.h"
#include "qgsfeatureiterator.h"
#include "qgsgeometry.h"
Expand Down Expand Up @@ -414,11 +415,44 @@ void QgsMapToolRotateFeature::applyRotation( double rotation )
request.setFilterFids( mRotatedFeatures ).setNoAttributes();
QgsFeatureIterator fi = vlayer->getFeatures( request );
QgsFeature f;

QgsAvoidIntersectionsOperation avoidIntersections;
connect( &avoidIntersections, &QgsAvoidIntersectionsOperation::messageEmitted, this, &QgsMapTool::messageEmitted );

// when removing intersections don't check for intersections with selected features
QSet<QgsFeatureId> ignoreFeatureIds;
for ( const auto &feat : mRotatedFeatures )
{
ignoreFeatureIds.insert( feat );
}

QHash<QgsVectorLayer *, QSet<QgsFeatureId> > ignoreFeatures;
ignoreFeatures.insert( vlayer, ignoreFeatureIds );
JuhoErvasti marked this conversation as resolved.
Show resolved Hide resolved

while ( fi.nextFeature( f ) )
{
const QgsFeatureId id = f.id();
QgsGeometry geom = f.geometry();
geom.rotate( mRotation, anchorPoint );

if ( vlayer->geometryType() == Qgis::GeometryType::Polygon )
{
const QgsAvoidIntersectionsOperation::Result res = avoidIntersections.apply( vlayer, id, geom, ignoreFeatures );

if ( res.operationResult == Qgis::GeometryOperationResult::InvalidInputGeometryType || geom.isEmpty() )
{
QString errorMessage = ( geom.isEmpty() ) ?
JuhoErvasti marked this conversation as resolved.
Show resolved Hide resolved
tr( "Resulting geometry would be empty" ) :
JuhoErvasti marked this conversation as resolved.
Show resolved Hide resolved
tr( "An error was reported during intersection removal" );

emit messageEmitted( errorMessage, Qgis::MessageLevel::Warning );
vlayer->destroyEditCommand();
deleteRotationWidget();
deleteRubberband();
return;
}
}

vlayer->changeGeometry( id, geom );
}

Expand Down
34 changes: 34 additions & 0 deletions src/app/qgsmaptoolscalefeature.cpp
Expand Up @@ -23,6 +23,7 @@
#include <cmath>

#include "qgsadvanceddigitizingdockwidget.h"
#include "qgsavoidintersectionsoperation.h"
#include "qgsmaptoolscalefeature.h"
#include "qgsfeatureiterator.h"
#include "qgsgeometry.h"
Expand Down Expand Up @@ -368,6 +369,20 @@ void QgsMapToolScaleFeature::applyScaling( double scale )
request.setFilterFids( mScaledFeatures ).setNoAttributes();
QgsFeatureIterator fi = vlayer->getFeatures( request );
QgsFeature feat;

QgsAvoidIntersectionsOperation avoidIntersections;
connect( &avoidIntersections, &QgsAvoidIntersectionsOperation::messageEmitted, this, &QgsMapTool::messageEmitted );

// when removing intersections don't check for intersections with selected features
QSet<QgsFeatureId> ignoreFeatureIds;
for ( const auto &f : mScaledFeatures )
{
ignoreFeatureIds.insert( f );
}

QHash<QgsVectorLayer *, QSet<QgsFeatureId> > ignoreFeatures;
ignoreFeatures.insert( vlayer, ignoreFeatureIds );
JuhoErvasti marked this conversation as resolved.
Show resolved Hide resolved

while ( fi.nextFeature( feat ) )
{
if ( !feat.hasGeometry() )
Expand All @@ -378,6 +393,25 @@ void QgsMapToolScaleFeature::applyScaling( double scale )
continue;

const QgsFeatureId id = feat.id();

if ( vlayer->geometryType() == Qgis::GeometryType::Polygon )
troopa81 marked this conversation as resolved.
Show resolved Hide resolved
{
const QgsAvoidIntersectionsOperation::Result res = avoidIntersections.apply( vlayer, id, geom, ignoreFeatures );

if ( res.operationResult == Qgis::GeometryOperationResult::InvalidInputGeometryType || geom.isEmpty() )
{
QString errorMessage = ( geom.isEmpty() ) ?
tr( "Resulting geometry would be empty" ) :
JuhoErvasti marked this conversation as resolved.
Show resolved Hide resolved
tr( "An error was reported during intersection removal" );

emit messageEmitted( errorMessage, Qgis::MessageLevel::Warning );
vlayer->destroyEditCommand();
deleteScalingWidget();
deleteRubberband();
return;
}
}

vlayer->changeGeometry( id, geom );
}

Expand Down