Skip to content

Commit 6fc3dc0

Browse files
author
jef
committed
[FEATURE] legend interface added to retrieve layers in legend order (supplied by Maxim Dubinin)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13264 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a049be1 commit 6fc3dc0

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

python/gui/qgslegendinterface.sip

+5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ class QgsLegendInterface : QObject
1616
/** Virtual destructor */
1717
~QgsLegendInterface();
1818

19+
//! Return a string list of groups
1920
virtual QStringList groups() =0;
2021

22+
//! Return all layers in the project in legend order
23+
//! @note added in 1.5
24+
virtual QList< QgsMapLayer * > layers() const = 0;
25+
2126
signals:
2227

2328
//! emitted when a group index has changed

src/app/legend/qgsapplegendinterface.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgsapplegendinterface.h"
1919

2020
#include "qgslegend.h"
21+
#include "qgslegendlayer.h"
2122
#include "qgsmaplayer.h"
2223

2324
QgsAppLegendInterface::QgsAppLegendInterface( QgsLegend * legend )
@@ -58,6 +59,22 @@ QStringList QgsAppLegendInterface::groups()
5859
return mLegend->groups();
5960
}
6061

62+
QList< QgsMapLayer * > QgsAppLegendInterface::layers() const
63+
{
64+
QList< QgsMapLayer * > items;
65+
QTreeWidgetItemIterator it( mLegend );
66+
while ( *it )
67+
{
68+
QgsLegendLayer *llayer = dynamic_cast<QgsLegendLayer *>( *it );
69+
if ( llayer )
70+
items.append( llayer->layer() );
71+
72+
++it;
73+
}
74+
75+
return items;
76+
}
77+
6178
void QgsAppLegendInterface::refreshLayerSymbology( QgsMapLayer *ml )
6279
{
6380
mLegend->refreshLayerSymbology( ml->getLayerID() );

src/app/legend/qgsapplegendinterface.h

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class QgsAppLegendInterface : public QgsLegendInterface
4444
//! Return a string list of groups
4545
QStringList groups();
4646

47+
//! Return all layers in the project in legend order
48+
QList< QgsMapLayer * > layers() const;
49+
4750
public slots:
4851

4952
//! Add a new group

src/gui/qgslegendinterface.h

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class GUI_EXPORT QgsLegendInterface : public QObject
4444
//! Return a string list of groups
4545
virtual QStringList groups() = 0;
4646

47+
//! Return all layers in the project in legend order
48+
//! @note added in 1.5
49+
virtual QList< QgsMapLayer * > layers() const = 0;
50+
4751
signals:
4852

4953
//! emitted when a group index has changed

0 commit comments

Comments
 (0)