Skip to content

Commit

Permalink
take into account parameter's metadata when creating widget wrapper
Browse files Browse the repository at this point in the history
The "widget_type" key allows to override standard widget wrapper for a
parameter type.
  • Loading branch information
alexbruy committed May 14, 2024
1 parent dd01d11 commit ef1c9df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/gui/processing/qgsprocessingguiregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingGuiRegistry::createPar
if ( !parameter )
return nullptr;

const QString parameterType = parameter->type();
const QVariantMap metadata = parameter->metadata();
const QString widgetType = metadata.value( QStringLiteral( "widget_wrapper" ) ).toMap().value( QStringLiteral( "widget_type" ) ).toString();
const QString parameterType = !widgetType.isEmpty() ? widgetType : parameter->type();
if ( !mParameterWidgetFactories.contains( parameterType ) )
return nullptr;

Expand Down
15 changes: 15 additions & 0 deletions tests/src/gui/testprocessinggui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,21 @@ void TestProcessingGui::testWrapperFactoryRegistry()
QCOMPARE( wrapper->parameterDefinition()->type(), QStringLiteral( "num" ) );
delete wrapper;

// creating wrapper using metadata
TestParamType customParam( QStringLiteral( "custom" ), QStringLiteral( "custom" ) );
wrapper = registry.createParameterWidgetWrapper( &customParam, QgsProcessingGui::Standard );
QVERIFY( !wrapper );
customParam.setMetadata( {{
QStringLiteral( "widget_wrapper" ), QVariantMap(
{{QStringLiteral( "widget_type" ), QStringLiteral( "str" ) }}
)
}
} );
wrapper = registry.createParameterWidgetWrapper( &customParam, QgsProcessingGui::Standard );
QVERIFY( wrapper );
QCOMPARE( wrapper->parameterDefinition()->type(), QStringLiteral( "custom" ) );
delete wrapper;

// removing
registry.removeParameterWidgetFactory( nullptr );
TestWidgetFactory *factory4 = new TestWidgetFactory( QStringLiteral( "xxxx" ) );
Expand Down

0 comments on commit ef1c9df

Please sign in to comment.