Skip to content

Commit

Permalink
select categories in copy style in legend menu entry
Browse files Browse the repository at this point in the history
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
  • Loading branch information
3nids authored and nyalldawson committed Sep 14, 2018
1 parent 4e58411 commit 15e0d87
Show file tree
Hide file tree
Showing 20 changed files with 238 additions and 155 deletions.
3 changes: 3 additions & 0 deletions python/core/auto_additions/qgsmaplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
QgsMapLayer.LayerFlag.baseClass = QgsMapLayer
QgsMapLayer.LayerFlags.baseClass = QgsMapLayer
LayerFlags = QgsMapLayer # dirty hack since SIP seems to introduce the flags in module
QgsMapLayer.StyleCategory.baseClass = QgsMapLayer
QgsMapLayer.StyleCategories.baseClass = QgsMapLayer
StyleCategories = QgsMapLayer # dirty hack since SIP seems to introduce the flags in module
4 changes: 0 additions & 4 deletions python/core/auto_additions/qgsmaplayerstyle.py

This file was deleted.

4 changes: 2 additions & 2 deletions python/core/auto_generated/mesh/qgsmeshlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ QgsMeshLayer cannot be copied.
virtual QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) /Factory/;

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

virtual QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const;
Expand Down
53 changes: 46 additions & 7 deletions python/core/auto_generated/qgsmaplayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,33 @@ This is the base class for all map layer types (vector, raster).
typedef QFlags<QgsMapLayer::LayerFlag> LayerFlags;


enum StyleCategory
{
LayerConfiguration,
Symbology,
Labels,
Fields,
Forms,
Actions,
MapTips,
Diagrams,
AttributeTable,
Rendering,
CustomProperties,
AllCategories
};
typedef QFlags<QgsMapLayer::StyleCategory> StyleCategories;


struct ReadableStyleCategory
{
public:
ReadableStyleCategory( const QString &name, const QString &toolTip = QString() );

QString name() const;
QString toolTip() const;
};

QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, const QString &name = QString(), const QString &source = QString() );
%Docstring
Constructor for QgsMapLayer
Expand Down Expand Up @@ -137,6 +164,15 @@ Returns the extension of a Property.
.. versionadded:: 3.0
%End

static ReadableStyleCategory readableStyleCategory( StyleCategory category );
%Docstring
Readable and Translated category

.. versionadded:: 3.4
%End



QString id() const;
%Docstring
Returns the layer's unique ID, which is used to access this layer from :py:class:`QgsProject`.
Expand Down Expand Up @@ -784,7 +820,7 @@ Import the properties of this layer from a QDomDocument
%End

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

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


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

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

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

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

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

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

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

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

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

.. versionadded:: 3.0
%End

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

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

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

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




