Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix for bug #85 (remove layer does not work for legend layer files)
git-svn-id: http://svn.osgeo.org/qgis/trunk@5440 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 11, 2006
1 parent 585ba1e commit 6578d2c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
3 changes: 0 additions & 3 deletions src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -102,7 +102,6 @@ void QgsMapToolCapture::canvasReleaseEvent(QMouseEvent * e)
QMessageBox::Ok);
return;
}

QgsPoint idPoint = toMapCoords(e->pos());

// emit signal - QgisApp can catch it and save point position to clipboard
Expand Down Expand Up @@ -150,8 +149,6 @@ QMessageBox::Ok);
}
else if (mTool == CaptureLine || mTool == CapturePolygon)
{
// LINE & POLYGON CAPTURING

//check we only use the line tool for line/multiline layers
if(mTool == CaptureLine && vlayer->vectorType() != QGis::Line)
{
Expand Down
66 changes: 39 additions & 27 deletions src/legend/qgslegend.cpp
Expand Up @@ -592,39 +592,51 @@ void QgsLegend::legendGroupRemove()

void QgsLegend::legendLayerRemove()
{
//remove all layers of the current legendLayer
//if the current item is a legend layer: remove all layers of the current legendLayer
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer*>(currentItem());
if(!ll)
{
return;
}

std::list<QgsMapLayer*> maplayers = ll->mapLayers();
mStateOfCheckBoxes.erase(ll);

//todo: also remove the entries for the QgsLegendLayerFiles from the map
std::list<QgsLegendLayerFile*> llfiles = ll->legendLayerFiles();
for(std::list<QgsLegendLayerFile*>::iterator it = llfiles.begin(); it != llfiles.end(); ++it)
{
mStateOfCheckBoxes.erase(*it);
}

for(std::list<QgsMapLayer*>::iterator it = maplayers.begin(); it!=maplayers.end(); ++it)
if(ll)
{
//remove the layer
if(*it)
std::list<QgsMapLayer*> maplayers = ll->mapLayers();
mStateOfCheckBoxes.erase(ll);

//also remove the entries for the QgsLegendLayerFiles from the map
std::list<QgsLegendLayerFile*> llfiles = ll->legendLayerFiles();
for(std::list<QgsLegendLayerFile*>::iterator it = llfiles.begin(); it != llfiles.end(); ++it)
{
mStateOfCheckBoxes.erase(*it);
}

for(std::list<QgsMapLayer*>::iterator it = maplayers.begin(); it!=maplayers.end(); ++it)
{
QgsMapLayerRegistry::instance()->removeMapLayer((*it)->getLayerID());
//remove the layer
if(*it)
{
QgsMapLayerRegistry::instance()->removeMapLayer((*it)->getLayerID());
}
}

if(maplayers.size()>0)
{
mMapCanvas->refresh();
}
removeItem(ll);
delete ll;
adjustIconSize();
return;
}

if(maplayers.size()>0)
{
mMapCanvas->refresh();
}
removeItem(ll);
delete ll;
adjustIconSize();
//if the current item is a legend layer file
QgsLegendLayerFile* llf = dynamic_cast<QgsLegendLayerFile*>(currentItem());
if(llf)
{
if(llf->layer())
{
//the map layer registry emits a signal an this will remove the legend layer
//from the legend and from memory by calling QgsLegend::removeLayer(QString layer key)
QgsMapLayerRegistry::instance()->removeMapLayer(llf->layer()->getLayerID());
}
}
return;
}

void QgsLegend::legendLayerAddToOverview()
Expand Down

0 comments on commit 6578d2c

Please sign in to comment.