summaryrefslogtreecommitdiff
path: root/src/plugins/find
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@digia.com>2013-04-17 13:16:16 +0200
committerEike Ziller <eike.ziller@digia.com>2013-04-17 13:48:53 +0200
commit3c5d7378340309ab5d5d41a2c5feb7527d8e53c4 (patch)
treee5e276d9783e7de3a5dc685fa4629103e16777c4 /src/plugins/find
parent7298984039bfa0fdc123bdcbd81bf1ecfbea83bc (diff)
downloadqt-creator-3c5d7378340309ab5d5d41a2c5feb7527d8e53c4.tar.gz
Fix searching in search results (and other tree views).
Task-number: QTCREATORBUG-9066 Change-Id: I76b7916b4ce64c400c175e72edc2b0a3ef015156 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Aurindam Jana <aurindam.jana@digia.com>
Diffstat (limited to 'src/plugins/find')
-rw-r--r--src/plugins/find/treeviewfind.cpp74
1 files changed, 38 insertions, 36 deletions
diff --git a/src/plugins/find/treeviewfind.cpp b/src/plugins/find/treeviewfind.cpp
index 292e075e35..4d3a3ccc11 100644
--- a/src/plugins/find/treeviewfind.cpp
+++ b/src/plugins/find/treeviewfind.cpp
@@ -166,7 +166,7 @@ IFindSupport::Result TreeViewFind::find(const QString &searchTxt,
Qt::CaseInsensitive));
if (searchExpr.indexIn(text) != -1
&& d->m_view->model()->flags(index) & Qt::ItemIsSelectable
- && currentRow != index.row())
+ && (index.row() != currentRow || index.parent() != currentIndex.parent()))
resultIndex = index;
} else {
QTextDocument doc(text);
@@ -174,7 +174,7 @@ IFindSupport::Result TreeViewFind::find(const QString &searchTxt,
flags & (Find::FindCaseSensitively |
Find::FindWholeWords)).isNull()
&& d->m_view->model()->flags(index) & Qt::ItemIsSelectable
- && currentRow != index.row())
+ && (index.row() != currentRow || index.parent() != currentIndex.parent()))
resultIndex = index;
}
}
@@ -202,33 +202,35 @@ QModelIndex TreeViewFind::nextIndex(const QModelIndex &idx, bool *wrapped) const
if (!idx.isValid())
return model->index(0, 0);
+ // same parent has more columns, go to next column
+ if (idx.column() + 1 < model->columnCount(idx.parent()))
+ return model->index(idx.row(), idx.column() + 1, idx.parent());
- if (model->rowCount(idx) > 0) {
- // node with children
- return idx.child(0, 0);
+ // tree views have their children attached to first column
+ // make sure we are at first column
+ QModelIndex current = model->index(idx.row(), 0, idx.parent());
+
+ // check for children
+ if (model->rowCount(current) > 0) {
+ return current.child(0, 0);
}
- // leaf node
+
+ // no more children, go up and look for parent with more children
QModelIndex nextIndex;
- QModelIndex current = idx;
while (!nextIndex.isValid()) {
int row = current.row();
- int column = current.column();
current = current.parent();
- if (column + 1 < model->columnCount(current)) {
- nextIndex = model->index(row, column + 1, current);
+ if (row + 1 < model->rowCount(current)) {
+ // Same parent has another child
+ nextIndex = model->index(row + 1, 0, current);
} else {
- if (row + 1 < model->rowCount(current)) {
- // Same parent has another child
- nextIndex = model->index(row + 1, 0, current);
- } else {
- // go up one parent
- if (!current.isValid()) {
- // we start from the beginning
- if (wrapped)
- *wrapped = true;
- nextIndex = model->index(0, 0);
- }
+ // go up one parent
+ if (!current.isValid()) {
+ // we start from the beginning
+ if (wrapped)
+ *wrapped = true;
+ nextIndex = model->index(0, 0);
}
}
}
@@ -239,34 +241,34 @@ QModelIndex TreeViewFind::prevIndex(const QModelIndex &idx, bool *wrapped) const
{
if (wrapped)
*wrapped = false;
+ QAbstractItemModel *model = d->m_view->model();
+ // if same parent has earlier columns, just move there
+ if (idx.column() > 0)
+ return model->index(idx.row(), idx.column() - 1, idx.parent());
+
QModelIndex current = idx;
bool checkForChildren = true;
- QAbstractItemModel *model = d->m_view->model();
if (current.isValid()) {
int row = current.row();
- int column = current.column();
- if (column > 0) {
- current = model->index(row, column - 1, current.parent());
+ if (row > 0) {
+ current = model->index(row - 1, 0, current.parent());
} else {
- if (row > 0) {
- current = model->index(row - 1, model->columnCount(current.parent()) - 1,
- current.parent());
- } else {
- current = current.parent();
- checkForChildren = !current.isValid();
- if (checkForChildren && wrapped) {
- // we start from the end
- *wrapped = true;
- }
+ current = current.parent();
+ checkForChildren = !current.isValid();
+ if (checkForChildren && wrapped) {
+ // we start from the end
+ *wrapped = true;
}
}
}
if (checkForChildren) {
// traverse down the hierarchy
while (int rc = model->rowCount(current)) {
- current = model->index(rc - 1, model->columnCount(current) - 1, current);
+ current = model->index(rc - 1, 0, current);
}
}
+ // set to last column
+ current = model->index(current.row(), model->columnCount(current.parent()) - 1, current.parent());
return current;
}