Skip to content

Commit 15e0d87

Browse files
3nidsnyalldawson
authored andcommittedSep 14, 2018
select categories in copy style in legend menu entry
not working yet, just set the menu entries QgsMapLayerStyle::StyleCategory has moved to QgsMapLayer to avoid making QgsMapLayerStyle a QObject and they are mostly used in QgsMapLayer
1 parent 4e58411 commit 15e0d87

20 files changed

+238
-155
lines changed
 

‎python/core/auto_additions/qgsmaplayer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
QgsMapLayer.LayerFlag.baseClass = QgsMapLayer
33
QgsMapLayer.LayerFlags.baseClass = QgsMapLayer
44
LayerFlags = QgsMapLayer # dirty hack since SIP seems to introduce the flags in module
5+
QgsMapLayer.StyleCategory.baseClass = QgsMapLayer
6+
QgsMapLayer.StyleCategories.baseClass = QgsMapLayer
7+
StyleCategories = QgsMapLayer # dirty hack since SIP seems to introduce the flags in module

‎python/core/auto_additions/qgsmaplayerstyle.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ QgsMeshLayer cannot be copied.
110110
virtual QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) /Factory/;
111111

112112
virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
113-
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All );
113+
QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories );
114114
virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
115-
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
115+
const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories ) 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: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,33 @@ This is the base class for all map layer types (vector, raster).
7575
typedef QFlags<QgsMapLayer::LayerFlag> LayerFlags;
7676

7777

78+
enum StyleCategory
79+
{
80+
LayerConfiguration,
81+
Symbology,
82+
Labels,
83+
Fields,
84+
Forms,
85+
Actions,
86+
MapTips,
87+
Diagrams,
88+
AttributeTable,
89+
Rendering,
90+
CustomProperties,
91+
AllCategories
92+
};
93+
typedef QFlags<QgsMapLayer::StyleCategory> StyleCategories;
94+
95+
96+
struct ReadableStyleCategory
97+
{
98+
public:
99+
ReadableStyleCategory( const QString &name, const QString &toolTip = QString() );
100+
101+
QString name() const;
102+
QString toolTip() const;
103+
};
104+
78105
QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, const QString &name = QString(), const QString &source = QString() );
79106
%Docstring
80107
Constructor for QgsMapLayer
@@ -137,6 +164,15 @@ Returns the extension of a Property.
137164
.. versionadded:: 3.0
138165
%End
139166

167+
static ReadableStyleCategory readableStyleCategory( StyleCategory category );
168+
%Docstring
169+
Readable and Translated category
170+
171+
.. versionadded:: 3.4
172+
%End
173+
174+
175+
140176
QString id() const;
141177
%Docstring
142178
Returns the layer's unique ID, which is used to access this layer from :py:class:`QgsProject`.
@@ -784,7 +820,7 @@ Import the properties of this layer from a QDomDocument
784820
%End
785821

786822
virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg /Out/, QgsReadWriteContext &context,
787-
QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
823+
QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories ) const;
788824
%Docstring
789825
Export the properties of this layer as named style in a QDomDocument
790826

@@ -867,7 +903,7 @@ Attempts to style the layer using the formatting from an SLD type file.
867903

868904

869905
virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
870-
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) = 0;
906+
QgsReadWriteContext &context, StyleCategories categories = AllCategories ) = 0;
871907
%Docstring
872908
Read the symbology for the current layer from the Dom node supplied.
873909

@@ -879,7 +915,7 @@ Read the symbology for the current layer from the Dom node supplied.
879915
%End
880916

881917
virtual bool readStyle( const QDomNode &node, QString &errorMessage,
882-
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All );
918+
QgsReadWriteContext &context, StyleCategories categories = AllCategories );
883919
%Docstring
884920
Read the style for the current layer from the Dom node supplied.
885921

@@ -897,7 +933,7 @@ Read the style for the current layer from the Dom node supplied.
897933
%End
898934

899935
virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
900-
QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const = 0;
936+
StyleCategories categories = AllCategories ) const = 0;
901937
%Docstring
902938
Write the style for the layer into the docment provided.
903939

@@ -914,7 +950,7 @@ Write the style for the layer into the docment provided.
914950
%End
915951

916952
virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
917-
QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
953+
StyleCategories categories = AllCategories ) const;
918954
%Docstring
919955
Write just the symbology information for the layer into the document
920956

@@ -1490,15 +1526,15 @@ Write style manager's configuration (if exists). To be called by subclasses.
14901526

14911527
void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
14921528
const QgsReadWriteContext &context,
1493-
QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
1529+
StyleCategories categories = AllCategories ) const;
14941530
%Docstring
14951531
Write style data common to all layer types
14961532

14971533
.. versionadded:: 3.0
14981534
%End
14991535

15001536
void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
1501-
QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All );
1537+
StyleCategories categories = AllCategories );
15021538
%Docstring
15031539
Read style data common to all layer types
15041540

@@ -1537,6 +1573,9 @@ Checks whether a new set of dependencies will introduce a cycle
15371573

15381574
QFlags<QgsMapLayer::LayerFlag> operator|(QgsMapLayer::LayerFlag f1, QFlags<QgsMapLayer::LayerFlag> f2);
15391575

1576+
QFlags<QgsMapLayer::StyleCategory> operator|(QgsMapLayer::StyleCategory f1, QFlags<QgsMapLayer::StyleCategory> f2);
1577+
1578+
15401579

15411580

