diff --git a/src/core/qgsmaplayerregistry.cpp b/src/core/qgsmaplayerregistry.cpp index 6a9cbe0ea14e..93f4fb535a31 100644 --- a/src/core/qgsmaplayerregistry.cpp +++ b/src/core/qgsmaplayerregistry.cpp @@ -191,7 +191,7 @@ void QgsMapLayerRegistry::reloadAllLayers() } } -const QMap& QgsMapLayerRegistry::mapLayers() +QMap QgsMapLayerRegistry::mapLayers() { return mMapLayers; } diff --git a/src/core/qgsmaplayerregistry.h b/src/core/qgsmaplayerregistry.h index f8e3f215113f..72ef3f07ce64 100644 --- a/src/core/qgsmaplayerregistry.h +++ b/src/core/qgsmaplayerregistry.h @@ -50,7 +50,32 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject QList mapLayersByName( const QString& layerName ); //! Retrieve the mapLayers collection (mainly intended for use by projection) - const QMap & mapLayers(); + QMap mapLayers(); + + /** + * Get map layers of a certain type. + * + * Example: + * + * QVector vectorLayers = QgsMapLayerRegistry::instance()->layers(); + * + * @note not available in Python bindings + * @note added in QGIS 2.16 + */ + template + QVector layers() const + { + QVector layers; + Q_FOREACH ( QgsMapLayer* layer, mMapLayers.values() ) + { + T tLayer = qobject_cast( layer ); + if ( tLayer ) + { + layers << tLayer; + } + } + return layers; + } /** * @brief