diff options
| author | Felix Ernst <[email protected]> | 2026-04-27 22:25:02 +0200 |
|---|---|---|
| committer | Felix Ernst <[email protected]> | 2026-04-29 01:51:03 +0200 |
| commit | 4a6d048a77d0954c350df5ce9b3657fc69c9ada4 (patch) | |
| tree | 4c5fddcba01eb06134e3346501e8d9092bed6aee | |
| parent | af12f10b7d0fdbc5b737abb226f27077e6f952a7 (diff) | |
Search/Selectors: Prevent unexpectedly removing a chip
One can close a chip by pressing the "X" close button on it. Prior to
this commit, one could also close a chip somewhat unexpectedly by
choosing an option from the Chip's dropdown. This commit removes any
"empty" options from the Chips which would lead to the Chip disappearing.
Example: Choosing "Any Rating" would remove the rating chip because it
would no longer act as a restriction on what the search should find. Now
the "Any Rating" option is not added to the Chip in the first place.
| -rw-r--r-- | src/search/selectors/dateselector.cpp | 7 | ||||
| -rw-r--r-- | src/search/selectors/filetypeselector.cpp | 5 | ||||
| -rw-r--r-- | src/search/selectors/minimumratingselector.cpp | 5 | ||||
| -rw-r--r-- | src/search/selectors/tagsselector.cpp | 12 |
4 files changed, 26 insertions, 3 deletions
diff --git a/src/search/selectors/dateselector.cpp b/src/search/selectors/dateselector.cpp index 70e563614..a7f4463e5 100644 --- a/src/search/selectors/dateselector.cpp +++ b/src/search/selectors/dateselector.cpp @@ -6,6 +6,7 @@ #include "dateselector.h" +#include "../chip.h" #include "../dolphinquery.h" #include <KDatePicker> @@ -19,7 +20,11 @@ Search::DateSelector::DateSelector(std::shared_ptr<const DolphinQuery> dolphinQu : QToolButton{parent} , UpdatableStateInterface{dolphinQuery} , m_datePickerPopup{ - new KDatePickerPopup{KDatePickerPopup::NoDate | KDatePickerPopup::DatePicker | KDatePickerPopup::Words, dolphinQuery->modifiedSinceDate(), this}} + new KDatePickerPopup{/* When in a Chip, we don't add the KDatePickerPopup::NoDate option because it would allow removing the Chip unexpectedly. */ + qobject_cast<ChipBase *>(parent) ? KDatePickerPopup::DatePicker | KDatePickerPopup::Words + : KDatePickerPopup::NoDate | KDatePickerPopup::DatePicker | KDatePickerPopup::Words, + dolphinQuery->modifiedSinceDate(), + this}} { setToolButtonStyle(Qt::ToolButtonTextBesideIcon); setPopupMode(QToolButton::InstantPopup); diff --git a/src/search/selectors/filetypeselector.cpp b/src/search/selectors/filetypeselector.cpp index acf5680e2..6c5bbc5d7 100644 --- a/src/search/selectors/filetypeselector.cpp +++ b/src/search/selectors/filetypeselector.cpp @@ -6,6 +6,7 @@ #include "filetypeselector.h" +#include "../chip.h" #include "../dolphinquery.h" #include <KFileMetaData/TypeInfo> @@ -20,7 +21,9 @@ FileTypeSelector::FileTypeSelector(std::shared_ptr<const DolphinQuery> dolphinQu for (KFileMetaData::Type::Type type = KFileMetaData::Type::FirstType; type <= KFileMetaData::Type::LastType; type = KFileMetaData::Type::Type(type + 1)) { switch (type) { case KFileMetaData::Type::Empty: - addItem(/** No icon for the empty state */ i18nc("@item:inlistbox", "Any Type"), type); + if (!qobject_cast<ChipBase *>(parent)) { // When in a Chip, we don't add the "Any Type" option because it would unexpectedly remove the Chip. + addItem(/* No icon for the empty state */ i18nc("@item:inlistbox", "Any Type"), type); + } continue; case KFileMetaData::Type::Archive: addItem(QIcon::fromTheme(QStringLiteral("package-x-generic")), KFileMetaData::TypeInfo{type}.displayName(), type); diff --git a/src/search/selectors/minimumratingselector.cpp b/src/search/selectors/minimumratingselector.cpp index 386f525db..b41561f6a 100644 --- a/src/search/selectors/minimumratingselector.cpp +++ b/src/search/selectors/minimumratingselector.cpp @@ -7,6 +7,7 @@ #include "minimumratingselector.h" +#include "../chip.h" #include "../dolphinquery.h" #include <KLocalizedString> @@ -17,7 +18,9 @@ MinimumRatingSelector::MinimumRatingSelector(std::shared_ptr<const DolphinQuery> : QComboBox{parent} , UpdatableStateInterface{dolphinQuery} { - addItem(/** No icon for the empty state */ i18nc("@item:inlistbox", "Any Rating"), 0); + if (!qobject_cast<ChipBase *>(parent)) { // When in a Chip, we don't add the "Any Rating" option because it would unexpectedly remove the Chip. + addItem(/* No icon for the empty state */ i18nc("@item:inlistbox", "Any Rating"), 0); + } addItem(QIcon::fromTheme(QStringLiteral("starred-symbolic")), i18nc("@item:inlistbox", "1 or more"), 2); addItem(QIcon::fromTheme(QStringLiteral("starred-symbolic")), i18nc("@item:inlistbox", "2 or more"), 4); addItem(QIcon::fromTheme(QStringLiteral("starred-symbolic")), i18nc("@item:inlistbox", "3 or more"), 6); diff --git a/src/search/selectors/tagsselector.cpp b/src/search/selectors/tagsselector.cpp index 6ad74af91..57ce02e2f 100644 --- a/src/search/selectors/tagsselector.cpp +++ b/src/search/selectors/tagsselector.cpp @@ -7,6 +7,7 @@ #include "tagsselector.h" +#include "../chip.h" #include "../dolphinquery.h" #include <KCoreDirLister> @@ -146,6 +147,9 @@ void TagsSelector::updateMenu(const std::shared_ptr<const DolphinQuery> &dolphin QAction *tagAction = new QAction{QIcon::fromTheme(QStringLiteral("tag")), tag, menu()}; tagAction->setCheckable(true); tagAction->setChecked(dolphinQuery->requiredTags().contains(tag)); + tagAction->setEnabled(/* When in a Chip, at least one tags needs to stay checked or the Chip will unexepectedly remove itself. */ + !tagAction->isChecked() || dolphinQuery->requiredTags().size() != 1 || !qobject_cast<ChipBase *>(parent())); + connect(tagAction, &QAction::triggered, this, [this, tag, onlyOneTagExists](bool checked) { QStringList requiredTags = m_searchConfiguration->requiredTags(); if (checked == requiredTags.contains(tag)) { @@ -160,11 +164,19 @@ void TagsSelector::updateMenu(const std::shared_ptr<const DolphinQuery> &dolphin searchConfigurationCopy.setRequiredTags(requiredTags); Q_EMIT configurationChanged(searchConfigurationCopy); + if (qobject_cast<ChipBase *>(parent())) { + auto tagActions = menu()->actions(); + for (auto tagAction : tagActions) { + tagAction->setEnabled(/* When in a Chip, at least one tags needs to stay checked or the Chip will unexepectedly remove itself. */ + !tagAction->isChecked() || searchConfigurationCopy.requiredTags().size() != 1); + } + } if (!onlyOneTagExists) { // Keep the menu open to allow easier tag multi-selection. menu()->show(); } }); + menu()->addAction(tagAction); } if (menuWasVisible) { |
