File tree Expand file tree Collapse file tree 4 files changed +61
-0
lines changed Expand file tree Collapse file tree 4 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -315,12 +315,29 @@ class QgsProcessingParameterDefinition
315
315
:rtype: bool
316
316
%End
317
317
318
+
319
+ QVariantMap &metadata();
320
+ %Docstring
321
+ Returns the parameter's freeform metadata. This is mostly used by parameter widget wrappers
322
+ in order to customise their appearance and behavior.
323
+ .. seealso:: setMetadata()
324
+ :rtype: QVariantMap
325
+ %End
326
+
327
+ void setMetadata( const QVariantMap &metadata );
328
+ %Docstring
329
+ Sets the parameter's freeform ``metadata``. This is mostly used by parameter widget wrappers
330
+ in order to customise their appearance and behavior.
331
+ .. seealso:: metadata()
332
+ %End
333
+
318
334
protected:
319
335
320
336
321
337
322
338
323
339
340
+
324
341
};
325
342
326
343
QFlags<QgsProcessingParameterDefinition::Flag> operator|(QgsProcessingParameterDefinition::Flag f1, QFlags<QgsProcessingParameterDefinition::Flag> f2);
Original file line number Diff line number Diff line change @@ -808,6 +808,7 @@ QVariantMap QgsProcessingParameterDefinition::toVariantMap() const
808
808
map.insert ( QStringLiteral ( " description" ), mDescription );
809
809
map.insert ( QStringLiteral ( " default" ), mDefault );
810
810
map.insert ( QStringLiteral ( " flags" ), static_cast < int >( mFlags ) );
811
+ map.insert ( QStringLiteral ( " metadata" ), mMetadata );
811
812
return map;
812
813
}
813
814
@@ -817,6 +818,7 @@ bool QgsProcessingParameterDefinition::fromVariantMap( const QVariantMap &map )
817
818
mDescription = map.value ( QStringLiteral ( " description" ) ).toString ();
818
819
mDefault = map.value ( QStringLiteral ( " default" ) );
819
820
mFlags = static_cast < Flags >( map.value ( QStringLiteral ( " flags" ) ).toInt () );
821
+ mMetadata = map.value ( QStringLiteral ( " metadata" ) ).toMap ();
820
822
return true ;
821
823
}
822
824
Original file line number Diff line number Diff line change @@ -344,6 +344,28 @@ class CORE_EXPORT QgsProcessingParameterDefinition
344
344
*/
345
345
virtual bool fromVariantMap ( const QVariantMap &map );
346
346
347
+ /* *
348
+ * Returns the parameter's freeform metadata. This is mostly used by parameter widget wrappers
349
+ * in order to customise their appearance and behavior.
350
+ * \see setMetadata()
351
+ * \note not available in Python bindings.
352
+ */
353
+ SIP_SKIP QVariantMap metadata () const { return mMetadata ; }
354
+
355
+ /* *
356
+ * Returns the parameter's freeform metadata. This is mostly used by parameter widget wrappers
357
+ * in order to customise their appearance and behavior.
358
+ * \see setMetadata()
359
+ */
360
+ QVariantMap &metadata () { return mMetadata ; }
361
+
362
+ /* *
363
+ * Sets the parameter's freeform \a metadata. This is mostly used by parameter widget wrappers
364
+ * in order to customise their appearance and behavior.
365
+ * \see metadata()
366
+ */
367
+ void setMetadata ( const QVariantMap &metadata ) { mMetadata = metadata; }
368
+
347
369
protected:
348
370
349
371
// ! Parameter name
@@ -358,6 +380,9 @@ class CORE_EXPORT QgsProcessingParameterDefinition
358
380
// ! Parameter flags
359
381
Flags mFlags ;
360
382
383
+ // ! Freeform metadata for parameter. Mostly used by widget wrappers to customise their appearance and behavior.
384
+ QVariantMap mMetadata ;
385
+
361
386
};
362
387
363
388
Q_DECLARE_OPERATORS_FOR_FLAGS ( QgsProcessingParameterDefinition::Flags )
Original file line number Diff line number Diff line change @@ -1321,6 +1321,23 @@ void TestQgsProcessing::parameterGeneral()
1321
1321
QCOMPARE ( param.defaultValue (), QVariant ( true ) );
1322
1322
param.setDefaultValue ( QVariant () );
1323
1323
QCOMPARE ( param.defaultValue (), QVariant () );
1324
+
1325
+ QVariantMap metadata;
1326
+ metadata.insert ( " p1" , 5 );
1327
+ metadata.insert ( " p2" , 7 );
1328
+ param.setMetadata ( metadata );
1329
+ QCOMPARE ( param.metadata (), metadata );
1330
+ param.metadata ().insert ( " p3" , 9 );
1331
+ QCOMPARE ( param.metadata ().value ( " p3" ).toInt (), 9 );
1332
+
1333
+ QVariantMap map = param.toVariantMap ();
1334
+ QgsProcessingParameterBoolean fromMap ( " x" );
1335
+ QVERIFY ( fromMap.fromVariantMap ( map ) );
1336
+ QCOMPARE ( fromMap.name (), param.name () );
1337
+ QCOMPARE ( fromMap.description (), param.description () );
1338
+ QCOMPARE ( fromMap.flags (), param.flags () );
1339
+ QCOMPARE ( fromMap.defaultValue (), param.defaultValue () );
1340
+ QCOMPARE ( fromMap.metadata (), param.metadata () );
1324
1341
}
1325
1342
1326
1343
void TestQgsProcessing::parameterBoolean ()
You can’t perform that action at this time.
0 commit comments