Skip to content

Commit c81ef4d

Browse files
authoredMar 27, 2020
Merge pull request #35404 from m-kuhn/join_edtiable_cannot_be_cached
[joins] Disable caching if editing is enabled
2 parents 8b832e7 + acbfb42 commit c81ef4d

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed
 

‎python/core/auto_generated/qgsvectorlayerjoininfo.sip.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ Returns prefix of fields from the joined layer. If ``None``, joined layer's name
7777
%Docstring
7878
Sets whether values from the joined layer should be cached in memory to speed up lookups
7979
%End
80+
8081
bool isUsingMemoryCache() const;
8182
%Docstring
82-
Returns whether values from the joined layer should be cached in memory to speed up lookups
83+
Returns whether values from the joined layer should be cached in memory to speed up lookups.
84+
Will return false if upsertOnEdit is enabled.
8385
%End
8486

8587
bool isDynamicFormEnabled() const;

‎src/core/qgsvectorlayerjoininfo.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ QString QgsVectorLayerJoinInfo::prefixedFieldName( const QgsField &f ) const
3535
return name;
3636
}
3737

38+
void QgsVectorLayerJoinInfo::setUsingMemoryCache( bool enabled )
39+
{
40+
mMemoryCache = enabled;
41+
}
42+
43+
bool QgsVectorLayerJoinInfo::isUsingMemoryCache() const
44+
{
45+
if ( mUpsertOnEdit )
46+
return false;
47+
48+
return mMemoryCache;
49+
}
50+
3851
void QgsVectorLayerJoinInfo::setEditable( bool enabled )
3952
{
4053
mEditable = enabled;

‎src/core/qgsvectorlayerjoininfo.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,13 @@ class CORE_EXPORT QgsVectorLayerJoinInfo
6565
QString prefix() const { return mPrefix; }
6666

6767
//! Sets whether values from the joined layer should be cached in memory to speed up lookups
68-
void setUsingMemoryCache( bool enabled ) { mMemoryCache = enabled; }
69-
//! Returns whether values from the joined layer should be cached in memory to speed up lookups
70-
bool isUsingMemoryCache() const { return mMemoryCache; }
68+
void setUsingMemoryCache( bool enabled );
69+
70+
/**
71+
* Returns whether values from the joined layer should be cached in memory to speed up lookups.
72+
* Will return false if upsertOnEdit is enabled.
73+
*/
74+
bool isUsingMemoryCache() const;
7175

7276
/**
7377
* Returns whether the form has to be dynamically updated with joined fields

‎src/gui/vector/qgsjoindialog.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ QgsJoinDialog::QgsJoinDialog( QgsVectorLayer *layer, QList<QgsMapLayer *> alread
6565
connect( mJoinLayerComboBox, &QgsMapLayerComboBox::layerChanged, this, &QgsJoinDialog::checkDefinitionValid );
6666
connect( mJoinFieldComboBox, &QgsFieldComboBox::fieldChanged, this, &QgsJoinDialog::checkDefinitionValid );
6767
connect( mTargetFieldComboBox, &QgsFieldComboBox::fieldChanged, this, &QgsJoinDialog::checkDefinitionValid );
68+
connect( mEditableJoinLayer, &QGroupBox::toggled, this, &QgsJoinDialog::editableJoinLayerChanged );
6869

6970
checkDefinitionValid();
7071
}
@@ -108,6 +109,8 @@ void QgsJoinDialog::setJoinInfo( const QgsVectorLayerJoinInfo &joinInfo )
108109
}
109110
}
110111
}
112+
113+
editableJoinLayerChanged();
111114
}
112115

113116
QgsVectorLayerJoinInfo QgsJoinDialog::joinInfo() const
@@ -201,3 +204,20 @@ void QgsJoinDialog::checkDefinitionValid()
201204
&& mJoinFieldComboBox->currentIndex() != -1
202205
&& mTargetFieldComboBox->currentIndex() != -1 );
203206
}
207+
208+
void QgsJoinDialog::editableJoinLayerChanged()
209+
{
210+
if ( mEditableJoinLayer->isChecked() )
211+
{
212+
mCacheInMemoryCheckBox->setEnabled( false );
213+
mCacheInMemoryCheckBox->setToolTip( tr( "Caching can not be enabled if editable join layer is enabled" ) );
214+
mCacheEnabled = mCacheInMemoryCheckBox->isChecked();
215+
mCacheInMemoryCheckBox->setChecked( false );
216+
}
217+
else
218+
{
219+
mCacheInMemoryCheckBox->setEnabled( true );
220+
mCacheInMemoryCheckBox->setToolTip( QString() );
221+
mCacheInMemoryCheckBox->setChecked( mCacheEnabled );
222+
}
223+
}

‎src/gui/vector/qgsjoindialog.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,14 @@ class GUI_EXPORT QgsJoinDialog: public QDialog, private Ui::QgsJoinDialogBase
4747

4848
void checkDefinitionValid();
4949

50+
void editableJoinLayerChanged();
51+
5052
private:
5153
//! Target layer
5254
QgsVectorLayer *mLayer = nullptr;
55+
56+
// Temporary storage for "cache" setting since the checkbox may be temporarily disabled
57+
bool mCacheEnabled = false;
5358
};
5459

5560

0 commit comments

Comments
 (0)
Please sign in to comment.