Skip to content

Commit c11ef58

Browse files
nyalldawsonm-kuhn
authored andcommitted
Generalise editor widget config saving/restoring props from gui
1 parent bea8377 commit c11ef58

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

python/gui/editorwidgets/core/qgseditorconfigwidget.sip

+2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,7 @@ class QgsEditorConfigWidget : QWidget
3232

3333
protected:
3434
void initializeDataDefinedButton( QgsPropertyOverrideButton *button, QgsWidgetWrapper::Property key );
35+
void updateDataDefinedButtons();
36+
void updateDataDefinedButton( QgsPropertyOverrideButton *button );
3537
};
3638

src/gui/editorwidgets/core/qgseditorconfigwidget.cpp

+29-1
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,36 @@ void QgsEditorConfigWidget::initializeDataDefinedButton( QgsPropertyOverrideButt
4343
{
4444
button->blockSignals( true );
4545
button->init( key, mPropertyCollection, QgsWidgetWrapper::propertyDefinitions(), mLayer );
46-
connect( button, &QgsPropertyOverrideButton::changed, this, &QgsEditorConfigWidget::changed );
46+
connect( button, &QgsPropertyOverrideButton::changed, this, &QgsEditorConfigWidget::updateProperty );
4747
button->registerExpressionContextGenerator( this );
4848
button->blockSignals( false );
4949
}
5050

51+
void QgsEditorConfigWidget::updateDataDefinedButtons()
52+
{
53+
Q_FOREACH ( QgsPropertyOverrideButton *button, findChildren< QgsPropertyOverrideButton * >() )
54+
{
55+
updateDataDefinedButton( button );
56+
}
57+
}
58+
59+
void QgsEditorConfigWidget::updateDataDefinedButton( QgsPropertyOverrideButton *button )
60+
{
61+
if ( !button )
62+
return;
63+
64+
if ( button->propertyKey() < 0 )
65+
return;
66+
67+
QgsWidgetWrapper::Property key = static_cast< QgsWidgetWrapper::Property >( button->propertyKey() );
68+
whileBlocking( button )->setToProperty( mPropertyCollection.property( key ) );
69+
}
70+
71+
void QgsEditorConfigWidget::updateProperty()
72+
{
73+
QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
74+
QgsWidgetWrapper::Property key = static_cast< QgsWidgetWrapper::Property >( button->propertyKey() );
75+
mPropertyCollection.setProperty( key, button->toProperty() );
76+
emit changed();
77+
}
78+

src/gui/editorwidgets/core/qgseditorconfigwidget.h

+14
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,23 @@ class GUI_EXPORT QgsEditorConfigWidget : public QWidget, public QgsExpressionCon
9292
*/
9393
void initializeDataDefinedButton( QgsPropertyOverrideButton *button, QgsWidgetWrapper::Property key );
9494

95+
/**
96+
* Updates all property override buttons to reflect the widgets's current properties.
97+
*/
98+
void updateDataDefinedButtons();
99+
100+
/**
101+
* Updates a specific property override \a button to reflect the widgets's current properties.
102+
*/
103+
void updateDataDefinedButton( QgsPropertyOverrideButton *button );
104+
95105
//! Temporary property collection for config widgets
96106
QgsPropertyCollection mPropertyCollection;
97107

108+
private slots:
109+
110+
void updateProperty();
111+
98112
private:
99113
QgsVectorLayer *mLayer = nullptr;
100114
int mField;

src/gui/editorwidgets/qgsexternalresourceconfigdlg.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ void QgsExternalResourceConfigDlg::chooseDefaultPath()
100100
void QgsExternalResourceConfigDlg::rootPathPropertyChanged()
101101
{
102102
QgsProperty prop = mRootPathPropertyOverrideButton->toProperty();
103-
mPropertyCollection.setProperty( QgsWidgetWrapper::RootPath, prop );
104103
setRootPathExpression( prop );
105104

106105
mRootPathExpression->setVisible( prop.isActive() );
@@ -152,8 +151,6 @@ QVariantMap QgsExternalResourceConfigDlg::config()
152151
if ( !mRootPath->text().isEmpty() )
153152
cfg.insert( QStringLiteral( "DefaultRoot" ), mRootPath->text() );
154153

155-
cfg.insert( QStringLiteral( "RootPathProperty" ), mRootPathPropertyOverrideButton->toProperty().toVariant() );
156-
157154
// Save Storage Mode
158155
cfg.insert( QStringLiteral( "StorageMode" ), mStorageButtonGroup->checkedId() );
159156

@@ -205,6 +202,8 @@ void QgsExternalResourceConfigDlg::setConfig( const QVariantMap &config )
205202
}
206203

207204
mPropertyCollection.loadVariant( config.value( QStringLiteral( "PropertyCollection" ) ), QgsWidgetWrapper::propertyDefinitions() );
205+
updateDataDefinedButtons();
206+
208207
setRootPathExpression( mPropertyCollection.property( QgsWidgetWrapper::RootPath ) );
209208
mRootPath->setText( config.value( QStringLiteral( "DefaultRoot" ) ).toString() );
210209

@@ -255,7 +254,6 @@ void QgsExternalResourceConfigDlg::setConfig( const QVariantMap &config )
255254

256255
void QgsExternalResourceConfigDlg::setRootPathExpression( const QgsProperty &property )
257256
{
258-
mRootPathPropertyOverrideButton->setToProperty( property );
259257
mRootPathExpression->setToolTip( property.asExpression() );
260258

261259
QgsExpressionContext ctx = layer()->createExpressionContext();

0 commit comments

Comments
 (0)