Skip to content
Permalink
Browse files
implement currentLayer() and setCurrentLayer() in QgsLegendInterface …
…to set/get current layer
  • Loading branch information
etiennesky committed Jan 28, 2013
1 parent 42d637d commit 9bed789f2e22c3382f4797312d6fb5ec76581169
Showing with 40 additions and 0 deletions.
  1. +11 −0 python/gui/qgslegendinterface.sip
  2. +10 −0 src/app/legend/qgsapplegendinterface.cpp
  3. +3 −0 src/app/legend/qgsapplegendinterface.h
  4. +16 −0 src/gui/qgslegendinterface.h
@@ -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
@@ -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 );
}
@@ -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
@@ -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

0 comments on commit 9bed789

Please sign in to comment.