Skip to content
Permalink
Browse files

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
  • Loading branch information
3nids authored and nyalldawson committed Sep 14, 2018
1 parent 4e58411 commit 15e0d873d95b33016b94049b708e28786b37c76b
@@ -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

This file was deleted.

@@ -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;
@@ -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
@@ -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`.
@@ -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

@@ -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.

@@ -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.

@@ -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.

@@ -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

@@ -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

@@ -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);




/************************************************************************
@@ -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
@@ -93,9 +71,6 @@ Write style configuration (for project file writing)

};

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



class QgsMapLayerStyleOverride
{
@@ -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.

@@ -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.

@@ -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.

@@ -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

@@ -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;
@@ -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();

@@ -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() )
{
@@ -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

/**
@@ -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 ) )
{
@@ -890,7 +890,6 @@ SET(QGIS_CORE_HDRS
qgsmaplayerdependency.h
qgsmaplayerrenderer.h
qgsmaplayerstyle.h
qgsmaplayerstylemanager.h
qgsmapsettings.h
qgsmapsettingsutils.h
qgsmaptopixel.h
@@ -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
@@ -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
@@ -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;

0 comments on commit 15e0d87

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