Skip to content
Permalink
Browse files
Move QgsLayerItem icon related static methods to new QgsIconUtils class
These utilities are used in a LOT of places in QGIS, but the
qgslayeritem.h include is a very heavy dependency. It makes sense
to have these utilities in a nice lightweight generic class.
  • Loading branch information
nyalldawson committed May 20, 2021
1 parent b5aace6 commit 06844626d147723c7eecb9e4889166a46d852305
Showing with 362 additions and 138 deletions.
  1. +85 −0 python/core/auto_generated/qgsiconutils.sip.in
  2. +1 −0 python/core/core_auto.sip
  3. +2 −3 src/app/qgsalignrasterdialog.cpp
  4. +2 −3 src/app/qgsnewspatialitelayerdialog.cpp
  5. +2 −0 src/core/CMakeLists.txt
  6. +6 −6 src/core/browser/qgsfieldsitem.cpp
  7. +11 −24 src/core/browser/qgslayeritem.cpp
  8. +11 −11 src/core/layertree/qgslayertreemodel.cpp
  9. +0 −1 src/core/providers/gdal/qgsgdalprovider.cpp
  10. +0 −1 src/core/providers/ogr/qgsogrprovider.cpp
  11. +6 −7 src/core/qgsdatabasetablemodel.cpp
  12. +85 −0 src/core/qgsiconutils.cpp
  13. +91 −0 src/core/qgsiconutils.h
  14. +10 −10 src/core/qgsmaplayermodel.cpp
  15. +0 −1 src/core/qgsmimedatautils.cpp
  16. +3 −3 src/gui/ogr/qgsvectorlayersaveasdialog.cpp
  17. +0 −1 src/gui/providers/gdal/qgsgdalguiprovider.cpp
  18. +0 −1 src/gui/providers/ogr/qgsogrdbtablemodel.cpp
  19. +2 −3 src/gui/qgsidentifymenu.cpp
  20. +2 −3 src/gui/qgsnewgeopackagelayerdialog.cpp
  21. +2 −3 src/gui/qgsnewmemorylayerdialog.cpp
  22. +2 −3 src/gui/qgsnewvectorlayerdialog.cpp
  23. +2 −3 src/gui/qgsnewvectortabledialog.cpp
  24. +4 −5 src/gui/qgstextformatwidget.cpp
  25. +4 −5 src/gui/symbology/qgsstylemanagerdialog.cpp
  26. +4 −5 src/gui/symbology/qgssymbollayerwidget.cpp
  27. +4 −5 src/plugins/geometry_checker/qgsgeometrycheckersetuptab.cpp
  28. +0 −1 src/providers/db2/qgsdb2provider.cpp
  29. +3 −3 src/providers/db2/qgsdb2sourceselect.cpp
  30. +3 −4 src/providers/db2/qgsdb2tablemodel.cpp
  31. +0 −1 src/providers/hana/qgshanatablemodel.cpp
  32. +3 −4 src/providers/mssql/qgsmssqlsourceselect.cpp
  33. +3 −4 src/providers/mssql/qgsmssqltablemodel.cpp
  34. +0 −1 src/providers/oracle/qgsoraclesourceselect.cpp
  35. +0 −1 src/providers/oracle/qgsoracletablemodel.cpp
  36. +3 −4 src/providers/postgres/qgspgsourceselect.cpp
  37. +2 −3 src/providers/postgres/qgspgtablemodel.cpp
  38. +4 −5 src/providers/spatialite/qgsspatialitetablemodel.cpp
@@ -0,0 +1,85 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsiconutils.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsIconUtils
{
%Docstring(signature="appended")
Contains utility functions for working with icons.

.. versionadded:: 3.20
%End

%TypeHeaderCode
#include "qgsiconutils.h"
%End
public:

static QIcon iconForWkbType( QgsWkbTypes::Type type );
%Docstring
Returns the icon for a vector layer whose geometry ``type`` is provided.
%End

static QIcon iconPoint();
%Docstring
Returns an icon representing point geometries.
%End

static QIcon iconLine();
%Docstring
Returns an icon representing line geometries.
%End

static QIcon iconPolygon();
%Docstring
Returns an icon representing polygon geometries.
%End

static QIcon iconTable();
%Docstring
Returns an icon representing non-spatial layers (tables).
%End

static QIcon iconRaster();
%Docstring
Returns an icon representing raster layers.
%End

static QIcon iconDefaultLayer();
%Docstring
Returns a default icon for layers, which aren't the standard raster/vector/... types.
%End

static QIcon iconMesh();
%Docstring
Returns an icon representing mesh layers.
%End

static QIcon iconVectorTile();
%Docstring
Returns an icon representing vector tile layers.
%End

static QIcon iconPointCloud();
%Docstring
Returns an icon representing point cloud layers.
%End

};



/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsiconutils.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -75,6 +75,7 @@
%Include auto_generated/qgshistogram.sip
%Include auto_generated/qgshstoreutils.sip
%Include auto_generated/qgshtmlutils.sip
%Include auto_generated/qgsiconutils.sip
%Include auto_generated/qgsidentifycontext.sip
%Include auto_generated/qgsimagecache.sip
%Include auto_generated/qgsinterval.sip
@@ -17,12 +17,11 @@
#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsalignraster.h"
#include "qgsdataitem.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayercombobox.h"
#include "qgsproject.h"
#include "qgsrasterlayer.h"
#include "qgslayeritem.h"
#include "qgsiconutils.h"

