Skip to content
Permalink
Browse files

add icons and export only selected category

  • Loading branch information
3nids authored and nyalldawson committed Sep 14, 2018
1 parent 15e0d87 commit 26ad2cbf98bb9eebff57df5000a4ecbd0e75706d
@@ -97,9 +97,10 @@ This is the base class for all map layer types (vector, raster).
{
public:
ReadableStyleCategory( const QString &name, const QString &toolTip = QString() );

ReadableStyleCategory( const QString &name, const QIcon &icon, const QString &toolTip = QString() );
QString name() const;
QString toolTip() const;
QIcon icon() const;
};

QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, const QString &name = QString(), const QString &source = QString() );
@@ -320,12 +320,17 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
{
QMenu *copyStyleMenu = menuStyleManager->addMenu( tr( "Copy Style…" ) );
copyStyleMenu->setToolTipsVisible( true );
auto enumMap = qgsEnumMap<QgsMapLayer::StyleCategory>();
for ( auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
QList<QgsMapLayer::StyleCategory> categories = qgsEnumMap<QgsMapLayer::StyleCategory>().keys();
categories.move( categories.indexOf( QgsMapLayer::AllCategories ), 0 ); // move All categories to top
for ( QgsMapLayer::StyleCategory category : categories )
{
QgsMapLayer::ReadableStyleCategory category = QgsMapLayer::readableStyleCategory( it.key() );
QAction *action = copyStyleMenu->addAction( category.name(), app, SLOT( copyStyle() ) );
action->setToolTip( category.toolTip() );
QgsMapLayer::ReadableStyleCategory readableCategory = QgsMapLayer::readableStyleCategory( category );
QAction *copyAction = new QAction( readableCategory.icon(), readableCategory.name() );
copyAction->setToolTip( readableCategory.toolTip() );
connect( copyAction, &QAction::triggered, this, [ = ]() {app->copyStyle( layer, category );} );
copyStyleMenu->addAction( copyAction );
if ( category == QgsMapLayer::AllCategories )
copyStyleMenu->addSeparator();
}
}
else
@@ -72,28 +72,42 @@ QgsMapLayer::ReadableStyleCategory QgsMapLayer::readableStyleCategory( QgsMapLay
switch ( category )
{
case LayerConfiguration:
return ReadableStyleCategory( tr( "Layer Configuration" ), tr( "Flags, display expression, read-only" ) );
case Symbology :
return ReadableStyleCategory( tr( "Symbology" ) );
case Labels :
return ReadableStyleCategory( tr( "Labels" ) );
case Fields :
return ReadableStyleCategory( tr( "Fields" ), tr( "Aliases, widgets, WMS/WFS, expressions, constraints, virtual fields" ) );
case Forms :
return ReadableStyleCategory( tr( "Forms" ) );
case Actions :
return ReadableStyleCategory( tr( "Actions" ) );
case MapTips :
return ReadableStyleCategory( tr( "Map Tips" ) );
case Diagrams :
return ReadableStyleCategory( tr( "Diagrams" ) );
case AttributeTable :
return ReadableStyleCategory( tr( "Attribute Table" ) );
case Rendering :
return ReadableStyleCategory( tr( "Rendering" ), tr( "Scale visibility, simplify method, opacity" ) );
case CustomProperties :
return ReadableStyleCategory( tr( "Custom Properties" ) );
case AllCategories :
return ReadableStyleCategory( tr( "Layer Configuration" ),
QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/system.svg" ) ),
tr( "Flags, display expression, read-only" ) );
case Symbology :
return ReadableStyleCategory( tr( "Symbology" ),
QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/symbology.svg" ) ) );
case Labels :
return ReadableStyleCategory( tr( "Labels" ),
QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/labels.svg" ) ) );
case Fields :
return ReadableStyleCategory( tr( "Fields" ),
QgsApplication::getThemeIcon( QStringLiteral( "/mSourceFields.svg" ) ),
tr( "Aliases, widgets, WMS/WFS, expressions, constraints, virtual fields" ) );
case Forms :
return ReadableStyleCategory( tr( "Forms" ),
QgsApplication::getThemeIcon( QStringLiteral( "/mActionFormView.svg" ) ) );
case Actions :
return ReadableStyleCategory( tr( "Actions" ),
QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/action.svg" ) ) );
case MapTips :
return ReadableStyleCategory( tr( "Map Tips" ),
QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/display.svg" ) ) );
case Diagrams :
return ReadableStyleCategory( tr( "Diagrams" ),
QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/diagram.svg" ) ) );
case AttributeTable :
return ReadableStyleCategory( tr( "Attribute Table" ),
QgsApplication::getThemeIcon( QStringLiteral( "/mActionOpenTable.svg" ) ) );
case Rendering :
return ReadableStyleCategory( tr( "Rendering" ),
QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/rendering.svg" ) ),
tr( "Scale visibility, simplify method, opacity" ) );
case CustomProperties :
return ReadableStyleCategory( tr( "Custom Properties" ),
QgsApplication::getThemeIcon( QStringLiteral( "/mActionOptions.svg" ) ) );
case AllCategories :
return ReadableStyleCategory( tr( "All categories" ) );
}
}
@@ -26,6 +26,7 @@
#include <QPainter>
#include <QUndoStack>
#include <QVariant>
#include <QIcon>

#include "qgis.h"
#include "qgserror.h"
@@ -148,7 +149,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
Actions = 1 << 5,
MapTips = 1 << 6,
Diagrams = 1 << 7,
AttributeTable = 7 << 8,
AttributeTable = 1 << 8,
Rendering = 1 << 9, //!< Scale visibility, simplify method, opacity
CustomProperties = 1 << 10,
AllCategories = LayerConfiguration | Symbology | Labels | Fields | Forms | Actions |
@@ -168,12 +169,16 @@ class CORE_EXPORT QgsMapLayer : public QObject
ReadableStyleCategory( const QString &name, const QString &toolTip = QString() )
: mName( name ), mToolTip( toolTip )
{}

ReadableStyleCategory( const QString &name, const QIcon &icon, const QString &toolTip = QString() )
: mName( name ), mToolTip( toolTip ), mIcon( icon )
{}
QString name() const {return mName;}
QString toolTip() const {return mToolTip;}
QIcon icon() const {return mIcon;}
private:
QString mName;
QString mToolTip;
QIcon mIcon;
};

/**

0 comments on commit 26ad2cb

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