30 , mPendingCanvasUpdate( false )
31 , mAutoSetupOnFirstLayer( true )
32 , mHasLayersLoaded( !root->findLayers().isEmpty() )
43 QList<QgsMapLayer *> canvasLayers, overviewLayers, allLayerOrder;
48 for (
const QgsMapLayer *layer : customOrderLayers )
56 allLayerOrder << nodeLayer->
layer();
58 canvasLayers << nodeLayer->
layer();
59 if ( nodeLayer->
customProperty( QStringLiteral(
"overview" ), 0 ).toInt() )
60 overviewLayers << nodeLayer->
layer();
69 const QList<QgsLayerTreeLayer *> layerNodes = mRoot->
findLayers();
70 int currentSpatialLayerCount = 0;
73 if ( layerNode->layer() && layerNode->layer()->isSpatial() )
74 currentSpatialLayerCount++;
77 bool firstLayers = mAutoSetupOnFirstLayer && !mHasLayersLoaded && currentSpatialLayerCount != 0;
80 if ( mOverviewCanvas )
81 mOverviewCanvas->
setLayers( overviewLayers );
94 if ( layerNode->layer() && layerNode->layer()->crs().isValid() )
96 mFirstCRS = layerNode->layer()->crs();
102 if ( mFirstCRS.
isValid() && firstLayers )
107 mHasLayersLoaded = currentSpatialLayerCount;
108 if ( currentSpatialLayerCount == 0 )
111 mPendingCanvasUpdate =
false;
123 allLayers << nodeLayer->
layer();
125 canvasLayers << nodeLayer->
layer();
126 if ( nodeLayer->
customProperty( QStringLiteral(
"overview" ), 0 ).toInt() )
127 overviewLayers << nodeLayer->
layer();
131 const QList<QgsLayerTreeNode *> children = node->
children();
136 void QgsLayerTreeMapCanvasBridge::deferredSetCanvasLayers()
138 if ( mPendingCanvasUpdate )
141 mPendingCanvasUpdate =
true;
142 QMetaObject::invokeMethod(
this,
"setCanvasLayers", Qt::QueuedConnection );
145 void QgsLayerTreeMapCanvasBridge::nodeVisibilityChanged()
147 deferredSetCanvasLayers();
150 void QgsLayerTreeMapCanvasBridge::nodeCustomPropertyChanged(
QgsLayerTreeNode *node,
const QString &key )
153 if ( key == QLatin1String(
"overview" ) )
154 deferredSetCanvasLayers();
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
Base class for all map layer types.
void layerOrderChanged()
Emitted when the layer order has changed.
bool isVisible() const
Returns whether a node is really visible (ie checked and all its ancestors checked as well) ...
Q_INVOKABLE void setCanvasLayers()
force update of canvas layers from the layer tree. Normally this should not be needed to be called...
Map canvas is a class for displaying all GIS data types on a canvas.
QList< QgsMapLayer * > customLayerOrder() const
The order in which layers will be rendered on the canvas.
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
Namespace with helper functions for layer tree operations.
void setLayers(const QList< QgsMapLayer *> &layers)
updates layer set for overview
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer. Properties are stored in a map and saved in project file...
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the project's native coordinate reference system.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
This class is a base class for nodes in a layer tree.
bool hasCustomLayerOrder() const
Determines if the layer order should be derived from the layer tree or if a custom override order sha...
void canvasLayersChanged(const QList< QgsMapLayer * > &layers)
Emitted when the set of layers (or order of layers) visible in the canvas changes.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
QgsLayerTreeMapCanvasBridge(QgsLayerTree *root, QgsMapCanvas *canvas, QObject *parent=nullptr)
Constructor: does not take ownership of the layer tree nor canvas.
void visibilityChanged(QgsLayerTreeNode *node)
Emitted when check state of a node within the tree has been changed.
void setLayers(const QList< QgsMapLayer *> &layers)
Sets the list of layers that should be shown in the canvas.
static QgsProject * instance()
Returns the QgsProject singleton instance.
void zoomToFullExtent()
Zoom to the full extent of all layers.
This class represents a coordinate reference system (CRS).
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes.
QgsLayerTreeLayer * findLayer(QgsMapLayer *layer) const
Find layer node representing the map layer.
void customPropertyChanged(QgsLayerTreeNode *node, const QString &key)
Emitted when a custom property of a node within the tree has been changed or removed.
Layer tree node points to a map layer.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.