Skip to content

Commit 07b3128

Browse files
committedOct 13, 2018
Fix rollback on large tables when attr table is opened
1 parent 9d82df5 commit 07b3128

File tree

10 files changed

+61
-69
lines changed

10 files changed

+61
-69
lines changed
 

‎python/core/auto_generated/qgsapplication.sip.in

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -821,20 +821,6 @@ Set translation
821821
%Docstring
822822
Emits the signal to collect all the strings of .qgs to be included in ts file
823823

824-
.. versionadded:: 3.4
825-
%End
826-
827-
void blockAttributeTableUpdates( const QgsVectorLayer *layer );
828-
%Docstring
829-
Emits the signal to block updates for attribute tables connected a particular ``layer``
830-
831-
.. versionadded:: 3.4
832-
%End
833-
834-
void unblockAttributeTableUpdates( const QgsVectorLayer *layer );
835-
%Docstring
836-
Emits the signal to unblock updates for attribute tables connected a particular ``layer``
837-
838824
.. versionadded:: 3.4
839825
%End
840826

@@ -864,20 +850,6 @@ Emitted whenever a custom global variable changes.
864850
Emitted when project strings which require translation are being collected for inclusion in a .ts file.
865851
In order to register translatable strings, connect to this signal and register the strings within the specified ``translationContext``.
866852

867-
.. versionadded:: 3.4
868-
%End
869-
870-
void attributeTableUpdateBlocked( const QgsVectorLayer *layer );
871-
%Docstring
872-
Emitted when attribute table updates for a particular ``layer`` must be blocked
873-
874-
.. versionadded:: 3.4
875-
%End
876-
877-
void attributeTableUpdateUnblocked( const QgsVectorLayer *layer );
878-
%Docstring
879-
Emitted when all attribute table updates for a particular ``layer`` must be unblocked
880-
881853
.. versionadded:: 3.4
882854
%End
883855

‎python/core/auto_generated/qgsvectorlayer.sip.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,6 +2371,13 @@ Is emitted, before changes are committed to the data provider
23712371
void beforeRollBack();
23722372
%Docstring
23732373
Is emitted, before changes are rolled back
2374+
%End
2375+
2376+
void afterRollBack();
2377+
%Docstring
2378+
Is emitted, after changes are rolled back
2379+
2380+
.. versionadded:: 3.4
23742381
%End
23752382

23762383
void attributeAdded( int idx );

‎src/app/qgisapp.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9189,6 +9189,17 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )
91899189
return res;
91909190
}
91919191

