mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-12 00:02:25 -04:00
Alternative approach to fixing #32819
Partially reverts 5d27d7c, fixes #33133
This commit is contained in:
parent
d8be3f5a43
commit
85095a70ff
@ -166,6 +166,7 @@ bool QgsAttributeTableModel::removeRows( int row, int count, const QModelIndex &
|
||||
if ( row < 0 || count < 1 )
|
||||
return false;
|
||||
|
||||
if ( !mResettingModel )
|
||||
beginRemoveRows( parent, row, row + count - 1 );
|
||||
|
||||
#ifdef QGISDEBUG
|
||||
@ -208,12 +209,13 @@ bool QgsAttributeTableModel::removeRows( int row, int count, const QModelIndex &
|
||||
|
||||
Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
|
||||
|
||||
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;
|
||||
@ -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() ) );
|
||||
}
|
||||
@ -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() );
|
||||
@ -472,6 +478,10 @@ void QgsAttributeTableModel::loadLayer()
|
||||
emit finished();
|
||||
connect( mLayerCache, &QgsVectorLayerCache::invalidated, this, &QgsAttributeTableModel::loadLayer, Qt::UniqueConnection );
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
|
||||
mResettingModel = false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user