Skip to content

Commit

Permalink
[processing] Add support for field alias and comments to field mapping
Browse files Browse the repository at this point in the history
parameter values
  • Loading branch information
nyalldawson committed Apr 21, 2023
1 parent c7659fb commit 7b0bfaf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/gui/processing/qgsprocessingfieldmapwidgetwrapper.cpp
Expand Up @@ -110,6 +110,8 @@ QVariant QgsProcessingFieldMapPanelWidget::value() const
def.insert( QStringLiteral( "precision" ), field.field.precision() );
def.insert( QStringLiteral( "sub_type" ), static_cast< int >( field.field.subType() ) );
def.insert( QStringLiteral( "expression" ), field.expression );
def.insert( QStringLiteral( "alias" ), field.field.alias() );
def.insert( QStringLiteral( "comment" ), field.field.comment() );
results.append( def );
}
return results;
Expand All @@ -135,6 +137,8 @@ void QgsProcessingFieldMapPanelWidget::setValue( const QVariant &value )
map.value( QStringLiteral( "precision" ), 0 ).toInt(),
QString(),
static_cast< QVariant::Type >( map.value( QStringLiteral( "sub_type" ), QVariant::Invalid ).toInt() ) );
f.setAlias( map.value( QStringLiteral( "alias" ) ).toString() );
f.setComment( map.value( QStringLiteral( "comment" ) ).toString() );

if ( map.contains( QStringLiteral( "constraints" ) ) )
{
Expand Down
8 changes: 8 additions & 0 deletions tests/src/gui/testprocessinggui.cpp
Expand Up @@ -8198,6 +8198,8 @@ void TestProcessingGui::testFieldMapWidget()
map2.insert( QStringLiteral( "name" ), QStringLiteral( "n2" ) );
map2.insert( QStringLiteral( "type" ), static_cast< int >( QVariant::String ) );
map2.insert( QStringLiteral( "expression" ), QStringLiteral( "'abc' || \"def\"" ) );
map2.insert( QStringLiteral( "alias" ), QStringLiteral( "my alias" ) );
map2.insert( QStringLiteral( "comment" ), QStringLiteral( "my comment" ) );

QSignalSpy spy( &widget, &QgsProcessingFieldMapPanelWidget::changed );
widget.setValue( QVariantList() << map << map2 );
Expand All @@ -8212,6 +8214,8 @@ void TestProcessingGui::testFieldMapWidget()
QCOMPARE( widget.value().toList().at( 1 ).toMap().value( QStringLiteral( "name" ) ).toString(), QStringLiteral( "n2" ) );
QCOMPARE( widget.value().toList().at( 1 ).toMap().value( QStringLiteral( "type" ) ).toInt(), static_cast< int >( QVariant::String ) );
QCOMPARE( widget.value().toList().at( 1 ).toMap().value( QStringLiteral( "expression" ) ).toString(), QStringLiteral( "'abc' || \"def\"" ) );
QCOMPARE( widget.value().toList().at( 1 ).toMap().value( QStringLiteral( "alias" ) ).toString(), QStringLiteral( "my alias" ) );
QCOMPARE( widget.value().toList().at( 1 ).toMap().value( QStringLiteral( "comment" ) ).toString(), QStringLiteral( "my comment" ) );
}

void TestProcessingGui::testFieldMapWrapper()
Expand All @@ -8237,6 +8241,8 @@ void TestProcessingGui::testFieldMapWrapper()
map2.insert( QStringLiteral( "name" ), QStringLiteral( "n2" ) );
map2.insert( QStringLiteral( "type" ), static_cast< int >( QVariant::String ) );
map2.insert( QStringLiteral( "expression" ), QStringLiteral( "'abc' || \"def\"" ) );
map2.insert( QStringLiteral( "alias" ), QStringLiteral( "my alias" ) );
map2.insert( QStringLiteral( "comment" ), QStringLiteral( "my comment" ) );

QSignalSpy spy( &wrapper, &QgsProcessingFieldMapWidgetWrapper::widgetValueHasChanged );
wrapper.setWidgetValue( QVariantList() << map << map2, context );
Expand All @@ -8249,6 +8255,8 @@ void TestProcessingGui::testFieldMapWrapper()
QCOMPARE( wrapper.widgetValue().toList().at( 1 ).toMap().value( QStringLiteral( "name" ) ).toString(), QStringLiteral( "n2" ) );
QCOMPARE( wrapper.widgetValue().toList().at( 1 ).toMap().value( QStringLiteral( "type" ) ).toInt(), static_cast< int >( QVariant::String ) );
QCOMPARE( wrapper.widgetValue().toList().at( 1 ).toMap().value( QStringLiteral( "expression" ) ).toString(), QStringLiteral( "'abc' || \"def\"" ) );
QCOMPARE( wrapper.widgetValue().toList().at( 1 ).toMap().value( QStringLiteral( "alias" ) ).toString(), QStringLiteral( "my alias" ) );
QCOMPARE( wrapper.widgetValue().toList().at( 1 ).toMap().value( QStringLiteral( "comment" ) ).toString(), QStringLiteral( "my comment" ) );

QCOMPARE( static_cast< QgsProcessingFieldMapPanelWidget * >( wrapper.wrappedWidget() )->value().toList().count(), 2 );
QCOMPARE( static_cast< QgsProcessingFieldMapPanelWidget * >( wrapper.wrappedWidget() )->value().toList().at( 0 ).toMap().value( QStringLiteral( "name" ) ).toString(), QStringLiteral( "n" ) );
Expand Down

0 comments on commit 7b0bfaf

Please sign in to comment.