Skip to content

Commit 51e9be0

Browse files
3nidsnyalldawson
authored andcommittedSep 14, 2018
add API to select section of layer style when reading/writing
1 parent 3875adf commit 51e9be0

18 files changed

+290
-166
lines changed
 
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# The following has been generated automatically from src/core/qgsmaplayerstyle.h
2+
QgsMapLayerStyle.StyleCategory.baseClass = QgsMapLayerStyle
3+
QgsMapLayerStyle.StyleCategories.baseClass = QgsMapLayerStyle
4+
StyleCategories = QgsMapLayerStyle # dirty hack since SIP seems to introduce the flags in module

‎python/core/auto_generated/mesh/qgsmeshlayer.sip.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ QgsMeshLayer cannot be copied.
109109

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

112-
virtual bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context );
113-
114-
virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const;
115-
112+
virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
113+
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All );
114+
virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
115+
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
116116
virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
117117

118118
virtual QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const;

‎python/core/auto_generated/qgsmaplayer.sip.in

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@ Sets state from Dom document
503503
The Dom node corresponds to a Dom document project file XML element read
504504
by :py:class:`QgsProject`.
505505

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

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

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

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

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

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

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

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

866867

867868

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

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

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

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

896-
virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const = 0;
899+
virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
900+
QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const = 0;
897901
%Docstring
898-
Write the symbology for the layer into the docment provided.
902+
Write the style for the layer into the docment provided.
899903

900904
:param node: the node that will have the style element added to it.
901905
:param doc: the document that will have the QDomNode added.
902906
:param errorMessage: reference to string that will be updated with any error messages
903907
:param context: writing context (used for transform from absolute to relative paths)
904908

909+
.. note::
910+
911+
There is a confusion of terms with the GUI. This method actually writes what is called a style in the application.
912+
905913
:return: true in case of success.
906914
%End
907915

908-
virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const;
916+
virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
917+
QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
909918
%Docstring
910-
Write just the style information for the layer into the document
919+
Write just the symbology information for the layer into the document
911920

912921
:param node: the node that will have the style element added to it.
913922
: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
920929

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

932+
.. note::
933+
934+
There is a confusion of terms with the GUI. This method actually writes what is known as the symbology in the application.
935+
923936
.. versionadded:: 2.16
924937
%End
925938

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

1478-
void writeCommonStyle( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
1491+
void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
1492+
const QgsReadWriteContext &context,
1493+
QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
14791494
%Docstring
14801495
Write style data common to all layer types
14811496

14821497
.. versionadded:: 3.0
14831498
%End
14841499

1485-
void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context );
1500+
void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
1501+
QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All );
14861502
%Docstring
14871503
Read style data common to all layer types
14881504

‎python/core/auto_generated/qgsmaplayerstyle.sip.in

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ only possible to read or write layer's current style.
2626
#include "qgsmaplayerstyle.h"
2727
%End
2828
public:
29+
static const QMetaObject staticMetaObject;
30+
31+
public:
32+
33+
enum StyleCategory
34+
{
35+
LayerConfiguration,
36+
Symbology,
37+
Labels,
38+
Fields,
39+
Forms,
40+
Actions,
41+
Tooltips,
42+
Diagrams,
43+
AttributeTable,
44+
Rendering,
45+
CustomProperties,
46+
All
47+
};
48+
typedef QFlags<QgsMapLayerStyle::StyleCategory> StyleCategories;
49+
2950

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

7394
};
7495

96+
QFlags<QgsMapLayerStyle::StyleCategory> operator|(QgsMapLayerStyle::StyleCategory f1, QFlags<QgsMapLayerStyle::StyleCategory> f2);
97+
98+
7599

76100
class QgsMapLayerStyleOverride
77101
{

‎python/core/auto_generated/qgsvectorlayer.sip.in

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,8 @@ Returns the current auxiliary layer.
870870
%End
871871

872872

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

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

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

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

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

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

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

‎python/core/auto_generated/raster/qgsrasterlayer.sip.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,16 +348,16 @@ Draws a preview of the rasterlayer into a QImage
348348
void showStatusMessage( const QString &message );
349349

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

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

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

357-
virtual bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const;
358-
359-
virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const;
360-
357+
virtual bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage,
358+
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
359+
virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
360+
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
361361
virtual bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
362362

363363
virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;

‎src/app/qgisapp.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8855,7 +8855,8 @@ void QgisApp::copyStyle( QgsMapLayer *sourceLayer )
88558855
{
88568856
QString errorMsg;
88578857
QDomDocument doc( QStringLiteral( "qgis" ) );
8858-
selectionLayer->exportNamedStyle( doc, errorMsg );
8858+
QgsReadWriteContext context;
8859+
selectionLayer->exportNamedStyle( doc, errorMsg, context );
88598860

88608861

88618862
if ( !errorMsg.isEmpty() )
@@ -9730,7 +9731,8 @@ void QgisApp::duplicateLayers( const QList<QgsMapLayer *> &lyrList )
97309731
// duplicate the layer style
97319732
QString errMsg;
97329733
QDomDocument style;
9733-
selectedLyr->exportNamedStyle( style, errMsg );
9734+
QgsReadWriteContext context;
9735+
selectedLyr->exportNamedStyle( style, errMsg, context );
97349736
if ( errMsg.isEmpty() )
97359737
dupLayer->importNamedStyle( style, errMsg );
97369738
if ( !errMsg.isEmpty() )

‎src/core/mesh/qgsmeshlayer.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,12 @@ QgsMapLayerRenderer *QgsMeshLayer::createMapRenderer( QgsRenderContext &renderer
242242
return new QgsMeshLayerRenderer( this, rendererContext );
243243
}
244244

245-
bool QgsMeshLayer::readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context )
245+
bool QgsMeshLayer::readSymbology( const QDomNode &node, QString &errorMessage,
246+
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories )
246247
{
247248
Q_UNUSED( errorMessage );
248249
Q_UNUSED( context );
250+
Q_UNUSED( categories );
249251

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

258-
bool QgsMeshLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const
260+
bool QgsMeshLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
261+
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories ) const
259262
{
260263
Q_UNUSED( errorMessage );
261264
Q_UNUSED( context );
265+
Q_UNUSED( categories );
262266

263267
QDomElement elem = node.toElement();
264268
QDomElement elemRendererSettings = mRendererSettings.writeXml( doc );

‎src/core/mesh/qgsmeshlayer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
125125
QgsMeshLayer *clone() const override SIP_FACTORY;
126126
QgsRectangle extent() const override;
127127
QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
128-
bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context ) override;
129-
bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const override;
128+
bool readSymbology( const QDomNode &node, QString &errorMessage,
129+
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) override;
130+
bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
131+
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const override;
130132
QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
131133
QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
132134
bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;

0 commit comments

Comments
 (0)
Please sign in to comment.