Skip to content

Commit

Permalink
Don't try to show CRS in map layer model for aspatial tables
Browse files Browse the repository at this point in the history
(cherry picked from commit cdaf99d)
  • Loading branch information
nyalldawson committed Nov 13, 2018
1 parent 2bd98ff commit e288bdb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsmaplayermodel.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const
if ( !layer ) if ( !layer )
return QVariant(); return QVariant();


if ( !mShowCrs ) if ( !mShowCrs || !layer->isSpatial() )
{ {
return layer->name(); return layer->name();
} }
Expand Down
12 changes: 9 additions & 3 deletions tests/src/python/test_qgsmaplayermodel.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -194,20 +194,26 @@ def testDisplayRole(self):
def testDisplayRoleShowCrs(self): def testDisplayRoleShowCrs(self):
l1 = create_layer('l1') l1 = create_layer('l1')
l2 = create_layer('l2') 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 = QgsMapLayerModel()
m.setShowCrs(True) m.setShowCrs(True)
self.assertEqual(m.data(m.index(0, 0), Qt.DisplayRole), 'l1 [EPSG:3111]') 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(1, 0), Qt.DisplayRole), 'l2 [EPSG:3111]')
self.assertEqual(m.data(m.index(2, 0), Qt.DisplayRole), 'no geom')

m.setAllowEmptyLayer(True) m.setAllowEmptyLayer(True)
self.assertFalse(m.data(m.index(0, 0), Qt.DisplayRole)) 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(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(2, 0), Qt.DisplayRole), 'l2 [EPSG:3111]')
self.assertEqual(m.data(m.index(3, 0), Qt.DisplayRole), 'no geom')


m.setAdditionalItems(['a']) 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): def testLayerIdRole(self):
l1 = create_layer('l1') l1 = create_layer('l1')
Expand Down

0 comments on commit e288bdb

Please sign in to comment.