24 #include <QDomElement>
32 if ( legendElem.isNull() )
35 QDomNodeList legendChildren = legendElem.childNodes();
37 for (
int i = 0; i < legendChildren.size(); ++i )
39 QDomElement currentChildElem = legendChildren.at( i ).toElement();
40 if ( currentChildElem.tagName() ==
"legendlayer" )
44 else if ( currentChildElem.tagName() ==
"legendgroup" )
57 QDomNodeList legendChildren = groupElem.childNodes();
59 for (
int i = 0; i < legendChildren.size(); ++i )
61 QDomElement currentChildElem = legendChildren.at( i ).toElement();
62 if ( currentChildElem.tagName() ==
"legendlayer" )
64 QDomElement layerFileElem = currentChildElem.firstChildElement(
"filegroup" ).firstChildElement(
"legendlayerfile" );
66 int layerIndex = currentChildElem.attribute(
"drawingOrder" ).toInt();
67 if ( layerIndex == -1 )
69 layerIndexes.insert( layerIndex, layerFileElem.attribute(
"layerid" ) );
71 else if ( currentChildElem.tagName() ==
"legendgroup" )
84 if ( legendElem.isNull() )
87 hasCustomOrder = legendElem.attribute(
"updateDrawingOrder" ) ==
"false";
90 QMap<int, QString> layerIndexes;
95 if ( !res && hasCustomOrder )
98 foreach ( QString layerId, layerIndexes )
101 order.append( layerId );
110 int drawingOrder = -1;
111 if ( hasCustomOrder )
112 drawingOrder = order.indexOf( nodeLayer->
layerId() );
114 QDomElement layerElem = doc.createElement(
"legendlayer" );
115 layerElem.setAttribute(
"drawingOrder", drawingOrder );
116 layerElem.setAttribute(
"open", nodeLayer->
isExpanded() ?
"true" :
"false" );
118 layerElem.setAttribute(
"name", nodeLayer->
layerName() );
119 layerElem.setAttribute(
"showFeatureCount", nodeLayer->
customProperty(
"showFeatureCount" ).toInt() );
121 QDomElement fileGroupElem = doc.createElement(
"filegroup" );
122 fileGroupElem.setAttribute(
"open", nodeLayer->
isExpanded() ?
"true" :
"false" );
123 fileGroupElem.setAttribute(
"hidden",
"false" );
125 QDomElement layerFileElem = doc.createElement(
"legendlayerfile" );
126 layerFileElem.setAttribute(
"isInOverview", nodeLayer->
customProperty(
"overview" ).toInt() );
127 layerFileElem.setAttribute(
"layerid", nodeLayer->
layerId() );
128 layerFileElem.setAttribute(
"visible", nodeLayer->
isVisible() == Qt::Checked ? 1 : 0 );
130 layerElem.appendChild( fileGroupElem );
131 fileGroupElem.appendChild( layerFileElem );
140 QDomElement groupElem = doc.createElement(
"legendgroup" );
141 groupElem.setAttribute(
"open", nodeGroup->
isExpanded() ?
"true" :
"false" );
142 groupElem.setAttribute(
"name", nodeGroup->
name() );
147 groupElem.setAttribute(
"embedded", 1 );
148 groupElem.setAttribute(
"project", nodeGroup->
customProperty(
"embedded_project" ).toString() );
174 QDomElement legendElem = doc.createElement(
"legend" );
175 legendElem.setAttribute(
"updateDrawingOrder", hasCustomOrder ?
"false" :
"true" );
187 case Qt::Unchecked:
return "Qt::Unchecked";
188 case Qt::PartiallyChecked:
return "Qt::PartiallyChecked";
189 case Qt::Checked:
default:
return "Qt::Checked";
195 if ( txt ==
"Qt::Unchecked" )
196 return Qt::Unchecked;
197 else if ( txt ==
"Qt::PartiallyChecked" )
198 return Qt::PartiallyChecked;
207 QDomNodeList groupChildren = groupElem.childNodes();
212 groupNode->
setExpanded( groupElem.attribute(
"open" ) ==
"true" );
214 if ( groupElem.attribute(
"embedded" ) ==
"1" )
217 groupNode->
setCustomProperty(
"embedded_project", groupElem.attribute(
"project" ) );
220 for (
int i = 0; i < groupChildren.size(); ++i )
222 QDomElement currentChildElem = groupChildren.at( i ).toElement();
223 if ( currentChildElem.tagName() ==
"legendlayer" )
227 else if ( currentChildElem.tagName() ==
"legendgroup" )
238 QDomElement layerFileElem = layerElem.firstChildElement(
"filegroup" ).firstChildElement(
"legendlayerfile" );
239 QString layerId = layerFileElem.attribute(
"layerid" );
243 layerNode->
setExpanded( layerElem.attribute(
"open" ) ==
"true" );
245 if ( layerFileElem.attribute(
"isInOverview" ) ==
"1" )
248 if ( layerElem.attribute(
"embedded" ) ==
"1" )
251 if ( layerElem.attribute(
"showFeatureCount" ) ==
"1" )
291 QList<QgsLayerTreeNode*> nodesToRemove;
299 nodesToRemove << node;
353 if ( !node->
customProperty(
"embedded_project" ).toString().isEmpty() )