implement currentLayer() and setCurrentLayer() in QgsLegendInterface to set/get current layer

This commit is contained in:
Etienne Tourigny 2013-01-28 18:18:25 -02:00
parent 42d637d9a0
commit 9bed789f2e
4 changed files with 40 additions and 0 deletions

View File

@ -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

View File

@ -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 );
}

View File

@ -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

View File

@ -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