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;
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;
99 void QgsProjectFileTransform::transform081to090()
143 bool doneDestination =
false;
144 for (
int i = 0; i < mapLayers.
count(); i++ )
157 if ( ! doneDestination )
165 doneDestination =
true;
176 for (
int i = 0; i < mapLayers.
count(); i++ )
184 for (
int j = 0; j < legendLayerFiles.
count(); j++ )
187 if (
id == legendLayerFile.
attribute(
"layerid" ) )
205 void QgsProjectFileTransform::transform091to0100()
212 for (
int i = 0; i < rasterPropertyList.
count(); i++ )
231 for (
int i = 0; i < symbolPropertyList.
count(); i++ )
243 if ( pointSize != 0 )
248 pointSize = pointSize + 2 + 2 * lineWidth;
252 newPointSizeProperty.
appendChild( newPointSizeTxt );
253 symbolProperty.
replaceChild( newPointSizeProperty, pointSymbol );
263 void QgsProjectFileTransform::transform0100to0110()
268 QPrinter myPrinter( QPrinter::ScreenResolution );
270 double widthScaleFactor = 25.4 / screenDpi;
273 for (
int i = 0; i < outlineWidthList.
size(); ++i )
277 double outlineWidth = currentOutlineElem.
text().
toDouble();
278 outlineWidth *= widthScaleFactor;
283 currentOutlineElem.
replaceChild( newOutlineText, outlineTextNode );
289 for (
int i = 0; i < pointSizeList.
size(); ++i )
293 double pointSize = currentPointSizeElem.
text().
toDouble();
294 pointSize *= widthScaleFactor;
299 currentPointSizeElem.
replaceChild( newPointSizeText, pointSizeTextNode );
304 void QgsProjectFileTransform::transform0110to1000()
309 for (
int i = 0; i < layerList.
size(); ++i )
313 if ( typeString !=
"vector" )
320 if ( dataSourceNode.
isNull() )
328 if ( providerNode.
isNull() )
351 for (
int j = 0; j < classificationFieldList.
size(); ++j )
354 int fieldNumber = classificationFieldElem.
text().
toInt();
355 if ( fieldNumber >= 0 && fieldNumber < theFields.
count() )
359 classificationFieldElem.
replaceChild( fieldName, nameNode );
367 void QgsProjectFileTransform::transform1100to1200()
378 if ( properties.
isNull() )
382 if ( digitizing.
isNull() )
390 if ( !tolUnitList.
isNull() )
398 value.
writeXML(
"LayerSnappingToleranceUnitList", digitizing, mDom );
401 void QgsProjectFileTransform::transform1400to1500()
413 for (
int i = 0; i < layerItemList.
size(); ++i )
415 currentLayerItemElem = layerItemList.
at( i ).
toElement();
416 if ( currentLayerItemElem.
isNull() )
420 currentLayerId = currentLayerItemElem.
attribute(
"layerId" );
424 for (
int j = 0; j < vectorClassificationList.
size(); ++j )
426 currentClassificationElem = vectorClassificationList.
at( j ).
toElement();
427 if ( !currentClassificationElem.
isNull() )
429 currentClassificationElem.
setAttribute(
"layerId", currentLayerId );
437 for (
int j = 0; j < textItemList.
size(); ++j )
439 currentTextItem = textItemList.
at( j ).
toElement();
440 if ( currentTextItem.
isNull() )
446 if ( !vectorClassificationList.
isEmpty() )
448 classificationElement = mDom.
createElement(
"VectorClassificationItem" );
452 classificationElement = mDom.
createElement(
"RasterClassificationItem" );
455 classificationElement.
setAttribute(
"layerId", currentLayerId );
457 currentLayerItemElem.
replaceChild( classificationElement, currentTextItem );
462 void QgsProjectFileTransform::transform1800to1900()
470 for (
int i = 0; i < layerItemList.
size(); ++i )
486 for (
int i = 0; i < composerMapList.
size(); ++i )
489 for (
int j = 0; j < gridList.
size(); ++j )
492 for (
int k = 0; k < annotationList.
size(); ++k )
540 for (
int i = 0; i < composerList.
size(); ++i )
546 if ( compositionElem.
isNull() )
553 if ( composerChildren.
size() < 1 )
558 for (
int j = composerChildren.
size() - 1; j >= 0; --j )
561 if ( childElem.
tagName() ==
"Composition" )
576 for (
int i = 0; i < rendererList.
size(); ++i )
579 for (
int j = 0; j < layerList.
size(); ++j )
582 if ( layerElem.
attribute(
"class" ) ==
"SimpleFill" )
585 for (
int k = 0; k < propList.
size(); ++k )
588 if ( propElem.
attribute(
"k" ) ==
"color" || propElem.
attribute(
"k" ) ==
"color_border" )
600 void QgsProjectFileTransform::transform2200to2300()
604 for (
int i = 0; i < composerPictureList.
size(); ++i )
642 if ( !invertColorElem.
isNull() )
644 if ( invertColorElem.
text() ==
"true" )
653 if ( !transparencyElem.
isNull() )
655 double transparency = transparencyElem.
text().
toInt();
663 int grayBand = rasterBandNumber( rasterPropertiesElem,
"mGrayBandName", rlayer );
673 if ( drawingStyle ==
"PalettedColor" )
678 for (
int i = 0; i < colorRampEntryList.
size(); ++i )
683 if ( value < 0 || value > 10000 || !
qgsDoubleNear( value, static_cast< int >( value ) ) )
686 drawingStyle =
"SingleBandPseudoColor";
692 if ( drawingStyle ==
"SingleBandGray" )
694 rasterRendererElem.
setAttribute(
"type",
"singlebandgray" );
695 rasterRendererElem.
setAttribute(
"grayBand", grayBand );
696 transformContrastEnhancement( doc, rasterPropertiesElem, rasterRendererElem );
698 else if ( drawingStyle ==
"SingleBandPseudoColor" )
700 rasterRendererElem.
setAttribute(
"type",
"singlebandpseudocolor" );
704 newRasterShaderElem.
appendChild( newColorRampShaderElem );
705 rasterRendererElem.
appendChild( newRasterShaderElem );
709 if ( colorShadingAlgorithm ==
"PseudoColorShader" || colorShadingAlgorithm ==
"FreakOutShader" )
711 newColorRampShaderElem.
setAttribute(
"colorRampType",
"INTERPOLATED" );
717 double breakSize = ( maxValue - minValue ) / 3;
720 if ( colorShadingAlgorithm ==
"FreakOutShader" )
722 colorList <<
"#ff00ff" <<
"#00ffff" <<
"#ff0000" <<
"#00ff00";
726 colorList <<
"#0000ff" <<
"#00ffff" <<
"#ffff00" <<
"#ff0000";
729 double boundValue = minValue;
730 for ( ; colorIt != colorList.
constEnd(); ++colorIt )
737 boundValue += breakSize;
740 else if ( colorShadingAlgorithm ==
"ColorRampShader" )
744 newColorRampShaderElem.
setAttribute(
"colorRampType", type );
749 int red, green, blue;
751 for (
int i = 0; i < colorNodeList.
size(); ++i )
753 currentItemElem = colorNodeList.
at( i ).
toElement();
754 value = currentItemElem.
attribute(
"value" );
755 label = currentItemElem.
attribute(
"label" );
759 newColor =
QColor( red, green, blue );
768 else if ( drawingStyle ==
"PalettedColor" )
781 for (
int i = 0; i < colorRampEntryList.
size(); ++i )
783 colorRampEntryElem = colorRampEntryList.
at( i ).
toElement();
785 value =
static_cast< int >( colorRampEntryElem.
attribute(
"value" ).
toDouble() );
798 rasterRendererElem.
appendChild( newColorPaletteElem );
800 else if ( drawingStyle ==
"MultiBandColor" )
802 rasterRendererElem.
setAttribute(
"type",
"multibandcolor" );
805 int redBand = rasterBandNumber( rasterPropertiesElem,
"mRedBandName", rlayer );
806 int greenBand = rasterBandNumber( rasterPropertiesElem,
"mGreenBandName", rlayer );
807 int blueBand = rasterBandNumber( rasterPropertiesElem,
"mBlueBandName", rlayer );
809 rasterRendererElem.
setAttribute(
"greenBand", greenBand );
810 rasterRendererElem.
setAttribute(
"blueBand", blueBand );
812 transformContrastEnhancement( doc, rasterPropertiesElem, rasterRendererElem );
820 if ( !parentNode.
isNull() )
822 parentNode.
replaceChild( rasterRendererElem, rasterPropertiesElem );
826 int QgsProjectFileTransform::rasterBandNumber(
const QDomElement &rasterPropertiesElem,
const QString &bandName,
836 if ( !rasterBandElem.
isNull() )
850 if ( rasterproperties.
isNull() || rendererElem.
isNull() )
855 double minimumValue = 0;
856 double maximumValue = 0;
858 if ( contrastMinMaxElem.
isNull() )
864 if ( contrastEnhancementAlgorithmElem.
isNull() )
870 int algorithmEnum = 0;
871 QString algorithmString = contrastEnhancementAlgorithmElem.
text();
872 if ( algorithmString ==
"StretchToMinimumMaximum" )
876 else if ( algorithmString ==
"StretchAndClipToMinimumMaximum" )
880 else if ( algorithmString ==
"ClipToMinimumMaximum" )
884 else if ( algorithmString ==
"UserDefinedEnhancement" )
891 if ( minMaxEntryList.
size() == 1 )
893 enhancementNameList <<
"contrastEnhancement";
895 if ( minMaxEntryList.
size() == 3 )
897 enhancementNameList <<
"redContrastEnhancement" <<
"greenContrastEnhancement" <<
"blueContrastEnhancement";
899 if ( minMaxEntryList.
size() > enhancementNameList.
size() )
905 for (
int i = 0; i < minMaxEntryList.
size(); ++i )
907 minMaxEntryElem = minMaxEntryList.
at( i ).
toElement();
926 newContrastEnhancementElem.
appendChild( newMinValElem );
930 newContrastEnhancementElem.
appendChild( newMaxValElem );
935 newContrastEnhancementElem.
appendChild( newAlgorithmElem );
937 rendererElem.
appendChild( newContrastEnhancementElem );
946 Q_UNUSED( rendererElem );
QDomNodeList elementsByTagName(const QString &tagname) const
QString cap(int nth) const
QDomNode item(int index) const
QDomNode appendChild(const QDomNode &newChild)
bool writeXML(const QString &nodeName, QDomElement &element, QDomDocument &document) override
keyElement created by parent QgsPropertyKey
QString attribute(const QString &name, const QString &defValue) const
void setTagName(const QString &name)
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QString toString(int indent) const
const T & at(int i) const
double maximumValue
The maximum cell value in the raster band.
Container of fields for a vector layer.
bool readLayerXML(const QDomElement &layerElement, const QString &relativeBasePath=QString())
Sets state from Dom document.
double toDouble(bool *ok) const
QDomNodeList childNodes() const
int count() const
Return number of items.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
QDomElement toElement() const
int indexIn(const QString &str, int offset, CaretMode caretMode) const
virtual QgsRasterBandStats bandStatistics(int theBandNo, int theStats=QgsRasterBandStats::All, const QgsRectangle &theExtent=QgsRectangle(), int theSampleSize=0)
Get band statistics.
QString number(int n, int base)
The RasterBandStats struct is a container for statistics about a single raster band.
bool hasAttribute(const QString &name) const
void setAttribute(const QString &name, const QString &value)
A class to describe the version of a project.
int toInt(bool *ok, int base) const
QDomNodeList elementsByTagName(const QString &tagname) const
const char * constData() const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
bool isValid()
Return the status of the layer.
QDomText createTextNode(const QString &value)
QDomNode removeChild(const QDomNode &oldChild)
QDomNode namedItem(const QString &name) const
virtual const QgsFields & fields() const =0
Return a map of indexes with field names for this layer.
QDomNode firstChild() const
QByteArray toLatin1() const
QDomNode parentNode() const
QDomNode replaceChild(const QDomNode &newChild, const QDomNode &oldChild)
QDomElement firstChildElement(const QString &tagName) const
double minimumValue
The minimum cell value in the raster band.
QString section(QChar sep, int start, int end, QFlags< QString::SectionFlag > flags) const
void removeAttribute(const QString &name)
QgsRasterDataProvider * dataProvider()
Returns the data provider.
QgsVectorDataProvider * dataProvider()
Returns the data provider.
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
const_iterator constBegin() const
This is the base class for vector data providers.
Represents a vector layer which manages a vector based data sets.
QDomNode at(int index) const