Skip to content

Commit

Permalink
Propagate path resolver through renderers, annotations, diagrams
Browse files Browse the repository at this point in the history
This is necessary in order to be able to correctly translate between absolute and relative paths
deeper in the code - e.g. paths to SVG files used in marker or fill symbols.

Until now, relative paths were translated to absolute paths on the fly.
This is now changed - paths to files should be always absolute within QGIS objects - and paths
only get turned into relative when saving projects. When loading a project, relative paths
are translated to absolute paths immediately.

This should lower the overall confusion about relative/absolute paths within QGIS, and also
allow having different base directories for relative paths (e.g. QML or QPT files may use relative paths
to their directory - rather than to the project directory)
  • Loading branch information
wonder-sk committed May 13, 2017
1 parent 6fe459d commit 8ffd91e
Show file tree
Hide file tree
Showing 109 changed files with 734 additions and 552 deletions.
8 changes: 4 additions & 4 deletions python/core/annotations/qgsannotation.sip
Expand Up @@ -56,8 +56,8 @@ class QgsAnnotation : QObject

void render( QgsRenderContext &context ) const;

virtual void writeXml( QDomElement &elem, QDomDocument &doc ) const = 0;
virtual void readXml( const QDomElement &itemElem, const QDomDocument &doc ) = 0;
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;

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;
void _readXml( const QDomElement &annotationElem, const QDomDocument &doc );
void _writeXml( QDomElement &itemElem, QDomDocument &doc, const QgsPathResolver &pathResolver ) const;
void _readXml( const QDomElement &annotationElem, const QDomDocument &doc, const QgsPathResolver &pathResolver );

void copyCommonProperties( QgsAnnotation *target ) const;

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

bool readXml( const QDomElement &element, const QDomDocument &doc );
bool readXml( const QDomElement &element, const QDomDocument &doc, const QgsPathResolver &pathResolver );
%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;
QDomElement writeXml( QDomDocument &doc, const QgsPathResolver &pathResolver ) 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
Expand Up @@ -50,8 +50,8 @@ class QgsHtmlAnnotation: QgsAnnotation
:rtype: str
%End

virtual void writeXml( QDomElement &elem, QDomDocument &doc ) const;
virtual void readXml( const QDomElement &itemElem, const QDomDocument &doc );
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 setAssociatedFeature( const QgsFeature &feature );

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


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

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

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

static QgsTextAnnotation *create() /Factory/;
%Docstring
Expand Down
8 changes: 4 additions & 4 deletions python/core/qgsconditionalstyle.sip
Expand Up @@ -52,13 +52,13 @@ class QgsConditionalLayerStyles
:rtype: list of QgsConditionalStyle
%End

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

bool writeXml( QDomNode &node, QDomDocument &doc ) const;
bool writeXml( QDomNode &node, QDomDocument &doc, const QgsPathResolver &pathResolver ) 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 );
bool readXml( const QDomNode &node, const QgsPathResolver &pathResolver );
%Docstring
Reads vector conditional style specific state from layer Dom node.
:rtype: bool
%End

bool writeXml( QDomNode &node, QDomDocument &doc ) const;
bool writeXml( QDomNode &node, QDomDocument &doc, const QgsPathResolver &pathResolver ) const;
%Docstring
Write vector conditional style specific state from layer Dom node.
:rtype: bool
Expand Down
16 changes: 8 additions & 8 deletions python/core/qgsdiagramrenderer.sip
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 ) = 0;
virtual void writeXml( QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer ) 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;

