Skip to content

Commit addea8a

Browse files
author
g_j_m
committedApr 23, 2006
Fix for ticket #94
Toggling all the layers on or off is now delegated to the legend, rather than being done QgisApp git-svn-id: http://svn.osgeo.org/qgis/trunk@5348 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent cb6e724 commit addea8a

File tree

3 files changed

+21
-34
lines changed

3 files changed

+21
-34
lines changed
 

‎src/gui/qgisapp.cpp

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3073,27 +3073,11 @@ void QgisApp::removeAllFromOverview()
30733073
//reimplements method from base (gui) class
30743074
void QgisApp::hideAllLayers()
30753075
{
3076-
// what's the point if we don't have any layers?
3077-
if ( QgsMapLayerRegistry::instance()->mapLayers().empty() )
3078-
{
3079-
return;
3080-
}
3081-
30823076
#ifdef QGISDEBUG
30833077
std::cout << "hiding all layers!" << std::endl;
30843078
#endif
30853079

3086-
mMapCanvas->freeze(true);
3087-
std::map<QString, QgsMapLayer *> myMapLayers = QgsMapLayerRegistry::instance()->mapLayers();
3088-
std::map<QString, QgsMapLayer *>::iterator myMapIterator;
3089-
for ( myMapIterator = myMapLayers.begin(); myMapIterator != myMapLayers.end(); ++myMapIterator )
3090-
{
3091-
QgsMapLayer * myMapLayer = myMapIterator->second;
3092-
myMapLayer->setVisible(false);
3093-
}
3094-
// draw the map
3095-
mMapCanvas->freeze(false);
3096-
mMapCanvas->refresh();
3080+
legend()->selectAll(false);
30973081

30983082
// notify the project we've made a change
30993083
QgsProject::instance()->dirty(true);
@@ -3103,27 +3087,11 @@ void QgisApp::hideAllLayers()
31033087
// reimplements method from base (gui) class
31043088
void QgisApp::showAllLayers()
31053089
{
3106-
// what's the point if we don't have any layers?
3107-
if ( QgsMapLayerRegistry::instance()->mapLayers().empty() )
3108-
{
3109-
return;
3110-
}
3111-
31123090
#ifdef QGISDEBUG
31133091
std::cout << "Showing all layers!" << std::endl;
31143092
#endif
31153093

3116-
mMapCanvas->freeze(true);
3117-
std::map<QString, QgsMapLayer *> myMapLayers = QgsMapLayerRegistry::instance()->mapLayers();
3118-
std::map<QString, QgsMapLayer *>::iterator myMapIterator;
3119-
for ( myMapIterator = myMapLayers.begin(); myMapIterator != myMapLayers.end(); ++myMapIterator )
3120-
{
3121-
QgsMapLayer * myMapLayer = myMapIterator->second;
3122-
myMapLayer->setVisible(true);
3123-
}
3124-
// draw the map
3125-
mMapCanvas->freeze(false);
3126-
mMapCanvas->refresh();
3094+
legend()->selectAll(true);
31273095

31283096
// notify the project we've made a change
31293097
QgsProject::instance()->dirty(true);

‎src/legend/qgslegend.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ void QgsLegend::removeAll()
115115
setIconSize(mMinimumIconSize);
116116
}
117117

118+
void QgsLegend::selectAll(bool select)
119+
{
120+
QTreeWidgetItem* theItem = firstItem();
121+
122+
while (theItem)
123+
{
124+
theItem->setCheckState(0, (select ? Qt::Checked : Qt::Unchecked));
125+
handleItemChange(theItem, 0);
126+
theItem = nextItem(theItem);
127+
}
128+
}
129+
118130
void QgsLegend::removeLayer(QString layer_key)
119131
{
120132
QTreeWidgetItem* theItem = firstItem();

‎src/legend/qgslegend.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ public slots:
178178
*/
179179
void removeAll();
180180

181+
/*!
182+
* Called when the user wishes to toggle on or off all of the layers in
183+
* the legend, and in the map.
184+
* @return void
185+
*/
186+
void selectAll(bool select);
187+
181188
/*!
182189
* Slot called when user wishes to add a new empty layer group to the legend.
183190
* The user will be prompted for the name of the newly added group.

0 commit comments

Comments
 (0)
Please sign in to comment.