Skip to content

Commit

Permalink
Ensure created memory layers have unique source
Browse files Browse the repository at this point in the history
Sometimes the layer source is used for "looser" comparison then
layer ID
  • Loading branch information
nyalldawson committed May 16, 2017
1 parent c484b50 commit a517c68
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/providers/memory/qgsmemoryproviderutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ QgsVectorLayer *QgsMemoryProviderUtils::createMemoryLayer( const QString &name,
{
parts << QStringLiteral( "field=%1:%2" ).arg( field.name(), memoryLayerFieldType( field.type() ) );
}
// required so that source differs between memory layers
parts << QStringLiteral( "uid=%1" ).arg( QUuid::createUuid().toString() );

QString uri = geomType + '?' + parts.join( '&' );

Expand Down
4 changes: 4 additions & 0 deletions tests/src/python/test_provider_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ def testCreateMemoryLayer(self):
self.assertEqual(layer.name(), 'my name')
self.assertTrue(layer.fields().isEmpty())

# similar layers should have unique sources
layer2 = QgsMemoryProviderUtils.createMemoryLayer('my name', QgsFields())
self.assertNotEqual(layer.source(), layer2.source())

# geometry type
layer = QgsMemoryProviderUtils.createMemoryLayer('my name', QgsFields(), QgsWkbTypes.Point)
self.assertTrue(layer.isValid())
Expand Down

0 comments on commit a517c68

Please sign in to comment.