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/trunk@6457 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 26, 2007
1 parent c7d894c commit afd03dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions src/app/legend/qgslegend.cpp
Expand Up @@ -1038,7 +1038,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 @@ -1103,8 +1103,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 @@ -1135,7 +1142,7 @@ bool QgsLegend::readXML(QDomNode& legendnode)

theLegendLayerFile->updateLegendItem();
refreshLayerSymbology(theMapLayer->getLayerID());
}
}
}
else if(childelem.tagName()=="filegroup")
{
Expand All @@ -1155,11 +1162,10 @@ 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
2 changes: 1 addition & 1 deletion src/core/qgsproject.cpp
Expand Up @@ -858,7 +858,7 @@ bool QgsProject::read()
// Since we could be executing this from the test harness which
// doesn't *have* layers -- nor a GUI for that matter -- we'll just
// leave in the whining and boldly stomp on.

emit readProject(*doc);
throw QgsProjectBadLayerException( getMapLayersResults.second );

// return false;
Expand Down

0 comments on commit afd03dc

Please sign in to comment.