Skip to content

Commit

Permalink
Fix crash on exit when remember last used attribute values is checked
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 4, 2021
1 parent 879379e commit 6329501
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/app/qgsfeatureaction.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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] );
}
}

Expand Down Expand Up @@ -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 );
}
}
}
Expand All @@ -319,4 +323,3 @@ QgsFeature QgsFeatureAction::feature() const
return mFeature ? *mFeature : QgsFeature();
}

QHash<QgsVectorLayer *, QgsAttributeMap> QgsFeatureAction::sLastUsedValues;
1 change: 0 additions & 1 deletion src/app/qgsfeatureaction.h
Expand Up @@ -92,7 +92,6 @@ class APP_EXPORT QgsFeatureAction : public QAction

bool mForceSuppressFormPopup = false;

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

#endif

0 comments on commit 6329501

Please sign in to comment.