Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use proper icon for unknown/collection geometry types, instead
of always using polygon icon
  • Loading branch information
nyalldawson committed Jul 22, 2021
1 parent 2fbcf30 commit 9441772
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 19 deletions.
7 changes: 7 additions & 0 deletions python/core/auto_generated/qgsiconutils.sip.in
Expand Up @@ -40,6 +40,13 @@ Returns an icon representing line geometries.
static QIcon iconPolygon();
%Docstring
Returns an icon representing polygon geometries.
%End

static QIcon iconGeometryCollection();
%Docstring
Returns an icon representing geometry collections.

.. versionadded:: 3.22
%End

static QIcon iconTable();
Expand Down
1 change: 1 addition & 0 deletions src/core/browser/qgsfieldsitem.cpp
Expand Up @@ -190,6 +190,7 @@ QIcon QgsFieldItem::icon()
case QgsWkbTypes::GeometryType::PolygonGeometry:
return QgsIconUtils::iconPolygon();
case QgsWkbTypes::GeometryType::UnknownGeometry:
return QgsIconUtils::iconGeometryCollection();
case QgsWkbTypes::GeometryType::NullGeometry:
return QgsIconUtils::iconDefaultLayer();
}
Expand Down
3 changes: 1 addition & 2 deletions src/core/browser/qgslayeritem.cpp
Expand Up @@ -180,9 +180,8 @@ QString QgsLayerItem::iconName( Qgis::BrowserLayerType layerType )
return QStringLiteral( "/mIconLineLayer.svg" );
case Qgis::BrowserLayerType::Polygon:
return QStringLiteral( "/mIconPolygonLayer.svg" );
// TODO add a new icon for generic Vector layers
case Qgis::BrowserLayerType::Vector :
return QStringLiteral( "/mIconVector.svg" );
return QStringLiteral( "/mIconGeometryCollectionLayer.svg" );
case Qgis::BrowserLayerType::TableLayer:
case Qgis::BrowserLayerType::Table:
return QStringLiteral( "/mIconTableLayer.svg" );
Expand Down
28 changes: 18 additions & 10 deletions src/core/layertree/qgslayertreemodel.cpp
Expand Up @@ -222,16 +222,24 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
case QgsMapLayerType::VectorLayer:
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( vlayer->geometryType() == QgsWkbTypes::PointGeometry )
icon = QgsIconUtils::iconPoint();
else if ( vlayer->geometryType() == QgsWkbTypes::LineGeometry )
icon = QgsIconUtils::iconLine();
else if ( vlayer->geometryType() == QgsWkbTypes::PolygonGeometry )
icon = QgsIconUtils::iconPolygon();
else if ( vlayer->geometryType() == QgsWkbTypes::NullGeometry )
icon = QgsIconUtils::iconTable();
else
icon = QgsIconUtils::iconDefaultLayer();
switch ( vlayer->geometryType() )
{
case QgsWkbTypes::PointGeometry:
icon = QgsIconUtils::iconPoint();
break;
case QgsWkbTypes::LineGeometry:
icon = QgsIconUtils::iconLine();
break;
case QgsWkbTypes::PolygonGeometry:
icon = QgsIconUtils::iconPolygon();
break;
case QgsWkbTypes::UnknownGeometry:
icon = QgsIconUtils::iconGeometryCollection();
break;
case QgsWkbTypes::NullGeometry:
icon = QgsIconUtils::iconTable();
break;
}
break;
}

Expand Down
8 changes: 6 additions & 2 deletions src/core/qgsdatabasetablemodel.cpp
Expand Up @@ -131,8 +131,12 @@ QVariant QgsDatabaseTableModel::data( const QModelIndex &index, int role ) const
{
return QgsIconUtils::iconLine();
}
default:
break;
case QgsWkbTypes::UnknownGeometry:
{
return QgsIconUtils::iconGeometryCollection();
}
case QgsWkbTypes::NullGeometry:
return QgsIconUtils::iconTable();
}

return QgsIconUtils::iconTable();
Expand Down
15 changes: 10 additions & 5 deletions src/core/qgsiconutils.cpp
Expand Up @@ -35,8 +35,8 @@ QIcon QgsIconUtils::iconForWkbType( QgsWkbTypes::Type type )
return iconLine();
case QgsWkbTypes::PolygonGeometry:
return iconPolygon();
default:
break;
case QgsWkbTypes::UnknownGeometry:
return iconGeometryCollection();
}
return iconDefaultLayer();
}
Expand All @@ -56,6 +56,11 @@ QIcon QgsIconUtils::iconPolygon()
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconPolygonLayer.svg" ) );
}

QIcon QgsIconUtils::iconGeometryCollection()
{
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconGeometryCollectionLayer.svg" ) );
}

QIcon QgsIconUtils::iconTable()
{
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconTableLayer.svg" ) );
Expand Down Expand Up @@ -126,9 +131,9 @@ QIcon QgsIconUtils::iconForLayer( const QgsMapLayer *layer )
{
return QgsIconUtils::iconTable();
}
default:
case QgsWkbTypes::UnknownGeometry:
{
return QIcon();
return QgsIconUtils::iconGeometryCollection();
}
}
}
Expand All @@ -153,7 +158,7 @@ QIcon QgsIconUtils::iconForLayerType( QgsMapLayerType type )
return QgsIconUtils::iconPointCloud();

case QgsMapLayerType::VectorLayer:
return QgsIconUtils::iconPolygon();
return QgsIconUtils::iconGeometryCollection();

case QgsMapLayerType::PluginLayer:
case QgsMapLayerType::AnnotationLayer:
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsiconutils.h
Expand Up @@ -55,6 +55,13 @@ class CORE_EXPORT QgsIconUtils
*/
static QIcon iconPolygon();

/**
* Returns an icon representing geometry collections.
*
* \since QGIS 3.22
*/
static QIcon iconGeometryCollection();

/**
* Returns an icon representing non-spatial layers (tables).
*/
Expand Down

0 comments on commit 9441772

Please sign in to comment.