summaryrefslogtreecommitdiffstats
path: root/src/corelib/itemmodels/qabstractitemmodel.cpp
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2012-08-22 18:01:32 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-23 15:54:02 +0200
commit96d5c28a112b5ccc1bfbb09c12e4fc76e8c6a82b (patch)
tree235e06e37055062e8215d1c110f6226b1379a36b /src/corelib/itemmodels/qabstractitemmodel.cpp
parent25c57e3188a14d987d6b59f48bd79b2ac3759257 (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.cpp')
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.cpp32
1 files changed, 19 insertions, 13 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