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:
@@ -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 {
|
||||
|
@@ -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 {
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user