32 , mPendingCanvasUpdate( false )
33 , mAutoSetupOnFirstLayer( true )
34 , mHasLayersLoaded( !root->findLayers().isEmpty() )
47 QList<QgsMapLayer *> canvasLayers, overviewLayers, allLayerOrder;
52 for (
const QgsMapLayer *layer : customOrderLayers )
60 allLayerOrder << nodeLayer->
layer();
62 canvasLayers << nodeLayer->
layer();
63 if ( nodeLayer->
customProperty( QStringLiteral(
"overview" ), 0 ).toInt() )
64 overviewLayers << nodeLayer->
layer();
73 const QList<QgsLayerTreeLayer *> layerNodes = mRoot->
findLayers();
74 int currentSpatialLayerCount = 0;
75 int currentValidSpatialLayerCount = 0;
78 if ( layerNode->layer() && layerNode->layer()->isSpatial() )
80 currentSpatialLayerCount++;
81 if ( layerNode->layer()->isValid() )
82 currentValidSpatialLayerCount++;
86 bool firstLayers = mAutoSetupOnFirstLayer && !mHasLayersLoaded && currentSpatialLayerCount != 0;
87 bool firstValidLayers = mAutoSetupOnFirstLayer && !mHasValidLayersLoaded && currentValidSpatialLayerCount != 0;
90 if ( mOverviewCanvas )
91 mOverviewCanvas->
setLayers( overviewLayers );
93 if ( firstValidLayers )
104 if ( layerNode->layer() && layerNode->layer()->crs().isValid() )
106 mFirstCRS = layerNode->layer()->crs();
112 if ( mFirstCRS.
isValid() && firstLayers )
115 switch ( projectCrsBehavior )
130 mHasLayersLoaded = currentSpatialLayerCount;
131 mHasValidLayersLoaded = currentValidSpatialLayerCount;
132 if ( currentSpatialLayerCount == 0 )
135 mPendingCanvasUpdate =
false;
147 allLayers << nodeLayer->
layer();
149 canvasLayers << nodeLayer->
layer();
150 if ( nodeLayer->
customProperty( QStringLiteral(
"overview" ), 0 ).toInt() )
151 overviewLayers << nodeLayer->
layer();
155 const QList<QgsLayerTreeNode *> children = node->
children();
160 void QgsLayerTreeMapCanvasBridge::deferredSetCanvasLayers()
162 if ( mPendingCanvasUpdate )
165 mPendingCanvasUpdate =
true;
166 QMetaObject::invokeMethod(
this,
"setCanvasLayers", Qt::QueuedConnection );
169 void QgsLayerTreeMapCanvasBridge::nodeVisibilityChanged()
171 deferredSetCanvasLayers();
174 void QgsLayerTreeMapCanvasBridge::nodeCustomPropertyChanged(
QgsLayerTreeNode *node,
const QString &key )
177 if ( key == QLatin1String(
"overview" ) )
178 deferredSetCanvasLayers();
181 void QgsLayerTreeMapCanvasBridge::layersAdded(
const QList<QgsMapLayer *> &layers )
189 if ( l->isValid() && l->isSpatial() && mAutoSetupOnFirstLayer && !mHasValidLayersLoaded )
191 mHasValidLayersLoaded = true;
193 mCanvas->zoomToFullExtent();