summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@nokia.com>2011-12-05 15:48:37 +0100
committerEike Ziller <eike.ziller@nokia.com>2011-12-05 17:06:10 +0100
commitc1f643e387788f905f5f8b0466c70ccebb9bc58e (patch)
tree1185aa2bc4d406fc4ee62495458b4a9c3ecbc6ba
parent0a59f347946a44583dc4f6271bbfa93b481d84dd (diff)
downloadqt-creator-c1f643e387788f905f5f8b0466c70ccebb9bc58e.tar.gz
Fix search next/prev in search results.
Broke with ebb9e252779aff1ff874565c2b056f1c8319c2c8 Change-Id: Ifb5821d4712e780df70bc1ec798123dd7b63b108 Reviewed-by: Jarek Kobus <jaroslaw.kobus@nokia.com>
-rw-r--r--src/plugins/find/searchresulttreemodel.cpp27
-rw-r--r--src/plugins/find/searchresulttreemodel.h6
-rw-r--r--src/plugins/find/searchresultwidget.cpp9
3 files changed, 27 insertions, 15 deletions
diff --git a/src/plugins/find/searchresulttreemodel.cpp b/src/plugins/find/searchresulttreemodel.cpp
index 95336e8a56..dc7f369956 100644
--- a/src/plugins/find/searchresulttreemodel.cpp
+++ b/src/plugins/find/searchresulttreemodel.cpp
@@ -492,6 +492,13 @@ QModelIndex SearchResultTreeModel::prevIndex(const QModelIndex &idx, bool *wrapp
return current;
}
+QModelIndex SearchResultTreeModel::followingIndex(const QModelIndex &idx, bool backward, bool includeGenerated, bool *wrapped)
+{
+ if (backward)
+ return prev(idx, includeGenerated, wrapped);
+ return next(idx, includeGenerated, wrapped);
+}
+
QModelIndex SearchResultTreeModel::prev(const QModelIndex &idx, bool includeGenerated, bool *wrapped) const
{
QModelIndex value = idx;
@@ -502,7 +509,8 @@ QModelIndex SearchResultTreeModel::prev(const QModelIndex &idx, bool includeGene
}
QModelIndex SearchResultTreeModel::find(const QRegExp &expr, const QModelIndex &index,
- QTextDocument::FindFlags flags, bool *wrapped)
+ QTextDocument::FindFlags flags,
+ bool startWithCurrentIndex, bool *wrapped)
{
QModelIndex resultIndex;
QModelIndex currentIndex = index;
@@ -512,6 +520,8 @@ QModelIndex SearchResultTreeModel::find(const QRegExp &expr, const QModelIndex &
bool anyWrapped = false;
bool stepWrapped = false;
+ if (!startWithCurrentIndex)
+ currentIndex = followingIndex(currentIndex, backward, true, &stepWrapped);
do {
anyWrapped |= stepWrapped; // update wrapped state if we actually stepped to next/prev item
if (currentIndex.isValid()) {
@@ -519,10 +529,7 @@ QModelIndex SearchResultTreeModel::find(const QRegExp &expr, const QModelIndex &
if (expr.indexIn(text) != -1)
resultIndex = currentIndex;
}
- if (backward)
- currentIndex = prev(currentIndex, true, &stepWrapped);
- else
- currentIndex = next(currentIndex, true, &stepWrapped);
+ currentIndex = followingIndex(currentIndex, backward, true, &stepWrapped);
} while (!resultIndex.isValid() && currentIndex.isValid() && currentIndex != index);
if (resultIndex.isValid() && wrapped)
*wrapped = anyWrapped;
@@ -530,7 +537,8 @@ QModelIndex SearchResultTreeModel::find(const QRegExp &expr, const QModelIndex &
}
QModelIndex SearchResultTreeModel::find(const QString &term, const QModelIndex &index,
- QTextDocument::FindFlags flags, bool *wrapped)
+ QTextDocument::FindFlags flags,
+ bool startWithCurrentIndex, bool *wrapped)
{
QModelIndex resultIndex;
QModelIndex currentIndex = index;
@@ -541,6 +549,8 @@ QModelIndex SearchResultTreeModel::find(const QString &term, const QModelIndex &
bool anyWrapped = false;
bool stepWrapped = false;
+ if (!startWithCurrentIndex)
+ currentIndex = followingIndex(currentIndex, backward, true, &stepWrapped);
do {
anyWrapped |= stepWrapped; // update wrapped state if we actually stepped to next/prev item
if (currentIndex.isValid()) {
@@ -549,10 +559,7 @@ QModelIndex SearchResultTreeModel::find(const QString &term, const QModelIndex &
if (!doc.find(term, 0, flags).isNull())
resultIndex = currentIndex;
}
- if (backward)
- currentIndex = prev(currentIndex, true, &stepWrapped);
- else
- currentIndex = next(currentIndex, true, &stepWrapped);
+ currentIndex = followingIndex(currentIndex, backward, true, &stepWrapped);
} while (!resultIndex.isValid() && currentIndex.isValid() && currentIndex != index);
if (resultIndex.isValid() && wrapped)
*wrapped = anyWrapped;
diff --git a/src/plugins/find/searchresulttreemodel.h b/src/plugins/find/searchresulttreemodel.h
index 40c2d789a1..e01a869785 100644
--- a/src/plugins/find/searchresulttreemodel.h
+++ b/src/plugins/find/searchresulttreemodel.h
@@ -71,9 +71,9 @@ public:
QList<QModelIndex> addResults(const QList<SearchResultItem> &items, SearchResult::AddMode mode);
QModelIndex find(const QRegExp &expr, const QModelIndex &index,
- QTextDocument::FindFlags flags, bool *wrapped = 0);
+ QTextDocument::FindFlags flags, bool startWithCurrentIndex, bool *wrapped = 0);
QModelIndex find(const QString &term, const QModelIndex &index,
- QTextDocument::FindFlags flags, bool *wrapped = 0);
+ QTextDocument::FindFlags flags, bool startWithCurrentIndex, bool *wrapped = 0);
signals:
void jumpToSearchResult(const QString &fileName, int lineNumber,
@@ -90,6 +90,8 @@ private:
bool setCheckState(const QModelIndex &idx, Qt::CheckState checkState, bool firstCall = true);
QModelIndex nextIndex(const QModelIndex &idx, bool *wrapped = 0) const;
QModelIndex prevIndex(const QModelIndex &idx, bool *wrapped = 0) const;
+ QModelIndex followingIndex(const QModelIndex &idx, bool backward, bool includeGenerated = false,
+ bool *wrapped = 0);
SearchResultTreeItem *treeItemAtIndex(const QModelIndex &idx) const;
SearchResultTreeItem *m_rootItem;
diff --git a/src/plugins/find/searchresultwidget.cpp b/src/plugins/find/searchresultwidget.cpp
index 34205ef4c7..556bd2409b 100644
--- a/src/plugins/find/searchresultwidget.cpp
+++ b/src/plugins/find/searchresultwidget.cpp
@@ -117,7 +117,7 @@ public:
}
m_view->setCurrentIndex(m_incrementalFindStart);
bool wrapped = false;
- IFindSupport::Result result = find(txt, findFlags, &wrapped);
+ IFindSupport::Result result = find(txt, findFlags, true/*startFromCurrent*/, &wrapped);
if (wrapped != m_incrementalWrappedState) {
m_incrementalWrappedState = wrapped;
showWrapIndicator(m_view);
@@ -128,7 +128,7 @@ public:
IFindSupport::Result findStep(const QString &txt, Find::FindFlags findFlags)
{
bool wrapped = false;
- IFindSupport::Result result = find(txt, findFlags, &wrapped);
+ IFindSupport::Result result = find(txt, findFlags, false/*startFromNext*/, &wrapped);
if (wrapped)
showWrapIndicator(m_view);
if (result == IFindSupport::Found) {
@@ -138,7 +138,8 @@ public:
return result;
}
- IFindSupport::Result find(const QString &txt, Find::FindFlags findFlags, bool *wrapped)
+ IFindSupport::Result find(const QString &txt, Find::FindFlags findFlags,
+ bool startFromCurrentIndex, bool *wrapped)
{
if (wrapped)
*wrapped = false;
@@ -150,11 +151,13 @@ public:
index = m_view->model()->find(QRegExp(txt, (sensitive ? Qt::CaseSensitive : Qt::CaseInsensitive)),
m_view->currentIndex(),
Find::textDocumentFlagsForFindFlags(findFlags),
+ startFromCurrentIndex,
wrapped);
} else {
index = m_view->model()->find(txt,
m_view->currentIndex(),
Find::textDocumentFlagsForFindFlags(findFlags),
+ startFromCurrentIndex,
wrapped);
}
if (index.isValid()) {