Skip to content
Permalink
Browse files
Fix list types
  • Loading branch information
domi4484 committed Aug 17, 2021
1 parent 92d713a commit 48f234c96a675d86150267d76505a3054b387e86
Showing with 37 additions and 3 deletions.
  1. +37 −3 src/core/providers/memory/qgsmemoryprovider.cpp
@@ -108,6 +108,12 @@ QgsMemoryProvider::QgsMemoryProvider( const QString &uri, const ProviderOptions
// blob
<< QgsVectorDataProvider::NativeType( tr( "Binary object (BLOB)" ), QStringLiteral( "binary" ), QVariant::ByteArray )

// list types
<< QgsVectorDataProvider::NativeType( tr( "String list" ), QStringLiteral( "stringlist" ), QVariant::StringList, 0, 0, 0, 0, QVariant::String )
<< QgsVectorDataProvider::NativeType( tr( "Integer list" ), QStringLiteral( "integerlist" ), QVariant::List, 0, 0, 0, 0, QVariant::Int )
<< QgsVectorDataProvider::NativeType( tr( "Decimal (real) list" ), QStringLiteral( "doublelist" ), QVariant::List, 0, 0, 0, 0, QVariant::Double )
<< QgsVectorDataProvider::NativeType( tr( "Integer (64bit) list" ), QStringLiteral( "doublelist" ), QVariant::List, 0, 0, 0, 0, QVariant::Double )

);

if ( query.hasQueryItem( QStringLiteral( "field" ) ) )
@@ -277,9 +283,38 @@ QString QgsMemoryProvider::dataSourceUri( bool expandAuthConfig ) const
QgsAttributeList attrs = const_cast<QgsMemoryProvider *>( this )->attributeIndexes();
for ( int i = 0; i < attrs.size(); i++ )
{
QgsField field = mFields.at( attrs[i] );
const QgsField field = mFields.at( attrs[i] );
QString fieldDef = field.name();
fieldDef.append( QStringLiteral( ":%2(%3,%4)" ).arg( field.typeName() ).arg( field.length() ).arg( field.precision() ) );

QString typeName = field.typeName();
bool isList = false;
if ( field.type() == QVariant::List || field.type() == QVariant::StringList )
{
switch ( field.subType() )
{
case QVariant::Int:
typeName = QStringLiteral( "integer" );
break;

case QVariant::LongLong:
typeName = QStringLiteral( "long" );
break;

case QVariant::Double:
typeName = QStringLiteral( "double" );
break;

case QVariant::String:
typeName = QStringLiteral( "string" );
break;

default:
break;
}
isList = true;
}

fieldDef.append( QStringLiteral( ":%2(%3,%4)%5" ).arg( typeName ).arg( field.length() ).arg( field.precision() ).arg( isList ? QStringLiteral( "[]" ) : QString() ) );
query.addQueryItem( QStringLiteral( "field" ), fieldDef );
}
uri.setQuery( query );
@@ -548,7 +583,6 @@ bool QgsMemoryProvider::addAttributes( const QList<QgsField> &attributes )
&& nativeTypeCandidate.mType == QVariant::Invalid )
nativeTypeCandidate = nativeType;
}

if ( !isNativeTypeName )
{
if ( nativeTypeCandidate.mType == QVariant::Invalid )

0 comments on commit 48f234c

Please sign in to comment.