Skip to content
Permalink
Browse files

do not list non spatial in custom layer order widget

fix #17887
  • Loading branch information
3nids committed Jan 19, 2018
1 parent efe378d commit 86024efcb221f3a87669961c9dec1eb6be1063c5
Showing with 35 additions and 10 deletions.
  1. +35 −10 src/core/layertree/qgslayertree.cpp
@@ -15,6 +15,7 @@

#include "qgslayertree.h"
#include "qgsmaplayerlistutils.h"
#include "qgsvectorlayer.h"

QgsLayerTree::QgsLayerTree()
{
@@ -38,7 +39,7 @@ QList<QgsMapLayer *> QgsLayerTree::customLayerOrder() const

void QgsLayerTree::setCustomLayerOrder( const QList<QgsMapLayer *> &customLayerOrder )
{
QgsWeakMapLayerPointerList newOrder = _qgis_listRawToQPointer( customLayerOrder );
QgsWeakMapLayerPointerList newOrder = _qgis_listRawToQPointer( customLayerOrder );

if ( newOrder == mCustomLayerOrder )
return;
@@ -54,31 +55,49 @@ void QgsLayerTree::setCustomLayerOrder( const QStringList &customLayerOrder )
{
QList<QgsMapLayer *> layers;

Q_FOREACH ( const QString &layerId, customLayerOrder )
for ( const auto &layerId : customLayerOrder )
{
QgsLayerTreeLayer *nodeLayer = findLayer( layerId );
if ( nodeLayer )
{
// configuration from 2.x projects might have non spatial layers
QgsMapLayer *layer = nodeLayer->layer();
if ( layer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
if ( vl && !vl->isSpatial() )
{
continue;
}
}
layers.append( nodeLayer->layer() );
}
}

setCustomLayerOrder( layers );
}

QList<QgsMapLayer *> QgsLayerTree::layerOrder() const
{
if ( mHasCustomLayerOrder )
{
return customLayerOrder();
}
else
{
QList<QgsMapLayer *> layers;

Q_FOREACH ( QgsLayerTreeLayer *treeLayer, findLayers() )
for ( const auto &treeLayer : findLayers() )
{
layers.append( treeLayer->layer() );
QgsMapLayer *layer = treeLayer->layer();
if ( layer && layer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
if ( vl && !vl->isSpatial() )
{
continue;
}
}
layers.append( layer );
}

return layers;
}
}
@@ -201,12 +220,18 @@ void QgsLayerTree::addMissingLayers()
{
bool changed = false;

QList<QgsLayerTreeLayer *> allLayers = findLayers();

Q_FOREACH ( QgsLayerTreeLayer *layer, allLayers )
for ( const auto layer : findLayers() )
{
if ( !mCustomLayerOrder.contains( layer->layer() ) && layer->layer() )
{
if ( layer->layer()->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer->layer() );
if ( vl && !vl->isSpatial() )
{
continue;
}
}
mCustomLayerOrder.append( layer->layer() );
changed = true;
}

0 comments on commit 86024ef

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