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>
This commit is contained in:
thohartm
2012-05-22 16:52:43 +02:00
committed by Thomas Hartmann
parent 871a25ff57
commit ca8cd6b806
2 changed files with 26 additions and 3 deletions

View File

@@ -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

View File

@@ -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