25 #include <QTextStream> 26 #include <QDomDocument> 35 QgsProjectFileTransform::transform QgsProjectFileTransform::transformers[] =
37 {
PFV( 0, 8, 0 ),
PFV( 0, 8, 1 ), &QgsProjectFileTransform::transformNull},
38 {
PFV( 0, 8, 1 ),
PFV( 0, 9, 0 ), &QgsProjectFileTransform::transform081to090},
39 {
PFV( 0, 9, 0 ),
PFV( 0, 9, 1 ), &QgsProjectFileTransform::transformNull},
40 {
PFV( 0, 9, 1 ),
PFV( 0, 10, 0 ), &QgsProjectFileTransform::transform091to0100},
43 {
PFV( 0, 9, 2 ),
PFV( 0, 11, 0 ), &QgsProjectFileTransform::transformNull},
44 {
PFV( 0, 10, 0 ),
PFV( 0, 11, 0 ), &QgsProjectFileTransform::transform0100to0110},
45 {
PFV( 0, 11, 0 ),
PFV( 1, 0, 0 ), &QgsProjectFileTransform::transform0110to1000},
46 {
PFV( 1, 0, 0 ),
PFV( 1, 1, 0 ), &QgsProjectFileTransform::transformNull},
47 {
PFV( 1, 0, 2 ),
PFV( 1, 1, 0 ), &QgsProjectFileTransform::transformNull},
48 {
PFV( 1, 1, 0 ),
PFV( 1, 2, 0 ), &QgsProjectFileTransform::transform1100to1200},
49 {
PFV( 1, 2, 0 ),
PFV( 1, 3, 0 ), &QgsProjectFileTransform::transformNull},
50 {
PFV( 1, 3, 0 ),
PFV( 1, 4, 0 ), &QgsProjectFileTransform::transformNull},
51 {
PFV( 1, 4, 0 ),
PFV( 1, 5, 0 ), &QgsProjectFileTransform::transform1400to1500},
52 {
PFV( 1, 5, 0 ),
PFV( 1, 6, 0 ), &QgsProjectFileTransform::transformNull},
53 {
PFV( 1, 6, 0 ),
PFV( 1, 7, 0 ), &QgsProjectFileTransform::transformNull},
54 {
PFV( 1, 7, 0 ),
PFV( 1, 8, 0 ), &QgsProjectFileTransform::transformNull},
55 {
PFV( 1, 8, 0 ),
PFV( 1, 9, 0 ), &QgsProjectFileTransform::transform1800to1900},
56 {
PFV( 1, 9, 0 ),
PFV( 2, 0, 0 ), &QgsProjectFileTransform::transformNull},
57 {
PFV( 2, 0, 0 ),
PFV( 2, 1, 0 ), &QgsProjectFileTransform::transformNull},
58 {
PFV( 2, 1, 0 ),
PFV( 2, 2, 0 ), &QgsProjectFileTransform::transformNull},
59 {
PFV( 2, 2, 0 ),
PFV( 2, 3, 0 ), &QgsProjectFileTransform::transform2200to2300},
64 Q_UNUSED( newVersion );
65 bool returnValue =
false;
67 if ( ! mDom.isNull() )
69 for ( std::size_t i = 0; i <
sizeof( transformers ) /
sizeof( transform ); i++ )
71 if ( transformers[i].from == mCurrentVersion )
74 ( this->*( transformers[i].transformFunc ) )();
75 mCurrentVersion = transformers[i].to;
85 QgsDebugMsg( QString(
"Current project file version is %1.%2.%3" )
91 std::cout << mDom.toString( 2 ).toLatin1().constData();
99 void QgsProjectFileTransform::transform081to090()
102 if ( ! mDom.isNull() )
106 QDomElement mapCanvas;
109 QDomNode qgis = mDom.firstChildElement(
"qgis" );
110 if ( ! qgis.isNull() )
115 mapCanvas = mDom.createElement(
"mapcanvas" );
117 qgis.appendChild( mapCanvas );
119 mapCanvas.appendChild( qgis.namedItem(
"units" ) );
121 mapCanvas.appendChild( qgis.namedItem(
"extent" ) );
125 QDomElement properties = qgis.firstChildElement(
"properties" );
126 QDomElement spatial = properties.firstChildElement(
"SpatialRefSys" );
127 QDomElement hasCrsTransformEnabled = spatial.firstChildElement(
"ProjectionsEnabled" );
130 QDomElement projection = mDom.createElement(
"projections" );
131 QgsDebugMsg( QString(
"Projection flag: " ) + hasCrsTransformEnabled.text() );
133 projection.appendChild( mDom.createTextNode( hasCrsTransformEnabled.text() ) );
135 mapCanvas.appendChild( projection );
142 QDomNodeList mapLayers = mDom.elementsByTagName(
"maplayer" );
143 bool doneDestination =
false;
144 for (
int i = 0; i < mapLayers.count(); i++ )
146 QDomNode mapLayer = mapLayers.item( i );
148 QDomNode coordinateTransform = mapLayer.namedItem(
"coordinatetransform" );
150 QDomNode sourceCrs = coordinateTransform.namedItem(
"sourcesrs" );
152 sourceCrs.toElement().setTagName(
"srs" );
154 mapLayer.appendChild( sourceCrs );
157 if ( ! doneDestination )
160 QDomNode destinationCRS = coordinateTransform.namedItem(
"destinationsrs" );
163 mapCanvas.appendChild( destinationCRS );
165 doneDestination =
true;
167 mapLayer.removeChild( coordinateTransform );
174 QDomNodeList legendLayerFiles = mDom.elementsByTagName(
"legendlayerfile" );
175 QgsDebugMsg( QString(
"Legend layer file entries: " ) + QString::number( legendLayerFiles.count() ) );
176 for (
int i = 0; i < mapLayers.count(); i++ )
179 QDomElement mapLayer = mapLayers.item( i ).toElement();
181 QString
id = mapLayer.firstChildElement(
"id" ).text();
184 for (
int j = 0; j < legendLayerFiles.count(); j++ )
186 QDomElement legendLayerFile = legendLayerFiles.item( j ).toElement();
187 if (
id == legendLayerFile.attribute(
"layerid" ) )
193 legendLayerFile.setAttribute(
"visible", mapLayer.attribute(
"visible" ) );
196 legendLayerFile.setAttribute(
"isInOverview", mapLayer.attribute(
"showInOverviewFlag" ) );
205 void QgsProjectFileTransform::transform091to0100()
208 if ( ! mDom.isNull() )
211 QDomNodeList rasterPropertyList = mDom.elementsByTagName(
"rasterproperties" );
212 QgsDebugMsg( QString(
"Raster properties file entries: " ) + QString::number( rasterPropertyList.count() ) );
213 for (
int i = 0; i < rasterPropertyList.count(); i++ )
216 QDomNode rasterProperty = rasterPropertyList.item( i );
219 rasterProperty.namedItem(
"stdDevsToPlotDouble" ).toElement().setTagName(
"mStandardDeviations" );
221 rasterProperty.namedItem(
"invertHistogramFlag" ).toElement().setTagName(
"mInvertPixelsFlag" );
222 rasterProperty.namedItem(
"showDebugOverLayFlag" ).toElement().setTagName(
"mDebugOverLayFlag" );
224 rasterProperty.namedItem(
"redBandNameQString" ).toElement().setTagName(
"mRedBandName" );
225 rasterProperty.namedItem(
"blueBandNameQString" ).toElement().setTagName(
"mBlueBandName" );
226 rasterProperty.namedItem(
"greenBandNameQString" ).toElement().setTagName(
"mGreenBandName" );
227 rasterProperty.namedItem(
"grayBandNameQString" ).toElement().setTagName(
"mGrayBandName" );
231 QDomNodeList symbolPropertyList = mDom.elementsByTagName(
"symbol" );
232 for (
int i = 0; i < symbolPropertyList.count(); i++ )
235 QDomNode symbolProperty = symbolPropertyList.item( i );
237 QDomElement pointSymbol = symbolProperty.firstChildElement(
"pointsymbol" );
238 if ( pointSymbol.text().startsWith(
"hard:" ) )
241 int lineWidth = symbolProperty.firstChildElement(
"outlinewidth" ).text().toInt();
242 int pointSize = symbolProperty.firstChildElement(
"pointsize" ).text().toInt();
244 if ( pointSize != 0 )
249 pointSize = pointSize + 2 + 2 * lineWidth;
250 QgsDebugMsg( QString(
"Setting point size to %1" ).arg( pointSize ) );
251 QDomElement newPointSizeProperty = mDom.createElement(
"pointsize" );
252 QDomText newPointSizeTxt = mDom.createTextNode( QString::number( pointSize ) );
253 newPointSizeProperty.appendChild( newPointSizeTxt );
254 symbolProperty.replaceChild( newPointSizeProperty, pointSymbol );
264 void QgsProjectFileTransform::transform0100to0110()
266 if ( ! mDom.isNull() )
269 QPrinter myPrinter( QPrinter::ScreenResolution );
270 int screenDpi = myPrinter.resolution();
271 double widthScaleFactor = 25.4 / screenDpi;
273 QDomNodeList outlineWidthList = mDom.elementsByTagName(
"outlinewidth" );
274 for (
int i = 0; i < outlineWidthList.size(); ++i )
277 QDomElement currentOutlineElem = outlineWidthList.at( i ).toElement();
278 double outlineWidth = currentOutlineElem.text().toDouble();
279 outlineWidth *= widthScaleFactor;
282 QDomNode outlineTextNode = currentOutlineElem.firstChild();
283 QDomText newOutlineText = mDom.createTextNode( QString::number( outlineWidth ) );
284 currentOutlineElem.replaceChild( newOutlineText, outlineTextNode );
289 QDomNodeList pointSizeList = mDom.elementsByTagName(
"pointsize" );
290 for (
int i = 0; i < pointSizeList.size(); ++i )
293 QDomElement currentPointSizeElem = pointSizeList.at( i ).toElement();
294 double pointSize = currentPointSizeElem.text().toDouble();
295 pointSize *= widthScaleFactor;
298 QDomNode pointSizeTextNode = currentPointSizeElem.firstChild();
299 QDomText newPointSizeText = mDom.createTextNode( QString::number((
int )pointSize ) );
300 currentPointSizeElem.replaceChild( newPointSizeText, pointSizeTextNode );
305 void QgsProjectFileTransform::transform0110to1000()
307 if ( ! mDom.isNull() )
309 QDomNodeList layerList = mDom.elementsByTagName(
"maplayer" );
310 for (
int i = 0; i < layerList.size(); ++i )
312 QDomElement layerElem = layerList.at( i ).toElement();
313 QString typeString = layerElem.attribute(
"type" );
314 if ( typeString !=
"vector" )
320 QDomNode dataSourceNode = layerElem.namedItem(
"datasource" );
321 if ( dataSourceNode.isNull() )
325 QString dataSource = dataSourceNode.toElement().text();
328 QDomNode providerNode = layerElem.namedItem(
"provider" );
329 if ( providerNode.isNull() )
333 QString providerKey = providerNode.toElement().text();
351 QDomNodeList classificationFieldList = layerElem.elementsByTagName(
"classificationfield" );
352 for (
int j = 0; j < classificationFieldList.size(); ++j )
354 QDomElement classificationFieldElem = classificationFieldList.
at( j ).toElement();
355 int fieldNumber = classificationFieldElem.text().toInt();
356 if ( fieldNumber >= 0 && fieldNumber < theFields.
count() )
358 QDomText fieldName = mDom.createTextNode( theFields[fieldNumber].name() );
359 QDomNode nameNode = classificationFieldElem.firstChild();
360 classificationFieldElem.replaceChild( fieldName, nameNode );
368 void QgsProjectFileTransform::transform1100to1200()
374 QDomNode qgis = mDom.firstChildElement(
"qgis" );
378 QDomElement properties = qgis.firstChildElement(
"properties" );
379 if ( properties.isNull() )
382 QDomElement digitizing = properties.firstChildElement(
"Digitizing" );
383 if ( digitizing.isNull() )
386 QDomElement tolList = digitizing.firstChildElement(
"LayerSnappingToleranceList" );
387 if ( tolList.isNull() )
390 QDomElement tolUnitList = digitizing.firstChildElement(
"LayerSnappingToleranceUnitList" );
391 if ( !tolUnitList.isNull() )
395 for (
int i = 0; i < tolList.childNodes().count(); i++ )
399 value.
writeXML(
"LayerSnappingToleranceUnitList", digitizing, mDom );
402 void QgsProjectFileTransform::transform1400to1500()
410 QDomNodeList layerItemList = mDom.elementsByTagName(
"LayerItem" );
411 QDomElement currentLayerItemElem;
412 QString currentLayerId;
414 for (
int i = 0; i < layerItemList.size(); ++i )
416 currentLayerItemElem = layerItemList.at( i ).toElement();
417 if ( currentLayerItemElem.isNull() )
421 currentLayerId = currentLayerItemElem.attribute(
"layerId" );
423 QDomNodeList vectorClassificationList = currentLayerItemElem.elementsByTagName(
"VectorClassificationItem" );
424 QDomElement currentClassificationElem;
425 for (
int j = 0; j < vectorClassificationList.size(); ++j )
427 currentClassificationElem = vectorClassificationList.at( j ).toElement();
428 if ( !currentClassificationElem.isNull() )
430 currentClassificationElem.setAttribute(
"layerId", currentLayerId );
435 QDomNodeList textItemList = currentLayerItemElem.elementsByTagName(
"TextItem" );
436 QDomElement currentTextItem;
438 for (
int j = 0; j < textItemList.size(); ++j )
440 currentTextItem = textItemList.at( j ).toElement();
441 if ( currentTextItem.isNull() )
446 QDomElement classificationElement;
447 if ( vectorClassificationList.size() > 0 )
449 classificationElement = mDom.createElement(
"VectorClassificationItem" );
453 classificationElement = mDom.createElement(
"RasterClassificationItem" );
456 classificationElement.setAttribute(
"layerId", currentLayerId );
457 classificationElement.setAttribute(
"text", currentTextItem.attribute(
"text" ) );
458 currentLayerItemElem.replaceChild( classificationElement, currentTextItem );
463 void QgsProjectFileTransform::transform1800to1900()
470 QDomNodeList layerItemList = mDom.elementsByTagName(
"rasterproperties" );
471 for (
int i = 0; i < layerItemList.size(); ++i )
473 QDomElement rasterPropertiesElem = layerItemList.at( i ).toElement();
474 QDomNode layerNode = rasterPropertiesElem.parentNode();
475 QDomElement dataSourceElem = layerNode.firstChildElement(
"datasource" );
476 QDomElement layerNameElem = layerNode.firstChildElement(
"layername" );
486 QDomNodeList composerMapList = mDom.elementsByTagName(
"ComposerMap" );
487 for (
int i = 0; i < composerMapList.size(); ++i )
489 QDomNodeList gridList = composerMapList.at( i ).toElement().elementsByTagName(
"Grid" );
490 for (
int j = 0; j < gridList.size(); ++j )
492 QDomNodeList annotationList = gridList.at( j ).toElement().elementsByTagName(
"Annotation" );
493 for (
int k = 0; k < annotationList.size(); ++k )
495 QDomElement annotationElem = annotationList.at( k ).toElement();
498 if ( annotationElem.hasAttribute(
"position" ) )
500 int pos = annotationElem.attribute(
"position" ).toInt();
501 annotationElem.setAttribute(
"leftPosition", pos );
502 annotationElem.setAttribute(
"rightPosition", pos );
503 annotationElem.setAttribute(
"topPosition", pos );
504 annotationElem.setAttribute(
"bottomPosition", pos );
505 annotationElem.removeAttribute(
"position" );
509 if ( annotationElem.hasAttribute(
"direction" ) )
511 int dir = annotationElem.attribute(
"direction" ).toInt();
514 annotationElem.setAttribute(
"leftDirection", 0 );
515 annotationElem.setAttribute(
"rightDirection", 0 );
516 annotationElem.setAttribute(
"topDirection", 1 );
517 annotationElem.setAttribute(
"bottomDirection", 1 );
521 annotationElem.setAttribute(
"leftDirection", 1 );
522 annotationElem.setAttribute(
"rightDirection", 1 );
523 annotationElem.setAttribute(
"topDirection", 0 );
524 annotationElem.setAttribute(
"bottomDirection", 0 );
528 annotationElem.setAttribute(
"leftDirection", dir );
529 annotationElem.setAttribute(
"rightDirection", dir );
530 annotationElem.setAttribute(
"topDirection", dir );
531 annotationElem.setAttribute(
"bottomDirection", dir );
533 annotationElem.removeAttribute(
"direction" );
540 QDomNodeList composerList = mDom.elementsByTagName(
"Composer" );
541 for (
int i = 0; i < composerList.size(); ++i )
543 QDomElement composerElem = composerList.at( i ).toElement();
546 QDomElement compositionElem = composerElem.firstChildElement(
"Composition" );
547 if ( compositionElem.isNull() )
552 QDomNodeList composerChildren = composerElem.childNodes();
554 if ( composerChildren.size() < 1 )
559 for (
int j = composerChildren.size() - 1; j >= 0; --j )
561 QDomElement childElem = composerChildren.at( j ).toElement();
562 if ( childElem.tagName() ==
"Composition" )
567 composerElem.removeChild( childElem );
568 compositionElem.appendChild( childElem );
576 QDomNodeList rendererList = mDom.elementsByTagName(
"renderer-v2" );
577 for (
int i = 0; i < rendererList.size(); ++i )
579 QDomNodeList layerList = rendererList.at( i ).toElement().elementsByTagName(
"layer" );
580 for (
int j = 0; j < layerList.size(); ++j )
582 QDomElement layerElem = layerList.at( j ).toElement();
583 if ( layerElem.attribute(
"class" ) ==
"SimpleFill" )
585 QDomNodeList propList = layerElem.elementsByTagName(
"prop" );
586 for (
int k = 0; k < propList.size(); ++k )
588 QDomElement propElem = propList.at( k ).toElement();
589 if ( propElem.attribute(
"k" ) ==
"color" || propElem.attribute(
"k" ) ==
"color_border" )
591 propElem.setAttribute(
"v", propElem.attribute(
"v" ).section(
",", 0, 2 ) +
",255" );
601 void QgsProjectFileTransform::transform2200to2300()
604 QDomNodeList composerPictureList = mDom.elementsByTagName(
"ComposerPicture" );
605 for (
int i = 0; i < composerPictureList.size(); ++i )
607 QDomElement picture = composerPictureList.at( i ).toElement();
608 picture.setAttribute(
"anchorPoint", QString::number( 4 ) );
617 QDomNode noDataNode = rasterPropertiesElem.namedItem(
"mNoDataValue" );
618 QDomElement noDataElement = noDataNode.toElement();
619 if ( !noDataElement.text().isEmpty() )
621 QgsDebugMsg(
"mNoDataValue = " + noDataElement.text() );
622 QDomElement noDataElem = doc.createElement(
"noData" );
624 QDomElement noDataRangeList = doc.createElement(
"noDataRangeList" );
625 noDataRangeList.setAttribute(
"bandNo", 1 );
627 QDomElement noDataRange = doc.createElement(
"noDataRange" );
628 noDataRange.setAttribute(
"min", noDataElement.text() );
629 noDataRange.setAttribute(
"max", noDataElement.text() );
630 noDataRangeList.appendChild( noDataRange );
632 noDataElem.appendChild( noDataRangeList );
634 parentNode.appendChild( noDataElem );
637 QDomElement rasterRendererElem = doc.createElement(
"rasterrenderer" );
641 rasterRendererElem.setAttribute(
"invertColor",
"0" );
642 QDomElement invertColorElem = rasterPropertiesElem.firstChildElement(
"mInvertColor" );
643 if ( !invertColorElem.isNull() )
645 if ( invertColorElem.text() ==
"true" )
647 rasterRendererElem.setAttribute(
"invertColor",
"1" );
652 rasterRendererElem.setAttribute(
"opacity",
"1" );
653 QDomElement transparencyElem = parentNode.firstChildElement(
"transparencyLevelInt" );
654 if ( !transparencyElem.isNull() )
656 double transparency = transparencyElem.text().toInt();
657 rasterRendererElem.setAttribute(
"opacity", QString::number( transparency / 255.0 ) );
661 rasterRendererElem.setAttribute(
"alphaBand", -1 );
664 int grayBand = rasterBandNumber( rasterPropertiesElem,
"mGrayBandName", rlayer );
667 QString drawingStyle = rasterPropertiesElem.firstChildElement(
"mDrawingStyle" ).text();
674 if ( drawingStyle ==
"PalettedColor" )
676 QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement(
"customColorRamp" );
677 QDomNodeList colorRampEntryList = customColorRampElem.elementsByTagName(
"colorRampEntry" );
679 for (
int i = 0; i < colorRampEntryList.size(); ++i )
681 QDomElement colorRampEntryElem = colorRampEntryList.at( i ).toElement();
682 QString strValue = colorRampEntryElem.attribute(
"value" );
683 double value = strValue.toDouble();
684 if ( value < 0 || value > 10000 || value != (
int )value )
686 QgsDebugMsg( QString(
"forcing SingleBandPseudoColor value = %1" ).arg( value ) );
687 drawingStyle =
"SingleBandPseudoColor";
693 if ( drawingStyle ==
"SingleBandGray" )
695 rasterRendererElem.setAttribute(
"type",
"singlebandgray" );
696 rasterRendererElem.setAttribute(
"grayBand", grayBand );
697 transformContrastEnhancement( doc, rasterPropertiesElem, rasterRendererElem );
699 else if ( drawingStyle ==
"SingleBandPseudoColor" )
701 rasterRendererElem.setAttribute(
"type",
"singlebandpseudocolor" );
702 rasterRendererElem.setAttribute(
"band", grayBand );
703 QDomElement newRasterShaderElem = doc.createElement(
"rastershader" );
704 QDomElement newColorRampShaderElem = doc.createElement(
"colorrampshader" );
705 newRasterShaderElem.appendChild( newColorRampShaderElem );
706 rasterRendererElem.appendChild( newRasterShaderElem );
709 QString colorShadingAlgorithm = rasterPropertiesElem.firstChildElement(
"mColorShadingAlgorithm" ).text();
710 if ( colorShadingAlgorithm ==
"PseudoColorShader" || colorShadingAlgorithm ==
"FreakOutShader" )
712 newColorRampShaderElem.setAttribute(
"colorRampType",
"INTERPOLATED" );
718 double breakSize = ( maxValue - minValue ) / 3;
720 QStringList colorList;
721 if ( colorShadingAlgorithm ==
"FreakOutShader" )
723 colorList <<
"#ff00ff" <<
"#00ffff" <<
"#ff0000" <<
"#00ff00";
727 colorList <<
"#0000ff" <<
"#00ffff" <<
"#ffff00" <<
"#ff0000";
729 QStringList::const_iterator colorIt = colorList.constBegin();
730 double boundValue = minValue;
731 for ( ; colorIt != colorList.constEnd(); ++colorIt )
733 QDomElement newItemElem = doc.createElement(
"item" );
734 newItemElem.setAttribute(
"value", QString::number( boundValue ) );
735 newItemElem.setAttribute(
"label", QString::number( boundValue ) );
736 newItemElem.setAttribute(
"color", *colorIt );
737 newColorRampShaderElem.appendChild( newItemElem );
738 boundValue += breakSize;
741 else if ( colorShadingAlgorithm ==
"ColorRampShader" )
743 QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement(
"customColorRamp" );
744 QString type = customColorRampElem.firstChildElement(
"colorRampType" ).text();
745 newColorRampShaderElem.setAttribute(
"colorRampType", type );
746 QDomNodeList colorNodeList = customColorRampElem.elementsByTagName(
"colorRampEntry" );
748 QString value, label;
750 int red, green, blue;
751 QDomElement currentItemElem;
752 for (
int i = 0; i < colorNodeList.size(); ++i )
754 currentItemElem = colorNodeList.at( i ).toElement();
755 value = currentItemElem.attribute(
"value" );
756 label = currentItemElem.attribute(
"label" );
757 red = currentItemElem.attribute(
"red" ).toInt();
758 green = currentItemElem.attribute(
"green" ).toInt();
759 blue = currentItemElem.attribute(
"blue" ).toInt();
760 newColor = QColor( red, green, blue );
761 QDomElement newItemElem = doc.createElement(
"item" );
762 newItemElem.setAttribute(
"value", value );
763 newItemElem.setAttribute(
"label", label );
764 newItemElem.setAttribute(
"color", newColor.name() );
765 newColorRampShaderElem.appendChild( newItemElem );
769 else if ( drawingStyle ==
"PalettedColor" )
771 rasterRendererElem.setAttribute(
"type",
"paletted" );
772 rasterRendererElem.setAttribute(
"band", grayBand );
773 QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement(
"customColorRamp" );
774 QDomNodeList colorRampEntryList = customColorRampElem.elementsByTagName(
"colorRampEntry" );
775 QDomElement newColorPaletteElem = doc.createElement(
"colorPalette" );
781 QDomElement colorRampEntryElem;
782 for (
int i = 0; i < colorRampEntryList.size(); ++i )
784 colorRampEntryElem = colorRampEntryList.at( i ).toElement();
785 QDomElement newPaletteElem = doc.createElement(
"paletteEntry" );
786 value = ( int )( colorRampEntryElem.attribute(
"value" ).toDouble() );
787 newPaletteElem.setAttribute(
"value", value );
788 red = colorRampEntryElem.attribute(
"red" ).toInt();
789 green = colorRampEntryElem.attribute(
"green" ).toInt();
790 blue = colorRampEntryElem.attribute(
"blue" ).toInt();
791 newPaletteElem.setAttribute(
"color", QColor( red, green, blue ).name() );
792 QString label = colorRampEntryElem.attribute(
"label" );
793 if ( !label.isEmpty() )
795 newPaletteElem.setAttribute(
"label", label );
797 newColorPaletteElem.appendChild( newPaletteElem );
799 rasterRendererElem.appendChild( newColorPaletteElem );
801 else if ( drawingStyle ==
"MultiBandColor" )
803 rasterRendererElem.setAttribute(
"type",
"multibandcolor" );
806 int redBand = rasterBandNumber( rasterPropertiesElem,
"mRedBandName", rlayer );
807 int greenBand = rasterBandNumber( rasterPropertiesElem,
"mGreenBandName", rlayer );
808 int blueBand = rasterBandNumber( rasterPropertiesElem,
"mBlueBandName", rlayer );
809 rasterRendererElem.setAttribute(
"redBand", redBand );
810 rasterRendererElem.setAttribute(
"greenBand", greenBand );
811 rasterRendererElem.setAttribute(
"blueBand", blueBand );
813 transformContrastEnhancement( doc, rasterPropertiesElem, rasterRendererElem );
821 if ( !parentNode.isNull() )
823 parentNode.replaceChild( rasterRendererElem, rasterPropertiesElem );
827 int QgsProjectFileTransform::rasterBandNumber(
const QDomElement &rasterPropertiesElem,
const QString &bandName,
836 QDomElement rasterBandElem = rasterPropertiesElem.firstChildElement( bandName );
837 if ( !rasterBandElem.isNull() )
839 QRegExp re(
"(\\d+)" );
841 if ( re.indexIn( rasterBandElem.text() ) >= 0 )
843 return re.cap( 1 ).toInt();
849 void QgsProjectFileTransform::transformContrastEnhancement( QDomDocument& doc,
const QDomElement& rasterproperties, QDomElement& rendererElem )
851 if ( rasterproperties.isNull() || rendererElem.isNull() )
856 double minimumValue = 0;
857 double maximumValue = 0;
858 QDomElement contrastMinMaxElem = rasterproperties.firstChildElement(
"contrastEnhancementMinMaxValues" );
859 if ( contrastMinMaxElem.isNull() )
864 QDomElement contrastEnhancementAlgorithmElem = rasterproperties.firstChildElement(
"mContrastEnhancementAlgorithm" );
865 if ( contrastEnhancementAlgorithmElem.isNull() )
871 int algorithmEnum = 0;
872 QString algorithmString = contrastEnhancementAlgorithmElem.text();
873 if ( algorithmString ==
"StretchToMinimumMaximum" )
877 else if ( algorithmString ==
"StretchAndClipToMinimumMaximum" )
881 else if ( algorithmString ==
"ClipToMinimumMaximum" )
885 else if ( algorithmString ==
"UserDefinedEnhancement" )
890 QDomNodeList minMaxEntryList = contrastMinMaxElem.elementsByTagName(
"minMaxEntry" );
891 QStringList enhancementNameList;
892 if ( minMaxEntryList.size() == 1 )
894 enhancementNameList <<
"contrastEnhancement";
896 if ( minMaxEntryList.size() == 3 )
898 enhancementNameList <<
"redContrastEnhancement" <<
"greenContrastEnhancement" <<
"blueContrastEnhancement";
900 if ( minMaxEntryList.size() > enhancementNameList.size() )
905 QDomElement minMaxEntryElem;
906 for (
int i = 0; i < minMaxEntryList.size(); ++i )
908 minMaxEntryElem = minMaxEntryList.at( i ).toElement();
909 QDomElement minElem = minMaxEntryElem.firstChildElement(
"min" );
910 if ( minElem.isNull() )
914 minimumValue = minElem.text().toDouble();
916 QDomElement maxElem = minMaxEntryElem.firstChildElement(
"max" );
917 if ( maxElem.isNull() )
921 maximumValue = maxElem.text().toDouble();
923 QDomElement newContrastEnhancementElem = doc.createElement( enhancementNameList.at( i ) );
924 QDomElement newMinValElem = doc.createElement(
"minValue" );
925 QDomText minText = doc.createTextNode( QString::number( minimumValue ) );
926 newMinValElem.appendChild( minText );
927 newContrastEnhancementElem.appendChild( newMinValElem );
928 QDomElement newMaxValElem = doc.createElement(
"maxValue" );
929 QDomText maxText = doc.createTextNode( QString::number( maximumValue ) );
930 newMaxValElem.appendChild( maxText );
931 newContrastEnhancementElem.appendChild( newMaxValElem );
933 QDomElement newAlgorithmElem = doc.createElement(
"algorithm" );
934 QDomText newAlgorithmText = doc.createTextNode( QString::number( algorithmEnum ) );
935 newAlgorithmElem.appendChild( newAlgorithmText );
936 newContrastEnhancementElem.appendChild( newAlgorithmElem );
938 rendererElem.appendChild( newContrastEnhancementElem );
942 void QgsProjectFileTransform::transformRasterTransparency( QDomDocument& doc,
const QDomElement& orig, QDomElement& rendererElem )
947 Q_UNUSED( rendererElem );
bool writeXML(const QString &nodeName, QDomElement &element, QDomDocument &document) override
keyElement created by parent QgsPropertyKey
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
double maximumValue
The maximum cell value in the raster band.
Container of fields for a vector layer.
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
virtual QgsRasterBandStats bandStatistics(int theBandNo, int theStats=QgsRasterBandStats::All, const QgsRectangle &theExtent=QgsRectangle(), int theSampleSize=0)
Get band statistics.
The RasterBandStats struct is a container for statistics about a single raster band.
A class to describe the version of a project.
int count() const
Return number of items.
virtual const QgsFields & fields() const =0
Return a map of indexes with field names for this layer.
double minimumValue
The minimum cell value in the raster band.
bool readLayerXML(const QDomElement &layerElement)
sets state from Dom document
QgsRasterDataProvider * dataProvider()
Returns the data provider.
QgsVectorDataProvider * dataProvider()
Returns the data provider.
This is the base class for vector data providers.
Represents a vector layer which manages a vector based data sets.