Skip to content

Commit

Permalink
Fix for ticket #94
Browse files Browse the repository at this point in the history
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/qgis@5348 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed Apr 23, 2006
1 parent 09ceb82 commit 9bf833d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 34 deletions.
36 changes: 2 additions & 34 deletions src/gui/qgisapp.cpp
Expand Up @@ -3073,27 +3073,11 @@ void QgisApp::removeAllFromOverview()
//reimplements method from base (gui) class
void QgisApp::hideAllLayers()
{
// what's the point if we don't have any layers?
if ( QgsMapLayerRegistry::instance()->mapLayers().empty() )
{
return;
}

#ifdef QGISDEBUG
std::cout << "hiding all layers!" << std::endl;
#endif

mMapCanvas->freeze(true);
std::map<QString, QgsMapLayer *> myMapLayers = QgsMapLayerRegistry::instance()->mapLayers();
std::map<QString, QgsMapLayer *>::iterator myMapIterator;
for ( myMapIterator = myMapLayers.begin(); myMapIterator != myMapLayers.end(); ++myMapIterator )
{
QgsMapLayer * myMapLayer = myMapIterator->second;
myMapLayer->setVisible(false);
}
// draw the map
mMapCanvas->freeze(false);
mMapCanvas->refresh();
legend()->selectAll(false);

// notify the project we've made a change
QgsProject::instance()->dirty(true);
Expand All @@ -3103,27 +3087,11 @@ void QgisApp::hideAllLayers()
// reimplements method from base (gui) class
void QgisApp::showAllLayers()
{
// what's the point if we don't have any layers?
if ( QgsMapLayerRegistry::instance()->mapLayers().empty() )
{
return;
}

#ifdef QGISDEBUG
std::cout << "Showing all layers!" << std::endl;
#endif

mMapCanvas->freeze(true);
std::map<QString, QgsMapLayer *> myMapLayers = QgsMapLayerRegistry::instance()->mapLayers();
std::map<QString, QgsMapLayer *>::iterator myMapIterator;
for ( myMapIterator = myMapLayers.begin(); myMapIterator != myMapLayers.end(); ++myMapIterator )
{
QgsMapLayer * myMapLayer = myMapIterator->second;
myMapLayer->setVisible(true);
}
// draw the map
mMapCanvas->freeze(false);
mMapCanvas->refresh();
legend()->selectAll(true);

// notify the project we've made a change
QgsProject::instance()->dirty(true);
Expand Down
12 changes: 12 additions & 0 deletions src/legend/qgslegend.cpp
Expand Up @@ -115,6 +115,18 @@ void QgsLegend::removeAll()
setIconSize(mMinimumIconSize);
}

void QgsLegend::selectAll(bool select)
{
QTreeWidgetItem* theItem = firstItem();

while (theItem)
{
theItem->setCheckState(0, (select ? Qt::Checked : Qt::Unchecked));
handleItemChange(theItem, 0);
theItem = nextItem(theItem);
}
}

void QgsLegend::removeLayer(QString layer_key)
{
QTreeWidgetItem* theItem = firstItem();
Expand Down
7 changes: 7 additions & 0 deletions src/legend/qgslegend.h
Expand Up @@ -178,6 +178,13 @@ public slots:
*/
void removeAll();

/*!
* Called when the user wishes to toggle on or off all of the layers in
* the legend, and in the map.
* @return void
*/
void selectAll(bool select);

/*!
* Slot called when user wishes to add a new empty layer group to the legend.
* The user will be prompted for the name of the newly added group.
Expand Down

0 comments on commit 9bf833d

Please sign in to comment.