diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2012-08-22 18:01:32 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-23 15:54:02 +0200 |
commit | 96d5c28a112b5ccc1bfbb09c12e4fc76e8c6a82b (patch) | |
tree | 235e06e37055062e8215d1c110f6226b1379a36b /src/corelib/itemmodels/qabstractitemmodel.h | |
parent | 25c57e3188a14d987d6b59f48bd79b2ac3759257 (diff) |
Make QAbstractItemModel::sibling virtual.
This would allow implementations to create an optimized way to create
sibling indexes.
A typical pattern of QAIM implementation is to use the same internalPointer
for each row of a subtable of a model (such that the internalPointer is
related to the common parent of each set of rows) and differentiate on the
row value in the QModelIndex. Alternatively, it is also common to have the
internalPointer correspond directly to the row value for the QModelIndex.
In both cases it is possible for the implementation to optimally create a
sibling QModelIndex in the same column as a known row. Provide a virtual
method for them to do so.
Change-Id: I3b076abcd5f6087a4cb108fbc6dceeef15529987
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src/corelib/itemmodels/qabstractitemmodel.h')
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.h | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index eab489438c..9587285d97 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -171,9 +171,7 @@ public: const QModelIndex &parent = QModelIndex()) const = 0; virtual QModelIndex parent(const QModelIndex &child) const = 0; - inline QModelIndex sibling(int row, int column, const QModelIndex &idx) const - { return (row == idx.row() && column == idx.column()) ? idx : index(row, column, parent(idx)); } - + virtual QModelIndex sibling(int row, int column, const QModelIndex &idx) const; virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0; virtual int columnCount(const QModelIndex &parent = QModelIndex()) const = 0; virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const; @@ -473,7 +471,7 @@ inline QModelIndex QModelIndex::parent() const { return m ? m->parent(*this) : QModelIndex(); } inline QModelIndex QModelIndex::sibling(int arow, int acolumn) const -{ return m ? (r == arow && c == acolumn) ? *this : m->index(arow, acolumn, m->parent(*this)) : QModelIndex(); } +{ return m ? (r == arow && c == acolumn) ? *this : m->sibling(arow, acolumn, *this) : QModelIndex(); } inline QModelIndex QModelIndex::child(int arow, int acolumn) const { return m ? m->index(arow, acolumn, *this) : QModelIndex(); } |