mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
feat: Enhance the ability to customize icons for QgsPluginLayer
This commit is contained in:
parent
37478db0c1
commit
33b22c6519
@ -58,6 +58,13 @@ Set source string. This is used for example in layer tree to show tooltip.
|
||||
virtual QgsDataProvider *dataProvider();
|
||||
|
||||
|
||||
virtual QIcon icon() const;
|
||||
%Docstring
|
||||
Returns an icon for the layer.
|
||||
|
||||
.. versionadded:: 3.42
|
||||
%End
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
|
||||
@ -58,6 +58,13 @@ Set source string. This is used for example in layer tree to show tooltip.
|
||||
virtual QgsDataProvider *dataProvider();
|
||||
|
||||
|
||||
virtual QIcon icon() const;
|
||||
%Docstring
|
||||
Returns an icon for the layer.
|
||||
|
||||
.. versionadded:: 3.42
|
||||
%End
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#include "qgsapplication.h"
|
||||
#include "qgsmaplayer.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgspluginlayer.h"
|
||||
|
||||
#include <QIcon>
|
||||
|
||||
@ -111,14 +112,23 @@ QIcon QgsIconUtils::iconForLayer( const QgsMapLayer *layer )
|
||||
case Qgis::LayerType::Mesh:
|
||||
case Qgis::LayerType::VectorTile:
|
||||
case Qgis::LayerType::PointCloud:
|
||||
case Qgis::LayerType::Plugin:
|
||||
case Qgis::LayerType::Annotation:
|
||||
case Qgis::LayerType::Group:
|
||||
case Qgis::LayerType::TiledScene:
|
||||
{
|
||||
return QgsIconUtils::iconForLayerType( layer->type() );
|
||||
}
|
||||
|
||||
case Qgis::LayerType::Plugin:
|
||||
{
|
||||
if ( const QgsPluginLayer *pl = qobject_cast<const QgsPluginLayer *>( layer ) )
|
||||
{
|
||||
const QIcon icon = pl->icon();
|
||||
if ( !icon.isNull() )
|
||||
return icon;
|
||||
}
|
||||
// fallback to default icon if layer did not provide a specific icon
|
||||
return QgsIconUtils::iconForLayerType( layer->type() );
|
||||
}
|
||||
case Qgis::LayerType::Vector:
|
||||
{
|
||||
const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer );
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
***************************************************************************/
|
||||
#include "qgspluginlayer.h"
|
||||
#include "moc_qgspluginlayer.cpp"
|
||||
#include "qgsiconutils.h"
|
||||
|
||||
QgsPluginLayer::QgsPluginLayer( const QString &layerType, const QString &layerName )
|
||||
: QgsMapLayer( Qgis::LayerType::Plugin, layerName )
|
||||
@ -56,6 +57,11 @@ const QgsDataProvider *QgsPluginLayer::dataProvider() const
|
||||
return mDataProvider;
|
||||
}
|
||||
|
||||
QIcon QgsPluginLayer::icon() const
|
||||
{
|
||||
return QgsIconUtils::iconForLayerType( Qgis::LayerType::Plugin );
|
||||
}
|
||||
|
||||
//
|
||||
// QgsPluginLayerDataProvider
|
||||
//
|
||||
|
||||
@ -64,6 +64,12 @@ class CORE_EXPORT QgsPluginLayer : public QgsMapLayer
|
||||
QgsDataProvider *dataProvider() override;
|
||||
const QgsDataProvider *dataProvider() const override SIP_SKIP;
|
||||
|
||||
/**
|
||||
* Returns an icon for the layer.
|
||||
* \since QGIS 3.42
|
||||
*/
|
||||
virtual QIcon icon() const;
|
||||
|
||||
protected:
|
||||
QString mPluginLayerType;
|
||||
QgsDataProvider *mDataProvider;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user