Skip to content

Commit

Permalink
Do not emit currentLayerChanged signal if the layer has not changed
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Feb 14, 2014
1 parent edb0e5f commit 7e34bd9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/app/legend/qgslegend.cpp
Expand Up @@ -181,8 +181,9 @@ void QgsLegend::showItem( QString msg, QTreeWidgetItem *item )

void QgsLegend::handleCurrentItemChanged( QTreeWidgetItem* current, QTreeWidgetItem* previous )
{
Q_UNUSED( current );
Q_UNUSED( previous );
if ( legendLayerForItem( current ) == legendLayerForItem( previous ) )
return; // do not re-emit signal when not necessary

QgsMapLayer *layer = currentLayer();

if ( mMapCanvas )
Expand Down Expand Up @@ -1214,7 +1215,12 @@ void QgsLegend::setLayerVisible( QgsMapLayer * layer, bool visible )

QgsLegendLayer* QgsLegend::currentLegendLayer()
{
QgsLegendItem* citem = dynamic_cast<QgsLegendItem *>( currentItem() );
return legendLayerForItem( currentItem() );
}

QgsLegendLayer* QgsLegend::legendLayerForItem( QTreeWidgetItem* item )
{
QgsLegendItem* citem = dynamic_cast<QgsLegendItem *>( item );

if ( citem )
{
Expand Down
3 changes: 3 additions & 0 deletions src/app/legend/qgslegend.h
Expand Up @@ -115,6 +115,9 @@ class QgsLegend : public QTreeWidget
//! Destructor
~QgsLegend();

/** Returns QgsLegendLayer accosiated with given item */
QgsLegendLayer* legendLayerForItem( QTreeWidgetItem* item );

/** Returns QgsLegendLayer associated with current layer */
QgsLegendLayer* currentLegendLayer();

Expand Down

0 comments on commit 7e34bd9

Please sign in to comment.