feat: Enhance the ability to customize icons for QgsPluginLayer

This commit is contained in:
hxbb00 2024-11-20 13:50:36 +00:00 committed by Nyall Dawson
parent 37478db0c1
commit 33b22c6519
5 changed files with 38 additions and 2 deletions

View File

@ -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:
};

View File

@ -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:
};

View File

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

View File

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

View File

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