Skip to content

Commit eb03f9a

Browse files
author
mhugent
committed
Fix for ticket 549: groups lost and all layers expanded, if layers missing opening the project
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6457 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c3736d3 commit eb03f9a

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/app/legend/qgslegend.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ bool QgsLegend::readXML(QDomNode& legendnode)
10381038
if(childelem.tagName()=="legendgroup")
10391039
{
10401040
QgsLegendGroup* theGroup = new QgsLegendGroup(this, name);
1041-
childelem.attribute("open") == "true" ? expandItem(theGroup) : collapseItem(theGroup);
1041+
childelem.attribute("open") == "true" ? expanded.push_back(theGroup) : collapsed.push_back(theGroup);
10421042
//set the checkbox of the legend group to the right state
10431043
blockSignals(true);
10441044
QString checked = childelem.attribute("checked");
@@ -1103,8 +1103,15 @@ bool QgsLegend::readXML(QDomNode& legendnode)
11031103
//find out the legendlayer
11041104
std::map<QString,QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
11051105
std::map<QString, QgsMapLayer*>::const_iterator iter = mapLayers.find(childelem.attribute("layerid"));
1106-
1107-
if(iter != mapLayers.end() && lastLayerFileGroup)
1106+
if(iter == mapLayers.end()) //the layer cannot be found (e.g. the file has been moved)
1107+
{
1108+
//remove the whole legendlayer if this is the only legendlayerfile
1109+
if(childelem.previousSibling().isNull() && childelem.nextSibling().isNull())
1110+
{
1111+
delete lastLayer;
1112+
}
1113+
}
1114+
else if(lastLayerFileGroup)
11081115
{
11091116
QgsMapLayer* theMapLayer = iter->second;
11101117
QgsLegendLayerFile* theLegendLayerFile = new QgsLegendLayerFile(lastLayerFileGroup, QgsLegendLayerFile::nameFromLayer(theMapLayer), theMapLayer);
@@ -1135,7 +1142,7 @@ bool QgsLegend::readXML(QDomNode& legendnode)
11351142

11361143
theLegendLayerFile->updateLegendItem();
11371144
refreshLayerSymbology(theMapLayer->getLayerID());
1138-
}
1145+
}
11391146
}
11401147
else if(childelem.tagName()=="filegroup")
11411148
{
@@ -1155,11 +1162,10 @@ bool QgsLegend::readXML(QDomNode& legendnode)
11551162
}
11561163

11571164
// Do the tree item expands and collapses.
1158-
for (int i = 0; i < collapsed.size(); ++i)
1159-
collapseItem(collapsed[i]);
1160-
11611165
for (int i = 0; i < expanded.size(); ++i)
11621166
expandItem(expanded[i]);
1167+
for (int i = 0; i < collapsed.size(); ++i)
1168+
collapseItem(collapsed[i]);
11631169

11641170
return true;
11651171
}

src/core/qgsproject.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ bool QgsProject::read()
858858
// Since we could be executing this from the test harness which
859859
// doesn't *have* layers -- nor a GUI for that matter -- we'll just
860860
// leave in the whining and boldly stomp on.
861-
861+
emit readProject(*doc);
862862
throw QgsProjectBadLayerException( getMapLayersResults.second );
863863

864864
// return false;

0 commit comments

Comments
 (0)