32 , mPendingCanvasUpdate( false )
33 , mAutoSetupOnFirstLayer( true )
34 , mLastLayerCount( !root->findLayers().isEmpty() )
45 QList<QgsMapLayer *> canvasLayers, overviewLayers, allLayerOrder;
57 allLayerOrder << nodeLayer->
layer();
59 canvasLayers << nodeLayer->
layer();
60 if ( nodeLayer->
customProperty( QStringLiteral(
"overview" ), 0 ).toInt() )
61 overviewLayers << nodeLayer->
layer();
68 const QList<QgsLayerTreeLayer *> layerNodes = mRoot->
findLayers();
69 int currentSpatialLayerCount = 0;
72 if ( layerNode->layer() && layerNode->layer()->isSpatial() )
73 currentSpatialLayerCount++;
76 bool firstLayers = mAutoSetupOnFirstLayer && mLastLayerCount == 0 && currentSpatialLayerCount != 0;
79 if ( mOverviewCanvas )
80 mOverviewCanvas->
setLayers( overviewLayers );
95 mFirstCRS = layerNode->
layer()->
crs();
101 if ( mFirstCRS.
isValid() && firstLayers )
104 switch ( projectCrsBehavior )
116 mLastLayerCount = currentSpatialLayerCount;
117 if ( currentSpatialLayerCount == 0 )
120 mPendingCanvasUpdate =
false;
132 allLayers << nodeLayer->
layer();
134 canvasLayers << nodeLayer->
layer();
135 if ( nodeLayer->
customProperty( QStringLiteral(
"overview" ), 0 ).toInt() )
136 overviewLayers << nodeLayer->
layer();
144 void QgsLayerTreeMapCanvasBridge::deferredSetCanvasLayers()
146 if ( mPendingCanvasUpdate )
149 mPendingCanvasUpdate =
true;
150 QMetaObject::invokeMethod(
this,
"setCanvasLayers", Qt::QueuedConnection );
153 void QgsLayerTreeMapCanvasBridge::nodeVisibilityChanged()
155 deferredSetCanvasLayers();
158 void QgsLayerTreeMapCanvasBridge::nodeCustomPropertyChanged(
QgsLayerTreeNode *node,
const QString &key )
161 if ( key == QLatin1String(
"overview" ) )
162 deferredSetCanvasLayers();
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
Base class for all map layer types.
This class is a composition of two QSettings instances:
Set the project CRS to the CRS of the first layer added to a new project.
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...
QgsMapLayer * layer() const
Returns the map layer associated with this node.
void layerOrderChanged()
Emitted when the layer order has changed.
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.
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of layers that should be shown in the canvas.
bool isVisible() const
Returns whether a node is really visible (ie checked and all its ancestors checked as well) ...
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
Namespace with helper functions for layer tree operations.
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes.
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.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
void setEllipsoid(const QString &ellipsoid)
Sets the project's ellipsoid from a proj string representation, e.g., "WGS84".
bool hasCustomLayerOrder() const
Determines if the layer order should be derived from the layer tree or if a custom override order sha...
QString ellipsoidAcronym() const
Returns the ellipsoid acronym for the ellipsoid used by the CRS.
void setLayers(const QList< QgsMapLayer * > &layers)
updates layer set for overview
QList< QgsMapLayer * > customLayerOrder() const
The order in which layers will be rendered on the canvas.
void canvasLayersChanged(const QList< QgsMapLayer * > &layers)
Emitted when the set of layers (or order of layers) visible in the canvas changes.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
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.
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).
Always set new projects to use a preset default CRS.
T enumValue(const QString &key, const T &defaultValue, const Section section=NoSection)
Returns the setting value for a setting based on an enum.
void customPropertyChanged(QgsLayerTreeNode *node, const QString &key)
Emitted when a custom property of a node within the tree has been changed or removed.
ProjectCrsBehavior
Defines the behavior to use when setting the CRS for a newly created project.
QgsLayerTreeLayer * findLayer(QgsMapLayer *layer) const
Find layer node representing the map layer.
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
QgsCoordinateReferenceSystem crs
Layer tree node points to a map layer.