Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #35404 from m-kuhn/join_edtiable_cannot_be_cached
[joins] Disable caching if editing is enabled
  • Loading branch information
m-kuhn committed Mar 27, 2020
2 parents 8b832e7 + acbfb42 commit c81ef4d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
4 changes: 3 additions & 1 deletion python/core/auto_generated/qgsvectorlayerjoininfo.sip.in
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
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
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
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
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

0 comments on commit c81ef4d

Please sign in to comment.