/************************************************************************
Expand Down
25 changes: 0 additions & 25 deletions python/core/auto_generated/qgsmaplayerstyle.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,6 @@ 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,
MapTips,
Diagrams,
AttributeTable,
Rendering,
CustomProperties,
All
};
typedef QFlags<QgsMapLayerStyle::StyleCategory> StyleCategories;


QgsMapLayerStyle();
%Docstring
construct invalid style
Expand Down Expand Up @@ -93,9 +71,6 @@ Write style configuration (for project file writing)

};

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



class QgsMapLayerStyleOverride
{
Expand Down
8 changes: 4 additions & 4 deletions python/core/auto_generated/qgsvectorlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ Returns the current auxiliary layer.


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

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

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

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

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

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

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

Expand Down
8 changes: 4 additions & 4 deletions python/core/auto_generated/raster/qgsrasterlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All );
virtual bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories );

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

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

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

virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
Expand Down
5 changes: 2 additions & 3 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8847,7 +8847,7 @@ std::unique_ptr<QgsVectorLayer> QgisApp::pasteToNewMemoryVector()
return layer;
}

void QgisApp::copyStyle( QgsMapLayer *sourceLayer )
void QgisApp::copyStyle( QgsMapLayer *sourceLayer, QgsMapLayer::StyleCategories categories )
{
QgsMapLayer *selectionLayer = sourceLayer ? sourceLayer : activeLayer();

Expand All @@ -8856,8 +8856,7 @@ void QgisApp::copyStyle( QgsMapLayer *sourceLayer )
QString errorMsg;
QDomDocument doc( QStringLiteral( "qgis" ) );
QgsReadWriteContext context;
selectionLayer->exportNamedStyle( doc, errorMsg, context );

selectionLayer->exportNamedStyle( doc, errorMsg, context, categories );

if ( !errorMsg.isEmpty() )
{
Expand Down
8 changes: 5 additions & 3 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -830,10 +830,12 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! copies style of the active layer to the clipboard

/**
\param sourceLayer The layer where the style will be taken from
(defaults to the active layer on the legend)
* Copy the style of a map layer
* \param sourceLayer The layer where the style will be taken from
(defaults to the active layer on the legend)
* \param categories The style categories to copy
*/
void copyStyle( QgsMapLayer *sourceLayer = nullptr );
void copyStyle( QgsMapLayer *sourceLayer = nullptr, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories );
//! pastes style on the clipboard to the active layer

/**
Expand Down
17 changes: 16 additions & 1 deletion src/app/qgsapplayertreeviewmenuprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,22 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
QMenu *menuStyleManager = new QMenu( tr( "Styles" ), menu );

QgisApp *app = QgisApp::instance();
menuStyleManager->addAction( tr( "Copy Style" ), app, SLOT( copyStyle() ) );
if ( layer->type() == QgsMapLayer::VectorLayer )
{
QMenu *copyStyleMenu = menuStyleManager->addMenu( tr( "Copy Style…" ) );
copyStyleMenu->setToolTipsVisible( true );
auto enumMap = qgsEnumMap<QgsMapLayer::StyleCategory>();
for ( auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
{
QgsMapLayer::ReadableStyleCategory category = QgsMapLayer::readableStyleCategory( it.key() );
QAction *action = copyStyleMenu->addAction( category.name(), app, SLOT( copyStyle() ) );
action->setToolTip( category.toolTip() );
}
}
else
{
menuStyleManager->addAction( tr( "Copy Style" ), app, SLOT( copyStyle() ) );
}

if ( app->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) )
{
Expand Down
1 change: 0 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,6 @@ SET(QGIS_CORE_HDRS
qgsmaplayerdependency.h
qgsmaplayerrenderer.h
qgsmaplayerstyle.h
qgsmaplayerstylemanager.h
qgsmapsettings.h
qgsmapsettingsutils.h
qgsmaptopixel.h
Expand Down
4 changes: 2 additions & 2 deletions src/core/mesh/qgsmeshlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ QgsMapLayerRenderer *QgsMeshLayer::createMapRenderer( QgsRenderContext &renderer
}

bool QgsMeshLayer::readSymbology( const QDomNode &node, QString &errorMessage,
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories )
QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
{
Q_UNUSED( errorMessage );
// TODO: implement categories for raster layer
Expand All @@ -260,7 +260,7 @@ bool QgsMeshLayer::readSymbology( const QDomNode &node, QString &errorMessage,
}

bool QgsMeshLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories ) const
const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
{
Q_UNUSED( errorMessage );
// TODO: implement categories for raster layer
Expand Down
4 changes: 2 additions & 2 deletions src/core/mesh/qgsmeshlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
QgsRectangle extent() const override;
QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
bool readSymbology( const QDomNode &node, QString &errorMessage,
QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) override;
QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories ) override;
bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
const QgsReadWriteContext &context, QgsMapLayerStyle::StyleCategories categories = QgsMapLayerStyle::All ) const override;
const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllCategories ) 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;
Expand Down

0 comments on commit 15e0d87

Please sign in to comment.