Skip to content

Commit 1142e94

Browse files
author
mhugent
committedMar 11, 2010
Applied patch #2492 provided by audun
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13048 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 01dcd47 commit 1142e94

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
 

‎src/app/legend/qgslegend.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,17 @@ void QgsLegend::addLayer( QgsMapLayer * layer )
538538
doItemsLayout();
539539
}
540540

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+
541552
QgsLegendLayer* QgsLegend::currentLegendLayer()
542553
{
543554
QgsLegendItem* citem = dynamic_cast<QgsLegendItem *>( currentItem() );
@@ -1746,3 +1757,22 @@ QTreeWidgetItem * QgsLegend::lastVisibleItem()
17461757
}
17471758
return current;
17481759
}
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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class QgsLegend : public QTreeWidget
187187
/*!Adds a new layer group with the maplayer to the canvas*/
188188
void addLayer( QgsMapLayer * layer );
189189

190-
void setMapCanvas( QgsMapCanvas * canvas ) {mMapCanvas = canvas;}
190+
void setMapCanvas( QgsMapCanvas * canvas );
191191

192192
/**Updates symbology items for a layer*/
193193
void refreshLayerSymbology( QString key, bool expandItem = true );
@@ -265,6 +265,8 @@ class QgsLegend : public QTreeWidget
265265
/**Shows the property dialog of the first legend layer file in a legend layer*/
266266
void legendLayerShowProperties();
267267

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

270272
/*!Event handler for mouse movements.

0 commit comments

Comments
 (0)