Skip to content

Commit

Permalink
Better memory management
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 19, 2022
1 parent ad98d28 commit df8f525
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/app/qgsfeatureaction.cpp
Expand Up @@ -167,7 +167,7 @@ bool QgsFeatureAction::editFeature( bool showModal )
return true;
}

bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, bool showModal, QgsExpressionContextScope *scope SIP_TRANSFER, bool hideParent )
bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, bool showModal, std::unique_ptr< QgsExpressionContextScope > scope, bool hideParent )
{
if ( !mLayer || !mLayer->isEditable() )
return false;
Expand Down Expand Up @@ -197,7 +197,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, boo
// values and field constraints
QgsExpressionContext context = mLayer->createExpressionContext();
if ( scope )
context.appendScope( scope );
context.appendScope( scope.release() );

const QgsFeature newFeature = QgsVectorLayerUtils::createFeature( mLayer, mFeature->geometry(), initialAttributeValues,
&context );
Expand Down
15 changes: 9 additions & 6 deletions src/app/qgsfeatureaction.h
Expand Up @@ -38,11 +38,6 @@ class APP_EXPORT QgsFeatureAction : public QAction
public:
QgsFeatureAction( const QString &name, QgsFeature &f, QgsVectorLayer *vl, QUuid actionId = QUuid(), int defaultAttr = -1, QObject *parent = nullptr );

public slots:
void execute();
bool viewFeatureForm( QgsHighlight *h = nullptr );
bool editFeature( bool showModal = true );

/**
* Add a new feature to the layer.
* Will set the default values to recently used or provider defaults based on settings
Expand All @@ -55,7 +50,15 @@ class APP_EXPORT QgsFeatureAction : public QAction
*
* \returns TRUE if feature was added if showModal is true. If showModal is FALSE, returns TRUE in every case
*/
bool addFeature( const QgsAttributeMap &defaultAttributes = QgsAttributeMap(), bool showModal = true, QgsExpressionContextScope *scope = nullptr, bool hideParent = false );
bool addFeature( const QgsAttributeMap &defaultAttributes = QgsAttributeMap(),
bool showModal = true,
std::unique_ptr<QgsExpressionContextScope >scope = std::unique_ptr< QgsExpressionContextScope >(),
bool hideParent = false );

public slots:
void execute();
bool viewFeatureForm( QgsHighlight *h = nullptr );
bool editFeature( bool showModal = true );

/**
* Sets whether to force suppression of the attribute form popup after creating a new feature.
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptooladdfeature.cpp
Expand Up @@ -56,11 +56,11 @@ QgsMapToolAddFeature::QgsMapToolAddFeature( QgsMapCanvas *canvas, CaptureMode mo
bool QgsMapToolAddFeature::addFeature( QgsVectorLayer *vlayer, const QgsFeature &f, bool showModal )
{
QgsFeature feat( f );
QgsExpressionContextScope *scope = QgsExpressionContextUtils::mapToolCaptureScope( snappingMatches() );
std::unique_ptr< QgsExpressionContextScope > scope( QgsExpressionContextUtils::mapToolCaptureScope( snappingMatches() ) );
QgsFeatureAction *action = new QgsFeatureAction( tr( "add feature" ), feat, vlayer, QUuid(), -1, this );
if ( QgsRubberBand *rb = takeRubberBand() )
connect( action, &QgsFeatureAction::addFeatureFinished, rb, &QgsRubberBand::deleteLater );
const bool res = action->addFeature( QgsAttributeMap(), showModal, scope );
const bool res = action->addFeature( QgsAttributeMap(), showModal, std::move( scope ) );
if ( showModal )
delete action;
return res;
Expand Down

0 comments on commit df8f525

Please sign in to comment.