Skip to content

Commit

Permalink
fix crash on close in attribute table (layer cache already destroyed …
Browse files Browse the repository at this point in the history
…when model dtor is called)
  • Loading branch information
jef-n committed Apr 15, 2013
1 parent 42e0bad commit cb6b951
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/core/qgsvectorlayercache.cpp
Expand Up @@ -232,8 +232,7 @@ void QgsVectorLayerCache::geometryChanged( QgsFeatureId fid, QgsGeometry& geom )

void QgsVectorLayerCache::layerDeleted()
{
emit( cachedLayerDeleted() );

emit cachedLayerDeleted();
mLayer = NULL;
}

Expand Down
3 changes: 1 addition & 2 deletions src/core/qgsvectorlayercache.h
Expand Up @@ -65,7 +65,7 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
// That's the reason we need this wrapper:
// Inform the cache that this feature has been removed
mCache->featureRemoved( mFeature->id() );
delete( mFeature );
delete mFeature;
}

inline const QgsFeature* feature() { return mFeature; }
Expand All @@ -86,7 +86,6 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
*
* @param cacheSize indicates the maximum number of features to keep in the cache
*/

void setCacheSize( int cacheSize );

/**
Expand Down
25 changes: 10 additions & 15 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -57,17 +57,13 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayerCache *layerCache,

QgsAttributeTableModel::~QgsAttributeTableModel()
{
if ( layer() )
const QMap<QString, QVariant> *item;
foreach ( item, mValueMaps )
{
const QgsFields& fields = layer()->pendingFields();
for ( int idx = 0; idx < fields.count(); ++idx )
{
if ( layer()->editType( idx ) != QgsVectorLayer::ValueRelation )
continue;

delete mValueMaps.take( idx );
}
delete item;
}

mValueMaps.clear();
}

bool QgsAttributeTableModel::loadFeatureAtId( QgsFeatureId fid ) const
Expand Down Expand Up @@ -165,14 +161,13 @@ void QgsAttributeTableModel::layerDeleted()
removeRows( 0, rowCount() );
endRemoveRows();

const QgsFields& fields = layer()->pendingFields();
for ( int idx = 0; idx < fields.count(); ++idx )
const QMap<QString, QVariant> *item;
foreach ( item, mValueMaps )
{
if ( layer()->editType( idx ) != QgsVectorLayer::ValueRelation )
continue;

delete mValueMaps.take( idx );
delete item;
}

mValueMaps.clear();
}

void QgsAttributeTableModel::attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value )
Expand Down

0 comments on commit cb6b951

Please sign in to comment.