aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/find
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@digia.com>2013-04-18 09:22:19 +0200
committerEike Ziller <eike.ziller@digia.com>2013-04-18 09:22:19 +0200
commit44931c098583ee5365ec7e3de716c0c6a74b8372 (patch)
treec2944dc59e6c1c679de1bfbb2880b4e129317b6c /src/plugins/find
parentea75b0d18312cd1eb8caf139413dc2a064f1d788 (diff)
parent1526011f32ae5becdedcf4ee55e32bbcf5724bcb (diff)
Merge remote-tracking branch 'origin/2.7'
Conflicts: src/plugins/pythoneditor/tools/lexical/pythonformattoken.h Change-Id: I7b921cd975aa755166a80d219ed5e8b69888aeb0
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 fe803f07a80..414be05fe75 100644
--- a/src/plugins/find/treeviewfind.cpp
+++ b/src/plugins/find/treeviewfind.cpp
@@ -167,7 +167,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);
@@ -175,7 +175,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;
}
}
@@ -203,33 +203,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);
}
}
}
@@ -240,34 +242,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;
}