Skip to content
Permalink
Browse files

Don't try to show CRS in map layer model for aspatial tables

(cherry picked from commit cdaf99d)
  • Loading branch information
nyalldawson committed Nov 9, 2018
1 parent 2bd98ff commit e288bdbce54322eab257d9f20a9f15d4858969ae
Showing with 10 additions and 4 deletions.
  1. +1 −1 src/core/qgsmaplayermodel.cpp
  2. +9 −3 tests/src/python/test_qgsmaplayermodel.py
@@ -233,7 +233,7 @@ QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const
if ( !layer )
return QVariant();

if ( !mShowCrs )
if ( !mShowCrs || !layer->isSpatial() )
{
return layer->name();
}
@@ -194,20 +194,26 @@ def testDisplayRole(self):
def testDisplayRoleShowCrs(self):
l1 = create_layer('l1')
l2 = create_layer('l2')
QgsProject.instance().addMapLayers([l1, l2])
l3 = QgsVectorLayer("NoGeometry?field=fldtxt:string&field=fldint:integer",
'no geom', "memory")

QgsProject.instance().addMapLayers([l1, l2, l3])
m = QgsMapLayerModel()
m.setShowCrs(True)
self.assertEqual(m.data(m.index(0, 0), Qt.DisplayRole), 'l1 [EPSG:3111]')
self.assertEqual(m.data(m.index(1, 0), Qt.DisplayRole), 'l2 [EPSG:3111]')
self.assertEqual(m.data(m.index(2, 0), Qt.DisplayRole), 'no geom')

m.setAllowEmptyLayer(True)
self.assertFalse(m.data(m.index(0, 0), Qt.DisplayRole))
self.assertEqual(m.data(m.index(1, 0), Qt.DisplayRole), 'l1 [EPSG:3111]')
self.assertEqual(m.data(m.index(2, 0), Qt.DisplayRole), 'l2 [EPSG:3111]')
self.assertEqual(m.data(m.index(3, 0), Qt.DisplayRole), 'no geom')

m.setAdditionalItems(['a'])
self.assertEqual(m.data(m.index(3, 0), Qt.DisplayRole), 'a')
self.assertEqual(m.data(m.index(4, 0), Qt.DisplayRole), 'a')

QgsProject.instance().removeMapLayers([l1.id(), l2.id()])
QgsProject.instance().removeMapLayers([l1.id(), l2.id(), l3.id()])

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

0 comments on commit e288bdb

Please sign in to comment.
You can’t perform that action at this time.