Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metadata setting to override widget wrapper used for a parameter #57860

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading