Skip to content
Permalink
Browse files
Also move QgsMapLayerModel::iconForLayer to QgsIconUtils
  • Loading branch information
nyalldawson committed May 20, 2021
1 parent 0684462 commit 9dda143cc92750903e5d9eba03474c7b3302617d
@@ -70,6 +70,11 @@ Returns an icon representing vector tile layers.
static QIcon iconPointCloud();
%Docstring
Returns an icon representing point cloud layers.
%End

static QIcon iconForLayer( const QgsMapLayer *layer );
%Docstring
Returns the icon corresponding to a specified map ``layer``.
%End

};
@@ -33,7 +33,6 @@
#include "qgslayertree.h"
#include "qgsfeedback.h"
#include "qgisapp.h"
#include "qgsmaplayermodel.h"
#include "qgsmessagebar.h"
#include "qgsmessagebaritem.h"
#include "qgslayoutmanager.h"
@@ -44,7 +43,7 @@
#include "qgssettings.h"
#include "qgsunittypes.h"
#include "qgslocatorwidget.h"

#include "qgsiconutils.h"

QgsLayerTreeLocatorFilter::QgsLayerTreeLocatorFilter( QObject *parent )
: QgsLocatorFilter( parent )
@@ -68,7 +67,7 @@ void QgsLayerTreeLocatorFilter::fetchResults( const QString &string, const QgsLo
QgsLocatorResult result;
result.displayString = layer->layer()->name();
result.userData = layer->layerId();
result.icon = QgsMapLayerModel::iconForLayer( layer->layer() );
result.icon = QgsIconUtils::iconForLayer( layer->layer() );

// return all the layers in case the string query is empty using an equal default score
if ( context.usingPrefix && string.isEmpty() )
@@ -363,7 +362,7 @@ QStringList QgsActiveLayerFeaturesLocatorFilter::prepare( const QString &string,
mFieldIterator = layer->getFeatures( req );

mLayerId = layer->id();
mLayerIcon = QgsMapLayerModel::iconForLayer( layer );
mLayerIcon = QgsIconUtils::iconForLayer( layer );
mAttributeAliases.clear();
for ( int idx = 0; idx < layer->fields().size(); ++idx )
{
@@ -584,7 +583,7 @@ QStringList QgsAllLayersFeaturesLocatorFilter::prepare( const QString &string, c
preparedLayer->featureSource.reset( new QgsVectorLayerFeatureSource( layer ) );
preparedLayer->request = req;
preparedLayer->exactMatchRequest = exactMatchRequest;
preparedLayer->layerIcon = QgsMapLayerModel::iconForLayer( layer );
preparedLayer->layerIcon = QgsIconUtils::iconForLayer( layer );

mPreparedLayers.append( preparedLayer );
}
@@ -17,6 +17,9 @@

#include "qgsiconutils.h"
#include "qgsapplication.h"
#include "qgsmaplayer.h"
#include "qgsvectorlayer.h"

#include <QIcon>

QIcon QgsIconUtils::iconForWkbType( QgsWkbTypes::Type type )
@@ -83,3 +86,67 @@ QIcon QgsIconUtils::iconDefaultLayer()
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconLayer.png" ) );
}

QIcon QgsIconUtils::iconForLayer( const QgsMapLayer *layer )
{
switch ( layer->type() )
{
case QgsMapLayerType::RasterLayer:
{
return QgsIconUtils::iconRaster();
}

case QgsMapLayerType::MeshLayer:
{
return QgsIconUtils::iconMesh();
}

case QgsMapLayerType::VectorTileLayer:
{
return QgsIconUtils::iconVectorTile();
}

case QgsMapLayerType::PointCloudLayer:
{
return QgsIconUtils::iconPointCloud();
}

case QgsMapLayerType::VectorLayer:
{
const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer );
if ( !vl )
{
return QIcon();
}
const QgsWkbTypes::GeometryType geomType = vl->geometryType();
switch ( geomType )
{
case QgsWkbTypes::PointGeometry:
{
return QgsIconUtils::iconPoint();
}
case QgsWkbTypes::PolygonGeometry :
{
return QgsIconUtils::iconPolygon();
}
case QgsWkbTypes::LineGeometry :
{
return QgsIconUtils::iconLine();
}
case QgsWkbTypes::NullGeometry :
{
return QgsIconUtils::iconTable();
}
default:
{
return QIcon();
}
}
}

default:
{
return QIcon();
}
}
}

@@ -22,6 +22,7 @@
#include "qgis.h"
#include "qgswkbtypes.h"

class QgsMapLayer;
class QIcon;

/**
@@ -84,6 +85,11 @@ class CORE_EXPORT QgsIconUtils
*/
static QIcon iconPointCloud();

/**
* Returns the icon corresponding to a specified map \a layer.
*/
static QIcon iconForLayer( const QgsMapLayer *layer );

};

#endif // QGSICONUTILS_H
@@ -516,69 +516,9 @@ Qt::DropActions QgsMapLayerModel::supportedDropActions() const

QIcon QgsMapLayerModel::iconForLayer( QgsMapLayer *layer )
{
switch ( layer->type() )
{
case QgsMapLayerType::RasterLayer:
{
return QgsIconUtils::iconRaster();
}

case QgsMapLayerType::MeshLayer:
{
return QgsIconUtils::iconMesh();
}

case QgsMapLayerType::VectorTileLayer:
{
return QgsIconUtils::iconVectorTile();
}

case QgsMapLayerType::PointCloudLayer:
{
return QgsIconUtils::iconPointCloud();
}

case QgsMapLayerType::VectorLayer:
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
if ( !vl )
{
return QIcon();
}
QgsWkbTypes::GeometryType geomType = vl->geometryType();
switch ( geomType )
{
case QgsWkbTypes::PointGeometry:
{
return QgsIconUtils::iconPoint();
}
case QgsWkbTypes::PolygonGeometry :
{
return QgsIconUtils::iconPolygon();
}
case QgsWkbTypes::LineGeometry :
{
return QgsIconUtils::iconLine();
}
case QgsWkbTypes::NullGeometry :
{
return QgsIconUtils::iconTable();
}
default:
{
return QIcon();
}
}
}

default:
{
return QIcon();
}
}
return QgsIconUtils::iconForLayer( layer );
}


bool QgsMapLayerModel::setData( const QModelIndex &index, const QVariant &value, int role )
{
if ( !index.isValid() )
@@ -25,7 +25,7 @@
#include "qgssettings.h"
#include "qgsrelationmanager.h"
#include "qgsapplication.h"
#include "qgsmaplayermodel.h"
#include "qgsiconutils.h"


//! Returns a HTML formatted string for use as a \a relation item help.
@@ -413,7 +413,7 @@ void QgsExpressionTreeView::loadLayers()
QMap<QString, QgsMapLayer *>::const_iterator layerIt = layers.constBegin();
for ( ; layerIt != layers.constEnd(); ++layerIt )
{
QIcon icon = QgsMapLayerModel::iconForLayer( layerIt.value() );
QIcon icon = QgsIconUtils::iconForLayer( layerIt.value() );
registerItem( QStringLiteral( "Map Layers" ), layerIt.value()->name(), QStringLiteral( "'%1'" ).arg( layerIt.key() ), formatLayerHelp( layerIt.value() ), QgsExpressionItem::ExpressionNode, false, 99, icon );
}
}

0 comments on commit 9dda143

Please sign in to comment.