Skip to content

File tree

2 files changed

+39
-30
lines changed

2 files changed

+39
-30
lines changed
 

‎src/gui/qgsmaptoolcapture.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ void QgsMapToolCapture::canvasReleaseEvent(QMouseEvent * e)
102102
QMessageBox::Ok);
103103
return;
104104
}
105-
106105
QgsPoint idPoint = toMapCoords(e->pos());
107106

108107
// emit signal - QgisApp can catch it and save point position to clipboard
@@ -150,8 +149,6 @@ QMessageBox::Ok);
150149
}
151150
else if (mTool == CaptureLine || mTool == CapturePolygon)
152151
{
153-
// LINE & POLYGON CAPTURING
154-
155152
//check we only use the line tool for line/multiline layers
156153
if(mTool == CaptureLine && vlayer->vectorType() != QGis::Line)
157154
{

‎src/legend/qgslegend.cpp

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -592,39 +592,51 @@ void QgsLegend::legendGroupRemove()
592592

593593
void QgsLegend::legendLayerRemove()
594594
{
595-
//remove all layers of the current legendLayer
595+
//if the current item is a legend layer: remove all layers of the current legendLayer
596596
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer*>(currentItem());
597-
if(!ll)
598-
{
599-
return;
600-
}
601-
602-
std::list<QgsMapLayer*> maplayers = ll->mapLayers();
603-
mStateOfCheckBoxes.erase(ll);
604-
605-
//todo: also remove the entries for the QgsLegendLayerFiles from the map
606-
std::list<QgsLegendLayerFile*> llfiles = ll->legendLayerFiles();
607-
for(std::list<QgsLegendLayerFile*>::iterator it = llfiles.begin(); it != llfiles.end(); ++it)
608-
{
609-
mStateOfCheckBoxes.erase(*it);
610-
}
611-
612-
for(std::list<QgsMapLayer*>::iterator it = maplayers.begin(); it!=maplayers.end(); ++it)
597+
if(ll)
613598
{
614-
//remove the layer
615-
if(*it)
599+
std::list<QgsMapLayer*> maplayers = ll->mapLayers();
600+
mStateOfCheckBoxes.erase(ll);
601+
602+
//also remove the entries for the QgsLegendLayerFiles from the map
603+
std::list<QgsLegendLayerFile*> llfiles = ll->legendLayerFiles();
604+
for(std::list<QgsLegendLayerFile*>::iterator it = llfiles.begin(); it != llfiles.end(); ++it)
605+
{
606+
mStateOfCheckBoxes.erase(*it);
607+
}
608+
609+
for(std::list<QgsMapLayer*>::iterator it = maplayers.begin(); it!=maplayers.end(); ++it)
616610
{
617-
QgsMapLayerRegistry::instance()->removeMapLayer((*it)->getLayerID());
611+
//remove the layer
612+
if(*it)
613+
{
614+
QgsMapLayerRegistry::instance()->removeMapLayer((*it)->getLayerID());
615+
}
618616
}
617+
618+
if(maplayers.size()>0)
619+
{
620+
mMapCanvas->refresh();
621+
}
622+
removeItem(ll);
623+
delete ll;
624+
adjustIconSize();
625+
return;
619626
}
620627

621-
if(maplayers.size()>0)
622-
{
623-
mMapCanvas->refresh();
624-
}
625-
removeItem(ll);
626-
delete ll;
627-
adjustIconSize();
628+
//if the current item is a legend layer file
629+
QgsLegendLayerFile* llf = dynamic_cast<QgsLegendLayerFile*>(currentItem());
630+
if(llf)
631+
{
632+
if(llf->layer())
633+
{
634+
//the map layer registry emits a signal an this will remove the legend layer
635+
//from the legend and from memory by calling QgsLegend::removeLayer(QString layer key)
636+
QgsMapLayerRegistry::instance()->removeMapLayer(llf->layer()->getLayerID());
637+
}
638+
}
639+
return;
628640
}
629641

630642
void QgsLegend::legendLayerAddToOverview()

0 commit comments

Comments
 (0)
Please sign in to comment.