Skip to content
Permalink
Browse files
Do not emit currentLayerChanged signal if the layer has not changed
  • Loading branch information
wonder-sk committed Feb 14, 2014
1 parent edb0e5f commit 7e34bd901fdaef002fb4eb2cdcc0c7cd9e4aa016
Showing with 12 additions and 3 deletions.
  1. +9 −3 src/app/legend/qgslegend.cpp
  2. +3 −0 src/app/legend/qgslegend.h
@@ -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 )
@@ -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 )
{
@@ -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();

0 comments on commit 7e34bd9

Please sign in to comment.