QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
16 #ifndef QGSMAPLAYERREF_H
17 #define QGSMAPLAYERREF_H
33 template<
typename TYPE>
57 ,
layerId( l ? l->id() : QString() )
58 ,
source( l ? l->publicSource() : QString() )
60 ,
provider( l && l->dataProvider() ? l->dataProvider()->
name() : QString() )
81 layerId = l ? l->id() : QString();
82 source = l ? l->publicSource() : QString();
83 name = l ? l->name() : QString();
84 provider = l && l->dataProvider() ? l->dataProvider()->name() : QString();
93 return static_cast< bool >(
layer.data() );
152 if ( project && !
layerId.isEmpty() )
166 if ( matchType & MatchType::Name && (
layer->name().isEmpty() ||
layer->name() !=
name ) )
174 if ( matchType & MatchType::Provider &&
layer->providerType() !=
provider )
178 if ( matchType & MatchType::Source &&
layer->publicSource() !=
source )
219 QList<QgsMapLayer *> layers;
221 if ( matchType & MatchType::Name )
223 if (
name.isEmpty() )
233 for (
auto it = layers.constBegin(); it != layers.constEnd(); ++it )
235 if ( TYPE *tl = qobject_cast< TYPE *>( *it ) )
277 if ( project && !
name.isEmpty() )
282 if ( TYPE *tl = qobject_cast< TYPE *>( l ) )
297 #endif // QGSMAPLAYERREF_H
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.
bool layerMatchesWeakly(QgsMapLayer *layer, MatchType matchType=MatchType::All) const
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.
bool layerMatchesSource(QgsMapLayer *layer) const
Returns true if a layer matches the weak references to layer public source, layer name and data provi...
_LayerRef(TYPE *l=nullptr)
Constructor for a layer reference from an existing map layer.
@ Provider
Match layer name.
_LayerRef< QgsMapLayer > QgsMapLayerRef
TYPE * resolveByIdOrNameOnly(const QgsProject *project)
Resolves the map layer by attempting to find a matching layer in a project using a weak match.
@ Source
Match layer provider name.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
QPointer< TYPE > layer
Weak pointer to map layer.
TYPE * operator->() const
Forwards the to map layer.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
QString layerId
Original layer ID.
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
QString provider
Weak reference to layer provider.
_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...
QString name
Weak reference to layer name.
MatchType
Flag for match type in weak resolution.
QString source
Weak reference to layer public source.
Base class for all map layer types. This is the base class for all map layer types (vector,...
Internal structure to keep weak pointer to QgsMapLayer or layerId if the layer is not available yet.
TYPE * resolve(const QgsProject *project)
Resolves the map layer by attempting to find a layer with matching ID within a project.
TYPE * get() const
Returns a pointer to the layer, or nullptr if the reference has not yet been matched to a layer.