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()
213 for (
int i = 0; i < rasterPropertyList.
count(); i++ )
232 for (
int i = 0; i < symbolPropertyList.
count(); i++ )
244 if ( pointSize != 0 )
249 pointSize = pointSize + 2 + 2 * lineWidth;
253 newPointSizeProperty.
appendChild( newPointSizeTxt );
254 symbolProperty.
replaceChild( newPointSizeProperty, pointSymbol );
264 void QgsProjectFileTransform::transform0100to0110()
269 QPrinter myPrinter( QPrinter::ScreenResolution );
270 int screenDpi = myPrinter.resolution();
271 double widthScaleFactor = 25.4 / screenDpi;
274 for (
int i = 0; i < outlineWidthList.
size(); ++i )
278 double outlineWidth = currentOutlineElem.
text().
toDouble();
279 outlineWidth *= widthScaleFactor;
284 currentOutlineElem.
replaceChild( newOutlineText, outlineTextNode );
290 for (
int i = 0; i < pointSizeList.
size(); ++i )
294 double pointSize = currentPointSizeElem.
text().
toDouble();
295 pointSize *= widthScaleFactor;
300 currentPointSizeElem.
replaceChild( newPointSizeText, pointSizeTextNode );
305 void QgsProjectFileTransform::transform0110to1000()
310 for (
int i = 0; i < layerList.
size(); ++i )
314 if ( typeString !=
"vector" )
321 if ( dataSourceNode.
isNull() )
329 if ( providerNode.
isNull() )
352 for (
int j = 0; j < classificationFieldList.
size(); ++j )
355 int fieldNumber = classificationFieldElem.
text().
toInt();
356 if ( fieldNumber >= 0 && fieldNumber < theFields.
count() )
360 classificationFieldElem.
replaceChild( fieldName, nameNode );
368 void QgsProjectFileTransform::transform1100to1200()
379 if ( properties.
isNull() )
383 if ( digitizing.
isNull() )
391 if ( !tolUnitList.
isNull() )
399 value.writeXML(
"LayerSnappingToleranceUnitList", digitizing, mDom );
402 void QgsProjectFileTransform::transform1400to1500()
414 for (
int i = 0; i < layerItemList.
size(); ++i )
416 currentLayerItemElem = layerItemList.
at( i ).
toElement();
417 if ( currentLayerItemElem.
isNull() )
421 currentLayerId = currentLayerItemElem.
attribute(
"layerId" );
425 for (
int j = 0; j < vectorClassificationList.
size(); ++j )
427 currentClassificationElem = vectorClassificationList.
at( j ).
toElement();
428 if ( !currentClassificationElem.
isNull() )
430 currentClassificationElem.
setAttribute(
"layerId", currentLayerId );
438 for (
int j = 0; j < textItemList.
size(); ++j )
440 currentTextItem = textItemList.
at( j ).
toElement();
441 if ( currentTextItem.
isNull() )
447 if ( vectorClassificationList.
size() > 0 )
449 classificationElement = mDom.
createElement(
"VectorClassificationItem" );
453 classificationElement = mDom.
createElement(
"RasterClassificationItem" );
456 classificationElement.
setAttribute(
"layerId", currentLayerId );
458 currentLayerItemElem.
replaceChild( classificationElement, currentTextItem );
463 void QgsProjectFileTransform::transform1800to1900()
471 for (
int i = 0; i < layerItemList.
size(); ++i )
487 for (
int i = 0; i < composerMapList.
size(); ++i )
490 for (
int j = 0; j < gridList.
size(); ++j )
493 for (
int k = 0; k < annotationList.
size(); ++k )
541 for (
int i = 0; i < composerList.
size(); ++i )
547 if ( compositionElem.
isNull() )
554 if ( composerChildren.
size() < 1 )
559 for (
int j = composerChildren.
size() - 1; j >= 0; --j )
562 if ( childElem.
tagName() ==
"Composition" )
577 for (
int i = 0; i < rendererList.
size(); ++i )
580 for (
int j = 0; j < layerList.
size(); ++j )
583 if ( layerElem.
attribute(
"class" ) ==
"SimpleFill" )
586 for (
int k = 0; k < propList.
size(); ++k )
589 if ( propElem.
attribute(
"k" ) ==
"color" || propElem.
attribute(
"k" ) ==
"color_border" )
601 void QgsProjectFileTransform::transform2200to2300()
605 for (
int i = 0; i < composerPictureList.
size(); ++i )
643 if ( !invertColorElem.
isNull() )
645 if ( invertColorElem.
text() ==
"true" )
654 if ( !transparencyElem.
isNull() )
656 double transparency = transparencyElem.
text().
toInt();
664 int grayBand = rasterBandNumber( rasterPropertiesElem,
"mGrayBandName", rlayer );
674 if ( drawingStyle ==
"PalettedColor" )
679 for (
int i = 0; i < colorRampEntryList.
size(); ++i )
684 if ( value < 0 || value > 10000 || value != (
int )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" );
705 newRasterShaderElem.
appendChild( newColorRampShaderElem );
706 rasterRendererElem.
appendChild( newRasterShaderElem );
710 if ( colorShadingAlgorithm ==
"PseudoColorShader" || colorShadingAlgorithm ==
"FreakOutShader" )
712 newColorRampShaderElem.
setAttribute(
"colorRampType",
"INTERPOLATED" );
718 double breakSize = ( maxValue - minValue ) / 3;
721 if ( colorShadingAlgorithm ==
"FreakOutShader" )
723 colorList <<
"#ff00ff" <<
"#00ffff" <<
"#ff0000" <<
"#00ff00";
727 colorList <<
"#0000ff" <<
"#00ffff" <<
"#ffff00" <<
"#ff0000";
730 double boundValue = minValue;
731 for ( ; colorIt != colorList.
constEnd(); ++colorIt )
738 boundValue += breakSize;
741 else if ( colorShadingAlgorithm ==
"ColorRampShader" )
745 newColorRampShaderElem.
setAttribute(
"colorRampType", type );
750 int red, green, blue;
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" );
760 newColor =
QColor( red, green, blue );
769 else if ( drawingStyle ==
"PalettedColor" )
782 for (
int i = 0; i < colorRampEntryList.
size(); ++i )
784 colorRampEntryElem = colorRampEntryList.
at( i ).
toElement();
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 );
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,
837 if ( !rasterBandElem.
isNull() )
841 if ( re.indexIn( rasterBandElem.
text() ) >= 0 )
843 return re.cap( 1 ).toInt();
851 if ( rasterproperties.
isNull() || rendererElem.
isNull() )
856 double minimumValue = 0;
857 double maximumValue = 0;
859 if ( contrastMinMaxElem.
isNull() )
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" )
892 if ( minMaxEntryList.
size() == 1 )
894 enhancementNameList <<
"contrastEnhancement";
896 if ( minMaxEntryList.
size() == 3 )
898 enhancementNameList <<
"redContrastEnhancement" <<
"greenContrastEnhancement" <<
"blueContrastEnhancement";
900 if ( minMaxEntryList.
size() > enhancementNameList.
size() )
906 for (
int i = 0; i < minMaxEntryList.
size(); ++i )
908 minMaxEntryElem = minMaxEntryList.
at( i ).
toElement();
927 newContrastEnhancementElem.
appendChild( newMinValElem );
931 newContrastEnhancementElem.
appendChild( newMaxValElem );
936 newContrastEnhancementElem.
appendChild( newAlgorithmElem );
938 rendererElem.
appendChild( newContrastEnhancementElem );
947 Q_UNUSED( rendererElem );
QDomNodeList elementsByTagName(const QString &tagname) const
QDomNode item(int index) const
QDomNode appendChild(const QDomNode &newChild)
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.
double toDouble(bool *ok) const
QDomNodeList childNodes() const
QDomElement toElement() 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
int count() const
Return number of items.
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
bool readLayerXML(const QDomElement &layerElement)
sets state from Dom document
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