From a7409b74058d2823493511ecbd3930198c4ca8ff Mon Sep 17 00:00:00 2001 From: Martin Dobias Date: Tue, 29 Oct 2013 10:55:02 +0700 Subject: [PATCH] Plugin layers: added support for legend symbology items --- python/core/qgspluginlayer.sip | 5 +++++ src/app/legend/qgslegendlayer.cpp | 10 ++++++++++ src/core/qgspluginlayer.cpp | 6 ++++++ src/core/qgspluginlayer.h | 7 +++++++ 4 files changed, 28 insertions(+) diff --git a/python/core/qgspluginlayer.sip b/python/core/qgspluginlayer.sip index 0be28d7339e..f19732a278f 100644 --- a/python/core/qgspluginlayer.sip +++ b/python/core/qgspluginlayer.sip @@ -12,4 +12,9 @@ class QgsPluginLayer : QgsMapLayer QString pluginLayerType(); void setExtent( const QgsRectangle &extent ); + + //! return a list of symbology items for the legend + //! (defult implementation returns nothing) + //! @note Added in v2.1 + virtual QgsLegendSymbologyList legendSymbologyItems( const QSize& iconSize ); }; diff --git a/src/app/legend/qgslegendlayer.cpp b/src/app/legend/qgslegendlayer.cpp index bd2115b604c..b25fb38753c 100644 --- a/src/app/legend/qgslegendlayer.cpp +++ b/src/app/legend/qgslegendlayer.cpp @@ -22,6 +22,7 @@ #include "qgsfield.h" #include "qgsmapcanvasmap.h" #include "qgsmaplayerregistry.h" +#include "qgspluginlayer.h" #include "qgsrasterlayer.h" #include "qgsvectorlayer.h" #include "qgsvectordataprovider.h" @@ -142,6 +143,15 @@ void QgsLegendLayer::refreshSymbology( const QString& key ) QgsRasterLayer* rlayer = qobject_cast( theMapLayer ); rasterLayerSymbology( rlayer ); // get and change symbology } + else if ( theMapLayer->type() == QgsMapLayer::PluginLayer ) + { + QgsPluginLayer* player = qobject_cast( theMapLayer ); + + QSize iconSize( 16, 16 ); + SymbologyList itemList = player->legendSymbologyItems( iconSize ); + + changeSymbologySettings( theMapLayer, itemList ); + } updateIcon(); } diff --git a/src/core/qgspluginlayer.cpp b/src/core/qgspluginlayer.cpp index 1aed2f1de8c..c7a931d394c 100644 --- a/src/core/qgspluginlayer.cpp +++ b/src/core/qgspluginlayer.cpp @@ -28,3 +28,9 @@ void QgsPluginLayer::setExtent( const QgsRectangle &extent ) { mExtent = extent; } + +QgsLegendSymbologyList QgsPluginLayer::legendSymbologyItems( const QSize& iconSize ) +{ + Q_UNUSED( iconSize ); + return QgsLegendSymbologyList(); +} diff --git a/src/core/qgspluginlayer.h b/src/core/qgspluginlayer.h index 06cc272f7ec..c6a42419434 100644 --- a/src/core/qgspluginlayer.h +++ b/src/core/qgspluginlayer.h @@ -17,6 +17,8 @@ #include "qgsmaplayer.h" +typedef QList< QPair > QgsLegendSymbologyList; + /** \ingroup core Base class for plugin layers. These can be implemented by plugins and registered in QgsPluginLayerRegistry. @@ -39,6 +41,11 @@ class CORE_EXPORT QgsPluginLayer : public QgsMapLayer void setExtent( const QgsRectangle &extent ); + //! return a list of symbology items for the legend + //! (defult implementation returns nothing) + //! @note Added in v2.1 + virtual QgsLegendSymbologyList legendSymbologyItems( const QSize& iconSize ); + protected: QString mPluginLayerType; };