Skip to content
Permalink
Browse files

Added static QgsLayerItem::iconName(LayerType) for reuse and consistency

  • Loading branch information
elpaso committed Sep 7, 2017
1 parent 51abef4 commit 31b51178b8546b083f9fb9b564928eaf00285a8e
Showing with 42 additions and 24 deletions.
  1. +8 −1 python/core/qgsdataitem.sip
  2. +28 −22 src/core/qgsdataitem.cpp
  3. +6 −1 src/core/qgsdataitem.h
@@ -414,7 +414,14 @@ Returns provider key

static QString layerTypeAsString( const LayerType &layerType );
%Docstring
Returns the string representatio of the given ``layerType``
Returns the string representation of the given ``layerType``
.. versionadded:: 3
:rtype: str
%End

static QString iconName( const LayerType &layerType );
%Docstring
Returns the icon name of the given ``layerType``
.. versionadded:: 3
:rtype: str
%End
@@ -545,49 +545,55 @@ QgsLayerItem::QgsLayerItem( QgsDataItem *parent, const QString &name, const QStr
, mProviderKey( providerKey )
, mUri( uri )
, mLayerType( layerType )
{
mIconName = iconName( layerType );
}

QgsMapLayer::LayerType QgsLayerItem::mapLayerType() const
{
if ( mLayerType == QgsLayerItem::Raster )
return QgsMapLayer::RasterLayer;
if ( mLayerType == QgsLayerItem::Plugin )
return QgsMapLayer::PluginLayer;
return QgsMapLayer::VectorLayer;
}

QString QgsLayerItem::layerTypeAsString( const QgsLayerItem::LayerType &layerType )
{
static int enumIdx = staticMetaObject.indexOfEnumerator( "LayerType" );
return staticMetaObject.enumerator( enumIdx ).valueToKey( layerType );
}

QString QgsLayerItem::iconName( const QgsLayerItem::LayerType &layerType )
{
switch ( layerType )
{
case Point:
mIconName = QStringLiteral( "/mIconPointLayer.svg" );
return QStringLiteral( "/mIconPointLayer.svg" );
break;
case Line:
mIconName = QStringLiteral( "/mIconLineLayer.svg" );
return QStringLiteral( "/mIconLineLayer.svg" );
break;
case Polygon:
mIconName = QStringLiteral( "/mIconPolygonLayer.svg" );
return QStringLiteral( "/mIconPolygonLayer.svg" );
break;
// TODO add a new icon for generic Vector layers
case Vector :
mIconName = QStringLiteral( "/mIconPolygonLayer.svg" );
return QStringLiteral( "/mIconPolygonLayer.svg" );
break;
case TableLayer:
mIconName = QStringLiteral( "/mIconTableLayer.svg" );
case Table:
return QStringLiteral( "/mIconTableLayer.svg" );
break;
case Raster:
mIconName = QStringLiteral( "/mIconRaster.svg" );
return QStringLiteral( "/mIconRaster.svg" );
break;
default:
mIconName = QStringLiteral( "/mIconLayer.png" );
return QStringLiteral( "/mIconLayer.png" );
break;
}
}

QgsMapLayer::LayerType QgsLayerItem::mapLayerType() const
{
if ( mLayerType == QgsLayerItem::Raster )
return QgsMapLayer::RasterLayer;
if ( mLayerType == QgsLayerItem::Plugin )
return QgsMapLayer::PluginLayer;
return QgsMapLayer::VectorLayer;
}

QString QgsLayerItem::layerTypeAsString( const QgsLayerItem::LayerType &layerType )
{
static int enumIdx = staticMetaObject.indexOfEnumerator( "LayerType" );
return staticMetaObject.enumerator( enumIdx ).valueToKey( layerType );
}

bool QgsLayerItem::equal( const QgsDataItem *other )
{
//QgsDebugMsg ( mPath + " x " + other->mPath );
@@ -384,11 +384,16 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem
*/
virtual QString comments() const { return QString(); }

/** Returns the string representatio of the given \a layerType
/** Returns the string representation of the given \a layerType
* \since QGIS 3
*/
static QString layerTypeAsString( const LayerType &layerType );

/** Returns the icon name of the given \a layerType
* \since QGIS 3
*/
static QString iconName( const LayerType &layerType );

protected:

//! The provider key

0 comments on commit 31b5117

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