Skip to content

Commit cdaf99d

Browse files
committed
Don't try to show CRS in map layer model for aspatial tables
1 parent e80c31e commit cdaf99d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/core/qgsmaplayermodel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const
233233
if ( !layer )
234234
return QVariant();
235235

236-
if ( !mShowCrs )
236+
if ( !mShowCrs || !layer->isSpatial() )
237237
{
238238
return layer->name();
239239
}

tests/src/python/test_qgsmaplayermodel.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,26 @@ def testDisplayRole(self):
194194
def testDisplayRoleShowCrs(self):
195195
l1 = create_layer('l1')
196196
l2 = create_layer('l2')
197-
QgsProject.instance().addMapLayers([l1, l2])
197+
l3 = QgsVectorLayer("NoGeometry?field=fldtxt:string&field=fldint:integer",
198+
'no geom', "memory")
199+
200+
QgsProject.instance().addMapLayers([l1, l2, l3])
198201
m = QgsMapLayerModel()
199202
m.setShowCrs(True)
200203
self.assertEqual(m.data(m.index(0, 0), Qt.DisplayRole), 'l1 [EPSG:3111]')
201204
self.assertEqual(m.data(m.index(1, 0), Qt.DisplayRole), 'l2 [EPSG:3111]')
205+
self.assertEqual(m.data(m.index(2, 0), Qt.DisplayRole), 'no geom')
206+
202207
m.setAllowEmptyLayer(True)
203208
self.assertFalse(m.data(m.index(0, 0), Qt.DisplayRole))
204209
self.assertEqual(m.data(m.index(1, 0), Qt.DisplayRole), 'l1 [EPSG:3111]')
205210
self.assertEqual(m.data(m.index(2, 0), Qt.DisplayRole), 'l2 [EPSG:3111]')
211+
self.assertEqual(m.data(m.index(3, 0), Qt.DisplayRole), 'no geom')
206212

207213
m.setAdditionalItems(['a'])
208-
self.assertEqual(m.data(m.index(3, 0), Qt.DisplayRole), 'a')
214+
self.assertEqual(m.data(m.index(4, 0), Qt.DisplayRole), 'a')
209215

210-
QgsProject.instance().removeMapLayers([l1.id(), l2.id()])
216+
QgsProject.instance().removeMapLayers([l1.id(), l2.id(), l3.id()])
211217

212218
def testLayerIdRole(self):
213219
l1 = create_layer('l1')

0 commit comments

Comments
 (0)