Skip to content
Permalink
Browse files

Fix for ticket 549: groups lost and all layers expanded, if layers mi…

…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
mhugent committed Jan 26, 2007
1 parent 8d5768b commit 100273ff4ed682cac86503f2f46265f77ab8d4d5
Showing with 26 additions and 5 deletions.
  1. +13 −0 src/gui/qgsproject.cpp
  2. +13 −5 src/legend/qgslegend.cpp
@@ -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;
@@ -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");
@@ -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);
@@ -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;
}

0 comments on commit 100273f

Please sign in to comment.
You can’t perform that action at this time.