Add option to keep selection when FilterComboBox entry doesn't exist

This commit is contained in:
WarmUpTill 2025-05-21 14:53:12 +02:00 committed by WarmUpTill
parent a84731b8fe
commit c43439ee64
2 changed files with 8 additions and 1 deletions

View File

@ -62,6 +62,11 @@ void FilterComboBox::SetFilterBehaviourEnabled(bool value)
FilterComboBox::_filteringEnabled = value;
}
void FilterComboBox::SetAllowUnmatchedSelection(bool allow)
{
_allowUnmatchedSelection = allow;
}
void FilterComboBox::setCurrentText(const QString &text)
{
if (_filteringEnabled) {
@ -82,7 +87,7 @@ void FilterComboBox::setItemText(int index, const QString &text)
void FilterComboBox::focusOutEvent(QFocusEvent *event)
{
// Reset on invalid selection
if (findText(currentText()) == -1) {
if (!_allowUnmatchedSelection && findText(currentText()) == -1) {
setCurrentIndex(-1);
Emit(-1, "");
}

View File

@ -13,6 +13,7 @@ public:
FilterComboBox(QWidget *parent = nullptr,
const QString &placehodler = "");
static void SetFilterBehaviourEnabled(bool);
void SetAllowUnmatchedSelection(bool allow);
void setCurrentText(const QString &text);
void setItemText(int index, const QString &text);
@ -27,6 +28,7 @@ private slots:
private:
void Emit(int index, const QString &text);
bool _allowUnmatchedSelection = false;
int _lastEmittedIndex = -1;
QString _lastEmittedText;