Add implementations of QAIM::sibling in public APIs.

Change-Id: I2248641f2ed8735c28bd9572470520995a4a5b62
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Stephen Kelly 2012-09-26 18:16:08 +02:00 committed by The Qt Project
parent 000025ca1e
commit 9dfba89c28
13 changed files with 82 additions and 0 deletions

View File

@ -420,6 +420,7 @@ public:
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent);
protected:
QAbstractTableModel(QAbstractItemModelPrivate &dd, QObject *parent);

View File

@ -360,6 +360,15 @@ bool QAbstractProxyModel::hasChildren(const QModelIndex &parent) const
return d->model->hasChildren(mapToSource(parent));
}
/*!
\reimp
*/
QModelIndex QAbstractProxyModel::sibling(int row, int column, const QModelIndex &idx) const
{
Q_D(const QAbstractProxyModel);
return d->model->sibling(row, column, mapToSource(idx));
}
/*!
\reimp
*/

View File

@ -90,6 +90,7 @@ public:
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
QSize span(const QModelIndex &index) const;
bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
QMimeData* mimeData(const QModelIndexList &indexes) const;
QStringList mimeTypes() const;

View File

@ -168,6 +168,15 @@ QModelIndex QIdentityProxyModel::index(int row, int column, const QModelIndex& p
return mapFromSource(sourceIndex);
}
/*!
\reimp
*/
QModelIndex QIdentityProxyModel::sibling(int row, int column, const QModelIndex &idx) const
{
Q_D(const QIdentityProxyModel);
return d->model->sibling(row, column, mapToSource(idx));
}
/*!
\reimp
*/

View File

@ -69,6 +69,7 @@ public:
int rowCount(const QModelIndex& parent = QModelIndex()) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent);
QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
QItemSelection mapSelectionFromSource(const QItemSelection& selection) const;
QItemSelection mapSelectionToSource(const QItemSelection& selection) const;

View File

@ -1868,6 +1868,22 @@ QModelIndex QSortFilterProxyModel::parent(const QModelIndex &child) const
return proxy_parent;
}
/*!
\reimp
*/
QModelIndex QSortFilterProxyModel::sibling(int row, int column, const QModelIndex &idx) const
{
Q_D(const QSortFilterProxyModel);
if (!d->indexValid(idx))
return QModelIndex();
const IndexMap::const_iterator it = d->index_to_iterator(idx);
if (it.value()->source_rows.count() <= row || it.value()->source_columns.count() <= column)
return QModelIndex();
return d->create_index(row, column, it);
}
/*!
\reimp
*/

View File

@ -135,6 +135,7 @@ public:
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &child) const;
QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;

View File

@ -126,6 +126,17 @@ int QStringListModel::rowCount(const QModelIndex &parent) const
return lst.count();
}
/*!
\reimp
*/
QModelIndex QStringListModel::sibling(int row, int column, const QModelIndex &idx) const
{
if (!idx.isValid() || column != 0 || row >= lst.count())
return QModelIndex();
return createIndex(row, 0);
}
/*!
Returns data for the specified \a role, from the item with the
given \a index.

View File

@ -60,6 +60,7 @@ public:
explicit QStringListModel(const QStringList &strings, QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);

View File

@ -2709,6 +2709,15 @@ bool QStandardItemModel::hasChildren(const QModelIndex &parent) const
return item ? item->hasChildren() : false;
}
/*!
\reimp
*/
QModelIndex QStandardItemModel::sibling(int row, int column, const QModelIndex &idx) const
{
Q_D(const QStandardItemModel);
return createIndex(row, column, idx.internalPointer());
}
/*!
\reimp
*/

View File

@ -332,6 +332,7 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);

View File

@ -392,6 +392,8 @@ void checkChildren(QAbstractItemModel *currentModel, const QModelIndex &parent,
int rows = currentModel->rowCount(parent);
int columns = currentModel->columnCount(parent);
const QModelIndex topLeftChild = currentModel->index( 0, 0, parent );
QCOMPARE(rows > 0, (currentModel->hasChildren(parent)));
// Some reasuring testing against rows(),columns(), and hasChildren()
@ -423,6 +425,15 @@ void checkChildren(QAbstractItemModel *currentModel, const QModelIndex &parent,
QModelIndex b = currentModel->index(r, c, parent);
QVERIFY(a == b);
{
const QModelIndex sibling = currentModel->sibling( r, c, topLeftChild );
QVERIFY( index == sibling );
}
{
const QModelIndex sibling = topLeftChild.sibling( r, c );
QVERIFY( index == sibling );
}
// Some basic checking on the index that is returned
QVERIFY(index.model() == currentModel);
QCOMPARE(index.row(), r);

View File

@ -339,6 +339,8 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
//qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows
// << "columns:" << columns << "parent column:" << parent.column();
const QModelIndex topLeftChild = model->index( 0, 0, parent );
QVERIFY( !model->hasIndex ( rows + 1, 0, parent ) );
for ( int r = 0; r < rows; ++r ) {
if ( model->canFetchMore ( parent ) ) {
@ -362,6 +364,15 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
QModelIndex b = model->index ( r, c, parent );
QVERIFY( a == b );
{
const QModelIndex sibling = model->sibling( r, c, topLeftChild );
QVERIFY( index == sibling );
}
{
const QModelIndex sibling = topLeftChild.sibling( r, c );
QVERIFY( index == sibling );
}
// Some basic checking on the index that is returned
QVERIFY( index.model() == model );
QCOMPARE( index.row(), r );