diff --git a/python/gui/qgslegendinterface.sip b/python/gui/qgslegendinterface.sip index d68c57e1a2d..a93cb464f6c 100644 --- a/python/gui/qgslegendinterface.sip +++ b/python/gui/qgslegendinterface.sip @@ -68,6 +68,17 @@ class QgsLegendInterface : QObject */ virtual bool removeLegendLayerAction( QAction* action ) = 0; + //! Returns the current layer if the current item is a QgsLegendLayer. + //! If the current item is a QgsLegendLayer, its first maplayer is returned. + //! Else, 0 is returned. + //! @note Added in 2.0 + virtual QgsMapLayer* currentLayer() = 0; + + //! set the current layer + //! returns true if the layer exists, false otherwise + //! @note Added in 2.0 + virtual bool setCurrentLayer( QgsMapLayer *layer ) = 0; + signals: //! emitted when a group index has changed diff --git a/src/app/legend/qgsapplegendinterface.cpp b/src/app/legend/qgsapplegendinterface.cpp index 70c3777ea69..abe0020acc8 100644 --- a/src/app/legend/qgsapplegendinterface.cpp +++ b/src/app/legend/qgsapplegendinterface.cpp @@ -30,6 +30,7 @@ QgsAppLegendInterface::QgsAppLegendInterface( QgsLegend * legend ) connect( legend, SIGNAL( itemMovedGroup( QgsLegendItem *, int ) ), this, SIGNAL( groupRelationsChanged() ) ); // connect( legend, SIGNAL( itemChanged( QTreeWidgetItem*, int ) ), this, SIGNAL( groupRelationsChanged() ) ); connect( legend, SIGNAL( itemRemoved() ), this, SIGNAL( itemRemoved() ) ); + connect( legend, SIGNAL( currentLayerChanged( QgsMapLayer * ) ), this, SIGNAL( currentLayerChanged( QgsMapLayer * ) ) ); } QgsAppLegendInterface::~QgsAppLegendInterface() @@ -208,3 +209,12 @@ bool QgsAppLegendInterface::removeLegendLayerAction( QAction* action ) return mLegend->removeLegendLayerAction( action ); } +QgsMapLayer* QgsAppLegendInterface::currentLayer() +{ + return mLegend->currentLayer(); +} + +bool QgsAppLegendInterface::setCurrentLayer( QgsMapLayer *layer ) +{ + return mLegend->setCurrentLayer( layer ); +} diff --git a/src/app/legend/qgsapplegendinterface.h b/src/app/legend/qgsapplegendinterface.h index 5ea7f024a37..ff031af2a80 100644 --- a/src/app/legend/qgsapplegendinterface.h +++ b/src/app/legend/qgsapplegendinterface.h @@ -72,6 +72,9 @@ class QgsAppLegendInterface : public QgsLegendInterface void addLegendLayerActionForLayer( QAction* action, QgsMapLayer* layer ); bool removeLegendLayerAction( QAction* action ); + QgsMapLayer* currentLayer(); + bool setCurrentLayer( QgsMapLayer *layer ); + public slots: //! Add a new group diff --git a/src/gui/qgslegendinterface.h b/src/gui/qgslegendinterface.h index b7035ef193d..986306c72ba 100644 --- a/src/gui/qgslegendinterface.h +++ b/src/gui/qgslegendinterface.h @@ -103,6 +103,17 @@ class GUI_EXPORT QgsLegendInterface : public QObject */ virtual bool removeLegendLayerAction( QAction* action ) = 0; + //! Returns the current layer if the current item is a QgsLegendLayer. + //! If the current item is a QgsLegendLayer, its first maplayer is returned. + //! Else, 0 is returned. + //! @note Added in 2.0 + virtual QgsMapLayer* currentLayer() = 0; + + //! set the current layer + //! returns true if the layer exists, false otherwise + //! @note Added in 2.0 + virtual bool setCurrentLayer( QgsMapLayer *layer ) = 0; + signals: //! emitted when a group index has changed @@ -117,6 +128,11 @@ class GUI_EXPORT QgsLegendInterface : public QObject /* //! emitted when an item (group/layer) is removed */ void itemRemoved( ); + //! Emitted whenever current (selected) layer changes + // the pointer to layer can be null if no layer is selected + //! @note Added in 2.0 + void currentLayerChanged( QgsMapLayer * layer ); + public slots: //! Add a new group