/** 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 );
void _writeXml( QDomElement &rendererElem, QDomDocument &doc, const QgsVectorLayer *layer ) const;
void _readXml( const QDomElement& elem, const QgsVectorLayer* layer, const QgsPathResolver &pathResolver );
void _writeXml( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer, const QgsPathResolver &pathResolver ) 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 );
void writeXml( QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer ) 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;

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 );
void writeXml( QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer ) 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;

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

Expand Down
16 changes: 10 additions & 6 deletions python/core/qgsmaplayer.sip
Expand Up @@ -629,20 +629,22 @@ A convenience function to (un)capitalize the layer name



virtual bool readSymbology( const QDomNode &node, QString &errorMessage ) = 0;
virtual bool readSymbology( const QDomNode &node, QString &errorMessage, const QgsPathResolver &pathResolver ) = 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
:return: true in case of success.
:rtype: bool
%End

virtual bool readStyle( const QDomNode &node, QString &errorMessage );
virtual bool readStyle( const QDomNode &node, QString &errorMessage, const QgsPathResolver &pathResolver );
%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
:return: true in case of success.
.. versionadded:: 2.16
.. note::
Expand All @@ -651,22 +653,24 @@ A convenience function to (un)capitalize the layer name
:rtype: bool
%End

virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage ) const = 0;
virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsPathResolver &pathResolver ) 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
:return: true in case of success.
:rtype: bool
%End

virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage ) const;
virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsPathResolver &pathResolver ) 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
:return: true in case of success.
.. versionadded:: 2.16
.. note::
Expand Down Expand Up @@ -1026,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 );
virtual bool readXml( const QDomNode &layer_node, const QgsPathResolver &pathResolver );
%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;
virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsPathResolver &pathResolver ) const;
%Docstring
Called by writeLayerXML(), used by children to write state specific to them to
project files.
Expand Down
16 changes: 10 additions & 6 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -685,7 +685,7 @@ Return the provider type for this layer
:rtype: str
%End

virtual bool readXml( const QDomNode &layer_node );
virtual bool readXml( const QDomNode &layer_node, const QgsPathResolver &pathResolver );
%Docstring
Reads vector layer specific state from project file Dom node.
.. note::
Expand All @@ -694,7 +694,7 @@ Return the provider type for this layer
:rtype: bool
%End

virtual bool writeXml( QDomNode &layer_node, QDomDocument &doc ) const;
virtual bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsPathResolver &pathResolver ) const;
%Docstring
Write vector layer specific state to project file Dom node.
.. note::
Expand Down Expand Up @@ -765,44 +765,48 @@ Return the provider type for this layer
:rtype: str
%End

virtual bool readSymbology( const QDomNode &layerNode, QString &errorMessage );
virtual bool readSymbology( const QDomNode &layerNode, QString &errorMessage, const QgsPathResolver &pathResolver );

%Docstring
Read the symbology for the current layer from the Dom node supplied.
\param layerNode 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
:return: true in case of success.
:rtype: bool
%End

virtual bool readStyle( const QDomNode &node, QString &errorMessage );
virtual bool readStyle( const QDomNode &node, QString &errorMessage, const QgsPathResolver &pathResolver );

%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
:return: true in case of success.
:rtype: bool
%End

virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage ) const;
virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsPathResolver &pathResolver ) const;

%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
:return: true in case of success.
:rtype: bool
%End

virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage ) const;
virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsPathResolver &pathResolver ) 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
:return: true in case of success.
:rtype: bool
%End
Expand Down
12 changes: 6 additions & 6 deletions python/core/raster/qgsrasterlayer.sip
Expand Up @@ -194,21 +194,21 @@ class QgsRasterLayer : QgsMapLayer

protected:
/** \brief Read the symbology for the current layer from the Dom node supplied */
bool readSymbology( const QDomNode &node, QString &errorMessage );
bool readSymbology( const QDomNode& node, QString& errorMessage, const QgsPathResolver &pathResolver );

/** \brief Read the style information for the current layer from the Dom node supplied */
bool readStyle(const QDomNode &node, QString &errorMessage);
bool readStyle(const QDomNode &node, QString &errorMessage, const QgsPathResolver &pathResolver);

/** \brief Reads layer specific state from project file Dom node */
bool readXml( const QDomNode &layer_node );
bool readXml( const QDomNode& layer_node, const QgsPathResolver &pathResolver );

/** \brief Write the symbology for the layer into the docment provided */
bool writeSymbology( QDomNode&, QDomDocument &doc, QString &errorMessage ) const;
bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage, const QgsPathResolver &pathResolver ) const;

/** \brief Write the style for the layer into the docment provided */
bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage) const;
bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsPathResolver &pathResolver) const;

/** \brief Write layer specific state to project file Dom node */
bool writeXml( QDomNode &layer_node, QDomDocument &doc ) const;
bool writeXml( QDomNode & layer_node, QDomDocument & doc, const QgsPathResolver &pathResolver ) const;
};

