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,7 +166,8 @@ bool QgsAttributeTableModel::removeRows( int row, int count, const QModelIndex &
|
|||||||
if ( row < 0 || count < 1 )
|
if ( row < 0 || count < 1 )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
beginRemoveRows( parent, row, row + count - 1 );
|
if ( !mResettingModel )
|
||||||
|
beginRemoveRows( parent, row, row + count - 1 );
|
||||||
|
|
||||||
#ifdef QGISDEBUG
|
#ifdef QGISDEBUG
|
||||||
if ( 3 <= QgsLogger::debugLevel() )
|
if ( 3 <= QgsLogger::debugLevel() )
|
||||||
@ -208,12 +209,13 @@ bool QgsAttributeTableModel::removeRows( int row, int count, const QModelIndex &
|
|||||||
|
|
||||||
Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
|
Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
|
||||||
|
|
||||||
endRemoveRows();
|
if ( !mResettingModel )
|
||||||
|
endRemoveRows();
|
||||||
|
|
||||||
return true;
|
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 );
|
QgsDebugMsgLevel( QStringLiteral( "(%2) fid: %1" ).arg( fid ).arg( mFeatureRequest.filterType() ), 4 );
|
||||||
bool featOk = true;
|
bool featOk = true;
|
||||||
@ -244,11 +246,11 @@ void QgsAttributeTableModel::featureAdded( QgsFeatureId fid, bool resettingModel
|
|||||||
if ( ! mIdRowMap.contains( fid ) )
|
if ( ! mIdRowMap.contains( fid ) )
|
||||||
{
|
{
|
||||||
int n = mRowIdMap.size();
|
int n = mRowIdMap.size();
|
||||||
if ( !resettingModel )
|
if ( !mResettingModel )
|
||||||
beginInsertRows( QModelIndex(), n, n );
|
beginInsertRows( QModelIndex(), n, n );
|
||||||
mIdRowMap.insert( fid, n );
|
mIdRowMap.insert( fid, n );
|
||||||
mRowIdMap.insert( n, fid );
|
mRowIdMap.insert( n, fid );
|
||||||
if ( !resettingModel )
|
if ( !mResettingModel )
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
reload( index( rowCount() - 1, 0 ), index( rowCount() - 1, columnCount() ) );
|
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
|
// (emit of progress() signal may enter event loop and thus attribute
|
||||||
// table view may be updated with inconsistent model which may assume
|
// table view may be updated with inconsistent model which may assume
|
||||||
// wrong number of attributes)
|
// wrong number of attributes)
|
||||||
|
|
||||||
loadAttributes();
|
loadAttributes();
|
||||||
|
|
||||||
|
mResettingModel = true;
|
||||||
|
beginResetModel();
|
||||||
|
|
||||||
if ( rowCount() != 0 )
|
if ( rowCount() != 0 )
|
||||||
{
|
{
|
||||||
removeRows( 0, rowCount() );
|
removeRows( 0, rowCount() );
|
||||||
@ -472,6 +478,10 @@ void QgsAttributeTableModel::loadLayer()
|
|||||||
emit finished();
|
emit finished();
|
||||||
connect( mLayerCache, &QgsVectorLayerCache::invalidated, this, &QgsAttributeTableModel::loadLayer, Qt::UniqueConnection );
|
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
|
* Launched when a feature has been added
|
||||||
* \param fid feature id
|
* \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
|
* 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
|
//! Flag for massive changes operations, set by edit command or rollback
|
||||||
bool mBulkEditCommandRunning = false;
|
bool mBulkEditCommandRunning = false;
|
||||||
|
|
||||||
|
//! TRUE if model is in the midst of a reset operation
|
||||||
|
bool mResettingModel = false;
|
||||||
|
|
||||||
//! Sets the flag for massive changes operations
|
//! Sets the flag for massive changes operations
|
||||||
void bulkEditCommandStarted();
|
void bulkEditCommandStarted();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user