15421581
/************************************************************************

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

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,6 @@ 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-
MapTips,
42-
Diagrams,
43-
AttributeTable,
44-
Rendering,
45-
CustomProperties,
46-
All
47-
};
48-
typedef QFlags<QgsMapLayerStyle::StyleCategory> StyleCategories;
49-
50-
5129
QgsMapLayerStyle();
5230
%Docstring
5331
construct invalid style
@@ -93,9 +71,6 @@ Write style configuration (for project file writing)
9371

9472
};
9573

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

10075
class QgsMapLayerStyleOverride
10176
{

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ Returns the current auxiliary layer.
871871

872872

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

@@ -883,7 +883,7 @@ Read the symbology for the current layer from the Dom node supplied.
883883
%End
884884

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

@@ -895,7 +895,7 @@ Read the style for the current layer from the Dom node supplied.
895895
%End
896896

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

@@ -908,7 +908,7 @@ Write the symbology for the layer into the docment provided.
908908
%End
909909

910910
virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
911-
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
911+
const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories ) 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: 4 additions & 4 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, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All );
351+
virtual bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories );
352352

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

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

357357
virtual bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage,
358-
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
358+
const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories ) const;
359359
virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
360-
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const;
360+
const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories ) 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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8847,7 +8847,7 @@ std::unique_ptr<QgsVectorLayer> QgisApp::pasteToNewMemoryVector()
88478847
return layer;
88488848
}
88498849

8850-
void QgisApp::copyStyle( QgsMapLayer *sourceLayer )
8850+
void QgisApp::copyStyle( QgsMapLayer *sourceLayer, QgsMapLayer::StyleCategories categories )
88518851
{
88528852
QgsMapLayer *selectionLayer = sourceLayer ? sourceLayer : activeLayer();
88538853

@@ -8856,8 +8856,7 @@ void QgisApp::copyStyle( QgsMapLayer *sourceLayer )
88568856
QString errorMsg;
88578857
QDomDocument doc( QStringLiteral( "qgis" ) );
88588858
QgsReadWriteContext context;
8859-
selectionLayer->exportNamedStyle( doc, errorMsg, context );
8860-
8859+
selectionLayer->exportNamedStyle( doc, errorMsg, context, categories );
88618860

88628861
if ( !errorMsg.isEmpty() )
88638862
{

‎src/app/qgisapp.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,10 +830,12 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
830830
//! copies style of the active layer to the clipboard
831831

832832
/**
833-
\param sourceLayer The layer where the style will be taken from
834-
(defaults to the active layer on the legend)
833+
* Copy the style of a map layer
834+
* \param sourceLayer The layer where the style will be taken from
835+
(defaults to the active layer on the legend)
836+
* \param categories The style categories to copy
835837
*/
836-
void copyStyle( QgsMapLayer *sourceLayer = nullptr );
838+
void copyStyle( QgsMapLayer *sourceLayer = nullptr, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories );
837839
//! pastes style on the clipboard to the active layer
838840

839841
/**

‎src/app/qgsapplayertreeviewmenuprovider.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,22 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
316316
QMenu *menuStyleManager = new QMenu( tr( "Styles" ), menu );
317317

318318
QgisApp *app = QgisApp::instance();
319-
menuStyleManager->addAction( tr( "Copy Style" ), app, SLOT( copyStyle() ) );
319+
if ( layer->type() == QgsMapLayer::VectorLayer )
320+
{
321+
QMenu *copyStyleMenu = menuStyleManager->addMenu( tr( "Copy Style…" ) );
322+
copyStyleMenu->setToolTipsVisible( true );
323+
auto enumMap = qgsEnumMap<QgsMapLayer::StyleCategory>();
324+
for ( auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
325+
{
326+
QgsMapLayer::ReadableStyleCategory category = QgsMapLayer::readableStyleCategory( it.key() );
327+
QAction *action = copyStyleMenu->addAction( category.name(), app, SLOT( copyStyle() ) );
328+
action->setToolTip( category.toolTip() );
329+
}
330+
}
331+
else
332+
{
333+
menuStyleManager->addAction( tr( "Copy Style" ), app, SLOT( copyStyle() ) );
334+
}
320335

321336
if ( app->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) )
322337
{

‎src/core/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,6 @@ SET(QGIS_CORE_HDRS
890890
qgsmaplayerdependency.h
891891
qgsmaplayerrenderer.h
892892
qgsmaplayerstyle.h
893-
qgsmaplayerstylemanager.h
894893
qgsmapsettings.h
895894
qgsmapsettingsutils.h
896895
qgsmaptopixel.h

‎src/core/mesh/qgsmeshlayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ QgsMapLayerRenderer *QgsMeshLayer::createMapRenderer( QgsRenderContext &renderer
243243
}
244244

245245
bool QgsMeshLayer::readSymbology( const QDomNode &node, QString &errorMessage,
246-
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories )
246+
QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
247247
{
248248
Q_UNUSED( errorMessage );
249249
// TODO: implement categories for raster layer
@@ -260,7 +260,7 @@ bool QgsMeshLayer::readSymbology( const QDomNode &node, QString &errorMessage,
260260
}
261261

262262
bool QgsMeshLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
263-
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories ) const
263+
const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
264264
{
265265
Q_UNUSED( errorMessage );
266266
// TODO: implement categories for raster layer

‎src/core/mesh/qgsmeshlayer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
126126
QgsRectangle extent() const override;
127127
QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
128128
bool readSymbology( const QDomNode &node, QString &errorMessage,
129-
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) override;
129+
QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories ) override;
130130
bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
131-
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const override;
131+
const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories ) const override;
132132
QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
133133
QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
134134
bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;

0 commit comments

Comments
 (0)
Please sign in to comment.