Skip to content
Permalink
Browse files
[API] Add method to QgsMapLayerRegistry to get layers using name
  • Loading branch information
NathanW2 committed Jan 7, 2013
1 parent 1afd153 commit 7e29d7ced11eed0e631d49969b6916a07de2f407
Showing with 19 additions and 0 deletions.
  1. +3 −0 python/core/qgsmaplayerregistry.sip
  2. +13 −0 src/core/qgsmaplayerregistry.cpp
  3. +3 −0 src/core/qgsmaplayerregistry.h
@@ -22,6 +22,9 @@ class QgsMapLayerRegistry : QObject
//! Retrieve a pointer to a loaded layer by id
QgsMapLayer *mapLayer( QString theLayerId );

//! Retrieve all layers using their name
QList<QgsMapLayer *> mapLayersByName( QString layerName );

//! Retrieve the mapLayers collection (mainly intended for use by projection)
QMap<QString, QgsMapLayer*> & mapLayers();

@@ -57,6 +57,19 @@ QgsMapLayer * QgsMapLayerRegistry::mapLayer( QString theLayerId )
return mMapLayers.value( theLayerId );
}

QList<QgsMapLayer *> QgsMapLayerRegistry::mapLayersByName( QString layerName )
{
QList<QgsMapLayer *> myResultList;
foreach ( QgsMapLayer* layer, mMapLayers )
{
if ( layer->name() == layerName )
{
myResultList << layer;
}
}
return myResultList;
}

//introduced in 1.8
QList<QgsMapLayer *> QgsMapLayerRegistry::addMapLayers(
QList<QgsMapLayer *> theMapLayers,
@@ -45,6 +45,9 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject
//! Retrieve a pointer to a loaded layer by id
QgsMapLayer *mapLayer( QString theLayerId );

//! Retrieve a pointer to a loaded layer by name
QList<QgsMapLayer *> mapLayersByName( QString layerName );

//! Retrieve the mapLayers collection (mainly intended for use by projection)
QMap<QString, QgsMapLayer*> & mapLayers();

0 comments on commit 7e29d7c

Please sign in to comment.