9192+
9193+
void QgisApp::unblockAttributeTableUpdates( const QgsVectorLayer *layer )
9194+
{
9195+
emit attributeTableUpdateUnblocked( layer );
9196+
}
9197+
9198+
void QgisApp::blockAttributeTableUpdates( const QgsVectorLayer *layer )
9199+
{
9200+
emit attributeTableUpdateBlocked( layer );
9201+
}
9202+
91929203
void QgisApp::saveActiveLayerEdits()
91939204
{
91949205
saveEdits( activeLayer(), true, true );

‎src/app/qgisapp.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,20 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
10081008
*/
10091009
void triggerCrashHandler();
10101010

1011+
/**
1012+
* Emits the signal to block updates for attribute tables connected a particular \a layer
1013+
*
1014+
* \since QGIS 3.4
1015+
*/
1016+
void blockAttributeTableUpdates( const QgsVectorLayer *layer );
1017+
1018+
/**
1019+
* Emits the signal to unblock updates for attribute tables connected a particular \a layer
1020+
*
1021+
* \since QGIS 3.4
1022+
*/
1023+
void unblockAttributeTableUpdates( const QgsVectorLayer *layer );
1024+
10111025
protected:
10121026

10131027
//! Handle state changes (WindowTitleChange)
@@ -1741,6 +1755,20 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
17411755
*/
17421756
void activeLayerChanged( QgsMapLayer *layer );
17431757

1758+
/**
1759+
* Emitted when attribute table updates for a particular \a layer must be blocked
1760+
*
1761+
* \since QGIS 3.4
1762+
*/
1763+
void attributeTableUpdateBlocked( const QgsVectorLayer *layer );
1764+
1765+
/**
1766+
* Emitted when all attribute table updates for a particular \a layer must be unblocked
1767+
*
1768+
* \since QGIS 3.4
1769+
*/
1770+
void attributeTableUpdateUnblocked( const QgsVectorLayer *layer );
1771+
17441772
private:
17451773
void startProfile( const QString &name );
17461774
void endProfile();

‎src/app/qgsattributetabledialog.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,19 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
112112
connect( mMainView, &QgsDualView::showContextMenuExternally, this, &QgsAttributeTableDialog::showContextMenu );
113113

114114
// Block/unblock table updates (feature cache signals)
115-
connect( QgsApplication::instance(), &QgsApplication::attributeTableUpdateBlocked, [ = ]( const QgsVectorLayer * layer )
115+
connect( QgisApp::instance(), &QgisApp::attributeTableUpdateBlocked, [ = ]( const QgsVectorLayer * layer )
116116
{
117117
if ( layer == mLayer )
118118
this->blockCacheUpdateSignals( true );
119119
} );
120-
connect( QgsApplication::instance(), &QgsApplication::attributeTableUpdateUnblocked, [ = ]( const QgsVectorLayer * layer )
120+
connect( QgisApp::instance(), &QgisApp::attributeTableUpdateUnblocked, [ = ]( const QgsVectorLayer * layer )
121121
{
122122
if ( layer == mLayer )
123123
this->blockCacheUpdateSignals( false );
124124
} );
125+
// Massive rollbacks can also freeze the GUI due to the feature cache signals
126+
connect( mLayer, &QgsVectorLayer::beforeRollBack, [ = ] { this->blockCacheUpdateSignals( true ); } );
127+
connect( mLayer, &QgsVectorLayer::afterRollBack, [ = ] { this->blockCacheUpdateSignals( false ); } );
125128

126129
const QgsFields fields = mLayer->fields();
127130
for ( const QgsField &field : fields )

‎src/app/qgsfieldcalculator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ void QgsFieldCalculator::accept()
269269

270270
// Begin feature modifications, block updates for attr tables
271271
// connected to this layer
272-
QgsApplication::instance()->blockAttributeTableUpdates( mVectorLayer );
272+
QgisApp::instance()->blockAttributeTableUpdates( mVectorLayer );
273273

274274
//go through all the features and change the new attribute
275275
QgsFeature feature;
@@ -321,7 +321,7 @@ void QgsFieldCalculator::accept()
321321
rownum++;
322322
}
323323

324-
QgsApplication::instance()->unblockAttributeTableUpdates( mVectorLayer );
324+
QgisApp::instance()->unblockAttributeTableUpdates( mVectorLayer );
325325

326326
QApplication::restoreOverrideCursor();
327327

‎src/core/qgsapplication.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,15 +1535,6 @@ void QgsApplication::collectTranslatableObjects( QgsTranslationContext *translat
15351535
emit requestForTranslatableObjects( translationContext );
15361536
}
15371537

1538-
void QgsApplication::unblockAttributeTableUpdates( const QgsVectorLayer *layer )
1539-
{
1540-
emit attributeTableUpdateUnblocked( layer );
1541-
}
1542-
1543-
void QgsApplication::blockAttributeTableUpdates( const QgsVectorLayer *layer )
1544-
{
1545-
emit attributeTableUpdateBlocked( layer );
1546-
}
15471538

15481539
QString QgsApplication::nullRepresentation()
15491540
{

‎src/core/qgsapplication.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -758,20 +758,6 @@ class CORE_EXPORT QgsApplication : public QApplication
758758
*/
759759
void collectTranslatableObjects( QgsTranslationContext *translationContext );
760760

761-
/**
762-
* Emits the signal to block updates for attribute tables connected a particular \a layer
763-
*
764-
* \since QGIS 3.4
765-
*/
766-
void blockAttributeTableUpdates( const QgsVectorLayer *layer );
767-
768-
/**
769-
* Emits the signal to unblock updates for attribute tables connected a particular \a layer
770-
*
771-
* \since QGIS 3.4
772-
*/
773-
void unblockAttributeTableUpdates( const QgsVectorLayer *layer );
774-
775761

776762
#ifdef SIP_RUN
777763
SIP_IF_FEATURE( ANDROID )
@@ -804,20 +790,6 @@ class CORE_EXPORT QgsApplication : public QApplication
804790
*/
805791
void requestForTranslatableObjects( QgsTranslationContext *translationContext );
806792

807-
/**
808-
* Emitted when attribute table updates for a particular \a layer must be blocked
809-
*
810-
* \since QGIS 3.4
811-
*/
812-
void attributeTableUpdateBlocked( const QgsVectorLayer *layer );
813-
814-
/**
815-
* Emitted when all attribute table updates for a particular \a layer must be unblocked
816-
*
817-
* \since QGIS 3.4
818-
*/
819-
void attributeTableUpdateUnblocked( const QgsVectorLayer *layer );
820-
821793

822794
private:
823795

‎src/core/qgsvectorlayer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2973,6 +2973,8 @@ bool QgsVectorLayer::rollBack( bool deleteBuffer )
29732973

29742974
mEditBuffer->rollBack();
29752975

2976+
emit afterRollBack();
2977+
29762978
if ( isModified() )
29772979
{
29782980
// new undo stack roll back method

‎src/core/qgsvectorlayer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
21672167
//! Is emitted, before changes are rolled back
21682168
void beforeRollBack();
21692169

2170+
/**
2171+
* Is emitted, after changes are rolled back
2172+
* \since QGIS 3.4
2173+
*/
2174+
void afterRollBack();
2175+
21702176
/**
21712177
* Will be emitted, when a new attribute has been added to this vector layer.
21722178
* Applies only to types QgsFields::OriginEdit, QgsFields::OriginProvider and QgsFields::OriginExpression

0 commit comments

Comments
 (0)
Please sign in to comment.