Skip to content

Commit 35ce545

Browse files
author
g_j_m
committed
Fix fo ticket #294 (load project didn't honour the collapsed/expanded state of
legend layers). Seems to be a bug in Qt, so this commit implements a workaround. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5955 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 34854ae commit 35ce545

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/legend/qgslegend.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,13 @@ bool QgsLegend::readXML(QDomNode& legendnode)
927927

928928
child = legendnode.firstChild();
929929

930+
// For some unexplained reason, collapsing/expanding the legendLayer items
931+
// immediately after they have been created doesn't work (they all end up
932+
// expanded). The legendGroups and legendLayerFiles seems ok through. The
933+
// workaround is to store the required states of the legendLayers and set
934+
// them at the end of this function.
935+
QList<QTreeWidgetItem*> collapsed, expanded;
936+
930937
if(!child.isNull())
931938
{
932939
clear(); //remove all items first
@@ -978,7 +985,7 @@ bool QgsLegend::readXML(QDomNode& legendnode)
978985
lastGroup = 0;
979986
}
980987

981-
childelem.attribute("open") == "true" ? expandItem(theLayer) : collapseItem(theLayer);
988+
childelem.attribute("open") == "true" ? expanded.push_back(theLayer) : collapsed.push_back(theLayer);
982989

983990
//set the checkbox of the legend layer to the right state
984991
blockSignals(true);
@@ -1056,6 +1063,14 @@ bool QgsLegend::readXML(QDomNode& legendnode)
10561063
}
10571064
while(!(child.isNull()));
10581065
}
1066+
1067+
// Do the tree item expands and collapses.
1068+
for (int i = 0; i < collapsed.size(); ++i)
1069+
collapseItem(collapsed[i]);
1070+
1071+
for (int i = 0; i < expanded.size(); ++i)
1072+
expandItem(expanded[i]);
1073+
10591074
return true;
10601075
}
10611076

0 commit comments

Comments
 (0)