Commit 2aab5510 authored by hjk's avatar hjk

TreeModel: Add a sibling() implementation

The base implementation uses the parent() index, which
in turn accesses the grand parent level. We can save
a few cycles here.

Change-Id: I3c3696118fe7c3d4563ee3cd28981fca62013828
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
parent 0a5abdae
......@@ -966,6 +966,18 @@ QModelIndex BaseTreeModel::parent(const QModelIndex &idx) const
return createIndex(i, 0, static_cast<void*>(parent));
}
QModelIndex BaseTreeModel::sibling(int row, int column, const QModelIndex &idx) const
{
const TreeItem *item = itemForIndex(idx);
QTC_ASSERT(item, return QModelIndex());
QModelIndex result;
if (TreeItem *parent = item->parent()) {
if (TreeItem *sibl = parent->childAt(row))
result = createIndex(row, column, static_cast<void*>(sibl));
}
return result;
}
int BaseTreeModel::rowCount(const QModelIndex &idx) const
{
CHECK_INDEX(idx);
......
......@@ -188,6 +188,7 @@ protected:
QVariant data(const QModelIndex &idx, int role) const override;
QModelIndex index(int, int, const QModelIndex &idx = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &idx) const override;
QModelIndex sibling(int row, int column, const QModelIndex &idx) const override;
Qt::ItemFlags flags(const QModelIndex &idx) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
bool hasChildren(const QModelIndex &idx) const override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment