Skip to content

Commit

Permalink
Fix for ticket 549: groups lost and all layers expanded, if layers mi…
Browse files Browse the repository at this point in the history
…ssing opening the project

git-svn-id: http://svn.osgeo.org/qgis/branches/Release-0_8_0@6458 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 26, 2007
1 parent 8d5768b commit 100273f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/gui/qgsproject.cpp
Expand Up @@ -1166,6 +1166,19 @@ bool QgsProject::read()
// doesn't *have* layers -- nor a GUI for that matter -- we'll just
// leave in the whining and boldly stomp on.

//also restore the legend before bailing out
QgsLegend* theLegend = _findLegend();
if(theLegend)
{
QDomNodeList ll = doc->elementsByTagName("legend");
if(ll.count()==1)
{
QDomNode legendnode = ll.item(0);
theLegend->readXML(legendnode);
}

}

throw QgsProjectBadLayerException( getMapLayersResults.second );

// return false;
Expand Down
18 changes: 13 additions & 5 deletions src/legend/qgslegend.cpp
Expand Up @@ -943,7 +943,7 @@ bool QgsLegend::readXML(QDomNode& legendnode)
if(childelem.tagName()=="legendgroup")
{
QgsLegendGroup* theGroup = new QgsLegendGroup(this, name);
childelem.attribute("open") == "true" ? expandItem(theGroup) : collapseItem(theGroup);
childelem.attribute("open") == "true" ? expanded.push_back(theGroup) : collapsed.push_back(theGroup);
//set the checkbox of the legend group to the right state
blockSignals(true);
QString checked = childelem.attribute("checked");
Expand Down Expand Up @@ -1009,7 +1009,15 @@ bool QgsLegend::readXML(QDomNode& legendnode)
//find out the legendlayer
std::map<QString,QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
std::map<QString, QgsMapLayer*>::const_iterator iter = mapLayers.find(childelem.attribute("layerid"));
if(iter != mapLayers.end() && lastLayerFileGroup)
if(iter == mapLayers.end()) //the layer cannot be found (e.g. the file has been moved)
{
//remove the whole legendlayer if this is the only legendlayerfile
if(childelem.previousSibling().isNull() && childelem.nextSibling().isNull())
{
delete lastLayer;
}
}
else if(lastLayerFileGroup)
{
QgsMapLayer* theMapLayer = iter->second;
QgsLegendLayerFile* theLegendLayerFile = new QgsLegendLayerFile(lastLayerFileGroup, QgsLegendLayerFile::nameFromLayer(theMapLayer), theMapLayer);
Expand Down Expand Up @@ -1060,11 +1068,11 @@ bool QgsLegend::readXML(QDomNode& legendnode)
}

// Do the tree item expands and collapses.
for (int i = 0; i < collapsed.size(); ++i)
collapseItem(collapsed[i]);

for (int i = 0; i < expanded.size(); ++i)
expandItem(expanded[i]);

for (int i = 0; i < collapsed.size(); ++i)
collapseItem(collapsed[i]);

return true;
}
Expand Down

0 comments on commit 100273f

Please sign in to comment.