10 changes: 5 additions & 5 deletions python/core/symbology-ng/qgs25drenderer.sip
Expand Up @@ -27,14 +27,14 @@ class Qgs25DRenderer : QgsFeatureRenderer
*
* @param element XML information
*/
static QgsFeatureRenderer *create( QDomElement &element );
QDomElement save( QDomDocument &doc );
static QgsFeatureRenderer* create( QDomElement& element, const QgsPathResolver &pathResolver ) /Factory/;
QDomElement save( QDomDocument& doc, const QgsPathResolver &pathResolver );

void startRender( QgsRenderContext &context, const QgsFields &fields );
void stopRender( QgsRenderContext &context );

QSet<QString> usedAttributes( const QgsRenderContext &context ) const;
QgsFeatureRenderer *clone() const;
QSet<QString> usedAttributes( const QgsRenderContext& context ) const;
QgsFeatureRenderer* clone() const /Factory/;

virtual QgsSymbol *symbolForFeature( QgsFeature &feature, QgsRenderContext &context );
virtual QgsSymbolList symbols( QgsRenderContext &context );
Expand Down Expand Up @@ -93,7 +93,7 @@ class Qgs25DRenderer : QgsFeatureRenderer
* we assume that the internals are not compatible and create a new default
* 2.5D renderer.
*/
static Qgs25DRenderer *convertFromRenderer( QgsFeatureRenderer *renderer );
static Qgs25DRenderer* convertFromRenderer( QgsFeatureRenderer* renderer ) /Factory/;

/**
* Is the shadow enabled
Expand Down
4 changes: 2 additions & 2 deletions python/core/symbology-ng/qgscategorizedsymbolrenderer.sip
Expand Up @@ -112,10 +112,10 @@ class QgsCategorizedSymbolRenderer : QgsFeatureRenderer
void setClassAttribute( const QString &attr );

//! create renderer from XML element
static QgsFeatureRenderer *create( QDomElement &element ) /Factory/;
static QgsFeatureRenderer* create( QDomElement& element, const QgsPathResolver &pathResolver ) /Factory/;

//! store renderer info to XML element
virtual QDomElement save( QDomDocument &doc );
virtual QDomElement save( QDomDocument& doc, const QgsPathResolver &pathResolver );

//! return a list of symbology items for the legend
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
Expand Down
9 changes: 5 additions & 4 deletions python/core/symbology-ng/qgsfillsymbollayer.sip
Expand Up @@ -668,12 +668,13 @@ class QgsSVGFillSymbolLayer: QgsImageFillSymbolLayer
%End

public:
QgsSVGFillSymbolLayer( const QString &svgFilePath = "", double width = 20, double rotation = 0.0 );
QgsSVGFillSymbolLayer( const QByteArray &svgData, double width = 20, double rotation = 0.0 );
QgsSVGFillSymbolLayer( const QString& svgFilePath, double width = 20, double rotation = 0.0 );
QgsSVGFillSymbolLayer( const QByteArray& svgData, double width = 20, double rotation = 0.0 );
~QgsSVGFillSymbolLayer();

static QgsSymbolLayer *create( const QgsStringMap &properties = QgsStringMap() ) /Factory/;
static QgsSymbolLayer *createFromSld( QDomElement &element ) /Factory/;
static QgsSymbolLayer* create( const QgsStringMap& properties = QgsStringMap() ) /Factory/;
static QgsSymbolLayer* createFromSld( QDomElement &element ) /Factory/;
static void resolvePaths( QgsStringMap& properties, const QgsPathResolver& pathResolver, bool saving );

// implemented from base classes

Expand Down
4 changes: 2 additions & 2 deletions python/core/symbology-ng/qgsgraduatedsymbolrenderer.sip
Expand Up @@ -218,10 +218,10 @@ class QgsGraduatedSymbolRenderer : QgsFeatureRenderer
);

//! create renderer from XML element
static QgsFeatureRenderer *create( QDomElement &element ) /Factory/;
static QgsFeatureRenderer* create( QDomElement& element, const QgsPathResolver &pathResolver ) /Factory/;

//! store renderer info to XML element
virtual QDomElement save( QDomDocument &doc );
virtual QDomElement save( QDomDocument& doc, const QgsPathResolver &pathResolver );

//! return a list of symbology items for the legend
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
Expand Down

0 comments on commit 8ffd91e

Please sign in to comment.