Skip to content

Commit 0ccaba7

Browse files
committed
Path resolver instead of project singleton in edit form config and svg annotation
1 parent 2857ef5 commit 0ccaba7

File tree

7 files changed

+24
-15
lines changed

7 files changed

+24
-15
lines changed

doc/api_break.dox

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,7 @@ QgsEditorWidgetRegistry::instance()->findBest() must be used instead.
10181018
have been removed. Use QgsVectorLayer.setConstraintExpression()/constraintExpression(),
10191019
or QgsField.constraintExpression()/QgsField.constraintDescription() instead.
10201020
- notNull() and setNotNull() have been removed. Use QgsVectorLayer.setFieldConstraint()/fieldConstraints(), or QgsField.constraints() instead.
1021+
- readXml() and writeXml() now also expect a reference to QgsReadWriteContext object.
10211022

10221023
QgsEditorWidgetWrapper {#qgis_api_break_3_0_QgsEditorWidgetWrapper}
10231024
----------------------

python/core/qgseditformconfig.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ class QgsEditFormConfig
197197
* Read XML information
198198
* Deserialize on project load
199199
*/
200-
void readXml( const QDomNode &node );
200+
void readXml( const QDomNode &node, const QgsReadWriteContext &context );
201201

202202
/**
203203
* Write XML information
204204
* Serialize on project save
205205
*/
206-
void writeXml( QDomNode &node ) const;
206+
void writeXml( QDomNode &node, const QgsReadWriteContext &context ) const;
207207

208208
/**
209209
* Deserialize drag and drop designer elements.

src/core/annotations/qgssvgannotation.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
***************************************************************************/
1717

1818
#include "qgssvgannotation.h"
19+
20+
#include "qgsreadwritecontext.h"
1921
#include "qgsproject.h"
22+
#include "qgssymbollayerutils.h"
23+
2024
#include <QDomDocument>
2125
#include <QDomElement>
2226

@@ -37,15 +41,16 @@ QgsSvgAnnotation *QgsSvgAnnotation::clone() const
3741

3842
void QgsSvgAnnotation::writeXml( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const
3943
{
44+
QString filePath = QgsSymbolLayerUtils::svgSymbolPathToName( mFilePath, context.pathResolver() );
4045
QDomElement svgAnnotationElem = doc.createElement( QStringLiteral( "SVGAnnotationItem" ) );
41-
svgAnnotationElem.setAttribute( QStringLiteral( "file" ), QgsProject::instance()->writePath( mFilePath ) );
46+
svgAnnotationElem.setAttribute( QStringLiteral( "file" ), filePath );
4247
_writeXml( svgAnnotationElem, doc, context );
4348
elem.appendChild( svgAnnotationElem );
4449
}
4550

4651
void QgsSvgAnnotation::readXml( const QDomElement &itemElem, const QgsReadWriteContext &context )
4752
{
48-
QString filePath = QgsProject::instance()->readPath( itemElem.attribute( QStringLiteral( "file" ) ) );
53+
QString filePath = QgsSymbolLayerUtils::svgSymbolNameToPath( itemElem.attribute( QStringLiteral( "file" ) ), context.pathResolver() );
4954
setFilePath( filePath );
5055
QDomElement annotationElem = itemElem.firstChildElement( QStringLiteral( "AnnotationItem" ) );
5156
if ( !annotationElem.isNull() )

src/core/qgseditformconfig.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
***************************************************************************/
1515
#include "qgseditformconfig_p.h"
1616
#include "qgseditformconfig.h"
17+
#include "qgspathresolver.h"
1718
#include "qgsproject.h"
19+
#include "qgsreadwritecontext.h"
1820
#include "qgsrelationmanager.h"
1921
#include "qgslogger.h"
2022

@@ -255,14 +257,14 @@ void QgsEditFormConfig::setSuppress( QgsEditFormConfig::FeatureFormSuppress s )
255257
d->mSuppressForm = s;
256258
}
257259

258-
void QgsEditFormConfig::readXml( const QDomNode &node )
260+
void QgsEditFormConfig::readXml( const QDomNode &node, const QgsReadWriteContext &context )
259261
{
260262
d.detach();
261263
QDomNode editFormNode = node.namedItem( QStringLiteral( "editform" ) );
262264
if ( !editFormNode.isNull() )
263265
{
264266
QDomElement e = editFormNode.toElement();
265-
d->mUiFormPath = QgsProject::instance()->readPath( e.text() );
267+
d->mUiFormPath = context.pathResolver().readPath( e.text() );
266268
}
267269

268270
QDomNode editFormInitNode = node.namedItem( QStringLiteral( "editforminit" ) );
@@ -299,7 +301,7 @@ void QgsEditFormConfig::readXml( const QDomNode &node )
299301
QDomNode editFormInitFilePathNode = node.namedItem( QStringLiteral( "editforminitfilepath" ) );
300302
if ( !editFormInitFilePathNode.isNull() && !editFormInitFilePathNode.toElement().text().isEmpty() )
301303
{
302-
setInitFilePath( QgsProject::instance()->readPath( editFormInitFilePathNode.toElement().text() ) );
304+
setInitFilePath( context.pathResolver().readPath( editFormInitFilePathNode.toElement().text() ) );
303305
}
304306

305307
QDomNode fFSuppNode = node.namedItem( QStringLiteral( "featformsuppress" ) );
@@ -357,12 +359,12 @@ void QgsEditFormConfig::readXml( const QDomNode &node )
357359
}
358360
}
359361

360-
void QgsEditFormConfig::writeXml( QDomNode &node ) const
362+
void QgsEditFormConfig::writeXml( QDomNode &node, const QgsReadWriteContext &context ) const
361363
{
362364
QDomDocument doc( node.ownerDocument() );
363365

364366
QDomElement efField = doc.createElement( QStringLiteral( "editform" ) );
365-
QDomText efText = doc.createTextNode( QgsProject::instance()->writePath( uiForm() ) );
367+
QDomText efText = doc.createTextNode( context.pathResolver().writePath( uiForm() ) );
366368
efField.appendChild( efText );
367369
node.appendChild( efField );
368370

@@ -376,7 +378,7 @@ void QgsEditFormConfig::writeXml( QDomNode &node ) const
376378
node.appendChild( eficsField );
377379

378380
QDomElement efifpField = doc.createElement( QStringLiteral( "editforminitfilepath" ) );
379-
efifpField.appendChild( doc.createTextNode( QgsProject::instance()->writePath( initFilePath() ) ) );
381+
efifpField.appendChild( doc.createTextNode( context.pathResolver().writePath( initFilePath() ) ) );
380382
node.appendChild( efifpField );
381383

382384
QDomElement eficField = doc.createElement( QStringLiteral( "editforminitcode" ) );

src/core/qgseditformconfig.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "qgsattributeeditorelement.h"
2828

29+
class QgsReadWriteContext;
2930
class QgsRelationManager;
3031
class QgsEditFormConfigPrivate;
3132

@@ -268,13 +269,13 @@ class CORE_EXPORT QgsEditFormConfig
268269
* Read XML information
269270
* Deserialize on project load
270271
*/
271-
void readXml( const QDomNode &node );
272+
void readXml( const QDomNode &node, const QgsReadWriteContext &context );
272273

273274
/**
274275
* Write XML information
275276
* Serialize on project save
276277
*/
277-
void writeXml( QDomNode &node ) const;
278+
void writeXml( QDomNode &node, const QgsReadWriteContext &context ) const;
278279

279280
/**
280281
* Deserialize drag and drop designer elements.

src/core/qgsproject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ bool QgsProject::read()
843843

844844
//crs
845845
QgsCoordinateReferenceSystem projectCrs;
846-
if ( QgsProject::instance()->readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectionsEnabled" ), 0 ) )
846+
if ( readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectionsEnabled" ), 0 ) )
847847
{
848848
long currentCRS = readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSID" ), -1 );
849849
if ( currentCRS != -1 )

src/core/qgsvectorlayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,7 +1734,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMes
17341734
mFieldWidgetSetups[fieldName] = setup;
17351735
}
17361736

1737-
mEditFormConfig.readXml( layerNode );
1737+
mEditFormConfig.readXml( layerNode, context );
17381738

17391739
mAttributeTableConfig.readXml( layerNode );
17401740

@@ -2008,7 +2008,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString
20082008
// add attribute actions
20092009
mActions->writeXml( node );
20102010
mAttributeTableConfig.writeXml( node );
2011-
mEditFormConfig.writeXml( node );
2011+
mEditFormConfig.writeXml( node, context );
20122012
mConditionalStyles->writeXml( node, doc, context );
20132013

20142014
// save expression fields

0 commit comments

Comments
 (0)