Skip to content
Permalink
Browse files

add API to select section of layer style when reading/writing

  • Loading branch information
3nids authored and nyalldawson committed Sep 14, 2018
1 parent 3875adf commit 51e9be05754c34a0db8e07bbff3a8a22965b3f7c
@@ -0,0 +1,4 @@
# The following has been generated automatically from src/core/qgsmaplayerstyle.h
QgsMapLayerStyle.StyleCategory.baseClass = QgsMapLayerStyle
QgsMapLayerStyle.StyleCategories.baseClass = QgsMapLayerStyle
StyleCategories = QgsMapLayerStyle # dirty hack since SIP seems to introduce the flags in module
@@ -109,10 +109,10 @@ QgsMeshLayer cannot be copied.

virtual QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) /Factory/;

virtual bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context );

virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const;

virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All );
virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;

virtual QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const;
@@ -503,8 +503,8 @@ Sets state from Dom document
The Dom node corresponds to a Dom document project file XML element read
by :py:class:`QgsProject`.

This, in turn, calls readXml(), which is over-rideable by sub-classes so
that they can read their own specific state from the given Dom node.
This, in turn, calls readXml() (and then readSymbology()), which is over-rideable
by sub-classes so that they can read their own specific state from the given Dom node.

Invoked by :py:func:`QgsProject.read()`

@@ -523,8 +523,8 @@ Stores state in Dom node
The Dom node corresponds to a Dom document project file XML element to be
written by :py:class:`QgsProject`.

This, in turn, calls writeXml(), which is over-rideable by sub-classes so
that they can write their own specific state to the given Dom node.
This, in turn, calls writeXml() (and then writeSymbology), which is over-rideable
by sub-classes so that they can write their own specific state to the given Dom node.

Invoked by :py:func:`QgsProject.write()`

@@ -783,7 +783,8 @@ Import the properties of this layer from a QDomDocument
.. versionadded:: 2.8
%End

virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg /Out/ ) const;
virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg /Out/, QgsReadWriteContext &context,
QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
%Docstring
Export the properties of this layer as named style in a QDomDocument

@@ -865,7 +866,8 @@ Attempts to style the layer using the formatting from an SLD type file.



virtual bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context ) = 0;
virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) = 0;
%Docstring
Read the symbology for the current layer from the Dom node supplied.

@@ -876,7 +878,8 @@ Read the symbology for the current layer from the Dom node supplied.
:return: true in case of success.
%End

virtual bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context );
virtual bool readStyle( const QDomNode &node, QString &errorMessage,
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All );
%Docstring
Read the style for the current layer from the Dom node supplied.

@@ -893,21 +896,27 @@ Read the style for the current layer from the Dom node supplied.
.. versionadded:: 2.16
%End

virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const = 0;
virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const = 0;
%Docstring
Write the symbology for the layer into the docment provided.
Write the style 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 context: writing context (used for transform from absolute to relative paths)

.. note::

There is a confusion of terms with the GUI. This method actually writes what is called a style in the application.

:return: true in case of success.
%End

virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const;
virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
%Docstring
Write just the style information for the layer into the document
Write just the symbology 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.
@@ -920,6 +929,10 @@ Write just the style information for the layer into the document

To be implemented in subclasses. Default implementation does nothing and returns false.

.. note::

There is a confusion of terms with the GUI. This method actually writes what is known as the symbology in the application.

.. versionadded:: 2.16
%End

@@ -1475,14 +1488,17 @@ Read style manager's configuration (if any). To be called by subclasses.
Write style manager's configuration (if exists). To be called by subclasses.
%End

void writeCommonStyle( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
const QgsReadWriteContext &context,
QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
%Docstring
Write style data common to all layer types

.. versionadded:: 3.0
%End

void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context );
void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All );
%Docstring
Read style data common to all layer types

@@ -26,6 +26,27 @@ only possible to read or write layer's current style.
#include "qgsmaplayerstyle.h"
%End
public:
static const QMetaObject staticMetaObject;

public:

enum StyleCategory
{
LayerConfiguration,
Symbology,
Labels,
Fields,
Forms,
Actions,
Tooltips,
Diagrams,
AttributeTable,
Rendering,
CustomProperties,
All
};
typedef QFlags<QgsMapLayerStyle::StyleCategory> StyleCategories;


