checkstateupdate.patch

Proposed fix - audun -, 2010-03-06 10:12 AM

Download (1.91 KB)

View differences:

src/app/legend/qgslegend.cpp Sat Mar 06 16:26:59 2010 +0100
538 538
  doItemsLayout();
539 539
}
540 540

  
541
void QgsLegend::setMapCanvas( QgsMapCanvas * canvas )
542
{
543
  if( mMapCanvas ) 
544
  {
545
    disconnect( mMapCanvas, SIGNAL( layersChanged() ) );
546
  }
547

  
548
  mMapCanvas = canvas;
549
  connect( mMapCanvas, SIGNAL( layersChanged() ), this, SLOT( refreshCheckStates() ) );
550
}
551

  
541 552
QgsLegendLayer* QgsLegend::currentLegendLayer()
542 553
{
543 554
  QgsLegendItem* citem = dynamic_cast<QgsLegendItem *>( currentItem() );
......
1746 1757
  }
1747 1758
  return current;
1748 1759
}
1760

  
1761
void QgsLegend::refreshCheckStates()
1762
{
1763
  if( !mMapCanvas )
1764
  {
1765
    return;
1766
  }
1767

  
1768
  QList<QgsMapLayer*> lst = mMapCanvas->layers();
1769
  for ( QTreeWidgetItem* item = firstItem(); item; item = nextItem( item ) ) 
1770
  {
1771
    QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( item );
1772
    if ( ll ) 
1773
    {
1774
      ll->setCheckState( 0, ( lst.contains( ll->layer() ) ? Qt::Checked : Qt::Unchecked ) );
1775
    }
1776
  }
1777
}
1778

  
src/app/legend/qgslegend.h Sat Mar 06 16:26:59 2010 +0100
187 187
    /*!Adds a new layer group with the maplayer to the canvas*/
188 188
    void addLayer( QgsMapLayer * layer );
189 189

  
190
    void setMapCanvas( QgsMapCanvas * canvas ) {mMapCanvas = canvas;}
190
    void setMapCanvas( QgsMapCanvas * canvas );
191 191

  
192 192
    /**Updates symbology items for a layer*/
193 193
    void refreshLayerSymbology( QString key, bool expandItem = true );
......
265 265
    /**Shows the property dialog of the first legend layer file in a legend layer*/
266 266
    void legendLayerShowProperties();
267 267

  
268
    /**Updates check states when the map canvas layer set is changed */
269
    void refreshCheckStates();
268 270
  protected:
269 271

  
270 272
    /*!Event handler for mouse movements.