Skip to content

Commit

Permalink
implement currentLayer() and setCurrentLayer() in QgsLegendInterface …
Browse files Browse the repository at this point in the history
…to set/get current layer
  • Loading branch information
etiennesky committed Jan 28, 2013
1 parent 42d637d commit 9bed789
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
11 changes: 11 additions & 0 deletions python/gui/qgslegendinterface.sip
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/app/legend/qgsapplegendinterface.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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 );
}
3 changes: 3 additions & 0 deletions src/app/legend/qgsapplegendinterface.h
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/gui/qgslegendinterface.h
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9bed789

Please sign in to comment.