QFileSystemModel: reimplement sibling for same-row
Since QFSM, like most models, uses QModelIndex::internalPointer() as an indicator of the row, getting a sibling in the same row is as easy as copying the internalPointer() of the incoming index and just creating a new index with the column adjusted. For rows, the situation is quite a bit more complicated, so we currently continue to call the generic implementation. Change-Id: I36921e3f9c01c458a75aa439018f21c4c657e1cf Reviewed-by: David Faure <david.faure@kdab.com>bb10
parent
f43885f8d1
commit
98ce9a6309
|
|
@ -250,6 +250,21 @@ QModelIndex QFileSystemModel::index(int row, int column, const QModelIndex &pare
|
|||
return createIndex(row, column, const_cast<QFileSystemModelPrivate::QFileSystemNode*>(indexNode));
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
QModelIndex QFileSystemModel::sibling(int row, int column, const QModelIndex &idx) const
|
||||
{
|
||||
if (row == idx.row() && column < QFileSystemModelPrivate::NumColumns) {
|
||||
// cheap sibling operation: just adjust the column:
|
||||
return createIndex(row, column, idx.internalPointer());
|
||||
} else {
|
||||
// for anything else: call the default implementation
|
||||
// (this could probably be optimized, too):
|
||||
return QAbstractItemModel::sibling(row, column, idx);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ public:
|
|||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
||||
QModelIndex index(const QString &path, int column = 0) const;
|
||||
QModelIndex parent(const QModelIndex &child) const Q_DECL_OVERRIDE;
|
||||
QModelIndex sibling(int row, int column, const QModelIndex &idx) const Q_DECL_OVERRIDE;
|
||||
bool hasChildren(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
||||
bool canFetchMore(const QModelIndex &parent) const Q_DECL_OVERRIDE;
|
||||
void fetchMore(const QModelIndex &parent) Q_DECL_OVERRIDE;
|
||||
|
|
|
|||
Loading…
Reference in New Issue