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 ) ) )
172 if ( project && !name.isEmpty() )
177 if ( TYPE *tl = qobject_cast< TYPE *>( l ) )
193 #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
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example...
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider.
TYPE * resolveWeakly(const QgsProject *project)
Resolves the map layer by attempting to find a matching layer in a project using a weak match...
virtual QString name() const =0
Returns a provider name.
_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.
bool layerMatchesSource(QgsMapLayer *layer) const
Returns true if a layer matches the weak references to layer public source, layer name and data provi...
QPointer< TYPE > layer
Weak pointer to map layer.
TYPE * operator->() const
Forwards the to map layer.
QString name
Weak reference to layer name.
Reads and writes project states.
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...
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.