[QGIS Commit] r13048 - trunk/qgis/src/app/legend
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Thu Mar 11 12:37:14 EST 2010
Author: mhugent
Date: 2010-03-11 12:37:13 -0500 (Thu, 11 Mar 2010)
New Revision: 13048
Modified:
trunk/qgis/src/app/legend/qgslegend.cpp
trunk/qgis/src/app/legend/qgslegend.h
Log:
Applied patch #2492 provided by audun
Modified: trunk/qgis/src/app/legend/qgslegend.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.cpp 2010-03-11 13:31:59 UTC (rev 13047)
+++ trunk/qgis/src/app/legend/qgslegend.cpp 2010-03-11 17:37:13 UTC (rev 13048)
@@ -538,6 +538,17 @@
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 @@
}
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 ) );
+ }
+ }
+}
+
Modified: trunk/qgis/src/app/legend/qgslegend.h
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.h 2010-03-11 13:31:59 UTC (rev 13047)
+++ trunk/qgis/src/app/legend/qgslegend.h 2010-03-11 17:37:13 UTC (rev 13048)
@@ -187,7 +187,7 @@
/*!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 @@
/**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.
More information about the QGIS-commit
mailing list