QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | List of all members
_LayerRef< TYPE > Struct Template Reference

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

#include <qgsmaplayerref.h>

Public Types

enum  MatchType { Name = 1 << 2 , Provider = 1 << 3 , Source = 1 << 4 , All = Provider | Source }
 Flag for match type in weak resolution. More...
 

Public Member Functions

 _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.
 
 _LayerRef (TYPE *l=nullptr)
 Constructor for a layer reference from an existing map layer.
 
TYPE * get () const
 Returns a pointer to the layer, or nullptr if the reference has not yet been matched to a layer.
 
bool 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.
 
bool layerMatchesWeakly (QgsMapLayer *layer, MatchType matchType=MatchType::All) const
 
 operator bool () const
 Returns true if the layer reference is resolved and contains a reference to an existing map layer.
 
TYPE * operator-> () const
 Forwards the to map layer.
 
bool readXml (const QDomElement &element, const QgsReadWriteContext &context)
 Reads the layer's properties from an XML element.
 
TYPE * resolve (const QgsProject *project)
 Resolves the map layer by attempting to find a layer with matching ID within a project.
 
TYPE * resolveByIdOrNameOnly (const QgsProject *project)
 Resolves the map layer by attempting to find a matching layer in a project using a weak match.
 
TYPE * resolveWeakly (const QgsProject *project, MatchType matchType=MatchType::All)
 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.
 
void writeXml (QDomElement &element, const QgsReadWriteContext &context) const
 Writes the layer's properties to a XML element.
 

Public Attributes

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.
 

Detailed Description

template<typename TYPE>
struct _LayerRef< TYPE >

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

Note
not available in Python bindings

Definition at line 35 of file qgsmaplayerref.h.

Member Enumeration Documentation

◆ MatchType

template<typename TYPE >
enum _LayerRef::MatchType

Flag for match type in weak resolution.

Since
QGIS 3.12
Enumerator
Name 
Provider 

Match layer name.

Source 

Match layer provider name.

All 

Match layer source.

Match all

Definition at line 42 of file qgsmaplayerref.h.

Constructor & Destructor Documentation

◆ _LayerRef() [1/2]

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

Constructor for a layer reference from an existing map layer.

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

Definition at line 56 of file qgsmaplayerref.h.

◆ _LayerRef() [2/2]

template<typename TYPE >
_LayerRef< TYPE >::_LayerRef ( const QString &  id,
const QString &  name = QString(),
const QString &  source = QString(),
const QString &  provider = QString() 
)
inline

Constructor for a weak layer reference, using a combination of layer ID, name, public source and provider key.

Definition at line 68 of file qgsmaplayerref.h.

Member Function Documentation

◆ get()

template<typename TYPE >
TYPE * _LayerRef< TYPE >::get ( ) const
inline

Returns a pointer to the layer, or nullptr if the reference has not yet been matched to a layer.

Definition at line 109 of file qgsmaplayerref.h.

◆ layerMatchesSource()

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

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

See also
resolveWeakly()

Definition at line 132 of file qgsmaplayerref.h.

◆ layerMatchesWeakly()

template<typename TYPE >
bool _LayerRef< TYPE >::layerMatchesWeakly ( QgsMapLayer layer,
MatchType  matchType = MatchType::All 
) const
inline

Definition at line 164 of file qgsmaplayerref.h.

◆ operator bool()

template<typename TYPE >
_LayerRef< TYPE >::operator bool ( ) const
inline

Returns true if the layer reference is resolved and contains a reference to an existing map layer.

Definition at line 92 of file qgsmaplayerref.h.

◆ operator->()

template<typename TYPE >
TYPE * _LayerRef< TYPE >::operator-> ( ) const
inline

Forwards the to map layer.

Definition at line 100 of file qgsmaplayerref.h.

◆ readXml()

template<typename TYPE >
bool _LayerRef< TYPE >::readXml ( const QDomElement &  element,
const QgsReadWriteContext context 
)
inline

Reads the layer's properties from an XML element.

See also
writeXml()
Since
QGIS 3.30

Definition at line 299 of file qgsmaplayerref.h.

◆ resolve()

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

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, nullptr is returned.

See also
resolveWeakly()

Definition at line 151 of file qgsmaplayerref.h.

◆ resolveByIdOrNameOnly()

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

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.

Failing a match by weak reference, the layer will be matched by using the name only.

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, nullptr is returned.

See also
resolve()
layerMatchesSource()
resolveWeakly()
Since
QGIS 3.8

Definition at line 271 of file qgsmaplayerref.h.

◆ resolveWeakly()

template<typename TYPE >
TYPE * _LayerRef< TYPE >::resolveWeakly ( const QgsProject project,
MatchType  matchType = MatchType::All 
)
inline

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.

The matchType enum can used to refine the matching criteria when using the weak reference and include layer name, provider name and layer source in the equality test, by default they are all checked.

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, nullptr is returned.

See also
resolve()
layerMatchesSource()
layerMatchesWeakly()
resolveByIdOrNameOnly()

Definition at line 212 of file qgsmaplayerref.h.

◆ setLayer()

template<typename TYPE >
void _LayerRef< TYPE >::setLayer ( TYPE *  l)
inline

Sets the reference to point to a specified layer.

Definition at line 79 of file qgsmaplayerref.h.

◆ writeXml()

template<typename TYPE >
void _LayerRef< TYPE >::writeXml ( QDomElement &  element,
const QgsReadWriteContext context 
) const
inline

Writes the layer's properties to a XML element.

See also
readXml()
Since
QGIS 3.30

Definition at line 316 of file qgsmaplayerref.h.

Member Data Documentation

◆ layer

template<typename TYPE >
QPointer<TYPE> _LayerRef< TYPE >::layer

Weak pointer to map layer.

Definition at line 115 of file qgsmaplayerref.h.

◆ layerId

template<typename TYPE >
QString _LayerRef< TYPE >::layerId

Original layer ID.

Definition at line 118 of file qgsmaplayerref.h.

◆ name

template<typename TYPE >
QString _LayerRef< TYPE >::name

Weak reference to layer name.

Definition at line 123 of file qgsmaplayerref.h.

◆ provider

template<typename TYPE >
QString _LayerRef< TYPE >::provider

Weak reference to layer provider.

Definition at line 125 of file qgsmaplayerref.h.

◆ source

template<typename TYPE >
QString _LayerRef< TYPE >::source

Weak reference to layer public source.

Definition at line 121 of file qgsmaplayerref.h.


The documentation for this struct was generated from the following file: