template<typename TYPE>
_LayerRef struct

Internal structure to keep weak pointer to QgsMapLayer or layerId if the layer is not available yet.

Constructors, destructors, conversion operators

_LayerRef(TYPE* l = nullptr)
Constructor for a layer reference from an existing map layer.
_LayerRef(const QString& id, const QString& name = QString(), const QString& source = QString(), const QString& provider = QString())
Constructor for a weak layer reference, using a combination of layer ID, name, public source and provider key.
operator bool() const
Returns true if the layer reference is resolved and contains a reference to an existing map layer.

Public functions

auto get() const -> TYPE*
Returns a pointer to the layer, or nullptr if the reference has not yet been matched to a layer.
auto layerMatchesSource(QgsMapLayer* layer) const -> bool
Returns true if a layer matches the weak references to layer public source, layer name and data provider contained in this layer reference.
auto operator->() const -> TYPE*
Forwards the to map layer.
auto resolve(const QgsProject* project) -> TYPE*
Resolves the map layer by attempting to find a layer with matching ID within a project.
auto resolveWeakly(const QgsProject* project) -> TYPE*
Resolves the map layer by attempting to find a matching layer in a project using a weak match.
void setLayer(TYPE* l)
Sets the reference to point to a specified layer.

Public variables

QPointer<TYPE> layer
Weak pointer to map layer.
QString layerId
Original layer ID.
QString name
Weak reference to layer name.
QString provider
Weak reference to layer provider.
QString source
Weak reference to layer public source.

Function documentation

template<typename TYPE>
_LayerRef<TYPE>::_LayerRef(TYPE* l = nullptr)

Constructor for a layer reference from an existing map layer.

The layerId, source, name and provider members will automatically be populated from this layer.

template<typename TYPE>
bool _LayerRef<TYPE>::layerMatchesSource(QgsMapLayer* layer) const

Returns true if a layer matches the weak references to layer public source, layer name and data provider contained in this layer reference.

template<typename TYPE>
TYPE* _LayerRef<TYPE>::resolve(const QgsProject* project)

Resolves the map layer by attempting to find a layer with matching ID within a project.

If found, this reference will be updated to match the found layer and the layer will be returned. If no matching layer is found, a nullptr is returned.

template<typename TYPE>
TYPE* _LayerRef<TYPE>::resolveWeakly(const QgsProject* project)

Resolves the map layer by attempting to find a matching layer in a project using a weak match.

First, the layer is attempted to match to project layers using the layer's ID (calling this method implicitly calls resolve()).

Failing a match by layer ID, the layer will be matched by using the weak references to layer public source, layer name and data provider contained in this layer reference.

If a matching layer is found, this reference will be updated to match the found layer and the layer will be returned. If no matching layer is found, a nullptr is returned.