Skip to content

Commit 5ef0799

Browse files
committed
Value Relation implementation
Values in the Value Relation widgets can be translated now - means changed. So the setting-change is made to get translated values over another layer.
1 parent c6b05b9 commit 5ef0799

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/core/qgsproject.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,18 @@ void QgsProject::registerTranslatableObjects( QgsTranslationContext *translation
479479
const QgsFields fields = vlayer->fields();
480480
for ( const QgsField &field : fields )
481481
{
482+
QString fieldName;
482483
if ( field.alias().isEmpty() )
483-
translationContext->registerTranslation( QStringLiteral( "project:layers:%1:fieldaliases" ).arg( vlayer->id() ), field.name() );
484+
fieldName = field.name();
484485
else
485-
translationContext->registerTranslation( QStringLiteral( "project:layers:%1:fieldaliases" ).arg( vlayer->id() ), field.alias() );
486+
fieldName = field.alias();
487+
488+
translationContext->registerTranslation( QStringLiteral( "project:layers:%1:fieldaliases" ).arg( vlayer->id() ), fieldName );
489+
490+
if ( field.editorWidgetSetup().type() == QStringLiteral( "ValueRelation" ) )
491+
{
492+
translationContext->registerTranslation( QStringLiteral( "project:layers:%1:fields:%2:valuerelationvalue" ).arg( vlayer->id(), field.name() ), field.editorWidgetSetup().config().value( QStringLiteral( "Value" ) ).toString() );
493+
}
486494
}
487495

488496
//register formcontainers

src/core/qgsvectorlayer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,10 @@ bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMes
20352035
const QDomElement cfgElem = fieldConfigElement.elementsByTagName( QStringLiteral( "config" ) ).at( 0 ).toElement();
20362036
const QDomElement optionsElem = cfgElem.childNodes().at( 0 ).toElement();
20372037
QVariantMap optionsMap = QgsXmlUtils::readVariant( optionsElem ).toMap();
2038+
if ( widgetType == QStringLiteral( "ValueRelation" ) )
2039+
{
2040+
optionsMap[ QStringLiteral( "Value" ) ] = context.projectTranslator()->translate( QStringLiteral( "project:layers:%1:fields:%2:valuerelationvalue" ).arg( layerNode.namedItem( QStringLiteral( "id" ) ).toElement().text(), fieldName ), optionsMap[ QStringLiteral( "Value" ) ].toString() );
2041+
}
20382042
QgsEditorWidgetSetup setup = QgsEditorWidgetSetup( widgetType, optionsMap );
20392043
mFieldWidgetSetups[fieldName] = setup;
20402044
}

tests/src/core/testqgstranslateproject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void TestQgsTranslateProject::cleanupTestCase()
7171

7272
//delete created ts file
7373
QString tsFileName( TEST_DATA_DIR );
74-
tsFileName = tsFileName + "/project_translation/points_translation_de.ts";
74+
tsFileName = tsFileName + "/project_translation/points_translation.ts";
7575
QFile tsFile( tsFileName );
7676
tsFile.remove();
7777
}
@@ -99,7 +99,7 @@ void TestQgsTranslateProject::createTsFile()
9999

100100
//check if ts file is created
101101
QString tsFileName( TEST_DATA_DIR );
102-
tsFileName = tsFileName + "/project_translation/points_translation_de.ts";
102+
tsFileName = tsFileName + "/project_translation/points_translation.ts";
103103
QFile tsFile( tsFileName );
104104
QVERIFY( tsFile.exists() );
105105

0 commit comments

Comments
 (0)