File tree Expand file tree Collapse file tree 4 files changed +29
-0
lines changed Expand file tree Collapse file tree 4 files changed +29
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1818#include " qgsapplegendinterface.h"
1919
2020#include " qgslegend.h"
21+ #include " qgslegendlayer.h"
2122#include " qgsmaplayer.h"
2223
2324QgsAppLegendInterface::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+
6178void QgsAppLegendInterface::refreshLayerSymbology ( QgsMapLayer *ml )
6279{
6380 mLegend ->refreshLayerSymbology ( ml->getLayerID () );
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments