From 96d5c28a112b5ccc1bfbb09c12e4fc76e8c6a82b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 22 Aug 2012 18:01:32 +0200 Subject: 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 Reviewed-by: Stephen Kelly --- src/corelib/itemmodels/qabstractitemmodel.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/corelib/itemmodels/qabstractitemmodel.h') 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(); } -- cgit v1.2.3