Skip to content
Permalink
Browse files
Simplify QgsMemoryProviderUtils::createMemoryLayer()
  • Loading branch information
nyalldawson committed May 6, 2017
1 parent ba2fdf0 commit e2a735f39e0c41be2915a2fe5eaae23037fd2f81
Showing with 4 additions and 15 deletions.
  1. +4 −15 src/core/providers/memory/qgsmemoryproviderutils.cpp
@@ -56,28 +56,17 @@ QgsVectorLayer *QgsMemoryProviderUtils::createMemoryLayer( const QString &name,
if ( geomType.isNull() )
geomType = QStringLiteral( "none" );

QString uri = geomType + '?';

bool first = true;
QStringList parts;
if ( crs.isValid() )
{
uri += QStringLiteral( "crs=" ) + crs.authid();
first = false;
parts << QStringLiteral( "crs=" ) + crs.authid();
}

QStringList fieldsStrings;
Q_FOREACH ( const QgsField &field, fields )
{
fieldsStrings << QStringLiteral( "field=%1:%2" ).arg( field.name(), memoryLayerFieldType( field.type() ) );
parts << QStringLiteral( "field=%1:%2" ).arg( field.name(), memoryLayerFieldType( field.type() ) );
}

if ( !fieldsStrings.isEmpty() )
{
if ( !first )
uri += '&';
first = false;
uri += fieldsStrings.join( '&' );
}
QString uri = geomType + '?' + parts.join( '&' );

return new QgsVectorLayer( uri, name, QStringLiteral( "memory" ) );
}

0 comments on commit e2a735f

Please sign in to comment.