38#include <QDomDocument>
39#include <QRegularExpression>
67 Q_UNUSED( newVersion )
68 bool returnValue =
false;
101 if ( !mDom.isNull() )
105 if ( transformer.to >= mCurrentVersion && ( transformer.from == mCurrentVersion || transformer.from.
isNull() ) )
108 ( *( transformer.transformFunc ) )( this );
109 mCurrentVersion = transformer.to;
119 QgsDebugMsgLevel( QStringLiteral(
"Current project file version is %1.%2.%3" )
125 std::cout << mDom.toString( 2 ).toLatin1().constData();
136 const QDomNodeList composerPictureList = pft->
dom().elementsByTagName( QStringLiteral(
"ComposerPicture" ) );
137 for (
int i = 0; i < composerPictureList.size(); ++i )
139 QDomElement picture = composerPictureList.at( i ).toElement();
140 picture.setAttribute( QStringLiteral(
"anchorPoint" ), QString::number( 4 ) );
147 QDomElement propsElem = pft->
dom().firstChildElement( QStringLiteral(
"qgis" ) ).toElement().firstChildElement( QStringLiteral(
"properties" ) );
148 if ( !propsElem.isNull() )
150 const QDomNodeList srsNodes = propsElem.elementsByTagName( QStringLiteral(
"SpatialRefSys" ) );
152 QDomElement projElem;
153 if ( srsNodes.count() > 0 )
155 srsElem = srsNodes.at( 0 ).toElement();
156 const QDomNodeList projNodes = srsElem.elementsByTagName( QStringLiteral(
"ProjectionsEnabled" ) );
157 if ( projNodes.count() == 0 )
159 projElem = pft->
dom().createElement( QStringLiteral(
"ProjectionsEnabled" ) );
160 projElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"int" ) );
161 const QDomText projText = pft->
dom().createTextNode( QStringLiteral(
"0" ) );
162 projElem.appendChild( projText );
163 srsElem.appendChild( projElem );
168 srsElem = pft->
dom().createElement( QStringLiteral(
"SpatialRefSys" ) );
169 projElem = pft->
dom().createElement( QStringLiteral(
"ProjectionsEnabled" ) );
170 projElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"int" ) );
171 const QDomText projText = pft->
dom().createTextNode( QStringLiteral(
"0" ) );
172 projElem.appendChild( projText );
173 srsElem.appendChild( projElem );
174 propsElem.appendChild( srsElem );
180 const QDomNodeList canvasNodes = pft->
dom().elementsByTagName( QStringLiteral(
"mapcanvas" ) );
181 if ( canvasNodes.count() > 0 )
183 const QDomElement canvasElem = canvasNodes.at( 0 ).toElement();
184 const QDomNodeList canvasSrsNodes = canvasElem.elementsByTagName( QStringLiteral(
"spatialrefsys" ) );
185 if ( canvasSrsNodes.count() > 0 )
187 const QDomElement canvasSrsElem = canvasSrsNodes.at( 0 ).toElement();
192 const QDomNodeList proj4Nodes = canvasSrsElem.elementsByTagName( QStringLiteral(
"proj4" ) );
193 if ( proj4Nodes.count() > 0 )
195 const QDomElement proj4Node = proj4Nodes.at( 0 ).toElement();
196 proj = proj4Node.text();
198 const QDomNodeList authidNodes = canvasSrsElem.elementsByTagName( QStringLiteral(
"authid" ) );
199 if ( authidNodes.count() > 0 )
201 const QDomElement authidNode = authidNodes.at( 0 ).toElement();
202 authid = authidNode.text();
204 const QDomNodeList srsidNodes = canvasSrsElem.elementsByTagName( QStringLiteral(
"srsid" ) );
205 if ( srsidNodes.count() > 0 )
207 const QDomElement srsidNode = srsidNodes.at( 0 ).toElement();
208 srsid = srsidNode.text();
212 const QDomNodeList oldProjectProj4Nodes = srsElem.elementsByTagName( QStringLiteral(
"ProjectCRSProj4String" ) );
213 for (
int i = oldProjectProj4Nodes.count(); i >= 0; --i )
215 srsElem.removeChild( oldProjectProj4Nodes.at( i ) );
217 const QDomNodeList oldProjectCrsNodes = srsElem.elementsByTagName( QStringLiteral(
"ProjectCrs" ) );
218 for (
int i = oldProjectCrsNodes.count(); i >= 0; --i )
220 srsElem.removeChild( oldProjectCrsNodes.at( i ) );
222 const QDomNodeList oldProjectCrsIdNodes = srsElem.elementsByTagName( QStringLiteral(
"ProjectCRSID" ) );
223 for (
int i = oldProjectCrsIdNodes.count(); i >= 0; --i )
225 srsElem.removeChild( oldProjectCrsIdNodes.at( i ) );
227 const QDomNodeList projectionsEnabledNodes = srsElem.elementsByTagName( QStringLiteral(
"ProjectionsEnabled" ) );
228 for (
int i = projectionsEnabledNodes.count(); i >= 0; --i )
230 srsElem.removeChild( projectionsEnabledNodes.at( i ) );
233 QDomElement proj4Elem = pft->
dom().createElement( QStringLiteral(
"ProjectCRSProj4String" ) );
234 proj4Elem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QString" ) );
235 const QDomText proj4Text = pft->
dom().createTextNode( proj );
236 proj4Elem.appendChild( proj4Text );
237 QDomElement projectCrsElem = pft->
dom().createElement( QStringLiteral(
"ProjectCrs" ) );
238 projectCrsElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QString" ) );
239 const QDomText projectCrsText = pft->
dom().createTextNode( authid );
240 projectCrsElem.appendChild( projectCrsText );
241 QDomElement projectCrsIdElem = pft->
dom().createElement( QStringLiteral(
"ProjectCRSID" ) );
242 projectCrsIdElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"int" ) );
243 const QDomText srsidText = pft->
dom().createTextNode( srsid );
244 projectCrsIdElem.appendChild( srsidText );
245 QDomElement projectionsEnabledElem = pft->
dom().createElement( QStringLiteral(
"ProjectionsEnabled" ) );
246 projectionsEnabledElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"int" ) );
247 const QDomText projectionsEnabledText = pft->
dom().createTextNode( QStringLiteral(
"1" ) );
248 projectionsEnabledElem.appendChild( projectionsEnabledText );
249 srsElem.appendChild( proj4Elem );
250 srsElem.appendChild( projectCrsElem );
251 srsElem.appendChild( projectCrsIdElem );
252 srsElem.appendChild( projectionsEnabledElem );
254 const QDomNodeList srsNodes = propsElem.elementsByTagName( QStringLiteral(
"SpatialRefSys" ) );
255 for (
int i = srsNodes.count(); i >= 0; --i )
257 propsElem.removeChild( srsNodes.at( i ) );
259 propsElem.appendChild( srsElem );
265 const QDomNodeList mapLayers = pft->
dom().elementsByTagName( QStringLiteral(
"maplayer" ) );
267 for (
int mapLayerIndex = 0; mapLayerIndex < mapLayers.count(); ++mapLayerIndex )
269 QDomElement layerElem = mapLayers.at( mapLayerIndex ).toElement();
272 QDomElement fieldConfigurationElement = pft->
dom().createElement( QStringLiteral(
"fieldConfiguration" ) );
273 layerElem.appendChild( fieldConfigurationElement );
275 const QDomNodeList editTypeNodes = layerElem.namedItem( QStringLiteral(
"edittypes" ) ).childNodes();
276 QDomElement constraintExpressionsElem = pft->
dom().createElement( QStringLiteral(
"constraintExpressions" ) );
277 layerElem.appendChild( constraintExpressionsElem );
279 for (
int i = 0; i < editTypeNodes.size(); ++i )
281 const QDomNode editTypeNode = editTypeNodes.at( i );
282 const QDomElement editTypeElement = editTypeNode.toElement();
284 QDomElement fieldElement = pft->
dom().createElement( QStringLiteral(
"field" ) );
285 fieldConfigurationElement.appendChild( fieldElement );
287 const QString name = editTypeElement.attribute( QStringLiteral(
"name" ) );
288 fieldElement.setAttribute( QStringLiteral(
"name" ), name );
289 QDomElement constraintExpressionElem = pft->
dom().createElement( QStringLiteral(
"constraint" ) );
290 constraintExpressionElem.setAttribute( QStringLiteral(
"field" ), name );
291 constraintExpressionsElem.appendChild( constraintExpressionElem );
293 QDomElement editWidgetElement = pft->
dom().createElement( QStringLiteral(
"editWidget" ) );
294 fieldElement.appendChild( editWidgetElement );
296 const QString ewv2Type = editTypeElement.attribute( QStringLiteral(
"widgetv2type" ) );
297 editWidgetElement.setAttribute( QStringLiteral(
"type" ), ewv2Type );
299 const QDomElement ewv2CfgElem = editTypeElement.namedItem( QStringLiteral(
"widgetv2config" ) ).toElement();
301 if ( !ewv2CfgElem.isNull() )
303 QDomElement editWidgetConfigElement = pft->
dom().createElement( QStringLiteral(
"config" ) );
304 editWidgetElement.appendChild( editWidgetConfigElement );
306 QVariantMap editWidgetConfiguration;
308 const QDomNamedNodeMap configAttrs = ewv2CfgElem.attributes();
309 for (
int configIndex = 0; configIndex < configAttrs.count(); ++configIndex )
311 const QDomAttr configAttr = configAttrs.item( configIndex ).toAttr();
312 if ( configAttr.name() == QLatin1String(
"fieldEditable" ) )
314 editWidgetConfigElement.setAttribute( QStringLiteral(
"fieldEditable" ), configAttr.value() );
316 else if ( configAttr.name() == QLatin1String(
"labelOnTop" ) )
318 editWidgetConfigElement.setAttribute( QStringLiteral(
"labelOnTop" ), configAttr.value() );
320 else if ( configAttr.name() == QLatin1String(
"notNull" ) )
322 editWidgetConfigElement.setAttribute( QStringLiteral(
"notNull" ), configAttr.value() );
324 else if ( configAttr.name() == QLatin1String(
"constraint" ) )
326 constraintExpressionElem.setAttribute( QStringLiteral(
"exp" ), configAttr.value() );
328 else if ( configAttr.name() == QLatin1String(
"constraintDescription" ) )
330 constraintExpressionElem.setAttribute( QStringLiteral(
"desc" ), configAttr.value() );
334 editWidgetConfiguration.insert( configAttr.name(), configAttr.value() );
338 if ( ewv2Type == QLatin1String(
"ValueMap" ) )
340 const QDomNodeList configElements = ewv2CfgElem.childNodes();
342 for (
int configIndex = 0; configIndex < configElements.count(); ++configIndex )
344 const QDomElement configElem = configElements.at( configIndex ).toElement();
345 map.insert( configElem.attribute( QStringLiteral(
"key" ) ), configElem.attribute( QStringLiteral(
"value" ) ) );
347 editWidgetConfiguration.insert( QStringLiteral(
"map" ), map );
349 else if ( ewv2Type == QLatin1String(
"Photo" ) )
351 editWidgetElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"ExternalResource" ) );
353 editWidgetConfiguration.insert( QStringLiteral(
"DocumentViewer" ), 1 );
354 editWidgetConfiguration.insert( QStringLiteral(
"DocumentViewerHeight" ), editWidgetConfiguration.value( QStringLiteral(
"Height" ) ) );
355 editWidgetConfiguration.insert( QStringLiteral(
"DocumentViewerWidth" ), editWidgetConfiguration.value( QStringLiteral(
"Width" ) ) );
356 editWidgetConfiguration.insert( QStringLiteral(
"RelativeStorage" ), 1 );
358 else if ( ewv2Type == QLatin1String(
"FileName" ) )
360 editWidgetElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"ExternalResource" ) );
362 editWidgetConfiguration.insert( QStringLiteral(
"RelativeStorage" ), 1 );
364 else if ( ewv2Type == QLatin1String(
"WebView" ) )
366 editWidgetElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"ExternalResource" ) );
368 editWidgetConfiguration.insert( QStringLiteral(
"DocumentViewerHeight" ), editWidgetConfiguration.value( QStringLiteral(
"Height" ) ) );
369 editWidgetConfiguration.insert( QStringLiteral(
"DocumentViewerWidth" ), editWidgetConfiguration.value( QStringLiteral(
"Width" ) ) );
370 editWidgetConfiguration.insert( QStringLiteral(
"RelativeStorage" ), 1 );
384 const QDomNode noDataNode = rasterPropertiesElem.namedItem( QStringLiteral(
"mNoDataValue" ) );
385 const QDomElement noDataElement = noDataNode.toElement();
386 if ( !noDataElement.text().isEmpty() )
389 QDomElement noDataElem = doc.createElement( QStringLiteral(
"noData" ) );
391 QDomElement noDataRangeList = doc.createElement( QStringLiteral(
"noDataRangeList" ) );
392 noDataRangeList.setAttribute( QStringLiteral(
"bandNo" ), 1 );
394 QDomElement noDataRange = doc.createElement( QStringLiteral(
"noDataRange" ) );
395 noDataRange.setAttribute( QStringLiteral(
"min" ), noDataElement.text() );
396 noDataRange.setAttribute( QStringLiteral(
"max" ), noDataElement.text() );
397 noDataRangeList.appendChild( noDataRange );
399 noDataElem.appendChild( noDataRangeList );
401 parentNode.appendChild( noDataElem );
404 QDomElement rasterRendererElem = doc.createElement( QStringLiteral(
"rasterrenderer" ) );
408 rasterRendererElem.setAttribute( QStringLiteral(
"invertColor" ), QStringLiteral(
"0" ) );
409 const QDomElement invertColorElem = rasterPropertiesElem.firstChildElement( QStringLiteral(
"mInvertColor" ) );
410 if ( !invertColorElem.isNull() )
412 if ( invertColorElem.text() == QLatin1String(
"true" ) )
414 rasterRendererElem.setAttribute( QStringLiteral(
"invertColor" ), QStringLiteral(
"1" ) );
419 rasterRendererElem.setAttribute( QStringLiteral(
"opacity" ), QStringLiteral(
"1" ) );
420 const QDomElement transparencyElem = parentNode.firstChildElement( QStringLiteral(
"transparencyLevelInt" ) );
421 if ( !transparencyElem.isNull() )
423 const double transparency = transparencyElem.text().toInt();
424 rasterRendererElem.setAttribute( QStringLiteral(
"opacity" ), QString::number( transparency / 255.0 ) );
428 rasterRendererElem.setAttribute( QStringLiteral(
"alphaBand" ), -1 );
431 const int grayBand =
rasterBandNumber( rasterPropertiesElem, QStringLiteral(
"mGrayBandName" ), rlayer );
434 QString drawingStyle = rasterPropertiesElem.firstChildElement( QStringLiteral(
"mDrawingStyle" ) ).text();
441 if ( drawingStyle == QLatin1String(
"PalettedColor" ) )
443 const QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement( QStringLiteral(
"customColorRamp" ) );
444 const QDomNodeList colorRampEntryList = customColorRampElem.elementsByTagName( QStringLiteral(
"colorRampEntry" ) );
446 for (
int i = 0; i < colorRampEntryList.size(); ++i )
448 const QDomElement colorRampEntryElem = colorRampEntryList.at( i ).toElement();
449 const QString strValue = colorRampEntryElem.attribute( QStringLiteral(
"value" ) );
450 const double value = strValue.toDouble();
451 if ( value < 0 || value > 10000 || !
qgsDoubleNear( value,
static_cast< int >( value ) ) )
453 QgsDebugMsgLevel( QStringLiteral(
"forcing SingleBandPseudoColor value = %1" ).arg( value ), 2 );
454 drawingStyle = QStringLiteral(
"SingleBandPseudoColor" );
460 if ( drawingStyle == QLatin1String(
"SingleBandGray" ) )
462 rasterRendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"singlebandgray" ) );
463 rasterRendererElem.setAttribute( QStringLiteral(
"grayBand" ), grayBand );
466 else if ( drawingStyle == QLatin1String(
"SingleBandPseudoColor" ) )
468 rasterRendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"singlebandpseudocolor" ) );
469 rasterRendererElem.setAttribute( QStringLiteral(
"band" ), grayBand );
470 QDomElement newRasterShaderElem = doc.createElement( QStringLiteral(
"rastershader" ) );
471 QDomElement newColorRampShaderElem = doc.createElement( QStringLiteral(
"colorrampshader" ) );
472 newRasterShaderElem.appendChild( newColorRampShaderElem );
473 rasterRendererElem.appendChild( newRasterShaderElem );
476 const QString colorShadingAlgorithm = rasterPropertiesElem.firstChildElement( QStringLiteral(
"mColorShadingAlgorithm" ) ).text();
477 if ( colorShadingAlgorithm == QLatin1String(
"PseudoColorShader" ) || colorShadingAlgorithm == QLatin1String(
"FreakOutShader" ) )
479 newColorRampShaderElem.setAttribute( QStringLiteral(
"colorRampType" ), QStringLiteral(
"INTERPOLATED" ) );
485 const double breakSize = ( maxValue - minValue ) / 3;
487 QStringList colorList;
488 if ( colorShadingAlgorithm == QLatin1String(
"FreakOutShader" ) )
490 colorList << QStringLiteral(
"#ff00ff" ) << QStringLiteral(
"#00ffff" ) << QStringLiteral(
"#ff0000" ) << QStringLiteral(
"#00ff00" );
494 colorList << QStringLiteral(
"#0000ff" ) << QStringLiteral(
"#00ffff" ) << QStringLiteral(
"#ffff00" ) << QStringLiteral(
"#ff0000" );
496 QStringList::const_iterator colorIt = colorList.constBegin();
497 double boundValue = minValue;
498 for ( ; colorIt != colorList.constEnd(); ++colorIt )
500 QDomElement newItemElem = doc.createElement( QStringLiteral(
"item" ) );
501 newItemElem.setAttribute( QStringLiteral(
"value" ), QString::number( boundValue ) );
502 newItemElem.setAttribute( QStringLiteral(
"label" ), QString::number( boundValue ) );
503 newItemElem.setAttribute( QStringLiteral(
"color" ), *colorIt );
504 newColorRampShaderElem.appendChild( newItemElem );
505 boundValue += breakSize;
508 else if ( colorShadingAlgorithm == QLatin1String(
"ColorRampShader" ) )
510 const QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement( QStringLiteral(
"customColorRamp" ) );
511 const QString type = customColorRampElem.firstChildElement( QStringLiteral(
"colorRampType" ) ).text();
512 newColorRampShaderElem.setAttribute( QStringLiteral(
"colorRampType" ), type );
513 const QDomNodeList colorNodeList = customColorRampElem.elementsByTagName( QStringLiteral(
"colorRampEntry" ) );
515 QString value, label;
517 int red, green, blue;
518 QDomElement currentItemElem;
519 for (
int i = 0; i < colorNodeList.size(); ++i )
521 currentItemElem = colorNodeList.at( i ).toElement();
522 value = currentItemElem.attribute( QStringLiteral(
"value" ) );
523 label = currentItemElem.attribute( QStringLiteral(
"label" ) );
524 red = currentItemElem.attribute( QStringLiteral(
"red" ) ).toInt();
525 green = currentItemElem.attribute( QStringLiteral(
"green" ) ).toInt();
526 blue = currentItemElem.attribute( QStringLiteral(
"blue" ) ).toInt();
527 newColor = QColor( red, green, blue );
528 QDomElement newItemElem = doc.createElement( QStringLiteral(
"item" ) );
529 newItemElem.setAttribute( QStringLiteral(
"value" ), value );
530 newItemElem.setAttribute( QStringLiteral(
"label" ), label );
531 newItemElem.setAttribute( QStringLiteral(
"color" ), newColor.name() );
532 newColorRampShaderElem.appendChild( newItemElem );
536 else if ( drawingStyle == QLatin1String(
"PalettedColor" ) )
538 rasterRendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"paletted" ) );
539 rasterRendererElem.setAttribute( QStringLiteral(
"band" ), grayBand );
540 const QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement( QStringLiteral(
"customColorRamp" ) );
541 const QDomNodeList colorRampEntryList = customColorRampElem.elementsByTagName( QStringLiteral(
"colorRampEntry" ) );
542 QDomElement newColorPaletteElem = doc.createElement( QStringLiteral(
"colorPalette" ) );
548 QDomElement colorRampEntryElem;
549 for (
int i = 0; i < colorRampEntryList.size(); ++i )
551 colorRampEntryElem = colorRampEntryList.at( i ).toElement();
552 QDomElement newPaletteElem = doc.createElement( QStringLiteral(
"paletteEntry" ) );
553 value =
static_cast< int >( colorRampEntryElem.attribute( QStringLiteral(
"value" ) ).toDouble() );
554 newPaletteElem.setAttribute( QStringLiteral(
"value" ), value );
555 red = colorRampEntryElem.attribute( QStringLiteral(
"red" ) ).toInt();
556 green = colorRampEntryElem.attribute( QStringLiteral(
"green" ) ).toInt();
557 blue = colorRampEntryElem.attribute( QStringLiteral(
"blue" ) ).toInt();
558 newPaletteElem.setAttribute( QStringLiteral(
"color" ), QColor( red, green, blue ).name() );
559 const QString label = colorRampEntryElem.attribute( QStringLiteral(
"label" ) );
560 if ( !label.isEmpty() )
562 newPaletteElem.setAttribute( QStringLiteral(
"label" ), label );
564 newColorPaletteElem.appendChild( newPaletteElem );
566 rasterRendererElem.appendChild( newColorPaletteElem );
568 else if ( drawingStyle == QLatin1String(
"MultiBandColor" ) )
570 rasterRendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"multibandcolor" ) );
573 const int redBand =
rasterBandNumber( rasterPropertiesElem, QStringLiteral(
"mRedBandName" ), rlayer );
574 const int greenBand =
rasterBandNumber( rasterPropertiesElem, QStringLiteral(
"mGreenBandName" ), rlayer );
575 const int blueBand =
rasterBandNumber( rasterPropertiesElem, QStringLiteral(
"mBlueBandName" ), rlayer );
576 rasterRendererElem.setAttribute( QStringLiteral(
"redBand" ), redBand );
577 rasterRendererElem.setAttribute( QStringLiteral(
"greenBand" ), greenBand );
578 rasterRendererElem.setAttribute( QStringLiteral(
"blueBand" ), blueBand );
588 if ( !parentNode.isNull() )
590 parentNode.replaceChild( rasterRendererElem, rasterPropertiesElem );
601 return mCurrentVersion;
612 const QDomElement rasterBandElem = rasterPropertiesElem.firstChildElement( bandName );
613 if ( !rasterBandElem.isNull() )
615 const thread_local QRegularExpression re(
"(\\d+)" );
616 const QRegularExpressionMatch match = re.match( rasterBandElem.text() );
617 if ( match.hasMatch() )
619 return match.captured( 1 ).toInt();
627 if ( rasterproperties.isNull() || rendererElem.isNull() )
632 double minimumValue = 0;
633 double maximumValue = 0;
634 const QDomElement contrastMinMaxElem = rasterproperties.firstChildElement( QStringLiteral(
"contrastEnhancementMinMaxValues" ) );
635 if ( contrastMinMaxElem.isNull() )
640 const QDomElement contrastEnhancementAlgorithmElem = rasterproperties.firstChildElement( QStringLiteral(
"mContrastEnhancementAlgorithm" ) );
641 if ( contrastEnhancementAlgorithmElem.isNull() )
647 int algorithmEnum = 0;
648 const QString algorithmString = contrastEnhancementAlgorithmElem.text();
649 if ( algorithmString == QLatin1String(
"StretchToMinimumMaximum" ) )
653 else if ( algorithmString == QLatin1String(
"StretchAndClipToMinimumMaximum" ) )
657 else if ( algorithmString == QLatin1String(
"ClipToMinimumMaximum" ) )
661 else if ( algorithmString == QLatin1String(
"UserDefinedEnhancement" ) )
666 const QDomNodeList minMaxEntryList = contrastMinMaxElem.elementsByTagName( QStringLiteral(
"minMaxEntry" ) );
667 QStringList enhancementNameList;
668 if ( minMaxEntryList.size() == 1 )
670 enhancementNameList << QStringLiteral(
"contrastEnhancement" );
672 if ( minMaxEntryList.size() == 3 )
674 enhancementNameList << QStringLiteral(
"redContrastEnhancement" ) << QStringLiteral(
"greenContrastEnhancement" ) << QStringLiteral(
"blueContrastEnhancement" );
676 if ( minMaxEntryList.size() > enhancementNameList.size() )
681 QDomElement minMaxEntryElem;
682 for (
int i = 0; i < minMaxEntryList.size(); ++i )
684 minMaxEntryElem = minMaxEntryList.at( i ).toElement();
685 const QDomElement minElem = minMaxEntryElem.firstChildElement( QStringLiteral(
"min" ) );
686 if ( minElem.isNull() )
690 minimumValue = minElem.text().toDouble();
692 const QDomElement maxElem = minMaxEntryElem.firstChildElement( QStringLiteral(
"max" ) );
693 if ( maxElem.isNull() )
697 maximumValue = maxElem.text().toDouble();
699 QDomElement newContrastEnhancementElem = doc.createElement( enhancementNameList.at( i ) );
700 QDomElement newMinValElem = doc.createElement( QStringLiteral(
"minValue" ) );
701 const QDomText minText = doc.createTextNode( QString::number( minimumValue ) );
702 newMinValElem.appendChild( minText );
703 newContrastEnhancementElem.appendChild( newMinValElem );
704 QDomElement newMaxValElem = doc.createElement( QStringLiteral(
"maxValue" ) );
705 const QDomText maxText = doc.createTextNode( QString::number( maximumValue ) );
706 newMaxValElem.appendChild( maxText );
707 newContrastEnhancementElem.appendChild( newMaxValElem );
709 QDomElement newAlgorithmElem = doc.createElement( QStringLiteral(
"algorithm" ) );
710 const QDomText newAlgorithmText = doc.createTextNode( QString::number( algorithmEnum ) );
711 newAlgorithmElem.appendChild( newAlgorithmText );
712 newContrastEnhancementElem.appendChild( newAlgorithmElem );
714 rendererElem.appendChild( newContrastEnhancementElem );
726 auto migrateOldReferences = [&mapLayers](
const QList<QgsSymbolLayerReference> &slRefs )
728 QList<QgsSymbolLayerReference> newRefs;
731 const QgsVectorLayer *vlRef = qobject_cast<QgsVectorLayer *>( mapLayers[ slRef.layerId() ] );
735 renderer, QSet<QgsSymbolLayerId>() << slRef.symbolLayerId() ) : QSet<const QgsSymbolLayer *>();
737 const QString slId = symbolLayers.isEmpty() ? QString() : ( *symbolLayers.constBegin() )->
id();
746 const QStringList subProviders = labeling->subProviders();
747 for (
const QString &provider : subProviders )
751 QList<QgsSymbolLayerReference> newMaskedSymbolLayers = migrateOldReferences( format.
mask().
maskedSymbolLayers() );
769 void visitSymbol(
const QgsSymbol *symbol )
778 visitSymbol( subSymbol );
781 maskSymbolLayers << maskLayer;
790 if ( symbolEntity->symbol() )
791 visitSymbol( symbolEntity->symbol() );
796 QList<const QgsMaskMarkerSymbolLayer *> maskSymbolLayers;
799 SymbolLayerVisitor visitor;
800 renderer->accept( &visitor );
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
Base class for all map layer types.
Special symbol layer that uses its sub symbol as a selective mask.
void setMasks(const QList< QgsSymbolLayerReference > &maskedLayers)
Sets the symbol layers that will be masked by the sub symbol's shape.
Contains settings for how a map layer will be labeled.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc.
A class to describe the version of a project.
int subVersion() const
Returns the sub version number.
int majorVersion() const
Returns the major version number.
int minorVersion() const
Returns the minor version number.
bool isNull() const
Returns true if this is a NULL project version.
The RasterBandStats struct is a container for statistics about a single raster band.
double minimumValue
The minimum cell value in the raster band.
double maximumValue
The maximum cell value in the raster band.
Q_DECL_DEPRECATED QgsRasterBandStats bandStatistics(int bandNo, int stats, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0, QgsRasterBlockFeedback *feedback=nullptr)
Returns the band statistics.
Represents a raster layer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
virtual QgsStyle::StyleEntity type() const =0
Returns the type of style entity.
An interface for classes which can visit style entity (e.g.
@ SymbolRule
Rule based symbology or label child rule.
A symbol entity for QgsStyle databases.
Type used to refer to a specific symbol layer in a symbol of a layer.
static Q_DECL_DEPRECATED QSet< const QgsSymbolLayer * > toSymbolLayerPointers(const QgsFeatureRenderer *renderer, const QSet< QgsSymbolLayerId > &symbolLayerIds)
Converts a set of symbol layer id to a set of pointers to actual symbol layers carried by the feature...
Abstract base class for all rendered symbols.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Container for all settings relating to text rendering.
QgsTextMaskSettings & mask()
Returns a reference to the masking settings.
void setMaskedSymbolLayers(const QList< QgsSymbolLayerReference > &maskedLayers)
Sets the symbol layers that will be masked by this buffer.
QList< QgsSymbolLayerReference > maskedSymbolLayers() const
Returns a list of references to symbol layers that are masked by this buffer.
Represents a vector layer which manages a vector based data sets.
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
#define QgsDebugMsgLevel(str, level)
Contains information relating to a node (i.e.
QgsStyleEntityVisitorInterface::NodeType type
Node type.
Contains information relating to the style entity currently being visited.
const QgsStyleEntityInterface * entity
Reference to style entity being visited.