forked from qt-creator/qt-creator
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 <Thomas.Hartmann@theqtcompany.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user