From 3f1ba81b7e971e08820f59a602dbb10b62a3ffe1 Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Mon, 27 May 2019 09:02:47 +0200 Subject: [PATCH] Address PR comments (minor changes) --- .../fieldformatter/qgsvaluerelationfieldformatter.sip.in | 2 +- src/core/fieldformatter/qgsvaluerelationfieldformatter.cpp | 6 +----- src/core/fieldformatter/qgsvaluerelationfieldformatter.h | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/python/core/auto_generated/fieldformatter/qgsvaluerelationfieldformatter.sip.in b/python/core/auto_generated/fieldformatter/qgsvaluerelationfieldformatter.sip.in index b552aa3bf2a..f4ed04fe6d4 100644 --- a/python/core/auto_generated/fieldformatter/qgsvaluerelationfieldformatter.sip.in +++ b/python/core/auto_generated/fieldformatter/qgsvaluerelationfieldformatter.sip.in @@ -59,7 +59,7 @@ Constructor for QgsValueRelationFieldFormatter. static QStringList valueToStringList( const QVariant &value ); %Docstring -Utility to convert an array or a string representation of an (C style: {1,2...}) array in the form ``value`` to a string list +Utility to convert a list or a string representation of an (hstore style: {1,2...}) list in ``value`` to a string list .. versionadded:: 3.2 %End diff --git a/src/core/fieldformatter/qgsvaluerelationfieldformatter.cpp b/src/core/fieldformatter/qgsvaluerelationfieldformatter.cpp index 2fcd50b5394..7a3de93fcc0 100644 --- a/src/core/fieldformatter/qgsvaluerelationfieldformatter.cpp +++ b/src/core/fieldformatter/qgsvaluerelationfieldformatter.cpp @@ -168,10 +168,6 @@ QgsValueRelationFieldFormatter::ValueRelationCache QgsValueRelationFieldFormatte QStringList QgsValueRelationFieldFormatter::valueToStringList( const QVariant &value ) { - // Note: the recommended way to pass a value is QVariant::StringList but - // for back compatibility a string representation either in the form - // of a JSON array or in the form of {"quoted_str", 1, ... } is - // also accepted QStringList checkList; if ( value.type() == QVariant::StringList ) { @@ -183,7 +179,7 @@ QStringList QgsValueRelationFieldFormatter::valueToStringList( const QVariant &v auto newVal { value }; if ( newVal.toString().trimmed().startsWith( '{' ) ) { - newVal = QVariant( newVal.toString().trimmed().mid( 1 ).chopped( 1 ).prepend( '[' ).append( ']' ) ); + newVal = QVariant( newVal.toString().trimmed().mid( 1 ).mid( 0, newVal.toString().length() - 2 ).prepend( '[' ).append( ']' ) ); } if ( newVal.toString().trimmed().startsWith( '[' ) ) { diff --git a/src/core/fieldformatter/qgsvaluerelationfieldformatter.h b/src/core/fieldformatter/qgsvaluerelationfieldformatter.h index 44dbcea3c9b..b2e540e8e47 100644 --- a/src/core/fieldformatter/qgsvaluerelationfieldformatter.h +++ b/src/core/fieldformatter/qgsvaluerelationfieldformatter.h @@ -66,7 +66,7 @@ class CORE_EXPORT QgsValueRelationFieldFormatter : public QgsFieldFormatter QVariant createCache( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config ) const override; /** - * Utility to convert an array or a string representation of an (C style: {1,2...}) array in the form \a value to a string list + * Utility to convert a list or a string representation of an (hstore style: {1,2...}) list in \a value to a string list * \since QGIS 3.2 */ static QStringList valueToStringList( const QVariant &value );