Skip to content
Permalink
Browse files
[gui] Show field types as icons in data defined field submenu, instead
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 191e9f9b5b924a6e17e5700a62b790fdc4029848
Showing with 10 additions and 4 deletions.
  1. +8 −3 src/gui/qgspropertyoverridebutton.cpp
  2. +2 −1 src/gui/qgspropertyoverridebutton.h
@@ -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;
@@ -201,8 +203,10 @@ void QgsPropertyOverrideButton::updateFieldLists()
if ( fieldMatch )
{
mFieldNameList << f.name();
mFieldTypeList << fieldType;
mFieldDisplayNameList << f.displayNameWithAlias();
mFieldIcons << fields.iconForField( idx, true );
}
idx++;
}
}
}
@@ -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 )
{
@@ -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;

0 comments on commit 191e9f9

Please sign in to comment.