Skip to content
Permalink
Browse files

Applied patch #2492 provided by audun

git-svn-id: http://svn.osgeo.org/qgis/trunk@13048 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Mar 11, 2010
1 parent 3b1e66b commit d80c2f5588a163c015fa4fd058afb61479979de3
Showing with 33 additions and 1 deletion.
  1. +30 −0 src/app/legend/qgslegend.cpp
  2. +3 −1 src/app/legend/qgslegend.h
@@ -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() );
@@ -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 ) );
}
}
}

@@ -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 );
@@ -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.

0 comments on commit d80c2f5

Please sign in to comment.
You can’t perform that action at this time.