Skip to content

Commit 31b5117

Browse files
committedSep 7, 2017
Added static QgsLayerItem::iconName(LayerType) for reuse and consistency
1 parent 51abef4 commit 31b5117

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed
 

‎python/core/qgsdataitem.sip

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,14 @@ Returns provider key
414414

415415
static QString layerTypeAsString( const LayerType &layerType );
416416
%Docstring
417-
Returns the string representatio of the given ``layerType``
417+
Returns the string representation of the given ``layerType``
418+
.. versionadded:: 3
419+
:rtype: str
420+
%End
421+
422+
static QString iconName( const LayerType &layerType );
423+
%Docstring
424+
Returns the icon name of the given ``layerType``
418425
.. versionadded:: 3
419426
:rtype: str
420427
%End

‎src/core/qgsdataitem.cpp

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -545,49 +545,55 @@ QgsLayerItem::QgsLayerItem( QgsDataItem *parent, const QString &name, const QStr
545545
, mProviderKey( providerKey )
546546
, mUri( uri )
547547
, mLayerType( layerType )
548+
{
549+
mIconName = iconName( layerType );
550+
}
551+
552+
QgsMapLayer::LayerType QgsLayerItem::mapLayerType() const
553+
{
554+
if ( mLayerType == QgsLayerItem::Raster )
555+
return QgsMapLayer::RasterLayer;
556+
if ( mLayerType == QgsLayerItem::Plugin )
557+
return QgsMapLayer::PluginLayer;
558+
return QgsMapLayer::VectorLayer;
559+
}
560+
561+
QString QgsLayerItem::layerTypeAsString( const QgsLayerItem::LayerType &layerType )
562+
{
563+
static int enumIdx = staticMetaObject.indexOfEnumerator( "LayerType" );
564+
return staticMetaObject.enumerator( enumIdx ).valueToKey( layerType );
565+
}
566+
567+
QString QgsLayerItem::iconName( const QgsLayerItem::LayerType &layerType )
548568
{
549569
switch ( layerType )
550570
{
551571
case Point:
552-
mIconName = QStringLiteral( "/mIconPointLayer.svg" );
572+
return QStringLiteral( "/mIconPointLayer.svg" );
553573
break;
554574
case Line:
555-
mIconName = QStringLiteral( "/mIconLineLayer.svg" );
575+
return QStringLiteral( "/mIconLineLayer.svg" );
556576
break;
557577
case Polygon:
558-
mIconName = QStringLiteral( "/mIconPolygonLayer.svg" );
578+
return QStringLiteral( "/mIconPolygonLayer.svg" );
559579
break;
560580
// TODO add a new icon for generic Vector layers
561581
case Vector :
562-
mIconName = QStringLiteral( "/mIconPolygonLayer.svg" );
582+
return QStringLiteral( "/mIconPolygonLayer.svg" );
563583
break;
564584
case TableLayer:
565-
mIconName = QStringLiteral( "/mIconTableLayer.svg" );
585+
case Table:
586+
return QStringLiteral( "/mIconTableLayer.svg" );
566587
break;
567588
case Raster:
568-
mIconName = QStringLiteral( "/mIconRaster.svg" );
589+
return QStringLiteral( "/mIconRaster.svg" );
569590
break;
570591
default:
571-
mIconName = QStringLiteral( "/mIconLayer.png" );
592+
return QStringLiteral( "/mIconLayer.png" );
572593
break;
573594
}
574595
}
575596

576-
QgsMapLayer::LayerType QgsLayerItem::mapLayerType() const
577-
{
578-
if ( mLayerType == QgsLayerItem::Raster )
579-
return QgsMapLayer::RasterLayer;
580-
if ( mLayerType == QgsLayerItem::Plugin )
581-
return QgsMapLayer::PluginLayer;
582-
return QgsMapLayer::VectorLayer;
583-
}
584-
585-
QString QgsLayerItem::layerTypeAsString( const QgsLayerItem::LayerType &layerType )
586-
{
587-
static int enumIdx = staticMetaObject.indexOfEnumerator( "LayerType" );
588-
return staticMetaObject.enumerator( enumIdx ).valueToKey( layerType );
589-
}
590-
591597
bool QgsLayerItem::equal( const QgsDataItem *other )
592598
{
593599
//QgsDebugMsg ( mPath + " x " + other->mPath );

‎src/core/qgsdataitem.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,16 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem
384384
*/
385385
virtual QString comments() const { return QString(); }
386386

387-
/** Returns the string representatio of the given \a layerType
387+
/** Returns the string representation of the given \a layerType
388388
* \since QGIS 3
389389
*/
390390
static QString layerTypeAsString( const LayerType &layerType );
391391

392+
/** Returns the icon name of the given \a layerType
393+
* \since QGIS 3
394+
*/
395+
static QString iconName( const LayerType &layerType );
396+
392397
protected:
393398

394399
//! The provider key

0 commit comments

Comments
 (0)
Please sign in to comment.