ThemeFilterProxyModel: Fix filter function containing a path with no return value
authorWuzzy <Wuzzy2@mail.ru>
Tue, 27 Mar 2018 04:39:31 +0200
changeset 13283 f816b9e73fcb
parent 13282 b13071610c07
child 13284 b504131f7405
ThemeFilterProxyModel: Fix filter function containing a path with no return value
QTfrontend/model/ThemeFilterProxyModel.cpp
QTfrontend/ui/widget/themeprompt.cpp
QTfrontend/ui/widget/themeprompt.h
--- a/QTfrontend/model/ThemeFilterProxyModel.cpp	Mon Mar 26 15:12:33 2018 +0200
+++ b/QTfrontend/model/ThemeFilterProxyModel.cpp	Tue Mar 27 04:39:31 2018 +0200
@@ -33,29 +33,28 @@
 
 bool ThemeFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
 {
+    QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
+    bool searchOkay = true;
+    if(!filterRegExp().isEmpty())
+    {
+        // Check regular expression set by the theme chooser search
+        QString name = index.data(ThemeModel::ActualNameRole).toString();
+        int in = filterRegExp().indexIn(name);
+        searchOkay = in != -1;
+    }
+
     if(isFilteringDLC || isFilteringHidden)
     {
-        QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
         bool isDLC = index.data(ThemeModel::IsDlcRole).toBool();
         bool isHidden = index.data(ThemeModel::IsHiddenRole).toBool();
-        if(
-            ((isFilteringDLC && !isDLC) || !isFilteringDLC) &&
-            ((isFilteringHidden && !isHidden) || !isFilteringHidden))
-        {
-            if(!filterRegExp().isEmpty())
-            {
-                // Also check regular expression set by the theme chooser search
-                QString name = index.data(ThemeModel::ActualNameRole).toString();
-                int index = filterRegExp().indexIn(name);
-                return index != -1;
-            }
-            else
-                return true;
-        }
+
+        return ( ((isFilteringDLC && !isDLC) || !isFilteringDLC) &&
+                 ((isFilteringHidden && !isHidden) || !isFilteringHidden) ) &&
+               searchOkay;
     }
     else
     {
-        return true;
+        return searchOkay;
     }
 }
 
--- a/QTfrontend/ui/widget/themeprompt.cpp	Mon Mar 26 15:12:33 2018 +0200
+++ b/QTfrontend/ui/widget/themeprompt.cpp	Tue Mar 27 04:39:31 2018 +0200
@@ -121,7 +121,7 @@
 
     // Cancel button (closes dialog)
     QPushButton * btnCancel = new QPushButton(tr("Cancel"));
-    connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
+    connect(btnCancel, SIGNAL(clicked()), this, SLOT(onRejected()));
 
     // Select button
     QPushButton * btnSelect = new QPushButton(tr("Use selected theme"));
@@ -170,9 +170,16 @@
     list->moveRight();
 }
 
+void ThemePrompt::onRejected()
+{
+    reject();
+    filterModel->setFilterFixedString(QString());
+}
+
 void ThemePrompt::onAccepted()
 {
     themeChosen(list->currentIndex());
+    filterModel->setFilterFixedString(QString());
 }
 
 // When a theme is selected
--- a/QTfrontend/ui/widget/themeprompt.h	Mon Mar 26 15:12:33 2018 +0200
+++ b/QTfrontend/ui/widget/themeprompt.h	Tue Mar 27 04:39:31 2018 +0200
@@ -54,6 +54,7 @@
 
     private slots:
         void onAccepted();
+        void onRejected();
         void themeChosen(const QModelIndex & index);
         void filterChanged(const QString & text);
         void moveUp();