Skip to content
Permalink
Browse files

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.
  • Loading branch information
signedav committed Aug 23, 2018
1 parent c6b05b9 commit 5ef079970d301968912e510521f670b19643fa1e
Showing with 16 additions and 4 deletions.
  1. +10 −2 src/core/qgsproject.cpp
  2. +4 −0 src/core/qgsvectorlayer.cpp
  3. +2 −2 tests/src/core/testqgstranslateproject.cpp
@@ -479,10 +479,18 @@ void QgsProject::registerTranslatableObjects( QgsTranslationContext *translation
const QgsFields fields = vlayer->fields();
for ( const QgsField &field : fields )
{
QString fieldName;
if ( field.alias().isEmpty() )
translationContext->registerTranslation( QStringLiteral( "project:layers:%1:fieldaliases" ).arg( vlayer->id() ), field.name() );
fieldName = field.name();
else
translationContext->registerTranslation( QStringLiteral( "project:layers:%1:fieldaliases" ).arg( vlayer->id() ), field.alias() );
fieldName = field.alias();

translationContext->registerTranslation( QStringLiteral( "project:layers:%1:fieldaliases" ).arg( vlayer->id() ), fieldName );

if ( field.editorWidgetSetup().type() == QStringLiteral( "ValueRelation" ) )
{
translationContext->registerTranslation( QStringLiteral( "project:layers:%1:fields:%2:valuerelationvalue" ).arg( vlayer->id(), field.name() ), field.editorWidgetSetup().config().value( QStringLiteral( "Value" ) ).toString() );
}
}

//register formcontainers
@@ -2035,6 +2035,10 @@ bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMes
const QDomElement cfgElem = fieldConfigElement.elementsByTagName( QStringLiteral( "config" ) ).at( 0 ).toElement();
const QDomElement optionsElem = cfgElem.childNodes().at( 0 ).toElement();
QVariantMap optionsMap = QgsXmlUtils::readVariant( optionsElem ).toMap();
if ( widgetType == QStringLiteral( "ValueRelation" ) )
{
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() );
}
QgsEditorWidgetSetup setup = QgsEditorWidgetSetup( widgetType, optionsMap );
mFieldWidgetSetups[fieldName] = setup;
}
@@ -71,7 +71,7 @@ void TestQgsTranslateProject::cleanupTestCase()

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

//check if ts file is created
QString tsFileName( TEST_DATA_DIR );
tsFileName = tsFileName + "/project_translation/points_translation_de.ts";
tsFileName = tsFileName + "/project_translation/points_translation.ts";
QFile tsFile( tsFileName );
QVERIFY( tsFile.exists() );

0 comments on commit 5ef0799

Please sign in to comment.
You can’t perform that action at this time.