Navigation Menu

Skip to content

Commit

Permalink
Applied patch #2492 provided by audun
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13048 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Mar 11, 2010
1 parent 01dcd47 commit 1142e94
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/app/legend/qgslegend.cpp
Expand Up @@ -538,6 +538,17 @@ void QgsLegend::addLayer( QgsMapLayer * layer )
doItemsLayout();
}

void QgsLegend::setMapCanvas( QgsMapCanvas * canvas )
{
if( mMapCanvas )
{
disconnect( mMapCanvas, SIGNAL( layersChanged() ) );
}

mMapCanvas = canvas;
connect( mMapCanvas, SIGNAL( layersChanged() ), this, SLOT( refreshCheckStates() ) );
}

QgsLegendLayer* QgsLegend::currentLegendLayer()
{
QgsLegendItem* citem = dynamic_cast<QgsLegendItem *>( currentItem() );
Expand Down Expand Up @@ -1746,3 +1757,22 @@ QTreeWidgetItem * QgsLegend::lastVisibleItem()
}
return current;
}

void QgsLegend::refreshCheckStates()
{
if( !mMapCanvas )
{
return;
}

QList<QgsMapLayer*> lst = mMapCanvas->layers();
for ( QTreeWidgetItem* item = firstItem(); item; item = nextItem( item ) )
{
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( item );
if ( ll )
{
ll->setCheckState( 0, ( lst.contains( ll->layer() ) ? Qt::Checked : Qt::Unchecked ) );
}
}
}

4 changes: 3 additions & 1 deletion src/app/legend/qgslegend.h
Expand Up @@ -187,7 +187,7 @@ class QgsLegend : public QTreeWidget
/*!Adds a new layer group with the maplayer to the canvas*/
void addLayer( QgsMapLayer * layer );

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

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

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

/*!Event handler for mouse movements.
Expand Down

0 comments on commit 1142e94

Please sign in to comment.