Skip to content
Permalink
Browse files

Refactor slots and update view when bulk command finishes

  • Loading branch information
elpaso committed Oct 16, 2018
1 parent 5defc03 commit 1d9cfdc1f2492bb548b09d83d3adf35467acc844
@@ -66,10 +66,9 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayerCache *layerCache,
connect( layer(), &QgsVectorLayer::attributeDeleted, this, &QgsAttributeTableModel::attributeDeleted );
connect( layer(), &QgsVectorLayer::updatedFields, this, &QgsAttributeTableModel::updatedFields );

connect( layer(), &QgsVectorLayer::editCommandStarted, this, [ = ]( const QString ) { mBulkEditCommandRunning = true; } );
connect( layer(), &QgsVectorLayer::editCommandEnded, this, [ = ] { mBulkEditCommandRunning = false; } );
connect( layer(), &QgsVectorLayer::beforeRollBack, this, [ = ] { mBulkEditCommandRunning = true; } );
connect( layer(), &QgsVectorLayer::afterRollBack, this, [ = ] { mBulkEditCommandRunning = false; } );
connect( layer(), &QgsVectorLayer::editCommandStarted, this, &QgsAttributeTableModel::bulkEditCommandStarted );
connect( layer(), &QgsVectorLayer::beforeRollBack, this, &QgsAttributeTableModel::bulkEditCommandStarted );
connect( layer(), &QgsVectorLayer::afterRollBack, this, &QgsAttributeTableModel::bulkEditCommandEnded );

connect( layer(), &QgsVectorLayer::editCommandEnded, this, &QgsAttributeTableModel::editCommandEnded );
connect( mLayerCache, &QgsVectorLayerCache::attributeValueChanged, this, &QgsAttributeTableModel::attributeValueChanged );
@@ -263,6 +262,7 @@ void QgsAttributeTableModel::editCommandEnded()
// do not do reload(...) due would trigger (dataChanged) row sort
// giving issue: https://issues.qgis.org/issues/15976
mChangedCellBounds = QRect();
bulkEditCommandEnded( );
}

void QgsAttributeTableModel::attributeDeleted( int idx )
@@ -807,6 +807,18 @@ bool QgsAttributeTableModel::fieldIsEditable( const QgsVectorLayer &layer, int f
( ( layer.dataProvider() && layer.dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ) || FID_IS_NEW( fid ) ) );
}

void QgsAttributeTableModel::bulkEditCommandStarted()
{
mBulkEditCommandRunning = true;
}

void QgsAttributeTableModel::bulkEditCommandEnded()
{
// Invalidate the whole model
mBulkEditCommandRunning = false;
emit dataChanged( createIndex( 0, 0 ), createIndex( rowCount() - 1, columnCount() - 1 ) );
}

void QgsAttributeTableModel::reload( const QModelIndex &index1, const QModelIndex &index2 )
{
mFeat.setId( std::numeric_limits<int>::min() );
@@ -391,9 +391,15 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel

int mExtraColumns = 0;

//! Edit command or rollback is running
//! Flag for massive changes operations, set by edit command or rollback
bool mBulkEditCommandRunning = false;

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

//! Clears the flag for massive changes operations and tells the view to update
void bulkEditCommandEnded();

friend class TestQgsAttributeTable;

};

0 comments on commit 1d9cfdc

Please sign in to comment.
You can’t perform that action at this time.