Skip to content

Commit

Permalink
QgsFields: make icon for type static
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Jul 6, 2020
1 parent a0c3f6f commit f89fb2a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions python/core/auto_generated/qgsfields.sip.in
Expand Up @@ -309,6 +309,14 @@ Returns an icon corresponding to a field index, based on the field's type and so
}
%End


static QIcon iconForFieldType( const QVariant::Type &type ) /Factory/;
%Docstring
Returns an icon corresponding to a field ``type``

.. versionadded:: 3.16
%End

operator QVariant() const;


Expand Down
7 changes: 6 additions & 1 deletion src/core/qgsfields.cpp
Expand Up @@ -274,7 +274,12 @@ QgsFields::iterator QgsFields::end()

QIcon QgsFields::iconForField( int fieldIdx ) const
{
switch ( d->fields.at( fieldIdx ).field.type() )
return QgsFields::iconForFieldType( d->fields.at( fieldIdx ).field.type() );
}

QIcon QgsFields::iconForFieldType( const QVariant::Type &type )
{
switch ( type )
{
case QVariant::Bool:
return QgsApplication::getThemeIcon( "/mIconFieldBool.svg" );
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsfields.h
Expand Up @@ -338,6 +338,13 @@ class CORE_EXPORT QgsFields
% End
#endif


/**
* Returns an icon corresponding to a field \a type
* \since QGIS 3.16
*/
static QIcon iconForFieldType( const QVariant::Type &type ) SIP_FACTORY;

//! Allows direct construction of QVariants from fields.
operator QVariant() const
{
Expand Down

0 comments on commit f89fb2a

Please sign in to comment.