Skip to content

Commit

Permalink
Path resolver instead of project singleton in edit form config and sv…
Browse files Browse the repository at this point in the history
…g annotation
  • Loading branch information
wonder-sk committed May 14, 2017
1 parent 2857ef5 commit 0ccaba7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -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}
----------------------
Expand Down
4 changes: 2 additions & 2 deletions python/core/qgseditformconfig.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions src/core/annotations/qgssvgannotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
***************************************************************************/

#include "qgssvgannotation.h"

#include "qgsreadwritecontext.h"
#include "qgsproject.h"
#include "qgssymbollayerutils.h"

#include <QDomDocument>
#include <QDomElement>

Expand All @@ -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() )
Expand Down
14 changes: 8 additions & 6 deletions src/core/qgseditformconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

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

Expand All @@ -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" ) );
Expand Down
5 changes: 3 additions & 2 deletions src/core/qgseditformconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "qgsattributeeditorelement.h"

class QgsReadWriteContext;
class QgsRelationManager;
class QgsEditFormConfigPrivate;

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0ccaba7

Please sign in to comment.