QgsMapLayerStyle();
%Docstring
@@ -72,6 +93,9 @@ Write style configuration (for project file writing)

};

QFlags<QgsMapLayerStyle::StyleCategory> operator|(QgsMapLayerStyle::StyleCategory f1, QFlags<QgsMapLayerStyle::StyleCategory> f2);



class QgsMapLayerStyleOverride
{
@@ -870,8 +870,8 @@ Returns the current auxiliary layer.
%End


virtual bool readSymbology( const QDomNode &layerNode, QString &errorMessage, QgsReadWriteContext &context );

virtual bool readSymbology( const QDomNode &layerNode, QString &errorMessage,
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All );
%Docstring
Read the symbology for the current layer from the Dom node supplied.

@@ -882,8 +882,8 @@ Read the symbology for the current layer from the Dom node supplied.
:return: true in case of success.
%End

virtual bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context );

virtual bool readStyle( const QDomNode &node, QString &errorMessage,
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All );
%Docstring
Read the style for the current layer from the Dom node supplied.

@@ -894,8 +894,8 @@ Read the style for the current layer from the Dom node supplied.
:return: true in case of success.
%End

virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const;

virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
%Docstring
Write the symbology for the layer into the docment provided.

@@ -907,8 +907,8 @@ Write the symbology for the layer into the docment provided.
:return: true in case of success.
%End

virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const;

virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
%Docstring
Write just the style information for the layer into the document

@@ -348,16 +348,16 @@ Draws a preview of the rasterlayer into a QImage
void showStatusMessage( const QString &message );

protected:
virtual bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context );
virtual bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All );

virtual bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context );
virtual bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All );

virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );

virtual bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const;

virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const;

virtual bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage,
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
virtual bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const;

virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
@@ -8855,7 +8855,8 @@ void QgisApp::copyStyle( QgsMapLayer *sourceLayer )
{
QString errorMsg;
QDomDocument doc( QStringLiteral( "qgis" ) );
selectionLayer->exportNamedStyle( doc, errorMsg );
QgsReadWriteContext context;
selectionLayer->exportNamedStyle( doc, errorMsg, context );


if ( !errorMsg.isEmpty() )
@@ -9730,7 +9731,8 @@ void QgisApp::duplicateLayers( const QList<QgsMapLayer *> &lyrList )
// duplicate the layer style
QString errMsg;
QDomDocument style;
selectedLyr->exportNamedStyle( style, errMsg );
QgsReadWriteContext context;
selectedLyr->exportNamedStyle( style, errMsg, context );
if ( errMsg.isEmpty() )
dupLayer->importNamedStyle( style, errMsg );
if ( !errMsg.isEmpty() )
@@ -242,10 +242,12 @@ QgsMapLayerRenderer *QgsMeshLayer::createMapRenderer( QgsRenderContext &renderer
return new QgsMeshLayerRenderer( this, rendererContext );
}

bool QgsMeshLayer::readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context )
bool QgsMeshLayer::readSymbology( const QDomNode &node, QString &errorMessage,
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories )
{
Q_UNUSED( errorMessage );
Q_UNUSED( context );
Q_UNUSED( categories );

QDomElement elem = node.toElement();
QDomElement elemRendererSettings = elem.firstChildElement( "mesh-renderer-settings" );
@@ -255,10 +257,12 @@ bool QgsMeshLayer::readSymbology( const QDomNode &node, QString &errorMessage, Q
return true;
}

bool QgsMeshLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const
bool QgsMeshLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories ) const
{
Q_UNUSED( errorMessage );
Q_UNUSED( context );
Q_UNUSED( categories );

QDomElement elem = node.toElement();
QDomElement elemRendererSettings = mRendererSettings.writeXml( doc );
@@ -125,8 +125,10 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
QgsMeshLayer *clone() const override SIP_FACTORY;
QgsRectangle extent() const override;
QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context ) override;
bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const override;
bool readSymbology( const QDomNode &node, QString &errorMessage,
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) override;
bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const override;
QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;

0 comments on commit 51e9be0

Please sign in to comment.
You can’t perform that action at this time.