146 if ( ! pft->
dom().isNull() )
150 QDomElement mapCanvas;
153 QDomNode qgis = pft->
dom().firstChildElement( QStringLiteral(
"qgis" ) );
154 if ( ! qgis.isNull() )
159 mapCanvas = pft->
dom().createElement( QStringLiteral(
"mapcanvas" ) );
161 qgis.appendChild( mapCanvas );
163 mapCanvas.appendChild( qgis.namedItem( QStringLiteral(
"units" ) ) );
165 mapCanvas.appendChild( qgis.namedItem( QStringLiteral(
"extent" ) ) );
169 const QDomElement properties = qgis.firstChildElement( QStringLiteral(
"properties" ) );
170 const QDomElement spatial = properties.firstChildElement( QStringLiteral(
"SpatialRefSys" ) );
171 const QDomElement hasCrsTransformEnabled = spatial.firstChildElement( QStringLiteral(
"ProjectionsEnabled" ) );
174 QDomElement projection = pft->
dom().createElement( QStringLiteral(
"projections" ) );
175 QgsDebugMsgLevel( QStringLiteral(
"Projection flag: " ) + hasCrsTransformEnabled.text(), 2 );
177 projection.appendChild( pft->
dom().createTextNode( hasCrsTransformEnabled.text() ) );
179 mapCanvas.appendChild( projection );
186 const QDomNodeList mapLayers = pft->
dom().elementsByTagName( QStringLiteral(
"maplayer" ) );
187 bool doneDestination =
false;
188 for (
int i = 0; i < mapLayers.count(); i++ )
190 QDomNode mapLayer = mapLayers.item( i );
192 const QDomNode coordinateTransform = mapLayer.namedItem( QStringLiteral(
"coordinatetransform" ) );
194 const QDomNode sourceCrs = coordinateTransform.namedItem( QStringLiteral(
"sourcesrs" ) );
196 sourceCrs.toElement().setTagName( QStringLiteral(
"srs" ) );
198 mapLayer.appendChild( sourceCrs );
201 if ( ! doneDestination )
204 const QDomNode destinationCRS = coordinateTransform.namedItem( QStringLiteral(
"destinationsrs" ) );
207 mapCanvas.appendChild( destinationCRS );
209 doneDestination =
true;
211 mapLayer.removeChild( coordinateTransform );
218 const QDomNodeList legendLayerFiles = pft->
dom().elementsByTagName( QStringLiteral(
"legendlayerfile" ) );
219 QgsDebugMsgLevel( QStringLiteral(
"Legend layer file entries: " ) + QString::number( legendLayerFiles.count() ), 2 );
220 for (
int i = 0; i < mapLayers.count(); i++ )
223 const QDomElement mapLayer = mapLayers.item( i ).toElement();
225 const QString
id = mapLayer.firstChildElement( QStringLiteral(
"id" ) ).text();
228 for (
int j = 0; j < legendLayerFiles.count(); j++ )
230 QDomElement legendLayerFile = legendLayerFiles.item( j ).toElement();
231 if (
id == legendLayerFile.attribute( QStringLiteral(
"layerid" ) ) )
237 legendLayerFile.setAttribute( QStringLiteral(
"visible" ), mapLayer.attribute( QStringLiteral(
"visible" ) ) );
240 legendLayerFile.setAttribute( QStringLiteral(
"isInOverview" ), mapLayer.attribute( QStringLiteral(
"showInOverviewFlag" ) ) );
249 if ( ! pft->
dom().isNull() )
252 const QDomNodeList rasterPropertyList = pft->
dom().elementsByTagName( QStringLiteral(
"rasterproperties" ) );
253 QgsDebugMsgLevel( QStringLiteral(
"Raster properties file entries: " ) + QString::number( rasterPropertyList.count() ), 2 );
254 for (
int i = 0; i < rasterPropertyList.count(); i++ )
257 const QDomNode rasterProperty = rasterPropertyList.item( i );
260 rasterProperty.namedItem( QStringLiteral(
"stdDevsToPlotDouble" ) ).toElement().setTagName( QStringLiteral(
"mStandardDeviations" ) );
262 rasterProperty.namedItem( QStringLiteral(
"invertHistogramFlag" ) ).toElement().setTagName( QStringLiteral(
"mInvertPixelsFlag" ) );
263 rasterProperty.namedItem( QStringLiteral(
"showDebugOverLayFlag" ) ).toElement().setTagName( QStringLiteral(
"mDebugOverLayFlag" ) );
265 rasterProperty.namedItem( QStringLiteral(
"redBandNameQString" ) ).toElement().setTagName( QStringLiteral(
"mRedBandName" ) );
266 rasterProperty.namedItem( QStringLiteral(
"blueBandNameQString" ) ).toElement().setTagName( QStringLiteral(
"mBlueBandName" ) );
267 rasterProperty.namedItem( QStringLiteral(
"greenBandNameQString" ) ).toElement().setTagName( QStringLiteral(
"mGreenBandName" ) );
268 rasterProperty.namedItem( QStringLiteral(
"grayBandNameQString" ) ).toElement().setTagName( QStringLiteral(
"mGrayBandName" ) );
272 const QDomNodeList symbolPropertyList = pft->
dom().elementsByTagName( QStringLiteral(
"symbol" ) );
273 for (
int i = 0; i < symbolPropertyList.count(); i++ )
276 QDomNode symbolProperty = symbolPropertyList.item( i );
278 const QDomElement pointSymbol = symbolProperty.firstChildElement( QStringLiteral(
"pointsymbol" ) );
279 if ( pointSymbol.text().startsWith( QLatin1String(
"hard:" ) ) )
282 const int lineWidth = symbolProperty.firstChildElement( QStringLiteral(
"outlinewidth" ) ).text().toInt();
283 int pointSize = symbolProperty.firstChildElement( QStringLiteral(
"pointsize" ) ).text().toInt();
285 if ( pointSize != 0 )
290 pointSize = pointSize + 2 + 2 * lineWidth;
291 QgsDebugMsgLevel( QStringLiteral(
"Setting point size to %1" ).arg( pointSize ), 2 );
292 QDomElement newPointSizeProperty = pft->
dom().createElement( QStringLiteral(
"pointsize" ) );
293 const QDomText newPointSizeTxt = pft->
dom().createTextNode( QString::number( pointSize ) );
294 newPointSizeProperty.appendChild( newPointSizeTxt );
295 symbolProperty.replaceChild( newPointSizeProperty, pointSymbol );
508 if ( pft->
dom().isNull() )
516 const QDomNodeList layerItemList = pft->
dom().elementsByTagName( QStringLiteral(
"rasterproperties" ) );
517 for (
int i = 0; i < layerItemList.size(); ++i )
519 QDomElement rasterPropertiesElem = layerItemList.at( i ).toElement();
520 QDomNode layerNode = rasterPropertiesElem.parentNode();
521 const QDomElement dataSourceElem = layerNode.firstChildElement( QStringLiteral(
"datasource" ) );
522 const QDomElement layerNameElem = layerNode.firstChildElement( QStringLiteral(
"layername" ) );
526 rasterLayer.
readLayerXml( layerNode.toElement(), context );
532 const QDomNodeList composerMapList = pft->
dom().elementsByTagName( QStringLiteral(
"ComposerMap" ) );
533 for (
int i = 0; i < composerMapList.size(); ++i )
535 const QDomNodeList gridList = composerMapList.at( i ).toElement().elementsByTagName( QStringLiteral(
"Grid" ) );
536 for (
int j = 0; j < gridList.size(); ++j )
538 const QDomNodeList annotationList = gridList.at( j ).toElement().elementsByTagName( QStringLiteral(
"Annotation" ) );
539 for (
int k = 0; k < annotationList.size(); ++k )
541 QDomElement annotationElem = annotationList.at( k ).toElement();
544 if ( annotationElem.hasAttribute( QStringLiteral(
"position" ) ) )
546 const int pos = annotationElem.attribute( QStringLiteral(
"position" ) ).toInt();
547 annotationElem.setAttribute( QStringLiteral(
"leftPosition" ), pos );
548 annotationElem.setAttribute( QStringLiteral(
"rightPosition" ), pos );
549 annotationElem.setAttribute( QStringLiteral(
"topPosition" ), pos );
550 annotationElem.setAttribute( QStringLiteral(
"bottomPosition" ), pos );
551 annotationElem.removeAttribute( QStringLiteral(
"position" ) );
555 if ( annotationElem.hasAttribute( QStringLiteral(
"direction" ) ) )
557 const int dir = annotationElem.attribute( QStringLiteral(
"direction" ) ).toInt();
560 annotationElem.setAttribute( QStringLiteral(
"leftDirection" ), 0 );
561 annotationElem.setAttribute( QStringLiteral(
"rightDirection" ), 0 );
562 annotationElem.setAttribute( QStringLiteral(
"topDirection" ), 1 );
563 annotationElem.setAttribute( QStringLiteral(
"bottomDirection" ), 1 );
567 annotationElem.setAttribute( QStringLiteral(
"leftDirection" ), 1 );
568 annotationElem.setAttribute( QStringLiteral(
"rightDirection" ), 1 );
569 annotationElem.setAttribute( QStringLiteral(
"topDirection" ), 0 );
570 annotationElem.setAttribute( QStringLiteral(
"bottomDirection" ), 0 );
574 annotationElem.setAttribute( QStringLiteral(
"leftDirection" ), dir );
575 annotationElem.setAttribute( QStringLiteral(
"rightDirection" ), dir );
576 annotationElem.setAttribute( QStringLiteral(
"topDirection" ), dir );
577 annotationElem.setAttribute( QStringLiteral(
"bottomDirection" ), dir );
579 annotationElem.removeAttribute( QStringLiteral(
"direction" ) );
586 const QDomNodeList composerList = pft->
dom().elementsByTagName( QStringLiteral(
"Composer" ) );
587 for (
int i = 0; i < composerList.size(); ++i )
589 QDomElement composerElem = composerList.at( i ).toElement();
592 QDomElement compositionElem = composerElem.firstChildElement( QStringLiteral(
"Composition" ) );
593 if ( compositionElem.isNull() )
598 const QDomNodeList composerChildren = composerElem.childNodes();
600 if ( composerChildren.size() < 1 )
605 for (
int j = composerChildren.size() - 1; j >= 0; --j )
607 const QDomElement childElem = composerChildren.at( j ).toElement();
608 if ( childElem.tagName() == QLatin1String(
"Composition" ) )
613 composerElem.removeChild( childElem );
614 compositionElem.appendChild( childElem );
622 const QDomNodeList rendererList = pft->
dom().elementsByTagName( QStringLiteral(
"renderer-v2" ) );
623 for (
int i = 0; i < rendererList.size(); ++i )
625 const QDomNodeList layerList = rendererList.at( i ).toElement().elementsByTagName( QStringLiteral(
"layer" ) );
626 for (
int j = 0; j < layerList.size(); ++j )
628 const QDomElement layerElem = layerList.at( j ).toElement();
629 if ( layerElem.attribute( QStringLiteral(
"class" ) ) == QLatin1String(
"SimpleFill" ) )
631 const QDomNodeList propList = layerElem.elementsByTagName( QStringLiteral(
"prop" ) );
632 for (
int k = 0; k < propList.size(); ++k )
634 QDomElement propElem = propList.at( k ).toElement();
635 if ( propElem.attribute( QStringLiteral(
"k" ) ) == QLatin1String(
"color" ) || propElem.attribute( QStringLiteral(
"k" ) ) == QLatin1String(
"color_border" ) )
637 propElem.setAttribute( QStringLiteral(
"v" ), propElem.attribute( QStringLiteral(
"v" ) ).section(
',', 0, 2 ) +
",255" );
661 QDomElement propsElem = pft->
dom().firstChildElement( QStringLiteral(
"qgis" ) ).toElement().firstChildElement( QStringLiteral(
"properties" ) );
662 if ( !propsElem.isNull() )
664 const QDomNodeList srsNodes = propsElem.elementsByTagName( QStringLiteral(
"SpatialRefSys" ) );
666 QDomElement projElem;
667 if ( srsNodes.count() > 0 )
669 srsElem = srsNodes.at( 0 ).toElement();
670 const QDomNodeList projNodes = srsElem.elementsByTagName( QStringLiteral(
"ProjectionsEnabled" ) );
671 if ( projNodes.count() == 0 )
673 projElem = pft->
dom().createElement( QStringLiteral(
"ProjectionsEnabled" ) );
674 projElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"int" ) );
675 const QDomText projText = pft->
dom().createTextNode( QStringLiteral(
"0" ) );
676 projElem.appendChild( projText );
677 srsElem.appendChild( projElem );
682 srsElem = pft->
dom().createElement( QStringLiteral(
"SpatialRefSys" ) );
683 projElem = pft->
dom().createElement( QStringLiteral(
"ProjectionsEnabled" ) );
684 projElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"int" ) );
685 const QDomText projText = pft->
dom().createTextNode( QStringLiteral(
"0" ) );
686 projElem.appendChild( projText );
687 srsElem.appendChild( projElem );
688 propsElem.appendChild( srsElem );
694 const QDomNodeList canvasNodes = pft->
dom().elementsByTagName( QStringLiteral(
"mapcanvas" ) );
695 if ( canvasNodes.count() > 0 )
697 const QDomElement canvasElem = canvasNodes.at( 0 ).toElement();
698 const QDomNodeList canvasSrsNodes = canvasElem.elementsByTagName( QStringLiteral(
"spatialrefsys" ) );
699 if ( canvasSrsNodes.count() > 0 )
701 const QDomElement canvasSrsElem = canvasSrsNodes.at( 0 ).toElement();
706 const QDomNodeList proj4Nodes = canvasSrsElem.elementsByTagName( QStringLiteral(
"proj4" ) );
707 if ( proj4Nodes.count() > 0 )
709 const QDomElement proj4Node = proj4Nodes.at( 0 ).toElement();
710 proj = proj4Node.text();
712 const QDomNodeList authidNodes = canvasSrsElem.elementsByTagName( QStringLiteral(
"authid" ) );
713 if ( authidNodes.count() > 0 )
715 const QDomElement authidNode = authidNodes.at( 0 ).toElement();
716 authid = authidNode.text();
718 const QDomNodeList srsidNodes = canvasSrsElem.elementsByTagName( QStringLiteral(
"srsid" ) );
719 if ( srsidNodes.count() > 0 )
721 const QDomElement srsidNode = srsidNodes.at( 0 ).toElement();
722 srsid = srsidNode.text();
726 const QDomNodeList oldProjectProj4Nodes = srsElem.elementsByTagName( QStringLiteral(
"ProjectCRSProj4String" ) );
727 for (
int i = oldProjectProj4Nodes.count(); i >= 0; --i )
729 srsElem.removeChild( oldProjectProj4Nodes.at( i ) );
731 const QDomNodeList oldProjectCrsNodes = srsElem.elementsByTagName( QStringLiteral(
"ProjectCrs" ) );
732 for (
int i = oldProjectCrsNodes.count(); i >= 0; --i )
734 srsElem.removeChild( oldProjectCrsNodes.at( i ) );
736 const QDomNodeList oldProjectCrsIdNodes = srsElem.elementsByTagName( QStringLiteral(
"ProjectCRSID" ) );
737 for (
int i = oldProjectCrsIdNodes.count(); i >= 0; --i )
739 srsElem.removeChild( oldProjectCrsIdNodes.at( i ) );
741 const QDomNodeList projectionsEnabledNodes = srsElem.elementsByTagName( QStringLiteral(
"ProjectionsEnabled" ) );
742 for (
int i = projectionsEnabledNodes.count(); i >= 0; --i )
744 srsElem.removeChild( projectionsEnabledNodes.at( i ) );
747 QDomElement proj4Elem = pft->
dom().createElement( QStringLiteral(
"ProjectCRSProj4String" ) );
748 proj4Elem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QString" ) );
749 const QDomText proj4Text = pft->
dom().createTextNode( proj );
750 proj4Elem.appendChild( proj4Text );
751 QDomElement projectCrsElem = pft->
dom().createElement( QStringLiteral(
"ProjectCrs" ) );
752 projectCrsElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QString" ) );
753 const QDomText projectCrsText = pft->
dom().createTextNode( authid );
754 projectCrsElem.appendChild( projectCrsText );
755 QDomElement projectCrsIdElem = pft->
dom().createElement( QStringLiteral(
"ProjectCRSID" ) );
756 projectCrsIdElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"int" ) );
757 const QDomText srsidText = pft->
dom().createTextNode( srsid );
758 projectCrsIdElem.appendChild( srsidText );
759 QDomElement projectionsEnabledElem = pft->
dom().createElement( QStringLiteral(
"ProjectionsEnabled" ) );
760 projectionsEnabledElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"int" ) );
761 const QDomText projectionsEnabledText = pft->
dom().createTextNode( QStringLiteral(
"1" ) );
762 projectionsEnabledElem.appendChild( projectionsEnabledText );
763 srsElem.appendChild( proj4Elem );
764 srsElem.appendChild( projectCrsElem );
765 srsElem.appendChild( projectCrsIdElem );
766 srsElem.appendChild( projectionsEnabledElem );
768 const QDomNodeList srsNodes = propsElem.elementsByTagName( QStringLiteral(
"SpatialRefSys" ) );
769 for (
int i = srsNodes.count(); i >= 0; --i )
771 propsElem.removeChild( srsNodes.at( i ) );
773 propsElem.appendChild( srsElem );
779 const QDomNodeList mapLayers = pft->
dom().elementsByTagName( QStringLiteral(
"maplayer" ) );
781 for (
int mapLayerIndex = 0; mapLayerIndex < mapLayers.count(); ++mapLayerIndex )
783 QDomElement layerElem = mapLayers.at( mapLayerIndex ).toElement();
786 QDomElement fieldConfigurationElement = pft->
dom().createElement( QStringLiteral(
"fieldConfiguration" ) );
787 layerElem.appendChild( fieldConfigurationElement );
789 const QDomNodeList editTypeNodes = layerElem.namedItem( QStringLiteral(
"edittypes" ) ).childNodes();
790 QDomElement constraintExpressionsElem = pft->
dom().createElement( QStringLiteral(
"constraintExpressions" ) );
791 layerElem.appendChild( constraintExpressionsElem );
793 for (
int i = 0; i < editTypeNodes.size(); ++i )
795 const QDomNode editTypeNode = editTypeNodes.at( i );
796 const QDomElement editTypeElement = editTypeNode.toElement();
798 QDomElement fieldElement = pft->
dom().createElement( QStringLiteral(
"field" ) );
799 fieldConfigurationElement.appendChild( fieldElement );
801 const QString name = editTypeElement.attribute( QStringLiteral(
"name" ) );
802 fieldElement.setAttribute( QStringLiteral(
"name" ), name );
803 QDomElement constraintExpressionElem = pft->
dom().createElement( QStringLiteral(
"constraint" ) );
804 constraintExpressionElem.setAttribute( QStringLiteral(
"field" ), name );
805 constraintExpressionsElem.appendChild( constraintExpressionElem );
807 QDomElement editWidgetElement = pft->
dom().createElement( QStringLiteral(
"editWidget" ) );
808 fieldElement.appendChild( editWidgetElement );
810 const QString ewv2Type = editTypeElement.attribute( QStringLiteral(
"widgetv2type" ) );
811 editWidgetElement.setAttribute( QStringLiteral(
"type" ), ewv2Type );
813 const QDomElement ewv2CfgElem = editTypeElement.namedItem( QStringLiteral(
"widgetv2config" ) ).toElement();
815 if ( !ewv2CfgElem.isNull() )
817 QDomElement editWidgetConfigElement = pft->
dom().createElement( QStringLiteral(
"config" ) );
818 editWidgetElement.appendChild( editWidgetConfigElement );
820 QVariantMap editWidgetConfiguration;
822 const QDomNamedNodeMap configAttrs = ewv2CfgElem.attributes();
823 for (
int configIndex = 0; configIndex < configAttrs.count(); ++configIndex )
825 const QDomAttr configAttr = configAttrs.item( configIndex ).toAttr();
826 if ( configAttr.name() == QLatin1String(
"fieldEditable" ) )
828 editWidgetConfigElement.setAttribute( QStringLiteral(
"fieldEditable" ), configAttr.value() );
830 else if ( configAttr.name() == QLatin1String(
"labelOnTop" ) )
832 editWidgetConfigElement.setAttribute( QStringLiteral(
"labelOnTop" ), configAttr.value() );
834 else if ( configAttr.name() == QLatin1String(
"notNull" ) )
836 editWidgetConfigElement.setAttribute( QStringLiteral(
"notNull" ), configAttr.value() );
838 else if ( configAttr.name() == QLatin1String(
"constraint" ) )
840 constraintExpressionElem.setAttribute( QStringLiteral(
"exp" ), configAttr.value() );
842 else if ( configAttr.name() == QLatin1String(
"constraintDescription" ) )
844 constraintExpressionElem.setAttribute( QStringLiteral(
"desc" ), configAttr.value() );
848 editWidgetConfiguration.insert( configAttr.name(), configAttr.value() );
852 if ( ewv2Type == QLatin1String(
"ValueMap" ) )
854 const QDomNodeList configElements = ewv2CfgElem.childNodes();
856 for (
int configIndex = 0; configIndex < configElements.count(); ++configIndex )
858 const QDomElement configElem = configElements.at( configIndex ).toElement();
859 map.insert( configElem.attribute( QStringLiteral(
"key" ) ), configElem.attribute( QStringLiteral(
"value" ) ) );
861 editWidgetConfiguration.insert( QStringLiteral(
"map" ), map );
863 else if ( ewv2Type == QLatin1String(
"Photo" ) )
865 editWidgetElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"ExternalResource" ) );
867 editWidgetConfiguration.insert( QStringLiteral(
"DocumentViewer" ), 1 );
868 editWidgetConfiguration.insert( QStringLiteral(
"DocumentViewerHeight" ), editWidgetConfiguration.value( QStringLiteral(
"Height" ) ) );
869 editWidgetConfiguration.insert( QStringLiteral(
"DocumentViewerWidth" ), editWidgetConfiguration.value( QStringLiteral(
"Width" ) ) );
870 editWidgetConfiguration.insert( QStringLiteral(
"RelativeStorage" ), 1 );
872 else if ( ewv2Type == QLatin1String(
"FileName" ) )
874 editWidgetElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"ExternalResource" ) );
876 editWidgetConfiguration.insert( QStringLiteral(
"RelativeStorage" ), 1 );
878 else if ( ewv2Type == QLatin1String(
"WebView" ) )
880 editWidgetElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"ExternalResource" ) );
882 editWidgetConfiguration.insert( QStringLiteral(
"DocumentViewerHeight" ), editWidgetConfiguration.value( QStringLiteral(
"Height" ) ) );
883 editWidgetConfiguration.insert( QStringLiteral(
"DocumentViewerWidth" ), editWidgetConfiguration.value( QStringLiteral(
"Width" ) ) );
884 editWidgetConfiguration.insert( QStringLiteral(
"RelativeStorage" ), 1 );
898 const QDomNode noDataNode = rasterPropertiesElem.namedItem( QStringLiteral(
"mNoDataValue" ) );
899 const QDomElement noDataElement = noDataNode.toElement();
900 if ( !noDataElement.text().isEmpty() )
903 QDomElement noDataElem = doc.createElement( QStringLiteral(
"noData" ) );
905 QDomElement noDataRangeList = doc.createElement( QStringLiteral(
"noDataRangeList" ) );
906 noDataRangeList.setAttribute( QStringLiteral(
"bandNo" ), 1 );
908 QDomElement noDataRange = doc.createElement( QStringLiteral(
"noDataRange" ) );
909 noDataRange.setAttribute( QStringLiteral(
"min" ), noDataElement.text() );
910 noDataRange.setAttribute( QStringLiteral(
"max" ), noDataElement.text() );
911 noDataRangeList.appendChild( noDataRange );
913 noDataElem.appendChild( noDataRangeList );
915 parentNode.appendChild( noDataElem );
918 QDomElement rasterRendererElem = doc.createElement( QStringLiteral(
"rasterrenderer" ) );
922 rasterRendererElem.setAttribute( QStringLiteral(
"invertColor" ), QStringLiteral(
"0" ) );
923 const QDomElement invertColorElem = rasterPropertiesElem.firstChildElement( QStringLiteral(
"mInvertColor" ) );
924 if ( !invertColorElem.isNull() )
926 if ( invertColorElem.text() == QLatin1String(
"true" ) )
928 rasterRendererElem.setAttribute( QStringLiteral(
"invertColor" ), QStringLiteral(
"1" ) );
933 rasterRendererElem.setAttribute( QStringLiteral(
"opacity" ), QStringLiteral(
"1" ) );
934 const QDomElement transparencyElem = parentNode.firstChildElement( QStringLiteral(
"transparencyLevelInt" ) );
935 if ( !transparencyElem.isNull() )
937 const double transparency = transparencyElem.text().toInt();
938 rasterRendererElem.setAttribute( QStringLiteral(
"opacity" ), QString::number( transparency / 255.0 ) );
942 rasterRendererElem.setAttribute( QStringLiteral(
"alphaBand" ), -1 );
945 const int grayBand =
rasterBandNumber( rasterPropertiesElem, QStringLiteral(
"mGrayBandName" ), rlayer );
948 QString drawingStyle = rasterPropertiesElem.firstChildElement( QStringLiteral(
"mDrawingStyle" ) ).text();
955 if ( drawingStyle == QLatin1String(
"PalettedColor" ) )
957 const QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement( QStringLiteral(
"customColorRamp" ) );
958 const QDomNodeList colorRampEntryList = customColorRampElem.elementsByTagName( QStringLiteral(
"colorRampEntry" ) );
960 for (
int i = 0; i < colorRampEntryList.size(); ++i )
962 const QDomElement colorRampEntryElem = colorRampEntryList.at( i ).toElement();
963 const QString strValue = colorRampEntryElem.attribute( QStringLiteral(
"value" ) );
964 const double value = strValue.toDouble();
965 if ( value < 0 || value > 10000 || !
qgsDoubleNear( value,
static_cast< int >( value ) ) )
967 QgsDebugMsgLevel( QStringLiteral(
"forcing SingleBandPseudoColor value = %1" ).arg( value ), 2 );
968 drawingStyle = QStringLiteral(
"SingleBandPseudoColor" );
974 if ( drawingStyle == QLatin1String(
"SingleBandGray" ) )
976 rasterRendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"singlebandgray" ) );
977 rasterRendererElem.setAttribute( QStringLiteral(
"grayBand" ), grayBand );
980 else if ( drawingStyle == QLatin1String(
"SingleBandPseudoColor" ) )
982 rasterRendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"singlebandpseudocolor" ) );
983 rasterRendererElem.setAttribute( QStringLiteral(
"band" ), grayBand );
984 QDomElement newRasterShaderElem = doc.createElement( QStringLiteral(
"rastershader" ) );
985 QDomElement newColorRampShaderElem = doc.createElement( QStringLiteral(
"colorrampshader" ) );
986 newRasterShaderElem.appendChild( newColorRampShaderElem );
987 rasterRendererElem.appendChild( newRasterShaderElem );
990 const QString colorShadingAlgorithm = rasterPropertiesElem.firstChildElement( QStringLiteral(
"mColorShadingAlgorithm" ) ).text();
991 if ( colorShadingAlgorithm == QLatin1String(
"PseudoColorShader" ) || colorShadingAlgorithm == QLatin1String(
"FreakOutShader" ) )
993 newColorRampShaderElem.setAttribute( QStringLiteral(
"colorRampType" ), QStringLiteral(
"INTERPOLATED" ) );
999 const double breakSize = ( maxValue - minValue ) / 3;
1001 QStringList colorList;
1002 if ( colorShadingAlgorithm == QLatin1String(
"FreakOutShader" ) )
1004 colorList << QStringLiteral(
"#ff00ff" ) << QStringLiteral(
"#00ffff" ) << QStringLiteral(
"#ff0000" ) << QStringLiteral(
"#00ff00" );
1008 colorList << QStringLiteral(
"#0000ff" ) << QStringLiteral(
"#00ffff" ) << QStringLiteral(
"#ffff00" ) << QStringLiteral(
"#ff0000" );
1010 QStringList::const_iterator colorIt = colorList.constBegin();
1011 double boundValue = minValue;
1012 for ( ; colorIt != colorList.constEnd(); ++colorIt )
1014 QDomElement newItemElem = doc.createElement( QStringLiteral(
"item" ) );
1015 newItemElem.setAttribute( QStringLiteral(
"value" ), QString::number( boundValue ) );
1016 newItemElem.setAttribute( QStringLiteral(
"label" ), QString::number( boundValue ) );
1017 newItemElem.setAttribute( QStringLiteral(
"color" ), *colorIt );
1018 newColorRampShaderElem.appendChild( newItemElem );
1019 boundValue += breakSize;
1022 else if ( colorShadingAlgorithm == QLatin1String(
"ColorRampShader" ) )
1024 const QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement( QStringLiteral(
"customColorRamp" ) );
1025 const QString type = customColorRampElem.firstChildElement( QStringLiteral(
"colorRampType" ) ).text();
1026 newColorRampShaderElem.setAttribute( QStringLiteral(
"colorRampType" ), type );
1027 const QDomNodeList colorNodeList = customColorRampElem.elementsByTagName( QStringLiteral(
"colorRampEntry" ) );
1029 QString value, label;
1031 int red, green, blue;
1032 QDomElement currentItemElem;
1033 for (
int i = 0; i < colorNodeList.size(); ++i )
1035 currentItemElem = colorNodeList.at( i ).toElement();
1036 value = currentItemElem.attribute( QStringLiteral(
"value" ) );
1037 label = currentItemElem.attribute( QStringLiteral(
"label" ) );
1038 red = currentItemElem.attribute( QStringLiteral(
"red" ) ).toInt();
1039 green = currentItemElem.attribute( QStringLiteral(
"green" ) ).toInt();
1040 blue = currentItemElem.attribute( QStringLiteral(
"blue" ) ).toInt();
1041 newColor = QColor( red, green, blue );
1042 QDomElement newItemElem = doc.createElement( QStringLiteral(
"item" ) );
1043 newItemElem.setAttribute( QStringLiteral(
"value" ), value );
1044 newItemElem.setAttribute( QStringLiteral(
"label" ), label );
1045 newItemElem.setAttribute( QStringLiteral(
"color" ), newColor.name() );
1046 newColorRampShaderElem.appendChild( newItemElem );
1050 else if ( drawingStyle == QLatin1String(
"PalettedColor" ) )
1052 rasterRendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"paletted" ) );
1053 rasterRendererElem.setAttribute( QStringLiteral(
"band" ), grayBand );
1054 const QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement( QStringLiteral(
"customColorRamp" ) );
1055 const QDomNodeList colorRampEntryList = customColorRampElem.elementsByTagName( QStringLiteral(
"colorRampEntry" ) );
1056 QDomElement newColorPaletteElem = doc.createElement( QStringLiteral(
"colorPalette" ) );
1062 QDomElement colorRampEntryElem;
1063 for (
int i = 0; i < colorRampEntryList.size(); ++i )
1065 colorRampEntryElem = colorRampEntryList.at( i ).toElement();
1066 QDomElement newPaletteElem = doc.createElement( QStringLiteral(
"paletteEntry" ) );
1067 value =
static_cast< int >( colorRampEntryElem.attribute( QStringLiteral(
"value" ) ).toDouble() );
1068 newPaletteElem.setAttribute( QStringLiteral(
"value" ), value );
1069 red = colorRampEntryElem.attribute( QStringLiteral(
"red" ) ).toInt();
1070 green = colorRampEntryElem.attribute( QStringLiteral(
"green" ) ).toInt();
1071 blue = colorRampEntryElem.attribute( QStringLiteral(
"blue" ) ).toInt();
1072 newPaletteElem.setAttribute( QStringLiteral(
"color" ), QColor( red, green, blue ).name() );
1073 const QString label = colorRampEntryElem.attribute( QStringLiteral(
"label" ) );
1074 if ( !label.isEmpty() )
1076 newPaletteElem.setAttribute( QStringLiteral(
"label" ), label );
1078 newColorPaletteElem.appendChild( newPaletteElem );
1080 rasterRendererElem.appendChild( newColorPaletteElem );
1082 else if ( drawingStyle == QLatin1String(
"MultiBandColor" ) )
1084 rasterRendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"multibandcolor" ) );
1087 const int redBand =
rasterBandNumber( rasterPropertiesElem, QStringLiteral(
"mRedBandName" ), rlayer );
1088 const int greenBand =
rasterBandNumber( rasterPropertiesElem, QStringLiteral(
"mGreenBandName" ), rlayer );
1089 const int blueBand =
rasterBandNumber( rasterPropertiesElem, QStringLiteral(
"mBlueBandName" ), rlayer );
1090 rasterRendererElem.setAttribute( QStringLiteral(
"redBand" ), redBand );
1091 rasterRendererElem.setAttribute( QStringLiteral(
"greenBand" ), greenBand );
1092 rasterRendererElem.setAttribute( QStringLiteral(
"blueBand" ), blueBand );
1102 if ( !parentNode.isNull() )
1104 parentNode.replaceChild( rasterRendererElem, rasterPropertiesElem );
1141 if ( rasterproperties.isNull() || rendererElem.isNull() )
1146 double minimumValue = 0;
1147 double maximumValue = 0;
1148 const QDomElement contrastMinMaxElem = rasterproperties.firstChildElement( QStringLiteral(
"contrastEnhancementMinMaxValues" ) );
1149 if ( contrastMinMaxElem.isNull() )
1154 const QDomElement contrastEnhancementAlgorithmElem = rasterproperties.firstChildElement( QStringLiteral(
"mContrastEnhancementAlgorithm" ) );
1155 if ( contrastEnhancementAlgorithmElem.isNull() )
1161 int algorithmEnum = 0;
1162 const QString algorithmString = contrastEnhancementAlgorithmElem.text();
1163 if ( algorithmString == QLatin1String(
"StretchToMinimumMaximum" ) )
1167 else if ( algorithmString == QLatin1String(
"StretchAndClipToMinimumMaximum" ) )
1171 else if ( algorithmString == QLatin1String(
"ClipToMinimumMaximum" ) )
1175 else if ( algorithmString == QLatin1String(
"UserDefinedEnhancement" ) )
1180 const QDomNodeList minMaxEntryList = contrastMinMaxElem.elementsByTagName( QStringLiteral(
"minMaxEntry" ) );
1181 QStringList enhancementNameList;
1182 if ( minMaxEntryList.size() == 1 )
1184 enhancementNameList << QStringLiteral(
"contrastEnhancement" );
1186 if ( minMaxEntryList.size() == 3 )
1188 enhancementNameList << QStringLiteral(
"redContrastEnhancement" ) << QStringLiteral(
"greenContrastEnhancement" ) << QStringLiteral(
"blueContrastEnhancement" );
1190 if ( minMaxEntryList.size() > enhancementNameList.size() )
1195 QDomElement minMaxEntryElem;
1196 for (
int i = 0; i < minMaxEntryList.size(); ++i )
1198 minMaxEntryElem = minMaxEntryList.at( i ).toElement();
1199 const QDomElement minElem = minMaxEntryElem.firstChildElement( QStringLiteral(
"min" ) );
1200 if ( minElem.isNull() )
1204 minimumValue = minElem.text().toDouble();
1206 const QDomElement maxElem = minMaxEntryElem.firstChildElement( QStringLiteral(
"max" ) );
1207 if ( maxElem.isNull() )
1211 maximumValue = maxElem.text().toDouble();
1213 QDomElement newContrastEnhancementElem = doc.createElement( enhancementNameList.at( i ) );
1214 QDomElement newMinValElem = doc.createElement( QStringLiteral(
"minValue" ) );
1215 const QDomText minText = doc.createTextNode( QString::number( minimumValue ) );
1216 newMinValElem.appendChild( minText );
1217 newContrastEnhancementElem.appendChild( newMinValElem );
1218 QDomElement newMaxValElem = doc.createElement( QStringLiteral(
"maxValue" ) );
1219 const QDomText maxText = doc.createTextNode( QString::number( maximumValue ) );
1220 newMaxValElem.appendChild( maxText );
1221 newContrastEnhancementElem.appendChild( newMaxValElem );
1223 QDomElement newAlgorithmElem = doc.createElement( QStringLiteral(
"algorithm" ) );
1224 const QDomText newAlgorithmText = doc.createTextNode( QString::number( algorithmEnum ) );
1225 newAlgorithmElem.appendChild( newAlgorithmText );
1226 newContrastEnhancementElem.appendChild( newAlgorithmElem );
1228 rendererElem.appendChild( newContrastEnhancementElem );