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>
This commit is contained in:
parent
25c57e3188
commit
96d5c28a11
3
dist/changes-5.0.0
vendored
3
dist/changes-5.0.0
vendored
@ -330,6 +330,9 @@ QtCore
|
||||
should now also connect to (and disconnect from) the rowsAboutToBeMoved and
|
||||
rowsMoved signals.
|
||||
|
||||
* The QAbstractItemModel::sibling method was made virtual, allowing implementations
|
||||
to optimize based on internal data.
|
||||
|
||||
* The default value of the property QSortFilterProxyModel::dynamicSortFilter was
|
||||
changed from false to true.
|
||||
|
||||
|
@ -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
|
||||
|
@ -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(); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user