Skip to content

Commit

Permalink
Alternative approach to fixing #32819
Browse files Browse the repository at this point in the history
Partially reverts 5d27d7c, fixes #33133
  • Loading branch information
nyalldawson committed Nov 29, 2019
1 parent d8be3f5 commit 85095a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
20 changes: 15 additions & 5 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -166,7 +166,8 @@ bool QgsAttributeTableModel::removeRows( int row, int count, const QModelIndex &
if ( row < 0 || count < 1 )
return false;

beginRemoveRows( parent, row, row + count - 1 );
if ( !mResettingModel )
beginRemoveRows( parent, row, row + count - 1 );

#ifdef QGISDEBUG
if ( 3 <= QgsLogger::debugLevel() )
Expand Down Expand Up @@ -208,12 +209,13 @@ bool QgsAttributeTableModel::removeRows( int row, int count, const QModelIndex &

Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );

endRemoveRows();
if ( !mResettingModel )
endRemoveRows();

return true;
}

void QgsAttributeTableModel::featureAdded( QgsFeatureId fid, bool resettingModel )
void QgsAttributeTableModel::featureAdded( QgsFeatureId fid )
{
QgsDebugMsgLevel( QStringLiteral( "(%2) fid: %1" ).arg( fid ).arg( mFeatureRequest.filterType() ), 4 );
bool featOk = true;
Expand Down Expand Up @@ -244,11 +246,11 @@ void QgsAttributeTableModel::featureAdded( QgsFeatureId fid, bool resettingModel
if ( ! mIdRowMap.contains( fid ) )
{
int n = mRowIdMap.size();
if ( !resettingModel )
if ( !mResettingModel )
beginInsertRows( QModelIndex(), n, n );
mIdRowMap.insert( fid, n );
mRowIdMap.insert( n, fid );
if ( !resettingModel )
if ( !mResettingModel )
endInsertRows();
reload( index( rowCount() - 1, 0 ), index( rowCount() - 1, columnCount() ) );
}
Expand Down Expand Up @@ -436,8 +438,12 @@ void QgsAttributeTableModel::loadLayer()
// (emit of progress() signal may enter event loop and thus attribute
// table view may be updated with inconsistent model which may assume
// wrong number of attributes)

loadAttributes();

mResettingModel = true;
beginResetModel();

if ( rowCount() != 0 )
{
removeRows( 0, rowCount() );
Expand Down Expand Up @@ -472,6 +478,10 @@ void QgsAttributeTableModel::loadLayer()
emit finished();
connect( mLayerCache, &QgsVectorLayerCache::invalidated, this, &QgsAttributeTableModel::loadLayer, Qt::UniqueConnection );
}

endResetModel();

mResettingModel = false;
}


Expand Down
7 changes: 4 additions & 3 deletions src/gui/attributetable/qgsattributetablemodel.h
Expand Up @@ -318,10 +318,8 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
/**
* Launched when a feature has been added
* \param fid feature id
* \param resettingModel set to TRUE if model is in the process of being reset
* and the normal begin/EndInsertRows calls should not be made
*/
virtual void featureAdded( QgsFeatureId fid, bool resettingModel = false );
virtual void featureAdded( QgsFeatureId fid );

/**
* Launched when layer has been deleted
Expand Down Expand Up @@ -384,6 +382,9 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
//! Flag for massive changes operations, set by edit command or rollback
bool mBulkEditCommandRunning = false;

//! TRUE if model is in the midst of a reset operation
bool mResettingModel = false;

//! Sets the flag for massive changes operations
void bulkEditCommandStarted();

Expand Down

0 comments on commit 85095a7

Please sign in to comment.