Skip to content

Commit

Permalink
[processing] Improve summary text for multi enum/field widgets
Browse files Browse the repository at this point in the history
Instead of just saying "n Options Selected", we now explicitly
list the selected options/fields in the main widget. (Unless
there's a large number of selected options, in which case
we fallback to the 'n Options Selected' string)
  • Loading branch information
nyalldawson committed Jan 18, 2022
1 parent d00356a commit 5e53eef
Showing 1 changed file with 57 additions and 5 deletions.
62 changes: 57 additions & 5 deletions src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
Expand Up @@ -2475,8 +2475,40 @@ void QgsProcessingEnumPanelWidget::showDialog()

void QgsProcessingEnumPanelWidget::updateSummaryText()
{
if ( mParam )
mLineEdit->setText( tr( "%1 options selected" ).arg( mValue.count() ) );
if ( !mParam )
return;

if ( mValue.empty() )
{
mLineEdit->setText( tr( "%1 options selected" ).arg( 0 ) );
}
else
{
QStringList values;
values.reserve( mValue.size() );
if ( mParam->usesStaticStrings() )
{
for ( const QVariant &val : std::as_const( mValue ) )
{
values << val.toString();
}
}
else
{
const QStringList options = mParam->options();
for ( const QVariant &val : std::as_const( mValue ) )
{
const int i = val.toInt();
values << ( options.size() > i ? options.at( i ) : QString() );
}
}

const QString concatenated = values.join( tr( "," ) );
if ( concatenated.length() < 100 )
mLineEdit->setText( concatenated );
else
mLineEdit->setText( tr( "%1 options selected" ).arg( mValue.count() ) );
}
}


Expand Down Expand Up @@ -4058,7 +4090,7 @@ QgsProcessingFieldPanelWidget::QgsProcessingFieldPanelWidget( QWidget *parent, c

if ( mParam )
{
mLineEdit->setText( tr( "%1 options selected" ).arg( 0 ) );
mLineEdit->setText( tr( "%1 fields selected" ).arg( 0 ) );
}

connect( mToolButton, &QToolButton::clicked, this, &QgsProcessingFieldPanelWidget::showDialog );
Expand Down Expand Up @@ -4125,8 +4157,28 @@ void QgsProcessingFieldPanelWidget::showDialog()

void QgsProcessingFieldPanelWidget::updateSummaryText()
{
if ( mParam )
mLineEdit->setText( tr( "%1 options selected" ).arg( mValue.count() ) );
if ( !mParam )
return;

if ( mValue.empty() )
{
mLineEdit->setText( tr( "%1 fields selected" ).arg( 0 ) );
}
else
{
QStringList values;
values.reserve( mValue.size() );
for ( const QVariant &val : std::as_const( mValue ) )
{
values << val.toString();
}

const QString concatenated = values.join( tr( "," ) );
if ( concatenated.length() < 100 )
mLineEdit->setText( concatenated );
else
mLineEdit->setText( tr( "%1 fields selected" ).arg( mValue.count() ) );
}
}


Expand Down

0 comments on commit 5e53eef

Please sign in to comment.