Skip to content

Commit d62087e

Browse files
committedJul 24, 2018
Do not crash when removing a layer with attr table open
.. in show features in current extent mode.
1 parent 929ab27 commit d62087e

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed
 

‎src/gui/attributetable/qgsattributetablemodel.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -429,32 +429,36 @@ void QgsAttributeTableModel::loadLayer()
429429
removeRows( 0, rowCount() );
430430
}
431431

432-
QgsFeatureIterator features = mLayerCache->getFeatures( mFeatureRequest );
433-
434-
int i = 0;
432+
// Layer might have been deleted and cache set to nullptr!
433+
if ( mLayerCache )
434+
{
435+
QgsFeatureIterator features = mLayerCache->getFeatures( mFeatureRequest );
435436

436-
QTime t;
437-
t.start();
437+
int i = 0;
438438

439-
while ( features.nextFeature( mFeat ) )
440-
{
441-
++i;
439+
QTime t;
440+
t.start();
442441

443-
if ( t.elapsed() > 1000 )
442+
while ( features.nextFeature( mFeat ) )
444443
{
445-
bool cancel = false;
446-
emit progress( i, cancel );
447-
if ( cancel )
448-
break;
444+
++i;
449445

450-
t.restart();
446+
if ( t.elapsed() > 1000 )
447+
{
448+
bool cancel = false;
449+
emit progress( i, cancel );
450+
if ( cancel )
451+
break;
452+
453+
t.restart();
454+
}
455+
featureAdded( mFeat.id(), true );
451456
}
452-
featureAdded( mFeat.id(), true );
453-
}
454457

455-
emit finished();
458+
emit finished();
459+
connect( mLayerCache, &QgsVectorLayerCache::invalidated, this, &QgsAttributeTableModel::loadLayer, Qt::UniqueConnection );
460+
}
456461

457-
connect( mLayerCache, &QgsVectorLayerCache::invalidated, this, &QgsAttributeTableModel::loadLayer, Qt::UniqueConnection );
458462
endResetModel();
459463
}
460464

0 commit comments

Comments
 (0)
Please sign in to comment.