]> cloud.milkyroute.net Git - dolphin.git/commitdiff
[dolphin/search] Reset search options when needed
authorIsmael Asensio <isma.af@mgmail.com>
Sun, 20 Oct 2019 09:51:59 +0000 (11:51 +0200)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Sun, 20 Oct 2019 09:51:59 +0000 (11:51 +0200)
Summary:
Adds a method to reset the options in `facetsWidget` in two cases: when disabled and before parsing a new search URL.
Otherwise, controls for a parameter (ex. `rating`) which are not found in the new URL would stay on the old positions, instead of the default "any".
See D24422

Test Plan: Controls on `facetsWidget` go back to the default in such two cases.

Reviewers: #dolphin, elvisangelaccio, meven, ngraham

Reviewed By: ngraham

Subscribers: kfm-devel

Tags: #dolphin

Differential Revision: https://phabricator.kde.org/D24450

src/search/dolphinfacetswidget.cpp
src/search/dolphinfacetswidget.h
src/search/dolphinsearchbox.cpp

index 35f0c67c1d457876278a446e0abd2a063d3308e7..08fe567b1cdefd425f577f46b55b0d8409824150 100644 (file)
@@ -24,6 +24,7 @@
 #include <QButtonGroup>
 #include <QCheckBox>
 #include <QDate>
+#include <QEvent>
 #include <QHBoxLayout>
 #include <QRadioButton>
 
@@ -106,15 +107,27 @@ DolphinFacetsWidget::DolphinFacetsWidget(QWidget* parent) :
     topLayout->addLayout(ratingLayout);
     topLayout->addStretch();
 
-    m_anyType->setChecked(true);
-    m_anytime->setChecked(true);
-    m_anyRating->setChecked(true);
+    resetOptions();
 }
 
 DolphinFacetsWidget::~DolphinFacetsWidget()
 {
 }
 
+void DolphinFacetsWidget::changeEvent(QEvent *event)
+{
+    if (event->type() == QEvent::EnabledChange && !isEnabled()) {
+        resetOptions();
+    }
+}
+
+void DolphinFacetsWidget::resetOptions()
+{
+    m_anyType->setChecked(true);
+    m_anytime->setChecked(true);
+    m_anyRating->setChecked(true);
+}
+
 QString DolphinFacetsWidget::ratingTerm() const
 {
     QStringList terms;
index 1e8ab6cea745affe57cf1c8ccc6b3dce503ecc76..9d875f0aeaaa5dee6cc3345a84453e4335a8bf14 100644 (file)
@@ -24,6 +24,7 @@
 
 class QButtonGroup;
 class QDate;
+class QEvent;
 class QRadioButton;
 
 /**
@@ -50,6 +51,8 @@ public:
     explicit DolphinFacetsWidget(QWidget* parent = nullptr);
     ~DolphinFacetsWidget() override;
 
+    void resetOptions();
+
     QString ratingTerm() const;
     QString facetType() const;
 
@@ -61,6 +64,9 @@ public:
 signals:
     void facetChanged();
 
+protected:
+    void changeEvent(QEvent* event) override;
+
 private:
     void setRating(const int stars);
     void setTimespan(const QDate& date);
index 5bcd6be6a8c57be81ff1c153ba17ac147fde197d..1b791c60aad1c671be93440454a72ea40b3a3e1d 100644 (file)
@@ -526,6 +526,8 @@ void DolphinSearchBox::fromBalooSearchUrl(const QUrl& url)
         setSearchPath(QUrl::fromLocalFile(QDir::homePath()));
     }
 
+    m_facetsWidget->resetOptions();
+
     setText(query.searchString());
 
     QStringList types = query.types();