Skip to content

Commit

Permalink
UX - Add icon for field types in expression widget (#8195)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Oct 24, 2018
1 parent 302529a commit 01d2fc5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion python/gui/auto_generated/qgsexpressionbuilderwidget.sip.in
Expand Up @@ -198,7 +198,8 @@ preview result and for populating the list of available functions and variables.
void registerItem( const QString &group, const QString &label, const QString &expressionText,
const QString &helpText = QString(),
QgsExpressionItem::ItemType type = QgsExpressionItem::ExpressionNode,
bool highlightedItem = false, int sortOrder = 1 );
bool highlightedItem = false, int sortOrder = 1,
QIcon icon = QIcon() );
%Docstring
Registers a node item for the expression builder.

Expand Down
11 changes: 7 additions & 4 deletions src/gui/qgsexpressionbuilderwidget.cpp
Expand Up @@ -388,6 +388,7 @@ void QgsExpressionBuilderWidget::loadFieldNames()
loadFieldNames( mLayer->fields() );
}


void QgsExpressionBuilderWidget::loadFieldNames( const QgsFields &fields )
{
if ( fields.isEmpty() )
Expand All @@ -396,13 +397,14 @@ void QgsExpressionBuilderWidget::loadFieldNames( const QgsFields &fields )
txtExpressionString->setFields( fields );

QStringList fieldNames;
//Q_FOREACH ( const QgsField& field, fields )
fieldNames.reserve( fields.count() );
for ( int i = 0; i < fields.count(); ++i )
{
QString fieldName = fields.at( i ).name();
QgsField field = fields.at( i );
QString fieldName = field.name();
fieldNames << fieldName;
registerItem( QStringLiteral( "Fields and Values" ), fieldName, " \"" + fieldName + "\" ", QString(), QgsExpressionItem::Field, false, i );
QIcon icon = fields.iconForField( i );
registerItem( QStringLiteral( "Fields and Values" ), fieldName, " \"" + fieldName + "\" ", QString(), QgsExpressionItem::Field, false, i, icon );
}
// highlighter->addFields( fieldNames );
}
Expand Down Expand Up @@ -465,11 +467,12 @@ void QgsExpressionBuilderWidget::registerItem( const QString &group,
const QString &label,
const QString &expressionText,
const QString &helpText,
QgsExpressionItem::ItemType type, bool highlightedItem, int sortOrder )
QgsExpressionItem::ItemType type, bool highlightedItem, int sortOrder, QIcon icon )
{
QgsExpressionItem *item = new QgsExpressionItem( label, expressionText, helpText, type );
item->setData( label, Qt::UserRole );
item->setData( sortOrder, QgsExpressionItem::CUSTOM_SORT_ROLE );
item->setIcon( icon );

// Look up the group and insert the new function.
if ( mExpressionGroups.contains( group ) )
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsexpressionbuilderwidget.h
Expand Up @@ -217,7 +217,8 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
void registerItem( const QString &group, const QString &label, const QString &expressionText,
const QString &helpText = QString(),
QgsExpressionItem::ItemType type = QgsExpressionItem::ExpressionNode,
bool highlightedItem = false, int sortOrder = 1 );
bool highlightedItem = false, int sortOrder = 1,
QIcon icon = QIcon() );

bool isExpressionValid();

Expand Down

0 comments on commit 01d2fc5

Please sign in to comment.