Skip to content

Commit

Permalink
Refactor slots and update view when bulk command finishes
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Oct 16, 2018
1 parent 5defc03 commit 1d9cfdc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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() );
Expand Down
8 changes: 7 additions & 1 deletion src/gui/attributetable/qgsattributetablemodel.h
Expand Up @@ -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;

};
Expand Down

0 comments on commit 1d9cfdc

Please sign in to comment.