Skip to content

Commit

Permalink
Store match flagswq
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Mar 11, 2024
1 parent 4427d27 commit cc05812
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/gui/editorwidgets/qgsvaluerelationconfigdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ QVariantMap QgsValueRelationConfigDlg::config()
cfg.insert( QStringLiteral( "OrderByValue" ), mOrderByValue->isChecked() );
cfg.insert( QStringLiteral( "FilterExpression" ), mFilterExpression->toPlainText() );
cfg.insert( QStringLiteral( "UseCompleter" ), mUseCompleter->isChecked() );
cfg.insert( QStringLiteral( "CompleterMatchFromStart" ), mCompleterMatchFromStart->isChecked() );
const Qt::MatchFlags completerMatchFlags { mCompleterMatchFromStart->isChecked() ? Qt::MatchFlag::MatchStartsWith : Qt::MatchFlag::MatchContains };
cfg.insert( QStringLiteral( "CompleterMatchFlags" ), static_cast<int>( completerMatchFlags ) );

return cfg;
}
Expand All @@ -108,8 +109,9 @@ void QgsValueRelationConfigDlg::setConfig( const QVariantMap &config )
mOrderByValue->setChecked( config.value( QStringLiteral( "OrderByValue" ) ).toBool() );
mFilterExpression->setPlainText( config.value( QStringLiteral( "FilterExpression" ) ).toString() );
mUseCompleter->setChecked( config.value( QStringLiteral( "UseCompleter" ) ).toBool() );
// Default is true for backwards compatibility
mCompleterMatchFromStart->setChecked( config.value( QStringLiteral( "CompleterMatchFromStart" ), true ).toBool() );
// Default is MatchStartsWith for backwards compatibility
const Qt::MatchFlags completerMatchFlags { config.contains( QStringLiteral( "CompleterMatchFlags" ) ) ? static_cast<Qt::MatchFlags>( config.value( QStringLiteral( "CompleterMatchFlags" ), Qt::MatchFlag::MatchStartsWith ).toInt( ) ) : Qt::MatchFlag::MatchStartsWith };
mCompleterMatchFromStart->setChecked( completerMatchFlags.testFlag( Qt::MatchFlag::MatchStartsWith ) );
}

void QgsValueRelationConfigDlg::layerChanged()
Expand Down
11 changes: 6 additions & 5 deletions src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,16 @@ void QgsValueRelationWidgetWrapper::populate()
}
QStringListModel *m = new QStringListModel( values, mLineEdit );
QCompleter *completer = new QCompleter( m, mLineEdit );
if ( config().value( QStringLiteral( "CompleterMatchFromStart" ), true ).toBool() )
{
// This is the default, but better explicit than implicit
completer->setFilterMode( Qt::MatchFlag::MatchStartsWith );

const Qt::MatchFlags completerMatchFlags { config().contains( QStringLiteral( "CompleterMatchFlags" ) ) ? static_cast<Qt::MatchFlags>( config().value( QStringLiteral( "CompleterMatchFlags" ), Qt::MatchFlag::MatchStartsWith ).toInt( ) ) : Qt::MatchFlag::MatchStartsWith };

if ( completerMatchFlags.testFlag( Qt::MatchFlag::MatchContains ) )
{
completer->setFilterMode( Qt::MatchFlag::MatchContains );
}
else
{
completer->setFilterMode( Qt::MatchFlag::MatchContains );
completer->setFilterMode( Qt::MatchFlag::MatchStartsWith );
}
completer->setCaseSensitivity( Qt::CaseInsensitive );
mLineEdit->setCompleter( completer );
Expand Down

0 comments on commit cc05812

Please sign in to comment.