@@ -261,7 +261,6 @@ void QgsAttributeTableModel::editCommandEnded()
261
261
{
262
262
// do not do reload(...) due would trigger (dataChanged) row sort
263
263
// giving issue: https://issues.qgis.org/issues/15976
264
- mChangedCellBounds = QRect ();
265
264
bulkEditCommandEnded ( );
266
265
}
267
266
@@ -301,13 +300,13 @@ void QgsAttributeTableModel::fieldFormatterRemoved( QgsFieldFormatter *fieldForm
301
300
302
301
void QgsAttributeTableModel::attributeValueChanged ( QgsFeatureId fid, int idx, const QVariant &value )
303
302
{
304
- // Defer all updates if an edit command is running
303
+ // Defer all updates if a bulk edit/rollback command is running
305
304
if ( mBulkEditCommandRunning )
306
305
{
307
306
mAttributeValueChanges .insert ( QPair<QgsFeatureId, int >( fid, idx ), value );
308
307
return ;
309
308
}
310
- QgsDebugMsgLevel ( QStringLiteral ( " (%4) fid: %1, idx: %2, value: %3" ).arg ( fid ).arg ( idx ).arg ( value.toString () ).arg ( mFeatureRequest .filterType () ), 3 );
309
+ QgsDebugMsgLevel ( QStringLiteral ( " (%4) fid: %1, idx: %2, value: %3" ).arg ( fid ).arg ( idx ).arg ( value.toString () ).arg ( mFeatureRequest .filterType () ), 2 );
311
310
312
311
for ( SortCache &cache : mSortCaches )
313
312
{
@@ -744,30 +743,6 @@ bool QgsAttributeTableModel::setData( const QModelIndex &index, const QVariant &
744
743
if ( !layer ()->isModified () )
745
744
return false ;
746
745
747
- if ( mChangedCellBounds .isNull () )
748
- {
749
- mChangedCellBounds = QRect ( index.column (), index.row (), 1 , 1 );
750
- }
751
- else
752
- {
753
- if ( index.column () < mChangedCellBounds .left () )
754
- {
755
- mChangedCellBounds .setLeft ( index.column () );
756
- }
757
- if ( index.row () < mChangedCellBounds .top () )
758
- {
759
- mChangedCellBounds .setTop ( index.row () );
760
- }
761
- if ( index.column () > mChangedCellBounds .right () )
762
- {
763
- mChangedCellBounds .setRight ( index.column () );
764
- }
765
- if ( index.row () > mChangedCellBounds .bottom () )
766
- {
767
- mChangedCellBounds .setBottom ( index.row () );
768
- }
769
- }
770
-
771
746
mRowStylesMap .remove ( index.row () );
772
747
773
748
return true ;
@@ -820,36 +795,43 @@ void QgsAttributeTableModel::bulkEditCommandEnded()
820
795
{
821
796
mBulkEditCommandRunning = false ;
822
797
// Full model update if the changed rows are more than half the total rows
823
- // or if their count is > 1000
824
- int minRow = rowCount ();
825
- int minCol = columnCount ();
826
- int maxRow = 0 ;
827
- int maxCol = 0 ;
828
- bool fullModelUpdate = mAttributeValueChanges .count () >= 1000 ||
829
- mAttributeValueChanges .count () >= rowCount () * 0.5 ;
830
- const auto keys = mAttributeValueChanges .keys ();
831
- for ( const auto &key : keys )
832
- {
833
-
834
- attributeValueChanged ( key.first , key.second , mAttributeValueChanges .value ( key ) );
835
- int row ( idToRow ( key.first ) );
836
- int col ( fieldCol ( key.second ) );
837
- if ( ! fullModelUpdate )
838
- {
839
- QModelIndex index ( createIndex ( row, col ) );
840
- emit dataChanged ( index, index );
841
- }
842
- else
798
+ // or if their count is > layer cache size
799
+ int changeCount ( mAttributeValueChanges .count () );
800
+ bool fullModelUpdate = changeCount > mLayerCache ->cacheSize () ||
801
+ changeCount > rowCount () * 0.5 ;
802
+
803
+ QgsDebugMsgLevel ( QStringLiteral ( " Bulk edit command ended with %1 modified rows over (%4), cache size is %2, starting %3 update." )
804
+ .arg ( changeCount )
805
+ .arg ( mLayerCache ->cacheSize () )
806
+ .arg ( fullModelUpdate ? QStringLiteral ( " full" ) : QStringLiteral ( " incremental" ) )
807
+ .arg ( rowCount () ),
808
+ 3 );
809
+ // Invalidates the whole model
810
+ if ( fullModelUpdate )
811
+ {
812
+ // Invalidates the cache (there is no API for doing this directly)
813
+ mLayerCache ->layer ()->dataChanged ();
814
+ emit dataChanged ( createIndex ( 0 , 0 ), createIndex ( rowCount () - 1 , columnCount () - 1 ) );
815
+ }
816
+ else
817
+ {
818
+ int minRow = rowCount ();
819
+ int minCol = columnCount ();
820
+ int maxRow = 0 ;
821
+ int maxCol = 0 ;
822
+ const auto keys = mAttributeValueChanges .keys ();
823
+ for ( const auto &key : keys )
843
824
{
825
+ attributeValueChanged ( key.first , key.second , mAttributeValueChanges .value ( key ) );
826
+ int row ( idToRow ( key.first ) );
827
+ int col ( fieldCol ( key.second ) );
844
828
minRow = std::min<int >( row, minRow );
845
829
minCol = std::min<int >( col, minCol );
846
830
maxRow = std::max<int >( row, maxRow );
847
831
maxCol = std::max<int >( col, maxCol );
848
832
}
849
- }
850
- // Invalidates the whole model: triggers an update in the view
851
- if ( fullModelUpdate )
852
833
emit dataChanged ( createIndex ( minRow, minCol ), createIndex ( maxRow, maxCol ) );
834
+ }
853
835
mAttributeValueChanges .clear ();
854
836
}
855
837
0 commit comments