CppEditor: replace OutlineModel::Range with Utils::Text::Range

Change-Id: I7d0e3b3c735e959d9cb9fb632c5f7819fbc66ac0
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2025-06-12 13:50:17 +02:00
parent 7be3814b2a
commit ec34c9bbd6
2 changed files with 9 additions and 12 deletions

View File

@@ -249,7 +249,7 @@ Utils::Text::Position OutlineModel::positionFromIndex(const QModelIndex &sourceI
return lineColumn; return lineColumn;
} }
OutlineModel::Range OutlineModel::rangeFromIndex(const QModelIndex &sourceIndex) const Utils::Text::Range OutlineModel::rangeFromIndex(const QModelIndex &sourceIndex) const
{ {
Utils::Text::Position lineColumn = positionFromIndex(sourceIndex); Utils::Text::Position lineColumn = positionFromIndex(sourceIndex);
return {lineColumn, lineColumn}; return {lineColumn, lineColumn};
@@ -287,13 +287,13 @@ void OutlineModel::buildTree(SymbolItem *root, bool isRoot)
} }
} }
static bool contains(const OutlineModel::Range &range, int line, int column) static bool contains(const Utils::Text::Range &range, int line, int column)
{ {
if (line < range.first.line || line > range.second.line) if (line < range.begin.line || line > range.end.line)
return false; return false;
if (line == range.first.line && column < range.first.column) if (line == range.begin.line && column < range.begin.column)
return false; return false;
if (line == range.second.line && column > range.second.column) if (line == range.end.line && column > range.end.column)
return false; return false;
return true; return true;
} }
@@ -305,11 +305,11 @@ QModelIndex OutlineModel::indexForPosition(int line, int column,
const int rowCount = this->rowCount(rootIndex); const int rowCount = this->rowCount(rootIndex);
for (int row = 0; row < rowCount; ++row) { for (int row = 0; row < rowCount; ++row) {
const QModelIndex index = this->index(row, 0, rootIndex); const QModelIndex index = this->index(row, 0, rootIndex);
const OutlineModel::Range range = rangeFromIndex(index); const Utils::Text::Range range = rangeFromIndex(index);
if (range.first.line > line) if (range.begin.line > line)
break; break;
// Skip ranges that do not include current line and column. // Skip ranges that do not include current line and column.
if (range.second != range.first && !contains(range, line, column)) if (range.end != range.begin && !contains(range, line, column))
continue; continue;
lastIndex = index; lastIndex = index;
} }

View File

@@ -13,8 +13,6 @@
#include <QSharedPointer> #include <QSharedPointer>
#include <QTimer> #include <QTimer>
#include <utility>
namespace Utils { namespace Utils {
class LineColumn; class LineColumn;
class Link; class Link;
@@ -47,8 +45,7 @@ public:
bool isGenerated(const QModelIndex &sourceIndex) const; bool isGenerated(const QModelIndex &sourceIndex) const;
Utils::Link linkFromIndex(const QModelIndex &sourceIndex) const; Utils::Link linkFromIndex(const QModelIndex &sourceIndex) const;
Utils::Text::Position positionFromIndex(const QModelIndex &sourceIndex) const; Utils::Text::Position positionFromIndex(const QModelIndex &sourceIndex) const;
using Range = std::pair<Utils::Text::Position, Utils::Text::Position>; Utils::Text::Range rangeFromIndex(const QModelIndex &sourceIndex) const;
Range rangeFromIndex(const QModelIndex &sourceIndex) const;
// line is 1-based and column is 0-based // line is 1-based and column is 0-based
QModelIndex indexForPosition(int line, int column, const QModelIndex &rootIndex = {}) const; QModelIndex indexForPosition(int line, int column, const QModelIndex &rootIndex = {}) const;