Skip to content

Commit

Permalink
mapLayerActions as members - avoiding crash
Browse files Browse the repository at this point in the history
mDuplicateFeatureAction and mDuplicateFeatureDigitizeAction are member pointers now.
Means they are deleted when the object QgisApp is destructed (when going out of scope) and there is no crash anymore on closing QGIS.
  • Loading branch information
signedav committed Jan 11, 2018
1 parent 5522f10 commit 5cd8827
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/app/qgisapp.cpp
Expand Up @@ -7451,23 +7451,23 @@ void QgisApp::setupLayoutManagerConnections()

void QgisApp::setupDuplicateFeaturesAction()
{
QgsMapLayerAction *action = new QgsMapLayerAction( QString( tr( "Duplicate feature" ) ),
this, QgsMapLayerAction::AllActions,
QgsApplication::getThemeIcon( QStringLiteral( "/mActionDuplicateFeature.svg" ) ) );
mDuplicateFeatureAction.reset( new QgsMapLayerAction( QString( tr( "Duplicate feature" ) ),
this, QgsMapLayerAction::AllActions,
QgsApplication::getThemeIcon( QStringLiteral( "/mActionDuplicateFeature.svg" ) ) ) );

QgsGui::mapLayerActionRegistry()->addMapLayerAction( action );
connect( action, &QgsMapLayerAction::triggeredForFeature, this, [this]( QgsMapLayer * layer, const QgsFeature & feat )
QgsGui::mapLayerActionRegistry()->addMapLayerAction( mDuplicateFeatureAction.get() );
connect( mDuplicateFeatureAction.get(), &QgsMapLayerAction::triggeredForFeature, this, [this]( QgsMapLayer * layer, const QgsFeature & feat )
{
duplicateFeatures( layer, feat );
}
);

action = new QgsMapLayerAction( QString( tr( "Duplicate feature and digitize" ) ),
this, QgsMapLayerAction::AllActions,
QgsApplication::getThemeIcon( QStringLiteral( "/mActionDuplicateFeatureDigitized.svg" ) ) );
mDuplicateFeatureDigitizeAction.reset( new QgsMapLayerAction( QString( tr( "Duplicate feature and digitize" ) ),
this, QgsMapLayerAction::AllActions,
QgsApplication::getThemeIcon( QStringLiteral( "/mActionDuplicateFeatureDigitized.svg" ) ) ) );

QgsGui::mapLayerActionRegistry()->addMapLayerAction( action );
connect( action, &QgsMapLayerAction::triggeredForFeature, this, [this]( QgsMapLayer * layer, const QgsFeature & feat )
QgsGui::mapLayerActionRegistry()->addMapLayerAction( mDuplicateFeatureDigitizeAction.get() );
connect( mDuplicateFeatureDigitizeAction.get(), &QgsMapLayerAction::triggeredForFeature, this, [this]( QgsMapLayer * layer, const QgsFeature & feat )
{
duplicateFeatureDigitized( layer, feat );
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -2146,6 +2146,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

QHash< QgsPrintLayout *, QgsMapLayerAction * > mAtlasFeatureActions;

std::unique_ptr<QgsMapLayerAction> mDuplicateFeatureAction;
std::unique_ptr<QgsMapLayerAction> mDuplicateFeatureDigitizeAction;

int mProjOpen = 0;

bool gestureEvent( QGestureEvent *event );
Expand Down

0 comments on commit 5cd8827

Please sign in to comment.