Skip to content
Permalink
Browse files

use general json conversion because it works for the different types

like QVariantMap, QVariantHash, QVariantList or QStringList
as fallback still the QString conversion is available
  • Loading branch information
signedav committed Jan 7, 2019
1 parent 386c16f commit a6f8db15c58bde2471528f15d79907d884f1a33d
Showing with 10 additions and 12 deletions.
  1. +8 −10 src/providers/ogr/qgsogrprovider.cpp
  2. +2 −2 src/providers/ogr/qgsogrprovider.h
@@ -1408,17 +1408,15 @@ OGRGeometryH QgsOgrProvider::ConvertGeometryIfNecessary( OGRGeometryH hGeom )
return OGR_G_ForceTo( hGeom, layerGeomType, nullptr );
}

QString QgsOgrProvider::jsonStringValue( const QVariant &value, const QVariant::Type &type ) const
QString QgsOgrProvider::jsonStringValue( const QVariant &value ) const
{
switch ( type )
QString stringValue = QString::fromUtf8( QJsonDocument::fromVariant( value ).toJson().constData() );
if ( stringValue.isEmpty() )
{
case QVariant::Map:
return QString::fromUtf8( QJsonDocument::fromVariant( value.toMap() ).toJson().data() );
case QVariant::List:
return QString::fromUtf8( QJsonDocument::fromVariant( value.toList() ).toJson().data() );
default:
return value.toString();
//store as string, because it's no valid QJson value
stringValue = value.toString();
}
return stringValue;
}

bool QgsOgrProvider::addFeaturePrivate( QgsFeature &f, Flags flags )
@@ -1550,7 +1548,7 @@ bool QgsOgrProvider::addFeaturePrivate( QgsFeature &f, Flags flags )

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
if ( OGR_Fld_GetSubType( fldDef ) == OFSTJSON )
stringValue = jsonStringValue( attrVal, attrVal.type() );
stringValue = jsonStringValue( attrVal );
else
{
stringValue = attrVal.toString();
@@ -2139,7 +2137,7 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
QString stringValue;
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
if ( OGR_Fld_GetSubType( fd ) == OFSTJSON )
stringValue = jsonStringValue( it2.value(), it2->type() );
stringValue = jsonStringValue( it2.value() );
else
stringValue = it2->toString();
#else
@@ -284,8 +284,8 @@ class QgsOgrProvider : public QgsVectorDataProvider

mutable QStringList mSubLayerList;

//! converts \a value from json QVariant to QString regarding to \a type
QString jsonStringValue( const QVariant &value, const QVariant::Type &type ) const;
//! converts \a value from json QVariant to QString
QString jsonStringValue( const QVariant &value ) const;

bool addFeaturePrivate( QgsFeature &f, QgsFeatureSink::Flags flags );
//! Deletes one feature

0 comments on commit a6f8db1

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