Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[API] Add method to QgsMapLayerRegistry to get layers using name
  • Loading branch information
NathanW2 committed Jan 7, 2013
1 parent 1afd153 commit 7e29d7c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/core/qgsmaplayerregistry.sip
Expand Up @@ -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();

Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsmaplayerregistry.cpp
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsmaplayerregistry.h
Expand Up @@ -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();

Expand Down

0 comments on commit 7e29d7c

Please sign in to comment.