Skip to content

Commit

Permalink
Fix rollback on large tables when attr table is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Oct 13, 2018
1 parent 9d82df5 commit 07b3128
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 69 deletions.
28 changes: 0 additions & 28 deletions python/core/auto_generated/qgsapplication.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -821,20 +821,6 @@ Set translation
%Docstring
Emits the signal to collect all the strings of .qgs to be included in ts file

.. versionadded:: 3.4
%End

void blockAttributeTableUpdates( const QgsVectorLayer *layer );
%Docstring
Emits the signal to block updates for attribute tables connected a particular ``layer``

.. versionadded:: 3.4
%End

void unblockAttributeTableUpdates( const QgsVectorLayer *layer );
%Docstring
Emits the signal to unblock updates for attribute tables connected a particular ``layer``

.. versionadded:: 3.4
%End

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

.. versionadded:: 3.4
%End

void attributeTableUpdateBlocked( const QgsVectorLayer *layer );
%Docstring
Emitted when attribute table updates for a particular ``layer`` must be blocked

.. versionadded:: 3.4
%End

void attributeTableUpdateUnblocked( const QgsVectorLayer *layer );
%Docstring
Emitted when all attribute table updates for a particular ``layer`` must be unblocked

.. versionadded:: 3.4
%End

Expand Down
7 changes: 7 additions & 0 deletions python/core/auto_generated/qgsvectorlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,13 @@ Is emitted, before changes are committed to the data provider
void beforeRollBack();
%Docstring
Is emitted, before changes are rolled back
%End

void afterRollBack();
%Docstring
Is emitted, after changes are rolled back

.. versionadded:: 3.4
%End

void attributeAdded( int idx );
Expand Down
11 changes: 11 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9189,6 +9189,17 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )
return res;
}


void QgisApp::unblockAttributeTableUpdates( const QgsVectorLayer *layer )
{
emit attributeTableUpdateUnblocked( layer );
}

void QgisApp::blockAttributeTableUpdates( const QgsVectorLayer *layer )
{
emit attributeTableUpdateBlocked( layer );
}

void QgisApp::saveActiveLayerEdits()
{
saveEdits( activeLayer(), true, true );
Expand Down
28 changes: 28 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,20 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*/
void triggerCrashHandler();

/**
* Emits the signal to block updates for attribute tables connected a particular \a layer
*
* \since QGIS 3.4
*/
void blockAttributeTableUpdates( const QgsVectorLayer *layer );

/**
* Emits the signal to unblock updates for attribute tables connected a particular \a layer
*
* \since QGIS 3.4
*/
void unblockAttributeTableUpdates( const QgsVectorLayer *layer );

protected:

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

/**
* Emitted when attribute table updates for a particular \a layer must be blocked
*
* \since QGIS 3.4
*/
void attributeTableUpdateBlocked( const QgsVectorLayer *layer );

/**
* Emitted when all attribute table updates for a particular \a layer must be unblocked
*
* \since QGIS 3.4
*/
void attributeTableUpdateUnblocked( const QgsVectorLayer *layer );

private:
void startProfile( const QString &name );
void endProfile();
Expand Down
7 changes: 5 additions & 2 deletions src/app/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,19 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
connect( mMainView, &QgsDualView::showContextMenuExternally, this, &QgsAttributeTableDialog::showContextMenu );

// Block/unblock table updates (feature cache signals)
connect( QgsApplication::instance(), &QgsApplication::attributeTableUpdateBlocked, [ = ]( const QgsVectorLayer * layer )
connect( QgisApp::instance(), &QgisApp::attributeTableUpdateBlocked, [ = ]( const QgsVectorLayer * layer )
{
if ( layer == mLayer )
this->blockCacheUpdateSignals( true );
} );
connect( QgsApplication::instance(), &QgsApplication::attributeTableUpdateUnblocked, [ = ]( const QgsVectorLayer * layer )
connect( QgisApp::instance(), &QgisApp::attributeTableUpdateUnblocked, [ = ]( const QgsVectorLayer * layer )
{
if ( layer == mLayer )
this->blockCacheUpdateSignals( false );
} );
// Massive rollbacks can also freeze the GUI due to the feature cache signals
connect( mLayer, &QgsVectorLayer::beforeRollBack, [ = ] { this->blockCacheUpdateSignals( true ); } );
connect( mLayer, &QgsVectorLayer::afterRollBack, [ = ] { this->blockCacheUpdateSignals( false ); } );

const QgsFields fields = mLayer->fields();
for ( const QgsField &field : fields )
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsfieldcalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void QgsFieldCalculator::accept()

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

//go through all the features and change the new attribute
QgsFeature feature;
Expand Down Expand Up @@ -321,7 +321,7 @@ void QgsFieldCalculator::accept()
rownum++;
}

QgsApplication::instance()->unblockAttributeTableUpdates( mVectorLayer );
QgisApp::instance()->unblockAttributeTableUpdates( mVectorLayer );

QApplication::restoreOverrideCursor();

Expand Down
9 changes: 0 additions & 9 deletions src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1535,15 +1535,6 @@ void QgsApplication::collectTranslatableObjects( QgsTranslationContext *translat
emit requestForTranslatableObjects( translationContext );
}

void QgsApplication::unblockAttributeTableUpdates( const QgsVectorLayer *layer )
{
emit attributeTableUpdateUnblocked( layer );
}

void QgsApplication::blockAttributeTableUpdates( const QgsVectorLayer *layer )
{
emit attributeTableUpdateBlocked( layer );
}

QString QgsApplication::nullRepresentation()
{
Expand Down
28 changes: 0 additions & 28 deletions src/core/qgsapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -758,20 +758,6 @@ class CORE_EXPORT QgsApplication : public QApplication
*/
void collectTranslatableObjects( QgsTranslationContext *translationContext );

/**
* Emits the signal to block updates for attribute tables connected a particular \a layer
*
* \since QGIS 3.4
*/
void blockAttributeTableUpdates( const QgsVectorLayer *layer );

/**
* Emits the signal to unblock updates for attribute tables connected a particular \a layer
*
* \since QGIS 3.4
*/
void unblockAttributeTableUpdates( const QgsVectorLayer *layer );


#ifdef SIP_RUN
SIP_IF_FEATURE( ANDROID )
Expand Down Expand Up @@ -804,20 +790,6 @@ class CORE_EXPORT QgsApplication : public QApplication
*/
void requestForTranslatableObjects( QgsTranslationContext *translationContext );

/**
* Emitted when attribute table updates for a particular \a layer must be blocked
*
* \since QGIS 3.4
*/
void attributeTableUpdateBlocked( const QgsVectorLayer *layer );

/**
* Emitted when all attribute table updates for a particular \a layer must be unblocked
*
* \since QGIS 3.4
*/
void attributeTableUpdateUnblocked( const QgsVectorLayer *layer );


private:

Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2973,6 +2973,8 @@ bool QgsVectorLayer::rollBack( bool deleteBuffer )

mEditBuffer->rollBack();

emit afterRollBack();

if ( isModified() )
{
// new undo stack roll back method
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
//! Is emitted, before changes are rolled back
void beforeRollBack();

/**
* Is emitted, after changes are rolled back
* \since QGIS 3.4
*/
void afterRollBack();

/**
* Will be emitted, when a new attribute has been added to this vector layer.
* Applies only to types QgsFields::OriginEdit, QgsFields::OriginProvider and QgsFields::OriginExpression
Expand Down

0 comments on commit 07b3128

Please sign in to comment.