21
21
#include " qgsapplication.h"
22
22
#include " qgsvectorlayer.h"
23
23
#include " qgspropertyoverridebutton.h"
24
+ #include " qgseditorwidgetwrapper.h"
24
25
25
26
#include < QFileDialog>
26
27
27
28
class QgsExternalResourceWidgetWrapper ;
28
29
29
- const QgsPropertiesDefinition &QgsExternalResourceConfigDlg::propertyDefinitions ()
30
- {
31
- static QgsPropertiesDefinition propertyDefinitions;
32
-
33
- if ( propertyDefinitions.isEmpty () )
34
- {
35
- propertyDefinitions = QgsPropertiesDefinition
36
- {
37
- { RootPath, QgsPropertyDefinition ( " propertyRootPath" , QgsPropertyDefinition::DataTypeString, QObject::tr ( " Root path" ), QString () ) }
38
- };
39
- }
40
-
41
- return propertyDefinitions;
42
- }
43
-
44
30
QgsExternalResourceConfigDlg::QgsExternalResourceConfigDlg ( QgsVectorLayer *vl, int fieldIdx, QWidget *parent )
45
31
: QgsEditorConfigWidget( vl, fieldIdx, parent )
46
32
{
@@ -57,9 +43,7 @@ QgsExternalResourceConfigDlg::QgsExternalResourceConfigDlg( QgsVectorLayer *vl,
57
43
58
44
connect ( mRootPathButton , &QToolButton::clicked, this , &QgsExternalResourceConfigDlg::chooseDefaultPath );
59
45
60
- mRootPathPropertyOverrideButton ->init ( RootPath, mPropertyCollection , propertyDefinitions (), vl );
61
-
62
- mRootPathPropertyOverrideButton ->setVectorLayer ( vl );
46
+ initializeDataDefinedButton ( mRootPathPropertyOverrideButton , QgsEditorWidgetWrapper::RootPath );
63
47
connect ( mRootPathPropertyOverrideButton , &QgsPropertyOverrideButton::changed, this , &QgsExternalResourceConfigDlg::rootPathPropertyChanged );
64
48
65
49
// Activate Relative Default Path option only if Default Path is set
@@ -116,8 +100,7 @@ void QgsExternalResourceConfigDlg::chooseDefaultPath()
116
100
void QgsExternalResourceConfigDlg::rootPathPropertyChanged ()
117
101
{
118
102
QgsProperty prop = mRootPathPropertyOverrideButton ->toProperty ();
119
-
120
- setRootPathExpression ( prop.expressionString () );
103
+ setRootPathExpression ( prop );
121
104
122
105
mRootPathExpression ->setVisible ( prop.isActive () );
123
106
mRootPath ->setVisible ( !prop.isActive () );
@@ -172,9 +155,6 @@ QVariantMap QgsExternalResourceConfigDlg::config()
172
155
if ( !mRootPath ->text ().isEmpty () )
173
156
cfg.insert ( QStringLiteral ( " DefaultRoot" ), mRootPath ->text () );
174
157
175
- if ( !mRootPathExpression ->text ().isEmpty () )
176
- cfg.insert ( QStringLiteral ( " DefaultRootExpression" ), mRootPathExpression ->toolTip () );
177
-
178
158
// Save Storage Mode
179
159
cfg.insert ( QStringLiteral ( " StorageMode" ), mStorageButtonGroup ->checkedId () );
180
160
@@ -226,18 +206,9 @@ void QgsExternalResourceConfigDlg::setConfig( const QVariantMap &config )
226
206
}
227
207
228
208
mRootPath ->setText ( config.value ( QStringLiteral ( " DefaultRoot" ) ).toString () );
229
- setRootPathExpression ( config.value ( QStringLiteral ( " DefaultRootExpression" ) ).toString () );
230
-
231
- bool rootPathIsExpression = config.value ( QStringLiteral ( " DefaultRootStyle" ) ) == QStringLiteral ( " expression" );
232
209
233
- QgsProperty prop = mRootPathPropertyOverrideButton ->toProperty ();
234
- prop.setActive ( rootPathIsExpression );
235
- mRootPathPropertyOverrideButton ->setToProperty ( prop );
236
210
rootPathPropertyChanged ();
237
211
238
- mRootPathExpression ->setVisible ( rootPathIsExpression );
239
- mRootPath ->setVisible ( !rootPathIsExpression );
240
-
241
212
// relative storage
242
213
if ( config.contains ( QStringLiteral ( " RelativeStorage" ) ) )
243
214
{
@@ -281,18 +252,12 @@ void QgsExternalResourceConfigDlg::setConfig( const QVariantMap &config )
281
252
}
282
253
}
283
254
284
- void QgsExternalResourceConfigDlg::setRootPathExpression ( const QString &expression )
255
+ void QgsExternalResourceConfigDlg::setRootPathExpression ( const QgsProperty &property )
285
256
{
286
- mRootPathExpression ->setToolTip ( expression );
287
- mRootPathPropertyOverrideButton ->setText ( expression );
288
-
289
- QgsProperty prop = mRootPathPropertyOverrideButton ->toProperty ();
290
- prop.setExpressionString ( expression );
291
- mRootPathPropertyOverrideButton ->setToProperty ( prop );
257
+ mRootPathExpression ->setToolTip ( property.asExpression () );
292
258
293
- QgsExpression exp ( expression );
294
259
QgsExpressionContext ctx = layer ()->createExpressionContext ();
295
260
296
- mRootPathExpression ->setText ( exp . evaluate ( & ctx ). toString ( ) );
261
+ mRootPathExpression ->setText ( property. valueAsString ( ctx ) );
297
262
enableRelativeDefault ();
298
263
}
0 commit comments