Skip to content
Permalink
Browse files

If no project layer order is set, fall back to stored layer order

when retrieving map theme layers

Since we don't ever want to return no layers in this situation
using the stored order is an acceptable last resort

Should only affect custom scripts run outside of QGIS app
in any case!
  • Loading branch information
nyalldawson committed Mar 13, 2017
1 parent 5eccaf6 commit 2c3c1f7fbbfe4700eba857433dab9d07fcb3c6cd
Showing with 22 additions and 3 deletions.
  1. +16 −3 src/core/qgsmapthemecollection.cpp
  2. +6 −0 tests/src/python/test_qgsmapthemecollection.py
@@ -248,14 +248,27 @@ QList<QgsMapLayer *> QgsMapThemeCollection::mapThemeVisibleLayers( const QString
{
QList<QgsMapLayer *> layers;
const QList<MapThemeLayerRecord> &recs = mMapThemes.value( name ).mLayerRecords;
Q_FOREACH ( QgsMapLayer *layer, masterLayerOrder() )
QList<QgsMapLayer *> layerOrder = masterLayerOrder();
if ( layerOrder.isEmpty() )
{
Q_FOREACH ( const MapThemeLayerRecord &layerRec, recs )
// no master layer order - so we have to just use the stored theme layer order as a fallback
Q_FOREACH ( const MapThemeLayerRecord &layerRec, mMapThemes.value( name ).mLayerRecords )
{
if ( layerRec.layer() == layer )
if ( layerRec.layer() )
layers << layerRec.layer();
}
}
else
{
Q_FOREACH ( QgsMapLayer *layer, layerOrder )
{
Q_FOREACH ( const MapThemeLayerRecord &layerRec, recs )
{
if ( layerRec.layer() == layer )
layers << layerRec.layer();
}
}
}

return layers;
}
@@ -168,6 +168,12 @@ def testMasterLayerOrder(self):
[layer.id(), layer2.id(), layer3.id()])
self.assertEqual(prj.mapThemeCollection().mapThemeVisibleLayerIds('theme3'), [layer.id(), layer2.id()])

# no layer order - should use stored order as a last resort
prj.setLayerOrder([])
self.assertEqual(prj.mapThemeCollection().mapThemeVisibleLayers('theme1'), [layer3, layer])
self.assertEqual(prj.mapThemeCollection().mapThemeVisibleLayers('theme2'), [layer3, layer2, layer])
self.assertEqual(prj.mapThemeCollection().mapThemeVisibleLayers('theme3'), [layer2, layer])


if __name__ == '__main__':
unittest.main()

0 comments on commit 2c3c1f7

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