Path resolver instead of project singleton in edit form config and svg annotation

This commit is contained in:
Martin Dobias 2017-05-14 10:34:01 +08:00
parent 2857ef59dc
commit 0ccaba7a70
7 changed files with 24 additions and 15 deletions

View File

@ -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}
----------------------

View File

@ -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.

View File

@ -16,7 +16,11 @@
***************************************************************************/
#include "qgssvgannotation.h"
#include "qgsreadwritecontext.h"
#include "qgsproject.h"
#include "qgssymbollayerutils.h"
#include <QDomDocument>
#include <QDomElement>
@ -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() )

View File

@ -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" ) );

View File

@ -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.

View File

@ -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 )

View File

@ -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