16 #ifndef QGSMAPLAYERREF_H
17 #define QGSMAPLAYERREF_H
32 template<
typename TYPE>
56 ,
layerId( l ? l->id() : QString() )
57 ,
source( l ? l->publicSource() : QString() )
59 ,
provider( l && l->dataProvider() ? l->dataProvider()->
name() : QString() )
80 layerId = l ? l->id() : QString();
81 source = l ? l->publicSource() : QString();
82 name = l ? l->name() : QString();
83 provider = l && l->dataProvider() ? l->dataProvider()->name() : QString();
92 return static_cast< bool >(
layer.data() );
151 if ( project && !
layerId.isEmpty() )
165 if ( matchType & MatchType::Name && (
layer->name().isEmpty() ||
layer->name() !=
name ) )
173 if ( matchType & MatchType::Provider &&
layer->providerType() !=
provider )
177 if ( matchType & MatchType::Source &&
layer->publicSource() !=
source )
218 QList<QgsMapLayer *> layers;
220 if ( matchType & MatchType::Name )
222 if (
name.isEmpty() )
234 if ( TYPE *tl = qobject_cast< TYPE *>( l ) )
276 if ( project && !
name.isEmpty() )
281 if ( TYPE *tl = qobject_cast< TYPE *>( l ) )
Base class for all map layer types.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
QList< QgsMapLayer * > mapLayersByName(const QString &layerName) const
Retrieve a list of matching registered layers by layer name.
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
_LayerRef< QgsMapLayer > QgsMapLayerRef
Internal structure to keep weak pointer to QgsMapLayer or layerId if the layer is not available yet.
TYPE * resolveByIdOrNameOnly(const QgsProject *project)
Resolves the map layer by attempting to find a matching layer in a project using a weak match.
_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...
_LayerRef(TYPE *l=nullptr)
Constructor for a layer reference from an existing map layer.
MatchType
Flag for match type in weak resolution.
@ Provider
Match layer name.
@ Source
Match layer provider name.
QString source
Weak reference to layer public source.
QString name
Weak reference to layer name.
TYPE * operator->() const
Forwards the to map layer.
TYPE * get() const
Returns a pointer to the layer, or nullptr if the reference has not yet been matched to a layer.
TYPE * resolve(const QgsProject *project)
Resolves the map layer by attempting to find a layer with matching ID within a project.
bool layerMatchesWeakly(QgsMapLayer *layer, MatchType matchType=MatchType::All)
QString provider
Weak reference to layer provider.
bool layerMatchesSource(QgsMapLayer *layer) const
Returns true if a layer matches the weak references to layer public source, layer name and data provi...
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.
QPointer< TYPE > layer
Weak pointer to map layer.
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
QString layerId
Original layer ID.