From ca8cd6b806b2c651fa6c941776cd5e587b531f08 Mon Sep 17 00:00:00 2001
From: thohartm <Thomas.Hartmann@nokia.com>
Date: Tue, 22 May 2012 16:52:43 +0200
Subject: [PATCH] WelcomePage: add delay to filter

Setting the filter is now delayed to allow proper typing.

Change-Id: I9faa2b9810766b2a51bf02d4a14222a9f0a81693
Reviewed-by: Alessandro Portale <alessandro.portale@nokia.com>
---
 src/plugins/qtsupport/exampleslistmodel.cpp | 21 +++++++++++++++++++--
 src/plugins/qtsupport/exampleslistmodel.h   |  8 +++++++-
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/plugins/qtsupport/exampleslistmodel.cpp b/src/plugins/qtsupport/exampleslistmodel.cpp
index 3b425c6b305..5a569010e58 100644
--- a/src/plugins/qtsupport/exampleslistmodel.cpp
+++ b/src/plugins/qtsupport/exampleslistmodel.cpp
@@ -476,7 +476,7 @@ void ExamplesListModel::ensureInitialized() const
 }
 
 ExamplesListModelFilter::ExamplesListModelFilter(ExamplesListModel *sourceModel, QObject *parent) :
-    QSortFilterProxyModel(parent), m_showTutorialsOnly(true), m_sourceModel(sourceModel)
+    QSortFilterProxyModel(parent), m_showTutorialsOnly(true), m_sourceModel(sourceModel), m_timerId(0)
 {
     connect(this, SIGNAL(showTutorialsOnlyChanged()), SLOT(updateFilter()));
     setSourceModel(m_sourceModel);
@@ -570,6 +570,23 @@ void ExamplesListModelFilter::setShowTutorialsOnly(bool showTutorialsOnly)
     emit showTutorialsOnlyChanged();
 }
 
+void ExamplesListModelFilter::delayedUpdateFilter()
+{
+    if (m_timerId != 0)
+        killTimer(m_timerId);
+
+    m_timerId = startTimer(320);
+}
+
+void ExamplesListModelFilter::timerEvent(QTimerEvent *timerEvent)
+{
+    if (m_timerId == timerEvent->timerId()) {
+        updateFilter();
+        killTimer(m_timerId);
+        m_timerId = 0;
+    }
+}
+
 struct SearchStringLexer {
     QString code;
     const QChar *codePtr;
@@ -675,7 +692,7 @@ void ExamplesListModelFilter::parseSearchString(const QString &arg)
 
     setSearchStrings(searchTerms);
     setFilterTags(tags);
-    updateFilter();
+    delayedUpdateFilter();
 }
 
 } // namespace Internal
diff --git a/src/plugins/qtsupport/exampleslistmodel.h b/src/plugins/qtsupport/exampleslistmodel.h
index 8068f516dc4..0de6612d1c5 100644
--- a/src/plugins/qtsupport/exampleslistmodel.h
+++ b/src/plugins/qtsupport/exampleslistmodel.h
@@ -141,7 +141,7 @@ public slots:
         if (m_searchString != arg) {
             m_searchString = arg;
             emit searchStrings(arg);
-            updateFilter();
+            delayedUpdateFilter();
         }
     }
 
@@ -155,11 +155,17 @@ signals:
 
     void searchStrings(const QStringList& arg);
 
+protected:
+    void timerEvent(QTimerEvent *event);
+
 private:
+    void delayedUpdateFilter();
+
     bool m_showTutorialsOnly;
     QStringList m_filterTags;
     QStringList m_searchString;
     ExamplesListModel *m_sourceModel;
+    int m_timerId;
 };
 
 } // namespace Internal
-- 
GitLab