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;
}
OutlineModel::Range OutlineModel::rangeFromIndex(const QModelIndex &sourceIndex) const
Utils::Text::Range OutlineModel::rangeFromIndex(const QModelIndex &sourceIndex) const
{
Utils::Text::Position lineColumn = positionFromIndex(sourceIndex);
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;
if (line == range.first.line && column < range.first.column)
if (line == range.begin.line && column < range.begin.column)
return false;
if (line == range.second.line && column > range.second.column)
if (line == range.end.line && column > range.end.column)
return false;
return true;
}
@@ -305,11 +305,11 @@ QModelIndex OutlineModel::indexForPosition(int line, int column,
const int rowCount = this->rowCount(rootIndex);
for (int row = 0; row < rowCount; ++row) {
const QModelIndex index = this->index(row, 0, rootIndex);
const OutlineModel::Range range = rangeFromIndex(index);
if (range.first.line > line)
const Utils::Text::Range range = rangeFromIndex(index);
if (range.begin.line > line)
break;
// 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;
lastIndex = index;
}

View File

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