From c43439ee6474077579e5e323292b418f6ded6ca9 Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Wed, 21 May 2025 14:53:12 +0200 Subject: [PATCH] Add option to keep selection when FilterComboBox entry doesn't exist --- lib/utils/filter-combo-box.cpp | 7 ++++++- lib/utils/filter-combo-box.hpp | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/utils/filter-combo-box.cpp b/lib/utils/filter-combo-box.cpp index 7a2306f1..491de79f 100644 --- a/lib/utils/filter-combo-box.cpp +++ b/lib/utils/filter-combo-box.cpp @@ -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, ""); } diff --git a/lib/utils/filter-combo-box.hpp b/lib/utils/filter-combo-box.hpp index 051e963a..b506febf 100644 --- a/lib/utils/filter-combo-box.hpp +++ b/lib/utils/filter-combo-box.hpp @@ -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;