Skip to content
Permalink
Browse files

Fix crash on exit when remember last used attribute values is checked

(cherry picked from commit f4e5fdb)
  • Loading branch information
nyalldawson committed Mar 19, 2021
1 parent e2f1a82 commit ada0bc793bc9e1174ced27bdecb75d2e495541df
Showing with 9 additions and 7 deletions.
  1. +9 −6 src/app/qgsfeatureaction.cpp
  2. +0 −1 src/app/qgsfeatureaction.h
@@ -34,6 +34,10 @@

#include <QPushButton>

typedef QHash<QgsVectorLayer *, QgsAttributeMap> CachedAttributesHash;
Q_GLOBAL_STATIC( CachedAttributesHash, sLastUsedValues )


QgsFeatureAction::QgsFeatureAction( const QString &name, QgsFeature &f, QgsVectorLayer *layer, QUuid actionId, int defaultAttr, QObject *parent )
: QAction( name, parent )
, mLayer( layer )
@@ -183,9 +187,9 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, boo
{
initialAttributeValues.insert( idx, defaultAttributes.value( idx ) );
}
else if ( reuseLastValues && sLastUsedValues.contains( mLayer ) && sLastUsedValues[ mLayer ].contains( idx ) )
else if ( reuseLastValues && sLastUsedValues()->contains( mLayer ) && ( *sLastUsedValues() )[ mLayer ].contains( idx ) )
{
initialAttributeValues.insert( idx, sLastUsedValues[ mLayer ][idx] );
initialAttributeValues.insert( idx, ( *sLastUsedValues() )[ mLayer ][idx] );
}
}

@@ -304,11 +308,11 @@ void QgsFeatureAction::onFeatureSaved( const QgsFeature &feature )
for ( int idx = 0; idx < fields.count(); ++idx )
{
QgsAttributes newValues = feature.attributes();
QgsAttributeMap origValues = sLastUsedValues[ mLayer ];
QgsAttributeMap origValues = ( *sLastUsedValues() )[ mLayer ];
if ( origValues[idx] != newValues.at( idx ) )
{
QgsDebugMsg( QStringLiteral( "saving %1 for %2" ).arg( sLastUsedValues[ mLayer ][idx].toString() ).arg( idx ) );
sLastUsedValues[ mLayer ][idx] = newValues.at( idx );
QgsDebugMsg( QStringLiteral( "saving %1 for %2" ).arg( ( *sLastUsedValues() )[ mLayer ][idx].toString() ).arg( idx ) );
( *sLastUsedValues() )[ mLayer ][idx] = newValues.at( idx );
}
}
}
@@ -319,4 +323,3 @@ QgsFeature QgsFeatureAction::feature() const
return mFeature ? *mFeature : QgsFeature();
}

QHash<QgsVectorLayer *, QgsAttributeMap> QgsFeatureAction::sLastUsedValues;
@@ -92,7 +92,6 @@ class APP_EXPORT QgsFeatureAction : public QAction

bool mForceSuppressFormPopup = false;

static QHash<QgsVectorLayer *, QgsAttributeMap> sLastUsedValues;
};

#endif

0 comments on commit ada0bc7

Please sign in to comment.