Skip to content
Permalink
Browse files

Merge pull request #8721 from signedav/json-for-valuerelations

Storing Value Releation multi-selection as JSON
  • Loading branch information
m-kuhn committed Jan 8, 2019
2 parents 3732cb7 + 6e91349 commit 15ddb270938ad667ebd24ccda64f0e870989ec02
@@ -39,9 +39,6 @@ QString QgsValueRelationFieldFormatter::id() const

QString QgsValueRelationFieldFormatter::representValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const
{
Q_UNUSED( layer )
Q_UNUSED( fieldIndex )

ValueRelationCache vrCache;

if ( cache.isValid() )
@@ -55,7 +52,18 @@ QString QgsValueRelationFieldFormatter::representValue( QgsVectorLayer *layer, i

if ( config.value( QStringLiteral( "AllowMulti" ) ).toBool() )
{
QStringList keyList = valueToStringList( value );
QStringList keyList;

if ( layer->fields().at( fieldIndex ).type() == QVariant::Map )
{
//because of json it's stored as QVariantList
keyList = value.toStringList();
}
else
{
keyList = valueToStringList( value );
}

QStringList valueList;

for ( const QgsValueRelationFieldFormatter::ValueRelationItem &item : qgis::as_const( vrCache ) )
@@ -69,7 +69,22 @@ QVariant QgsValueRelationWidgetWrapper::value() const
}
}
}
v = selection.join( QStringLiteral( "," ) ).prepend( '{' ).append( '}' );

if ( layer()->fields().at( fieldIdx() ).type() == QVariant::Map )
{
QVariantList vl;
//store as QVariantList because it's json
for ( const QString &s : qgis::as_const( selection ) )
{
vl << s;
}
v = vl;
}
else
{
//store as hstore string
v = selection.join( ',' ).prepend( '{' ).append( '}' );
}
}

if ( mLineEdit )
@@ -149,7 +164,17 @@ void QgsValueRelationWidgetWrapper::setValue( const QVariant &value )
{
if ( mTableWidget )
{
QStringList checkList( QgsValueRelationFieldFormatter::valueToStringList( value ) );
QStringList checkList;

if ( layer()->fields().at( fieldIdx() ).type() == QVariant::Map )
{
//because of json it's stored as QVariantList
checkList = value.toStringList();
}
else
{
checkList = QgsValueRelationFieldFormatter::valueToStringList( value );
}

QTableWidgetItem *lastChangedItem = nullptr;

0 comments on commit 15ddb27

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