-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes slow update in field calculator #8177
Changes from 5 commits
d79e3ad
afc873d
9d82df5
07b3128
20e8592
c8ea3a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,21 @@ 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( QgisApp::instance(), &QgisApp::attributeTableUpdateBlocked, [ = ]( const QgsVectorLayer * layer ) | ||
{ | ||
if ( layer == mLayer ) | ||
this->blockCacheUpdateSignals( true ); | ||
} ); | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have the same issue with attribute addition/deletion too, don't we? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I you mean removing the columns as a whole, apparently not, at least I didn't observe the issue when removing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed: with my PR removing a colum is FAST. |
||
connect( mLayer, &QgsVectorLayer::beforeRollBack, [ = ] { this->blockCacheUpdateSignals( true ); } ); | ||
connect( mLayer, &QgsVectorLayer::afterRollBack, [ = ] { this->blockCacheUpdateSignals( false ); } ); | ||
|
||
const QgsFields fields = mLayer->fields(); | ||
for ( const QgsField &field : fields ) | ||
{ | ||
|
@@ -718,7 +733,6 @@ void QgsAttributeTableDialog::mActionOpenFieldCalculator_triggered() | |
if ( calc.exec() == QDialog::Accepted ) | ||
{ | ||
int col = masterModel->fieldCol( calc.changedAttributeId() ); | ||
|
||
if ( col >= 0 ) | ||
{ | ||
masterModel->reload( masterModel->index( 0, col ), masterModel->index( masterModel->rowCount() - 1, col ) ); | ||
|
@@ -1130,6 +1144,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 ) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could use one signal and one slot here with a
bool blocked
argumentThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I first implemented it like that. But I was in doubt, because in general we don't like bool switches, do we?
But you solved my doubt, so I'm fine with the bool now. (I've always thought that
blockSignals(bool)
was not very consistent with the rest of Qt API).