summaryrefslogtreecommitdiff
path: root/src/plugins/cppeditor/cppoverviewmodel.cpp
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2022-08-17 13:26:49 +0200
committerDavid Schulz <david.schulz@qt.io>2022-08-19 05:04:29 +0000
commit33001a866f400c03041ecbad2b5de630a7ca697e (patch)
tree09e1ff25c5f63fbc7fe88ff8dee273a90f42bd9f /src/plugins/cppeditor/cppoverviewmodel.cpp
parent7c7fdf6460a5bd07fa26544b48d9224dfe228427 (diff)
downloadqt-creator-33001a866f400c03041ecbad2b5de630a7ca697e.tar.gz
CppEditor: remove dependencies between different outline views
Change-Id: If371811ac236c971d21815ef8738df5a169865e3 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/cppeditor/cppoverviewmodel.cpp')
-rw-r--r--src/plugins/cppeditor/cppoverviewmodel.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/plugins/cppeditor/cppoverviewmodel.cpp b/src/plugins/cppeditor/cppoverviewmodel.cpp
index bc1ea2e0f9..a2cfd79470 100644
--- a/src/plugins/cppeditor/cppoverviewmodel.cpp
+++ b/src/plugins/cppeditor/cppoverviewmodel.cpp
@@ -290,4 +290,39 @@ void OverviewModel::buildTree(SymbolItem *root, bool isRoot)
}
}
+static bool contains(const OverviewModel::Range &range, int line, int column)
+{
+ if (line < range.first.line || line > range.second.line)
+ return false;
+ if (line == range.first.line && column < range.first.column)
+ return false;
+ if (line == range.second.line && column > range.second.column)
+ return false;
+ return true;
+}
+
+QModelIndex OverviewModel::indexForPosition(int line, int column,
+ const QModelIndex &rootIndex) const
+{
+ QModelIndex lastIndex = rootIndex;
+ const int rowCount = this->rowCount(rootIndex);
+ for (int row = 0; row < rowCount; ++row) {
+ const QModelIndex index = this->index(row, 0, rootIndex);
+ const OverviewModel::Range range = rangeFromIndex(index);
+ if (range.first.line > line)
+ break;
+ // Skip ranges that do not include current line and column.
+ if (range.second != range.first && !contains(range, line, column))
+ continue;
+ lastIndex = index;
+ }
+
+ if (lastIndex != rootIndex) {
+ // recurse
+ lastIndex = indexForPosition(line, column, lastIndex);
+ }
+
+ return lastIndex;
+}
+
} // namespace CppEditor::Internal