25 #include <QTextStream>
26 #include <QDomDocument>
55 bool returnValue =
false;
57 if ( !
mDom.isNull() )
75 QgsDebugMsg( QString(
"Current project file version is %1.%2.%3" )
81 std::cout <<
mDom.toString( 2 ).toLatin1().constData();
92 if ( !
mDom.isNull() )
96 QDomElement mapCanvas;
99 QDomNode qgis =
mDom.firstChildElement(
"qgis" );
100 if ( ! qgis.isNull() )
105 mapCanvas =
mDom.createElement(
"mapcanvas" );
107 qgis.appendChild( mapCanvas );
109 mapCanvas.appendChild( qgis.namedItem(
"units" ) );
111 mapCanvas.appendChild( qgis.namedItem(
"extent" ) );
115 QDomElement properties = qgis.firstChildElement(
"properties" );
116 QDomElement spatial = properties.firstChildElement(
"SpatialRefSys" );
117 QDomElement hasCrsTransformEnabled = spatial.firstChildElement(
"ProjectionsEnabled" );
120 QDomElement projection =
mDom.createElement(
"projections" );
121 QgsDebugMsg( QString(
"Projection flag: " ) + hasCrsTransformEnabled.text() );
123 projection.appendChild(
mDom.createTextNode( hasCrsTransformEnabled.text() ) );
125 mapCanvas.appendChild( projection );
132 QDomNodeList mapLayers =
mDom.elementsByTagName(
"maplayer" );
133 bool doneDestination =
false;
134 for (
int i = 0; i < mapLayers.count(); i++ )
136 QDomNode mapLayer = mapLayers.item( i );
138 QDomNode coordinateTransform = mapLayer.namedItem(
"coordinatetransform" );
140 QDomNode sourceCrs = coordinateTransform.namedItem(
"sourcesrs" );
142 sourceCrs.toElement().setTagName(
"srs" );
144 mapLayer.appendChild( sourceCrs );
147 if ( ! doneDestination )
150 QDomNode destinationCRS = coordinateTransform.namedItem(
"destinationsrs" );
153 mapCanvas.appendChild( destinationCRS );
155 doneDestination =
true;
157 mapLayer.removeChild( coordinateTransform );
164 QDomNodeList legendLayerFiles =
mDom.elementsByTagName(
"legendlayerfile" );
165 QgsDebugMsg( QString(
"Legend layer file entries: " ) + QString::number( legendLayerFiles.count() ) );
166 for (
int i = 0; i < mapLayers.count(); i++ )
169 QDomElement mapLayer = mapLayers.item( i ).toElement();
171 QString
id = mapLayer.firstChildElement(
"id" ).text();
174 for (
int j = 0; j < legendLayerFiles.count(); j++ )
176 QDomElement legendLayerFile = legendLayerFiles.item( j ).toElement();
177 if (
id == legendLayerFile.attribute(
"layerid" ) )
183 legendLayerFile.setAttribute(
"visible", mapLayer.attribute(
"visible" ) );
186 legendLayerFile.setAttribute(
"isInOverview", mapLayer.attribute(
"showInOverviewFlag" ) );
198 if ( !
mDom.isNull() )
201 QDomNodeList rasterPropertyList =
mDom.elementsByTagName(
"rasterproperties" );
202 QgsDebugMsg( QString(
"Raster properties file entries: " ) + QString::number( rasterPropertyList.count() ) );
203 for (
int i = 0; i < rasterPropertyList.count(); i++ )
206 QDomNode rasterProperty = rasterPropertyList.item( i );
209 rasterProperty.namedItem(
"stdDevsToPlotDouble" ).toElement().setTagName(
"mStandardDeviations" );
211 rasterProperty.namedItem(
"invertHistogramFlag" ).toElement().setTagName(
"mInvertPixelsFlag" );
212 rasterProperty.namedItem(
"showDebugOverLayFlag" ).toElement().setTagName(
"mDebugOverLayFlag" );
214 rasterProperty.namedItem(
"redBandNameQString" ).toElement().setTagName(
"mRedBandName" );
215 rasterProperty.namedItem(
"blueBandNameQString" ).toElement().setTagName(
"mBlueBandName" );
216 rasterProperty.namedItem(
"greenBandNameQString" ).toElement().setTagName(
"mGreenBandName" );
217 rasterProperty.namedItem(
"grayBandNameQString" ).toElement().setTagName(
"mGrayBandName" );
221 QDomNodeList symbolPropertyList =
mDom.elementsByTagName(
"symbol" );
222 for (
int i = 0; i < symbolPropertyList.count(); i++ )
225 QDomNode symbolProperty = symbolPropertyList.item( i );
227 QDomElement pointSymbol = symbolProperty.firstChildElement(
"pointsymbol" );
228 if ( pointSymbol.text().startsWith(
"hard:" ) )
231 int lineWidth = symbolProperty.firstChildElement(
"outlinewidth" ).text().toInt();
232 int pointSize = symbolProperty.firstChildElement(
"pointsize" ).text().toInt();
234 if ( pointSize != 0 )
239 pointSize = pointSize + 2 + 2 * lineWidth;
240 QgsDebugMsg( QString(
"Setting point size to %1" ).arg( pointSize ) );
241 QDomElement newPointSizeProperty =
mDom.createElement(
"pointsize" );
242 QDomText newPointSizeTxt =
mDom.createTextNode( QString::number( pointSize ) );
243 newPointSizeProperty.appendChild( newPointSizeTxt );
244 symbolProperty.replaceChild( newPointSizeProperty, pointSymbol );
256 if ( !
mDom.isNull() )
259 QPrinter myPrinter( QPrinter::ScreenResolution );
260 int screenDpi = myPrinter.resolution();
261 double widthScaleFactor = 25.4 / screenDpi;
263 QDomNodeList outlineWidthList =
mDom.elementsByTagName(
"outlinewidth" );
264 for (
int i = 0; i < outlineWidthList.size(); ++i )
267 QDomElement currentOutlineElem = outlineWidthList.at( i ).toElement();
268 double outlineWidth = currentOutlineElem.text().toDouble();
269 outlineWidth *= widthScaleFactor;
272 QDomNode outlineTextNode = currentOutlineElem.firstChild();
273 QDomText newOutlineText =
mDom.createTextNode( QString::number( outlineWidth ) );
274 currentOutlineElem.replaceChild( newOutlineText, outlineTextNode );
279 QDomNodeList pointSizeList =
mDom.elementsByTagName(
"pointsize" );
280 for (
int i = 0; i < pointSizeList.size(); ++i )
283 QDomElement currentPointSizeElem = pointSizeList.at( i ).toElement();
284 double pointSize = currentPointSizeElem.text().toDouble();
285 pointSize *= widthScaleFactor;
288 QDomNode pointSizeTextNode = currentPointSizeElem.firstChild();
289 QDomText newPointSizeText =
mDom.createTextNode( QString::number((
int )pointSize ) );
290 currentPointSizeElem.replaceChild( newPointSizeText, pointSizeTextNode );
297 if ( !
mDom.isNull() )
299 QDomNodeList layerList =
mDom.elementsByTagName(
"maplayer" );
300 for (
int i = 0; i < layerList.size(); ++i )
302 QDomElement layerElem = layerList.at( i ).toElement();
303 QString typeString = layerElem.attribute(
"type" );
304 if ( typeString !=
"vector" )
310 QDomNode dataSourceNode = layerElem.namedItem(
"datasource" );
311 if ( dataSourceNode.isNull() )
315 QString dataSource = dataSourceNode.toElement().text();
318 QDomNode providerNode = layerElem.namedItem(
"provider" );
319 if ( providerNode.isNull() )
323 QString providerKey = providerNode.toElement().text();
341 QDomNodeList classificationFieldList = layerElem.elementsByTagName(
"classificationfield" );
342 for (
int j = 0; j < classificationFieldList.size(); ++j )
344 QDomElement classificationFieldElem = classificationFieldList.at( j ).toElement();
345 int fieldNumber = classificationFieldElem.text().toInt();
346 QgsFieldMap::const_iterator field_it = theFieldMap.find( fieldNumber );
347 if ( field_it != theFieldMap.constEnd() )
349 QDomText fieldName =
mDom.createTextNode( field_it.value().name() );
350 QDomNode nameNode = classificationFieldElem.firstChild();
351 classificationFieldElem.replaceChild( fieldName, nameNode );
365 QDomNode qgis =
mDom.firstChildElement(
"qgis" );
369 QDomElement properties = qgis.firstChildElement(
"properties" );
370 if ( properties.isNull() )
373 QDomElement digitizing = properties.firstChildElement(
"Digitizing" );
374 if ( digitizing.isNull() )
377 QDomElement tolList = digitizing.firstChildElement(
"LayerSnappingToleranceList" );
378 if ( tolList.isNull() )
381 QDomElement tolUnitList = digitizing.firstChildElement(
"LayerSnappingToleranceUnitList" );
382 if ( !tolUnitList.isNull() )
386 for (
int i = 0; i < tolList.childNodes().count(); i++ )
390 value.
writeXML(
"LayerSnappingToleranceUnitList", digitizing,
mDom );
401 QDomNodeList layerItemList =
mDom.elementsByTagName(
"LayerItem" );
402 QDomElement currentLayerItemElem;
403 QString currentLayerId;
405 for (
int i = 0; i < layerItemList.size(); ++i )
407 currentLayerItemElem = layerItemList.at( i ).toElement();
408 if ( currentLayerItemElem.isNull() )
412 currentLayerId = currentLayerItemElem.attribute(
"layerId" );
414 QDomNodeList vectorClassificationList = currentLayerItemElem.elementsByTagName(
"VectorClassificationItem" );
415 QDomElement currentClassificationElem;
416 for (
int j = 0; j < vectorClassificationList.size(); ++j )
418 currentClassificationElem = vectorClassificationList.at( j ).toElement();
419 if ( !currentClassificationElem.isNull() )
421 currentClassificationElem.setAttribute(
"layerId", currentLayerId );
426 QDomNodeList textItemList = currentLayerItemElem.elementsByTagName(
"TextItem" );
427 QDomElement currentTextItem;
429 for (
int j = 0; j < textItemList.size(); ++j )
431 currentTextItem = textItemList.at( j ).toElement();
432 if ( currentTextItem.isNull() )
437 QDomElement classificationElement;
438 if ( vectorClassificationList.size() > 0 )
440 classificationElement =
mDom.createElement(
"VectorClassificationItem" );
444 classificationElement =
mDom.createElement(
"RasterClassificationItem" );
447 classificationElement.setAttribute(
"layerId", currentLayerId );
448 classificationElement.setAttribute(
"text", currentTextItem.attribute(
"text" ) );
449 currentLayerItemElem.replaceChild( classificationElement, currentTextItem );