Skip to content
Permalink
Browse files

Forward to app blocking/unblocking of attr table updates

Fixes #20094 - Extracting z-coordinates takes ages and makes the system unresponsive
  • Loading branch information
elpaso committed Oct 13, 2018
1 parent afc873d commit 9d82df5d16ebb3e13dfc09e45307c6d1a7d1828a
@@ -824,6 +824,21 @@ 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


%If (ANDROID)
//dummy method to workaround sip generation issue
bool x11EventFilter( XEvent *event );
@@ -852,6 +867,21 @@ In order to register translatable strings, connect to this signal and register t
.. 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


};


@@ -7090,13 +7090,14 @@ void QgisApp::fieldCalculator()

void QgisApp::attributeTable( QgsAttributeTableFilterModel::FilterMode filter )
{
QgsVectorLayer *myLayer = qobject_cast<QgsVectorLayer *>( activeLayer() );
if ( !myLayer )
QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( activeLayer() );
if ( !vectorLayer )
{
return;
}

QgsAttributeTableDialog *mDialog = new QgsAttributeTableDialog( myLayer, filter );
QgsAttributeTableDialog *mDialog = new QgsAttributeTableDialog( vectorLayer, filter );

mDialog->show();
// the dialog will be deleted by itself on close
}
@@ -111,6 +111,18 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
connect( mActionExpressionSelect, &QAction::triggered, this, &QgsAttributeTableDialog::mActionExpressionSelect_triggered );
connect( mMainView, &QgsDualView::showContextMenuExternally, this, &QgsAttributeTableDialog::showContextMenu );

// Block/unblock table updates (feature cache signals)
connect( QgsApplication::instance(), &QgsApplication::attributeTableUpdateBlocked, [ = ]( const QgsVectorLayer * layer )
{
if ( layer == mLayer )
this->blockCacheUpdateSignals( true );
} );
connect( QgsApplication::instance(), &QgsApplication::attributeTableUpdateUnblocked, [ = ]( const QgsVectorLayer * layer )
{
if ( layer == mLayer )
this->blockCacheUpdateSignals( false );
} );

const QgsFields fields = mLayer->fields();
for ( const QgsField &field : fields )
{
@@ -715,20 +727,14 @@ void QgsAttributeTableDialog::mActionOpenFieldCalculator_triggered()
QgsAttributeTableModel *masterModel = mMainView->masterModel();

QgsFieldCalculator calc( mLayer, this );
masterModel->layerCache()->blockSignals( true );
if ( calc.exec() == QDialog::Accepted )
{
masterModel->layerCache()->blockSignals( false );
int col = masterModel->fieldCol( calc.changedAttributeId() );
if ( col >= 0 )
{
masterModel->reload( masterModel->index( 0, col ), masterModel->index( masterModel->rowCount() - 1, col ) );
}
}
else
{
masterModel->layerCache()->blockSignals( false );
}
}

void QgsAttributeTableDialog::mActionSaveEdits_triggered()
@@ -1135,6 +1141,15 @@ void QgsAttributeTableDialog::setFilterExpression( const QString &filterString,
mMainView->setFilterMode( QgsAttributeTableFilterModel::ShowFilteredList );
}

void QgsAttributeTableDialog::blockCacheUpdateSignals( const bool block )
{
QgsAttributeTableModel *masterModel = mMainView->masterModel();

if ( ! masterModel )
return;

masterModel->layerCache()->blockSignals( block );
}

void QgsAttributeTableDialog::deleteFeature( const QgsFeatureId fid )
{
@@ -242,6 +242,7 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib

void updateMultiEditButtonState();
void deleteFeature( QgsFeatureId fid );
void blockCacheUpdateSignals( const bool block );

friend class TestQgsAttributeTable;
};
@@ -267,6 +267,10 @@ void QgsFieldCalculator::accept()
return;
}

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

//go through all the features and change the new attribute
QgsFeature feature;
bool calculationSuccess = true;
@@ -317,6 +321,8 @@ void QgsFieldCalculator::accept()
rownum++;
}

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

QApplication::restoreOverrideCursor();

if ( !calculationSuccess )
@@ -1535,6 +1535,16 @@ 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()
{
ApplicationMembers *appMembers = members();
@@ -49,6 +49,7 @@ class QgsLayoutItemRegistry;
class QgsAuthManager;
class QgsNetworkContentFetcherRegistry;
class QTranslator;
class QgsVectorLayer;

/**
* \ingroup core
@@ -757,6 +758,21 @@ 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 )
//dummy method to workaround sip generation issue
@@ -788,6 +804,21 @@ 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:

static void copyPath( const QString &src, const QString &dst );

1 comment on commit 9d82df5

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson commented on 9d82df5 Oct 13, 2018

Sorry, not sure I explained this well. I meant QgisApp::instance, not QgsApplication::instance. But otherwise this looks good.

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