Skip to content
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

[joins] Disable caching if editing is enabled #35404

Merged
merged 1 commit into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/core/auto_generated/qgsvectorlayerjoininfo.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ Returns prefix of fields from the joined layer. If ``None``, joined layer's name
%Docstring
Sets whether values from the joined layer should be cached in memory to speed up lookups
%End

bool isUsingMemoryCache() const;
%Docstring
Returns whether values from the joined layer should be cached in memory to speed up lookups
Returns whether values from the joined layer should be cached in memory to speed up lookups.
Will return false if upsertOnEdit is enabled.
%End

bool isDynamicFormEnabled() const;
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsvectorlayerjoininfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ QString QgsVectorLayerJoinInfo::prefixedFieldName( const QgsField &f ) const
return name;
}

void QgsVectorLayerJoinInfo::setUsingMemoryCache( bool enabled )
{
mMemoryCache = enabled;
}

bool QgsVectorLayerJoinInfo::isUsingMemoryCache() const
{
if ( mUpsertOnEdit )
return false;

return mMemoryCache;
}

void QgsVectorLayerJoinInfo::setEditable( bool enabled )
{
mEditable = enabled;
Expand Down
10 changes: 7 additions & 3 deletions src/core/qgsvectorlayerjoininfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ class CORE_EXPORT QgsVectorLayerJoinInfo
QString prefix() const { return mPrefix; }

//! Sets whether values from the joined layer should be cached in memory to speed up lookups
void setUsingMemoryCache( bool enabled ) { mMemoryCache = enabled; }
//! Returns whether values from the joined layer should be cached in memory to speed up lookups
bool isUsingMemoryCache() const { return mMemoryCache; }
void setUsingMemoryCache( bool enabled );

/**
* Returns whether values from the joined layer should be cached in memory to speed up lookups.
* Will return false if upsertOnEdit is enabled.
*/
bool isUsingMemoryCache() const;

/**
* Returns whether the form has to be dynamically updated with joined fields
Expand Down
20 changes: 20 additions & 0 deletions src/gui/vector/qgsjoindialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ QgsJoinDialog::QgsJoinDialog( QgsVectorLayer *layer, QList<QgsMapLayer *> alread
connect( mJoinLayerComboBox, &QgsMapLayerComboBox::layerChanged, this, &QgsJoinDialog::checkDefinitionValid );
connect( mJoinFieldComboBox, &QgsFieldComboBox::fieldChanged, this, &QgsJoinDialog::checkDefinitionValid );
connect( mTargetFieldComboBox, &QgsFieldComboBox::fieldChanged, this, &QgsJoinDialog::checkDefinitionValid );
connect( mEditableJoinLayer, &QGroupBox::toggled, this, &QgsJoinDialog::editableJoinLayerChanged );

checkDefinitionValid();
}
Expand Down Expand Up @@ -108,6 +109,8 @@ void QgsJoinDialog::setJoinInfo( const QgsVectorLayerJoinInfo &joinInfo )
}
}
}

editableJoinLayerChanged();
}

QgsVectorLayerJoinInfo QgsJoinDialog::joinInfo() const
Expand Down Expand Up @@ -201,3 +204,20 @@ void QgsJoinDialog::checkDefinitionValid()
&& mJoinFieldComboBox->currentIndex() != -1
&& mTargetFieldComboBox->currentIndex() != -1 );
}

void QgsJoinDialog::editableJoinLayerChanged()
{
if ( mEditableJoinLayer->isChecked() )
{
mCacheInMemoryCheckBox->setEnabled( false );
mCacheInMemoryCheckBox->setToolTip( tr( "Caching can not be enabled if editable join layer is enabled" ) );
mCacheEnabled = mCacheInMemoryCheckBox->isChecked();
mCacheInMemoryCheckBox->setChecked( false );
}
else
{
mCacheInMemoryCheckBox->setEnabled( true );
mCacheInMemoryCheckBox->setToolTip( QString() );
mCacheInMemoryCheckBox->setChecked( mCacheEnabled );
}
}
5 changes: 5 additions & 0 deletions src/gui/vector/qgsjoindialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ class GUI_EXPORT QgsJoinDialog: public QDialog, private Ui::QgsJoinDialogBase

void checkDefinitionValid();

void editableJoinLayerChanged();

private:
//! Target layer
QgsVectorLayer *mLayer = nullptr;

// Temporary storage for "cache" setting since the checkbox may be temporarily disabled
bool mCacheEnabled = false;
};


Expand Down