Skip to content

Commit

Permalink
Introduce QgsReadWriteContext that encapsulates QgsPathResolver
Browse files Browse the repository at this point in the history
This should make the read/write methods more flexible if we need to give them extra context.
  • Loading branch information
wonder-sk committed May 13, 2017
1 parent 15fc16d commit 23a7bd0
Show file tree
Hide file tree
Showing 109 changed files with 702 additions and 553 deletions.
7 changes: 5 additions & 2 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ QgsDiagramRenderer {#qgis_api_break_3_0_QgsDiagramRenderer}
- xform, fields were no longer required and are removed.
- referencedFields() no longer takes a QgsFields argument.
- renderDiagram() now takes an optional data defined overrides collection argument.
- readXml(), _readXml(), writeXml(), _writeXml() do not take QgsVectorLayer as an argument anymore.


QgsDiagramLayerSettings {#qgis_api_break_3_0_QgsDiagramLayerSettings}
Expand Down Expand Up @@ -951,11 +952,13 @@ setting data defined properties instead.
- The renderer member variable was removed, and getRenderer() was renamed to renderer()
- The showAll member variable was removed. setShowAllDiagrams() and showAllDiagrams() should be used instead.
- referencedFields() no longer requires a QgsFields argument.
- readXml() and writeXml() do not take QgsVectorLayer as an argument anymore.

QgsDiagramSettings {#qgis_api_break_3_0_QgsDiagramSettings}
------------------

- The SizeType enum was removed. Use QgsUnitTypes.RenderUnit instead.
- readXml() and writeXml() do not take QgsVectorLayer as an argument anymore.

QgsDial {#qgis_api_break_3_0_QgsDial}
-------
Expand Down Expand Up @@ -1280,7 +1283,7 @@ QgsLayerDefinition {#qgis_api_break_3_0_QgsLayerDefinition}
------------------

- loadLayerDefinition() now also requires QgsProject as the second argument
- loadLayerDefinition() and exportLayerDefinition() variants that take QDomDocument as the first argument now expect QgsPathResolver as the last argument
- loadLayerDefinition() and exportLayerDefinition() variants that take QDomDocument as the first argument now expect QgsReadWriteContext as the last argument


QgsLayerPropertiesWidget {#qgis_api_break_3_0_QgsLayerPropertiesWidget}
Expand Down Expand Up @@ -1413,7 +1416,7 @@ screenUpdateRequested() were removed. These members have had no effect for a num
- capitaliseLayerName() was renamed to capitalizeLayerName() <!--#spellok-->
- asLayerDefinition(), fromLayerDefinition(), fromLayerDefinitionFile() were moved to QgsLayerDefinition class and renamed to exportLayerDefinitionLayers() resp. loadLayerDefinitionLayers()
- loadNamedStyleFromDb() was renamed to loadNamedStyleFromDatabase()
- readLayerXml() and writeLayerXml() expect QgsPathResolver reference as the last argument
- readLayerXml() and writeLayerXml() expect QgsReadWriteContext reference as the last argument
- the invalidTransformInput() slot was removed - calling this slot had no effect
- metadata() was renamed to htmlMetadata()

Expand Down
8 changes: 4 additions & 4 deletions python/core/annotations/qgsannotation.sip
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class QgsAnnotation : QObject

void render( QgsRenderContext &context ) const;

virtual void writeXml( QDomElement &elem, QDomDocument &doc, const QgsPathResolver &pathResolver ) const = 0;
virtual void readXml( const QDomElement &itemElem, const QDomDocument &doc, const QgsPathResolver &pathResolver ) = 0;
virtual void writeXml( QDomElement& elem, QDomDocument & doc, const QgsReadWriteContext &context ) const = 0;
virtual void readXml( const QDomElement& itemElem, const QgsReadWriteContext &context ) = 0;

void setMarkerSymbol( QgsMarkerSymbol *symbol /Transfer/ );
QgsMarkerSymbol *markerSymbol() const;
Expand All @@ -80,8 +80,8 @@ class QgsAnnotation : QObject

virtual QSizeF minimumFrameSize() const;

void _writeXml( QDomElement &itemElem, QDomDocument &doc, const QgsPathResolver &pathResolver ) const;
void _readXml( const QDomElement &annotationElem, const QDomDocument &doc, const QgsPathResolver &pathResolver );
void _writeXml( QDomElement& itemElem, QDomDocument& doc, const QgsReadWriteContext &context ) const;
void _readXml( const QDomElement& annotationElem, const QgsReadWriteContext &context );

void copyCommonProperties( QgsAnnotation *target ) const;

Expand Down
4 changes: 2 additions & 2 deletions python/core/annotations/qgsannotationmanager.sip
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ class QgsAnnotationManager : QObject
:rtype: list of QgsAnnotation
%End

bool readXml( const QDomElement &element, const QDomDocument &doc, const QgsPathResolver &pathResolver );
bool readXml( const QDomElement &element, const QgsReadWriteContext &context );
%Docstring
Reads the manager's state from a DOM element, restoring all annotations
present in the XML document.
.. seealso:: writeXml()
:rtype: bool
%End

QDomElement writeXml( QDomDocument &doc, const QgsPathResolver &pathResolver ) const;
QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
%Docstring
Returns a DOM element representing the state of the manager.
.. seealso:: readXml()
Expand Down
4 changes: 2 additions & 2 deletions python/core/annotations/qgshtmlannotation.sip
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class QgsHtmlAnnotation: QgsAnnotation
:rtype: str
%End

virtual void writeXml( QDomElement &elem, QDomDocument &doc, const QgsPathResolver &pathResolver ) const;
virtual void readXml( const QDomElement &itemElem, const QDomDocument &doc, const QgsPathResolver &pathResolver );
virtual void writeXml( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const;
virtual void readXml( const QDomElement &itemElem, const QgsReadWriteContext &context );

virtual void setAssociatedFeature( const QgsFeature &feature );

Expand Down
4 changes: 2 additions & 2 deletions python/core/annotations/qgssvgannotation.sip
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class QgsSvgAnnotation: QgsAnnotation
virtual QgsSvgAnnotation *clone() const /Factory/;


virtual void writeXml( QDomElement &elem, QDomDocument &doc, const QgsPathResolver &pathResolver ) const;
virtual void readXml( const QDomElement &itemElem, const QDomDocument &doc, const QgsPathResolver &pathResolver );
virtual void writeXml( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const;
virtual void readXml( const QDomElement &itemElem, const QgsReadWriteContext &context );

void setFilePath( const QString &file );
%Docstring
Expand Down
4 changes: 2 additions & 2 deletions python/core/annotations/qgstextannotation.sip
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class QgsTextAnnotation: QgsAnnotation
.. seealso:: document()
%End

virtual void writeXml( QDomElement &elem, QDomDocument &doc, const QgsPathResolver &pathResolver ) const;
virtual void readXml( const QDomElement &itemElem, const QDomDocument &doc, const QgsPathResolver &pathResolver );
virtual void writeXml( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const;
virtual void readXml( const QDomElement &itemElem, const QgsReadWriteContext &context );

static QgsTextAnnotation *create() /Factory/;
%Docstring
Expand Down
1 change: 1 addition & 0 deletions python/core/core.sip
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
%Include qgsproviderregistry.sip
%Include qgspythonrunner.sip
%Include qgsrange.sip
%Include qgsreadwritecontext.sip
%Include qgsrelation.sip
%Include qgsrelationmanager.sip
%Include qgsrenderchecker.sip
Expand Down
8 changes: 4 additions & 4 deletions python/core/qgsconditionalstyle.sip
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ class QgsConditionalLayerStyles
:rtype: list of QgsConditionalStyle
%End

bool readXml( const QDomNode &node, const QgsPathResolver &pathResolver );
bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
%Docstring
Reads field ui properties specific state from Dom node.
:rtype: bool
%End

bool writeXml( QDomNode &node, QDomDocument &doc, const QgsPathResolver &pathResolver ) const;
bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
%Docstring
Write field ui properties specific state from Dom node.
:rtype: bool
Expand Down Expand Up @@ -244,13 +244,13 @@ class QgsConditionalStyle
:rtype: QgsConditionalStyle
%End

bool readXml( const QDomNode &node, const QgsPathResolver &pathResolver );
bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
%Docstring
Reads vector conditional style specific state from layer Dom node.
:rtype: bool
%End

bool writeXml( QDomNode &node, QDomDocument &doc, const QgsPathResolver &pathResolver ) const;
bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
%Docstring
Write vector conditional style specific state from layer Dom node.
:rtype: bool
Expand Down
26 changes: 13 additions & 13 deletions python/core/qgsdiagramrenderer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ class QgsDiagramLayerSettings
*/
void setShowAllDiagrams( bool showAllDiagrams );

void readXml( const QDomElement &elem, const QgsVectorLayer *layer );
void writeXml( QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer ) const;
bool prepare( const QgsExpressionContext &context = QgsExpressionContext() ) const;
void readXml( const QDomElement& elem );
void writeXml( QDomElement& layerElem, QDomDocument& doc ) const;
bool prepare( const QgsExpressionContext& context = QgsExpressionContext() ) const;

/** Returns the set of any fields referenced by the layer's diagrams.
* @param context expression context the diagrams will be drawn using
Expand Down Expand Up @@ -294,8 +294,8 @@ class QgsDiagramSettings
//! Scale diagrams smaller than mMinimumSize to mMinimumSize
double minimumSize;

void readXml( const QDomElement &elem, const QgsVectorLayer *layer );
void writeXml( QDomElement &rendererElem, QDomDocument &doc, const QgsVectorLayer *layer ) const;
void readXml( const QDomElement& elem );
void writeXml( QDomElement& rendererElem, QDomDocument& doc ) const;

/** Returns list of legend nodes for the diagram
* @note caller is responsible for deletion of QgsLayerTreeModelLegendNodes
Expand Down Expand Up @@ -365,8 +365,8 @@ class QgsDiagramRenderer
/** Returns list with all diagram settings in the renderer*/
virtual QList<QgsDiagramSettings> diagramSettings() const = 0;

virtual void readXml( const QDomElement& elem, const QgsVectorLayer* layer, const QgsPathResolver &pathResolver ) = 0;
virtual void writeXml( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer, const QgsPathResolver &pathResolver ) const = 0;
virtual void readXml( const QDomElement& elem, const QgsReadWriteContext &context ) = 0;
virtual void writeXml( QDomElement& layerElem, QDomDocument& doc, const QgsReadWriteContext &context ) const = 0;

/** Returns list of legend nodes for the diagram
* @note caller is responsible for deletion of QgsLayerTreeModelLegendNodes
Expand Down Expand Up @@ -442,8 +442,8 @@ class QgsDiagramRenderer
static int dpiPaintDevice( const QPainter* );

//read / write diagram
void _readXml( const QDomElement& elem, const QgsVectorLayer* layer, const QgsPathResolver &pathResolver );
void _writeXml( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer, const QgsPathResolver &pathResolver ) const;
void _readXml( const QDomElement& elem, const QgsReadWriteContext &context );
void _writeXml( QDomElement& rendererElem, QDomDocument& doc, const QgsReadWriteContext &context ) const;
};

/** Renders the diagrams for all features with the same settings*/
Expand All @@ -467,8 +467,8 @@ class QgsSingleCategoryDiagramRenderer : QgsDiagramRenderer

QList<QgsDiagramSettings> diagramSettings() const;

void readXml( const QDomElement& elem, const QgsVectorLayer* layer, const QgsPathResolver &pathResolver );
void writeXml( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer, const QgsPathResolver &pathResolver ) const;
void readXml( const QDomElement& elem, const QgsReadWriteContext &context );
void writeXml( QDomElement& layerElem, QDomDocument& doc, const QgsReadWriteContext &context ) const;

virtual QList< QgsLayerTreeModelLegendNode * > legendItems( QgsLayerTreeLayer *nodeLayer ) const /Factory/;

Expand Down Expand Up @@ -533,8 +533,8 @@ class QgsLinearlyInterpolatedDiagramRenderer : QgsDiagramRenderer
bool classificationAttributeIsExpression() const;
void setClassificationAttributeIsExpression( bool isExpression );

void readXml( const QDomElement& elem, const QgsVectorLayer* layer, const QgsPathResolver &pathResolver );
void writeXml( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer, const QgsPathResolver &pathResolver ) const;
void readXml( const QDomElement& elem, const QgsReadWriteContext &context );
void writeXml( QDomElement& layerElem, QDomDocument& doc, const QgsReadWriteContext &context ) const;

virtual QList< QgsLayerTreeModelLegendNode * > legendItems( QgsLayerTreeLayer *nodeLayer ) const /Factory/;

Expand Down
12 changes: 6 additions & 6 deletions python/core/qgslayerdefinition.sip
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class QgsLayerDefinition
#include <qgslayerdefinition.h>
%End
public:
static bool loadLayerDefinition( const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage /Out/ );
static bool loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage /Out/, const QgsPathResolver &pathResolver );
static bool exportLayerDefinition( QString path, const QList<QgsLayerTreeNode*> &selectedTreeNodes, QString &errorMessage /Out/ );
static bool exportLayerDefinition( QDomDocument doc, const QList<QgsLayerTreeNode*> &selectedTreeNodes, QString &errorMessage /Out/, const QgsPathResolver &pathResolver );
static bool loadLayerDefinition( const QString & path, QgsProject* project, QgsLayerTreeGroup* rootGroup, QString &errorMessage /Out/ );
static bool loadLayerDefinition( QDomDocument doc, QgsProject* project, QgsLayerTreeGroup* rootGroup, QString &errorMessage /Out/, const QgsReadWriteContext &context );
static bool exportLayerDefinition( QString path, const QList<QgsLayerTreeNode*>& selectedTreeNodes, QString &errorMessage /Out/ );
static bool exportLayerDefinition( QDomDocument doc, const QList<QgsLayerTreeNode*>& selectedTreeNodes, QString &errorMessage /Out/, const QgsReadWriteContext &context );

static QDomDocument exportLayerDefinitionLayers( const QList<QgsMapLayer*> &layers, const QgsPathResolver &pathResolver );
static QList<QgsMapLayer*> loadLayerDefinitionLayers( QDomDocument &document, const QgsPathResolver &pathResolver ) /Factory/;
static QDomDocument exportLayerDefinitionLayers( const QList<QgsMapLayer*>& layers, const QgsReadWriteContext &context );
static QList<QgsMapLayer*> loadLayerDefinitionLayers( QDomDocument& document, const QgsReadWriteContext &context ) /Factory/;
static QList<QgsMapLayer*> loadLayerDefinitionLayers( const QString &qlrfile ) /Factory/;

/**
Expand Down
28 changes: 14 additions & 14 deletions python/core/qgsmaplayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,11 @@ Returns true if the layer can be edited.
:rtype: bool
%End

bool readLayerXml( const QDomElement &layerElement, const QgsPathResolver &pathResolver );
bool readLayerXml( const QDomElement &layerElement, const QgsReadWriteContext &context );
%Docstring
Sets state from Dom document
\param layerElement The Dom element corresponding to ``maplayer'' tag
\param pathResolver object for conversion between relative and absolute paths
\param context writing context (e.g. for conversion between relative and absolute paths)
\note

The Dom node corresponds to a Dom document project file XML element read
Expand All @@ -428,12 +428,12 @@ Invoked by QgsProject.read().
:rtype: bool
%End

bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsPathResolver &pathResolver ) const;
bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
%Docstring
Stores state in Dom node
\param layerElement is a Dom element corresponding to ``maplayer'' tag
\param document is a the dom document being written
\param pathResolver object for conversion between relative and absolute paths
\param context reading context (e.g. for conversion between relative and absolute paths)
\note

The Dom node corresponds to a Dom document project file XML element to be
Expand Down Expand Up @@ -629,22 +629,22 @@ A convenience function to (un)capitalize the layer name



virtual bool readSymbology( const QDomNode &node, QString &errorMessage, const QgsPathResolver &pathResolver ) = 0;
virtual bool readSymbology( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context ) = 0;
%Docstring
Read the symbology for the current layer from the Dom node supplied.
\param node node that will contain the symbology definition for this layer.
\param errorMessage reference to string that will be updated with any error messages
\param pathResolver for transform from relative to absolute paths
\param context reading context (used for transform from relative to absolute paths)
:return: true in case of success.
:rtype: bool
%End

virtual bool readStyle( const QDomNode &node, QString &errorMessage, const QgsPathResolver &pathResolver );
virtual bool readStyle( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context );
%Docstring
Read the style for the current layer from the Dom node supplied.
\param node node that will contain the style definition for this layer.
\param errorMessage reference to string that will be updated with any error messages
\param pathResolver for transform from relative to absolute paths
\param context reading context (used for transform from relative to absolute paths)
:return: true in case of success.
.. versionadded:: 2.16
.. note::
Expand All @@ -653,24 +653,24 @@ A convenience function to (un)capitalize the layer name
:rtype: bool
%End

virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsPathResolver &pathResolver ) const = 0;
virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const = 0;
%Docstring
Write the symbology for the layer into the docment provided.
\param node the node that will have the style element added to it.
\param doc the document that will have the QDomNode added.
\param errorMessage reference to string that will be updated with any error messages
\param pathResolver for transform from absolute to relative paths
\param context writing context (used for transform from absolute to relative paths)
:return: true in case of success.
:rtype: bool
%End

virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsPathResolver &pathResolver ) const;
virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const;
%Docstring
Write just the style information for the layer into the document
\param node the node that will have the style element added to it.
\param doc the document that will have the QDomNode added.
\param errorMessage reference to string that will be updated with any error messages
\param pathResolver for transform from absolute to relative paths
\param context writing context (used for transform from absolute to relative paths)
:return: true in case of success.
.. versionadded:: 2.16
.. note::
Expand Down Expand Up @@ -1030,14 +1030,14 @@ Set the extent
Set whether layer is valid or not - should be used in constructor.
%End

virtual bool readXml( const QDomNode &layer_node, const QgsPathResolver &pathResolver );
virtual bool readXml( const QDomNode &layer_node, const QgsReadWriteContext &context );
%Docstring
Called by readLayerXML(), used by children to read state specific to them from
project files.
:rtype: bool
%End

virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsPathResolver &pathResolver ) const;
virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
%Docstring
Called by writeLayerXML(), used by children to write state specific to them to
project files.
Expand Down
Loading

0 comments on commit 23a7bd0

Please sign in to comment.