16 #ifndef QGSMAPLAYERREF_H 17 #define QGSMAPLAYERREF_H 32 template<
typename TYPE>
43 ,
layerId( l ? l->id() : QString() )
44 ,
source( l ? l->publicSource() : QString() )
46 ,
provider( l && l->dataProvider() ? l->dataProvider()->
name() : QString() )
67 layerId = l ? l->id() : QString();
68 source = l ? l->publicSource() : QString();
69 name = l ? l->name() : QString();
70 provider = l && l->dataProvider() ? l->dataProvider()->name() : QString();
79 return static_cast< bool >(
layer.data() );
138 if ( project && !layerId.isEmpty() )
140 if ( TYPE *l = qobject_cast<TYPE *>( project->
mapLayer( layerId ) ) )
173 if ( project && !name.isEmpty() )
178 if ( TYPE *tl = qobject_cast< TYPE *>( l ) )
220 if ( project && !name.isEmpty() )
225 if ( TYPE *tl = qobject_cast< TYPE *>( l ) )
240 #endif // QGSMAPLAYERREF_H Base class for all map layer types.
Internal structure to keep weak pointer to QgsMapLayer or layerId if the layer is not available yet...
_LayerRef< QgsMapLayer > QgsMapLayerRef
bool layerMatchesSource(QgsMapLayer *layer) const
Returns true if a layer matches the weak references to layer public source, layer name and data provi...
TYPE * resolveByIdOrNameOnly(const QgsProject *project)
Resolves the map layer by attempting to find a matching layer in a project using a weak match...
TYPE * operator->() const
Forwards the to map layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
TYPE * resolveWeakly(const QgsProject *project)
Resolves the map layer by attempting to find a matching layer in a project using a weak match...
_LayerRef(TYPE *l=nullptr)
Constructor for a layer reference from an existing map layer.
QString provider
Weak reference to layer provider.
QString layerId
Original layer ID.
QPointer< TYPE > layer
Weak pointer to map layer.
QString name
Weak reference to layer name.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example...
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
QString source
Weak reference to layer public source.
QList< QgsMapLayer * > mapLayersByName(const QString &layerName) const
Retrieve a list of matching registered layers by layer name.
_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 prov...
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
TYPE * resolve(const QgsProject *project)
Resolves the map layer by attempting to find a layer with matching ID within a project.