Skip to content

Commit 63429f0

Browse files
author
wonder
committed
Added QgsMapCanvas::layers() method
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12935 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e3a71fd commit 63429f0

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

python/gui/qgsmapcanvas.sip

+3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ class QgsMapCanvas : QGraphicsView
128128
//! return number of layers on the map
129129
int layerCount() const;
130130

131+
//! return list of layers within map canvas. Added in v1.5
132+
QList<QgsMapLayer*> layers() const;
133+
131134
/*! Freeze/thaw the map canvas. This is used to prevent the canvas from
132135
* responding to events while layers are being added/removed etc.
133136
* @param frz Boolean specifying if the canvas should be frozen (true) or

src/gui/qgsmapcanvas.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,18 @@ int QgsMapCanvas::layerCount() const
11641164
} // layerCount
11651165

11661166

1167+
QList<QgsMapLayer*> QgsMapCanvas::layers() const
1168+
{
1169+
QList<QgsMapLayer*> lst;
1170+
foreach ( QString layerID, mMapRenderer->layerSet() )
1171+
{
1172+
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerID );
1173+
if ( layer )
1174+
lst.append(layer);
1175+
}
1176+
return lst;
1177+
}
1178+
11671179

11681180
void QgsMapCanvas::layerStateChange()
11691181
{

src/gui/qgsmapcanvas.h

+3
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
185185
//! return number of layers on the map
186186
int layerCount() const;
187187

188+
//! return list of layers within map canvas. Added in v1.5
189+
QList<QgsMapLayer*> layers() const;
190+
188191
/*! Freeze/thaw the map canvas. This is used to prevent the canvas from
189192
* responding to events while layers are being added/removed etc.
190193
* @param frz Boolean specifying if the canvas should be frozen (true) or

0 commit comments

Comments
 (0)