Skip to content

Commit

Permalink
[gui] Show field types as icons in data defined field submenu, instead
Browse files Browse the repository at this point in the history
of appending the type as a text string

It's easier to quickly identify types via the icons vs text.
Also show field aliases if present.
  • Loading branch information
nyalldawson committed Jun 3, 2021
1 parent c57d7ad commit 191e9f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/gui/qgspropertyoverridebutton.cpp
Expand Up @@ -152,12 +152,14 @@ void QgsPropertyOverrideButton::init( int propertyKey, const QgsAbstractProperty
void QgsPropertyOverrideButton::updateFieldLists()
{
mFieldNameList.clear();
mFieldTypeList.clear();
mFieldDisplayNameList.clear();
mFieldIcons.clear();

if ( mVectorLayer )
{
// store just a list of fields of unknown type or those that match the expected type
const QgsFields fields = mVectorLayer->fields();
int idx = 0;
for ( const QgsField &f : fields )
{
bool fieldMatch = false;
Expand Down Expand Up @@ -201,8 +203,10 @@ void QgsPropertyOverrideButton::updateFieldLists()
if ( fieldMatch )
{
mFieldNameList << f.name();
mFieldTypeList << fieldType;
mFieldDisplayNameList << f.displayNameWithAlias();
mFieldIcons << fields.iconForField( idx, true );
}
idx++;
}
}
}
Expand Down Expand Up @@ -395,7 +399,8 @@ void QgsPropertyOverrideButton::aboutToShowMenu()
for ( int j = 0; j < mFieldNameList.count(); ++j )
{
QString fldname = mFieldNameList.at( j );
QAction *act = mFieldsMenu->addAction( fldname + " (" + mFieldTypeList.at( j ) + ')' );
QAction *act = mFieldsMenu->addAction( mFieldDisplayNameList.at( j ) );
act->setIcon( mFieldIcons.at( j ) );
act->setData( QVariant( fldname ) );
if ( mFieldName == fldname )
{
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgspropertyoverridebutton.h
Expand Up @@ -273,7 +273,8 @@ class GUI_EXPORT QgsPropertyOverrideButton: public QToolButton
const QgsVectorLayer *mVectorLayer = nullptr;

QStringList mFieldNameList;
QStringList mFieldTypeList;
QStringList mFieldDisplayNameList;
QList< QIcon > mFieldIcons;

QString mExpressionString;
QString mFieldName;
Expand Down

0 comments on commit 191e9f9

Please sign in to comment.