Skip to content

Commit

Permalink
Simplify QgsMemoryProviderUtils::createMemoryLayer()
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 6, 2017
1 parent ba2fdf0 commit e2a735f
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/core/providers/memory/qgsmemoryproviderutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.