diff --git a/doc/api_break.dox b/doc/api_break.dox index 48c516a6b58..7a46af3199a 100644 --- a/doc/api_break.dox +++ b/doc/api_break.dox @@ -1018,6 +1018,7 @@ QgsEditorWidgetRegistry::instance()->findBest() must be used instead. have been removed. Use QgsVectorLayer.setConstraintExpression()/constraintExpression(), or QgsField.constraintExpression()/QgsField.constraintDescription() instead. - notNull() and setNotNull() have been removed. Use QgsVectorLayer.setFieldConstraint()/fieldConstraints(), or QgsField.constraints() instead. +- readXml() and writeXml() now also expect a reference to QgsReadWriteContext object. QgsEditorWidgetWrapper {#qgis_api_break_3_0_QgsEditorWidgetWrapper} ---------------------- diff --git a/python/core/qgseditformconfig.sip b/python/core/qgseditformconfig.sip index 1daa5ee2632..230f3b93c09 100644 --- a/python/core/qgseditformconfig.sip +++ b/python/core/qgseditformconfig.sip @@ -197,13 +197,13 @@ class QgsEditFormConfig * Read XML information * Deserialize on project load */ - void readXml( const QDomNode &node ); + void readXml( const QDomNode &node, const QgsReadWriteContext &context ); /** * Write XML information * Serialize on project save */ - void writeXml( QDomNode &node ) const; + void writeXml( QDomNode &node, const QgsReadWriteContext &context ) const; /** * Deserialize drag and drop designer elements. diff --git a/src/core/annotations/qgssvgannotation.cpp b/src/core/annotations/qgssvgannotation.cpp index 0fa9695fbfe..988cc946c6f 100644 --- a/src/core/annotations/qgssvgannotation.cpp +++ b/src/core/annotations/qgssvgannotation.cpp @@ -16,7 +16,11 @@ ***************************************************************************/ #include "qgssvgannotation.h" + +#include "qgsreadwritecontext.h" #include "qgsproject.h" +#include "qgssymbollayerutils.h" + #include #include @@ -37,15 +41,16 @@ QgsSvgAnnotation *QgsSvgAnnotation::clone() const void QgsSvgAnnotation::writeXml( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const { + QString filePath = QgsSymbolLayerUtils::svgSymbolPathToName( mFilePath, context.pathResolver() ); QDomElement svgAnnotationElem = doc.createElement( QStringLiteral( "SVGAnnotationItem" ) ); - svgAnnotationElem.setAttribute( QStringLiteral( "file" ), QgsProject::instance()->writePath( mFilePath ) ); + svgAnnotationElem.setAttribute( QStringLiteral( "file" ), filePath ); _writeXml( svgAnnotationElem, doc, context ); elem.appendChild( svgAnnotationElem ); } void QgsSvgAnnotation::readXml( const QDomElement &itemElem, const QgsReadWriteContext &context ) { - QString filePath = QgsProject::instance()->readPath( itemElem.attribute( QStringLiteral( "file" ) ) ); + QString filePath = QgsSymbolLayerUtils::svgSymbolNameToPath( itemElem.attribute( QStringLiteral( "file" ) ), context.pathResolver() ); setFilePath( filePath ); QDomElement annotationElem = itemElem.firstChildElement( QStringLiteral( "AnnotationItem" ) ); if ( !annotationElem.isNull() ) diff --git a/src/core/qgseditformconfig.cpp b/src/core/qgseditformconfig.cpp index 3f860e9b855..eb3e7ea7911 100644 --- a/src/core/qgseditformconfig.cpp +++ b/src/core/qgseditformconfig.cpp @@ -14,7 +14,9 @@ ***************************************************************************/ #include "qgseditformconfig_p.h" #include "qgseditformconfig.h" +#include "qgspathresolver.h" #include "qgsproject.h" +#include "qgsreadwritecontext.h" #include "qgsrelationmanager.h" #include "qgslogger.h" @@ -255,14 +257,14 @@ void QgsEditFormConfig::setSuppress( QgsEditFormConfig::FeatureFormSuppress s ) d->mSuppressForm = s; } -void QgsEditFormConfig::readXml( const QDomNode &node ) +void QgsEditFormConfig::readXml( const QDomNode &node, const QgsReadWriteContext &context ) { d.detach(); QDomNode editFormNode = node.namedItem( QStringLiteral( "editform" ) ); if ( !editFormNode.isNull() ) { QDomElement e = editFormNode.toElement(); - d->mUiFormPath = QgsProject::instance()->readPath( e.text() ); + d->mUiFormPath = context.pathResolver().readPath( e.text() ); } QDomNode editFormInitNode = node.namedItem( QStringLiteral( "editforminit" ) ); @@ -299,7 +301,7 @@ void QgsEditFormConfig::readXml( const QDomNode &node ) QDomNode editFormInitFilePathNode = node.namedItem( QStringLiteral( "editforminitfilepath" ) ); if ( !editFormInitFilePathNode.isNull() && !editFormInitFilePathNode.toElement().text().isEmpty() ) { - setInitFilePath( QgsProject::instance()->readPath( editFormInitFilePathNode.toElement().text() ) ); + setInitFilePath( context.pathResolver().readPath( editFormInitFilePathNode.toElement().text() ) ); } QDomNode fFSuppNode = node.namedItem( QStringLiteral( "featformsuppress" ) ); @@ -357,12 +359,12 @@ void QgsEditFormConfig::readXml( const QDomNode &node ) } } -void QgsEditFormConfig::writeXml( QDomNode &node ) const +void QgsEditFormConfig::writeXml( QDomNode &node, const QgsReadWriteContext &context ) const { QDomDocument doc( node.ownerDocument() ); QDomElement efField = doc.createElement( QStringLiteral( "editform" ) ); - QDomText efText = doc.createTextNode( QgsProject::instance()->writePath( uiForm() ) ); + QDomText efText = doc.createTextNode( context.pathResolver().writePath( uiForm() ) ); efField.appendChild( efText ); node.appendChild( efField ); @@ -376,7 +378,7 @@ void QgsEditFormConfig::writeXml( QDomNode &node ) const node.appendChild( eficsField ); QDomElement efifpField = doc.createElement( QStringLiteral( "editforminitfilepath" ) ); - efifpField.appendChild( doc.createTextNode( QgsProject::instance()->writePath( initFilePath() ) ) ); + efifpField.appendChild( doc.createTextNode( context.pathResolver().writePath( initFilePath() ) ) ); node.appendChild( efifpField ); QDomElement eficField = doc.createElement( QStringLiteral( "editforminitcode" ) ); diff --git a/src/core/qgseditformconfig.h b/src/core/qgseditformconfig.h index 7ce3156542d..cad6037f657 100644 --- a/src/core/qgseditformconfig.h +++ b/src/core/qgseditformconfig.h @@ -26,6 +26,7 @@ #include "qgsattributeeditorelement.h" +class QgsReadWriteContext; class QgsRelationManager; class QgsEditFormConfigPrivate; @@ -268,13 +269,13 @@ class CORE_EXPORT QgsEditFormConfig * Read XML information * Deserialize on project load */ - void readXml( const QDomNode &node ); + void readXml( const QDomNode &node, const QgsReadWriteContext &context ); /** * Write XML information * Serialize on project save */ - void writeXml( QDomNode &node ) const; + void writeXml( QDomNode &node, const QgsReadWriteContext &context ) const; /** * Deserialize drag and drop designer elements. diff --git a/src/core/qgsproject.cpp b/src/core/qgsproject.cpp index 071da64d84b..9445c79dcc4 100644 --- a/src/core/qgsproject.cpp +++ b/src/core/qgsproject.cpp @@ -843,7 +843,7 @@ bool QgsProject::read() //crs QgsCoordinateReferenceSystem projectCrs; - if ( QgsProject::instance()->readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectionsEnabled" ), 0 ) ) + if ( readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectionsEnabled" ), 0 ) ) { long currentCRS = readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSID" ), -1 ); if ( currentCRS != -1 ) diff --git a/src/core/qgsvectorlayer.cpp b/src/core/qgsvectorlayer.cpp index 9347e1923e0..ba8f45a046e 100644 --- a/src/core/qgsvectorlayer.cpp +++ b/src/core/qgsvectorlayer.cpp @@ -1734,7 +1734,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMes mFieldWidgetSetups[fieldName] = setup; } - mEditFormConfig.readXml( layerNode ); + mEditFormConfig.readXml( layerNode, context ); mAttributeTableConfig.readXml( layerNode ); @@ -2008,7 +2008,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString // add attribute actions mActions->writeXml( node ); mAttributeTableConfig.writeXml( node ); - mEditFormConfig.writeXml( node ); + mEditFormConfig.writeXml( node, context ); mConditionalStyles->writeXml( node, doc, context ); // save expression fields