#include <QCheckBox>
#include <QFileDialog>
@@ -146,7 +145,7 @@ void QgsAlignRasterDialog::populateLayersView()
{
QString layerName = _rasterLayerName( item.inputFilename );

QStandardItem *si = new QStandardItem( QgsLayerItem::iconRaster(), layerName );
QStandardItem *si = new QStandardItem( QgsIconUtils::iconRaster(), layerName );
model->appendRow( si );

if ( i == refLayerIndex )
@@ -24,7 +24,6 @@
#include "qgsapplication.h"
#include "qgsabstractdatabaseproviderconnection.h"
#include "qgisapp.h" // <- for theme icons
#include "qgsdataitem.h"
#include "qgsvectorlayer.h"
#include "qgsproject.h"
#include "qgscoordinatereferencesystem.h"
@@ -37,7 +36,7 @@
#include "qgslogger.h"
#include "qgssettings.h"
#include "qgsgui.h"
#include "qgslayeritem.h"
#include "qgsiconutils.h"

#include <QPushButton>
#include <QLineEdit>
@@ -54,7 +53,7 @@ QgsNewSpatialiteLayerDialog::QgsNewSpatialiteLayerDialog( QWidget *parent, Qt::W

const auto addGeomItem = [this]( QgsWkbTypes::Type type, const QString & sqlType )
{
mGeometryTypeBox->addItem( QgsLayerItem::iconForWkbType( type ), QgsWkbTypes::translatedDisplayString( type ), sqlType );
mGeometryTypeBox->addItem( QgsIconUtils::iconForWkbType( type ), QgsWkbTypes::translatedDisplayString( type ), sqlType );
};

addGeomItem( QgsWkbTypes::NoGeometry, QString() );
@@ -339,6 +339,7 @@ set(QGIS_CORE_SRCS
qgshistogram.cpp
qgshstoreutils.cpp
qgshtmlutils.cpp
qgsiconutils.cpp
qgsidentifycontext.cpp
qgsimagecache.cpp
qgsinterval.cpp
@@ -951,6 +952,7 @@ set(QGIS_CORE_HDRS
qgshistogram.h
qgshstoreutils.h
qgshtmlutils.h
qgsiconutils.h
qgsidentifycontext.h
qgsimagecache.h
qgsindexedfeature.h
@@ -16,7 +16,7 @@
***************************************************************************/

#include "qgsfieldsitem.h"
#include "qgslayeritem.h"
#include "qgsiconutils.h"
#include "qgsproviderregistry.h"
#include "qgsprovidermetadata.h"
#include "qgslogger.h"
@@ -163,20 +163,20 @@ QIcon QgsFieldItem::icon()
{
if ( mField.typeName() == QLatin1String( "raster" ) )
{
return QgsLayerItem::iconRaster();
return QgsIconUtils::iconRaster();
}
const QgsWkbTypes::GeometryType geomType { QgsWkbTypes::geometryType( parentFields->tableProperty()->geometryColumnTypes().first().wkbType ) };
switch ( geomType )
{
case QgsWkbTypes::GeometryType::LineGeometry:
return QgsLayerItem::iconLine();
return QgsIconUtils::iconLine();
case QgsWkbTypes::GeometryType::PointGeometry:
return QgsLayerItem::iconPoint();
return QgsIconUtils::iconPoint();
case QgsWkbTypes::GeometryType::PolygonGeometry:
return QgsLayerItem::iconPolygon();
return QgsIconUtils::iconPolygon();
case QgsWkbTypes::GeometryType::UnknownGeometry:
case QgsWkbTypes::GeometryType::NullGeometry:
return QgsLayerItem::iconDefault();
return QgsIconUtils::iconDefaultLayer();
}
}
const QIcon icon { QgsFields::iconForFieldType( mField.type() ) };
@@ -19,69 +19,56 @@
#include "qgsapplication.h"
#include "qgsmaplayer.h"
#include "qgsvectorlayer.h"
#include "qgsiconutils.h"

QIcon QgsLayerItem::iconForWkbType( QgsWkbTypes::Type type )
{
QgsWkbTypes::GeometryType geomType = QgsWkbTypes::geometryType( QgsWkbTypes::Type( type ) );
switch ( geomType )
{
case QgsWkbTypes::NullGeometry:
return iconTable();
case QgsWkbTypes::PointGeometry:
return iconPoint();
case QgsWkbTypes::LineGeometry:
return iconLine();
case QgsWkbTypes::PolygonGeometry:
return iconPolygon();
default:
break;
}
return iconDefault();
return QgsIconUtils::iconForWkbType( type );
}

QIcon QgsLayerItem::iconPoint()
{
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPointLayer.svg" ) );
return QgsIconUtils::iconPoint();
}

QIcon QgsLayerItem::iconLine()
{
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconLineLayer.svg" ) );
return QgsIconUtils::iconLine();
}

QIcon QgsLayerItem::iconPolygon()
{
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPolygonLayer.svg" ) );
return QgsIconUtils::iconPolygon();
}

QIcon QgsLayerItem::iconTable()
{
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconTableLayer.svg" ) );
return QgsIconUtils::iconTable();
}

QIcon QgsLayerItem::iconRaster()
{
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconRaster.svg" ) );
return QgsIconUtils::iconRaster();
}

QIcon QgsLayerItem::iconMesh()
{
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconMeshLayer.svg" ) );
return QgsIconUtils::iconMesh();
}

QIcon QgsLayerItem::iconVectorTile()
{
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconVectorTileLayer.svg" ) );
return QgsIconUtils::iconVectorTile();
}

QIcon QgsLayerItem::iconPointCloud()
{
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPointCloudLayer.svg" ) );
return QgsIconUtils::iconPointCloud();
}

QIcon QgsLayerItem::iconDefault()
{
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconLayer.png" ) );
return QgsIconUtils::iconDefaultLayer();
}

QgsLayerItem::QgsLayerItem( QgsDataItem *parent, const QString &name, const QString &path,
@@ -23,7 +23,6 @@
#include "qgslayertreeutils.h"
#include "qgslayertreemodellegendnode.h"
#include "qgsproject.h"
#include "qgsdataitem.h"
#include "qgsmaphittest.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerlegend.h"
@@ -34,7 +33,8 @@
#include "qgssymbollayerutils.h"
#include "qgsvectorlayer.h"
#include "qgslayerdefinition.h"
#include "qgslayeritem.h"
#include "qgsiconutils.h"
#include "qgsmimedatautils.h"

#include <QPalette>

@@ -203,34 +203,34 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
switch ( layer->type() )
{
case QgsMapLayerType::RasterLayer:
icon = QgsLayerItem::iconRaster();
icon = QgsIconUtils::iconRaster();
break;

case QgsMapLayerType::MeshLayer:
icon = QgsLayerItem::iconMesh();
icon = QgsIconUtils::iconMesh();
break;

case QgsMapLayerType::VectorTileLayer:
icon = QgsLayerItem::iconVectorTile();
icon = QgsIconUtils::iconVectorTile();
break;

case QgsMapLayerType::PointCloudLayer:
icon = QgsLayerItem::iconPointCloud();
icon = QgsIconUtils::iconPointCloud();
break;

case QgsMapLayerType::VectorLayer:
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( vlayer->geometryType() == QgsWkbTypes::PointGeometry )
icon = QgsLayerItem::iconPoint();
icon = QgsIconUtils::iconPoint();
else if ( vlayer->geometryType() == QgsWkbTypes::LineGeometry )
icon = QgsLayerItem::iconLine();
icon = QgsIconUtils::iconLine();
else if ( vlayer->geometryType() == QgsWkbTypes::PolygonGeometry )
icon = QgsLayerItem::iconPolygon();
icon = QgsIconUtils::iconPolygon();
else if ( vlayer->geometryType() == QgsWkbTypes::NullGeometry )
icon = QgsLayerItem::iconTable();
icon = QgsIconUtils::iconTable();
else
icon = QgsLayerItem::iconDefault();
icon = QgsIconUtils::iconDefaultLayer();
break;
}

@@ -28,7 +28,6 @@
#include "qgsapplication.h"
#include "qgsauthmanager.h"
#include "qgscoordinatetransform.h"
#include "qgsdataitem.h"
#include "qgsdataitemprovider.h"
#include "qgsdatasourceuri.h"
#include "qgsgdaldataitems.h"
@@ -29,7 +29,6 @@ email : sherman at mrcc.com
#include "qgsapplication.h"
#include "qgsauthmanager.h"
#include "qgscplhttpfetchoverrider.h"
#include "qgsdataitem.h"
#include "qgsdataprovider.h"
#include "qgsfeature.h"
#include "qgsfields.h"
@@ -16,8 +16,7 @@
#include "qgsproviderregistry.h"
#include "qgsprovidermetadata.h"
#include "qgsabstractdatabaseproviderconnection.h"
#include "qgsdataitem.h"
#include "qgslayeritem.h"
#include "qgsiconutils.h"

QgsDatabaseTableModel::QgsDatabaseTableModel( const QString &provider, const QString &connection, const QString &schema, QObject *parent )
: QAbstractItemModel( parent )
@@ -109,7 +108,7 @@ QVariant QgsDatabaseTableModel::data( const QModelIndex &index, int role ) const
if ( table.geometryColumnTypes().empty() )
{
if ( role == Qt::DecorationRole )
return QgsLayerItem::iconTable();
return QgsIconUtils::iconTable();
else
return QVariant();
}
@@ -121,21 +120,21 @@ QVariant QgsDatabaseTableModel::data( const QModelIndex &index, int role ) const
{
case QgsWkbTypes::PointGeometry:
{
return QgsLayerItem::iconPoint();
return QgsIconUtils::iconPoint();
}
case QgsWkbTypes::PolygonGeometry:
{
return QgsLayerItem::iconPolygon();
return QgsIconUtils::iconPolygon();
}
case QgsWkbTypes::LineGeometry:
{
return QgsLayerItem::iconLine();
return QgsIconUtils::iconLine();
}
default:
break;
}

return QgsLayerItem::iconTable();
return QgsIconUtils::iconTable();
}
else if ( role == RoleWkbType )
return table.geometryColumnTypes().at( 0 ).wkbType;

0 comments on commit 0684462

Please sign in to comment.