diff options
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.cpp | 32 | ||||
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.h | 6 |
2 files changed, 21 insertions, 17 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 4a266e4891..5f6fcc6fd9 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -1394,19 +1394,6 @@ QAbstractItemModel::~QAbstractItemModel() d_func()->invalidatePersistentIndexes(); } -/*! - \fn QModelIndex QAbstractItemModel::sibling(int row, int column, const QModelIndex &index) const - - Returns the sibling at \a row and \a column for the item at \a index, or an - invalid QModelIndex if there is no sibling at that location. - - sibling() is just a convenience function that finds the item's parent, and - uses it to retrieve the index of the child item in the specified \a row and - \a column. - - \sa index(), QModelIndex::row(), QModelIndex::column() -*/ - /*! \fn int QAbstractItemModel::rowCount(const QModelIndex &parent) const @@ -1657,6 +1644,25 @@ bool QAbstractItemModel::hasChildren(const QModelIndex &parent) const return (rowCount(parent) > 0) && (columnCount(parent) > 0); } +/*! + \fn QModelIndex QAbstractItemModel::sibling(int row, int column, const QModelIndex &index) const + + Returns the sibling at \a row and \a column for the item at \a index, or an + invalid QModelIndex if there is no sibling at that location. + + sibling() is just a convenience function that finds the item's parent, and + uses it to retrieve the index of the child item in the specified \a row and + \a column. + + This method can optionally be overridden for implementation-specific optimization. + + \sa index(), QModelIndex::row(), QModelIndex::column() +*/ +QModelIndex QAbstractItemModel::sibling(int row, int column, const QModelIndex &idx) const +{ + return (row == idx.row() && column == idx.column()) ? idx : index(row, column, parent(idx)); +} + /*! Returns a map with values for all predefined roles in the model for the 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(); } |