File tree 2 files changed +27
-2
lines changed
2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -191,7 +191,7 @@ void QgsMapLayerRegistry::reloadAllLayers()
191
191
}
192
192
}
193
193
194
- const QMap<QString, QgsMapLayer*>& QgsMapLayerRegistry::mapLayers ()
194
+ QMap<QString, QgsMapLayer*> QgsMapLayerRegistry::mapLayers ()
195
195
{
196
196
return mMapLayers ;
197
197
}
Original file line number Diff line number Diff line change @@ -50,7 +50,32 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject
50
50
QList<QgsMapLayer *> mapLayersByName ( const QString& layerName );
51
51
52
52
// ! Retrieve the mapLayers collection (mainly intended for use by projection)
53
- const QMap<QString, QgsMapLayer*> & mapLayers ();
53
+ QMap<QString, QgsMapLayer*> mapLayers ();
54
+
55
+ /* *
56
+ * Get map layers of a certain type.
57
+ *
58
+ * Example:
59
+ *
60
+ * QVector<QgsVectorLayer*> vectorLayers = QgsMapLayerRegistry::instance()->layers<QgsVectorLayer*>();
61
+ *
62
+ * @note not available in Python bindings
63
+ * @note added in QGIS 2.16
64
+ */
65
+ template <typename T>
66
+ QVector<T> layers () const
67
+ {
68
+ QVector<T> layers;
69
+ Q_FOREACH ( QgsMapLayer* layer, mMapLayers .values () )
70
+ {
71
+ T tLayer = qobject_cast<T>( layer );
72
+ if ( tLayer )
73
+ {
74
+ layers << tLayer;
75
+ }
76
+ }
77
+ return layers;
78
+ }
54
79
55
80
/* *
56
81
* @brief
You can’t perform that action at this time.
0 commit comments