From 457cfcfae98f81a3a1c45a451a6e77345a4d023b Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 31 Oct 2016 14:32:47 +0100 Subject: [PATCH] Welcome: Fix that filter string was cleared when changing page In examples and tutorials pages. Since the pages are unloaded and loaded again when the tab changes, they loose their internal state and require the search text to be kept as state in the model (which makes sense anyhow). Task-number: QTCREATORBUG-15901 Change-Id: I4fb05ca47f8337008c51e17cc95962a5e9e67fef Reviewed-by: Thomas Hartmann --- share/qtcreator/welcomescreen/examples.qml | 4 +-- share/qtcreator/welcomescreen/tutorials.qml | 4 +-- src/plugins/qtsupport/exampleslistmodel.cpp | 34 ++++++++++++++++++--- src/plugins/qtsupport/exampleslistmodel.h | 31 ++++++------------- 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/share/qtcreator/welcomescreen/examples.qml b/share/qtcreator/welcomescreen/examples.qml index 063a1f5a49b..99476d8817b 100644 --- a/share/qtcreator/welcomescreen/examples.qml +++ b/share/qtcreator/welcomescreen/examples.qml @@ -66,9 +66,9 @@ Item { anchors.leftMargin: 18 anchors.rightMargin: 20 anchors.right: parent.right - + text: examplesModel.searchString placeholderText: qsTr("Search in Examples...") - onTextChanged: examplesModel.parseSearchString(text) + onTextChanged: examplesModel.setSearchString(text) } CustomizedGridView { diff --git a/share/qtcreator/welcomescreen/tutorials.qml b/share/qtcreator/welcomescreen/tutorials.qml index 4c8535bedb6..eb227bf5117 100644 --- a/share/qtcreator/welcomescreen/tutorials.qml +++ b/share/qtcreator/welcomescreen/tutorials.qml @@ -39,9 +39,9 @@ Item { anchors.rightMargin: 20 anchors.left: parent.left anchors.leftMargin: 30 - + text: tutorialsModel.searchString placeholderText: qsTr("Search in Tutorials...") - onTextChanged: tutorialsModel.parseSearchString(text) + onTextChanged: tutorialsModel.setSearchString(text) } CustomizedGridView { diff --git a/src/plugins/qtsupport/exampleslistmodel.cpp b/src/plugins/qtsupport/exampleslistmodel.cpp index 83a7256e6a9..ac2fd0d36ab 100644 --- a/src/plugins/qtsupport/exampleslistmodel.cpp +++ b/src/plugins/qtsupport/exampleslistmodel.cpp @@ -760,6 +760,14 @@ void ExamplesListModelFilter::updateFilter() } } +void ExamplesListModelFilter::setFilterStrings(const QStringList &arg) +{ + if (m_filterStrings != arg) { + m_filterStrings = arg; + delayedUpdateFilter(); + } +} + bool containsSubString(const QStringList &list, const QString &substr, Qt::CaseSensitivity cs) { return Utils::contains(list, [&substr, &cs](const QString &elem) { @@ -789,11 +797,11 @@ bool ExamplesListModelFilter::filterAcceptsRow(int sourceRow, const QModelIndex }); } - if (!m_searchString.isEmpty()) { + if (!m_filterStrings.isEmpty()) { const QString description = sourceModel()->index(sourceRow, 0, sourceParent).data(Description).toString(); const QString name = sourceModel()->index(sourceRow, 0, sourceParent).data(Name).toString(); - foreach (const QString &subString, m_searchString) { + foreach (const QString &subString, m_filterStrings) { bool wordMatch = false; wordMatch |= (bool)name.contains(subString, Qt::CaseInsensitive); if (wordMatch) @@ -835,6 +843,14 @@ void ExamplesListModelFilter::filterForExampleSet(int index) m_sourceModel->selectExampleSet(index); } +void ExamplesListModelFilter::setFilterTags(const QStringList &arg) +{ + if (m_filterTags != arg) { + m_filterTags = arg; + emit filterTagsChanged(arg); + } +} + void ExamplesListModelFilter::setShowTutorialsOnly(bool showTutorialsOnly) { m_showTutorialsOnly = showTutorialsOnly; @@ -984,8 +1000,13 @@ struct SearchStringLexer } }; -void ExamplesListModelFilter::parseSearchString(const QString &arg) +void ExamplesListModelFilter::setSearchString(const QString &arg) { + if (m_searchString == arg) + return; + m_searchString = arg; + emit searchStringChanged(m_searchString); + // parse and update QStringList tags; QStringList searchTerms; SearchStringLexer lex(arg); @@ -1007,10 +1028,15 @@ void ExamplesListModelFilter::parseSearchString(const QString &arg) } } - setSearchStrings(searchTerms); + setFilterStrings(searchTerms); setFilterTags(tags); delayedUpdateFilter(); } +QString ExamplesListModelFilter::searchString() const +{ + return m_searchString; +} + } // namespace Internal } // namespace QtSupport diff --git a/src/plugins/qtsupport/exampleslistmodel.h b/src/plugins/qtsupport/exampleslistmodel.h index cc1f9a735f0..522bd92624e 100644 --- a/src/plugins/qtsupport/exampleslistmodel.h +++ b/src/plugins/qtsupport/exampleslistmodel.h @@ -163,7 +163,7 @@ class ExamplesListModelFilter : public QSortFilterProxyModel public: Q_PROPERTY(bool showTutorialsOnly READ showTutorialsOnly WRITE setShowTutorialsOnly NOTIFY showTutorialsOnlyChanged) Q_PROPERTY(QStringList filterTags READ filterTags WRITE setFilterTags NOTIFY filterTagsChanged) - Q_PROPERTY(QStringList searchStrings READ searchStrings WRITE setSearchStrings NOTIFY searchStrings) + Q_PROPERTY(QString searchString READ searchString WRITE setSearchString NOTIFY searchStringChanged) Q_PROPERTY(int exampleSetIndex READ exampleSetIndex NOTIFY exampleSetIndexChanged) @@ -171,9 +171,11 @@ public: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; + Q_INVOKABLE void setSearchString(const QString &arg); + QString searchString() const; + bool showTutorialsOnly() { return m_showTutorialsOnly; } QStringList filterTags() const { return m_filterTags; } - QStringList searchStrings() const { return m_searchString; } int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; @@ -182,35 +184,21 @@ public: Q_INVOKABLE void filterForExampleSet(int index); public slots: - void setFilterTags(const QStringList &arg) - { - if (m_filterTags != arg) { - m_filterTags = arg; - emit filterTagsChanged(arg); - } - } + void setFilterTags(const QStringList &arg); void updateFilter(); - void setSearchStrings(const QStringList &arg) - { - if (m_searchString != arg) { - m_searchString = arg; - emit searchStrings(arg); - delayedUpdateFilter(); - } - } - - void parseSearchString(const QString &arg); void setShowTutorialsOnly(bool showTutorialsOnly); void handleQtVersionsChanged(); signals: void showTutorialsOnlyChanged(); void filterTagsChanged(const QStringList &arg); - void searchStrings(const QStringList &arg); + void searchStringChanged(const QString &arg); void exampleSetIndexChanged(); private: + void setFilterStrings(const QStringList &arg); + void qtVersionManagerLoaded(); void helpManagerInitialized(); @@ -221,8 +209,9 @@ private: int exampleSetIndex() const; bool m_showTutorialsOnly; + QString m_searchString; QStringList m_filterTags; - QStringList m_searchString; + QStringList m_filterStrings; ExamplesListModel *m_sourceModel; int m_timerId; bool m_blockIndexUpdate;