From c74deadf4b7eeb2800b318e0952dac8f700d9236 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Thu, 21 Jan 2010 14:58:48 +0100 Subject: add QModelIndex::rowCount() and QModelIndex::ColumnCount convenience methods Merge-request: 438 Reviewed-by: Leonardo Sobral Cunha --- src/corelib/kernel/qabstractitemmodel.cpp | 22 +++++++++++++++++++++- src/corelib/kernel/qabstractitemmodel.h | 8 ++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/corelib/kernel/qabstractitemmodel.cpp b/src/corelib/kernel/qabstractitemmodel.cpp index dbf422e..fdbc5ba 100644 --- a/src/corelib/kernel/qabstractitemmodel.cpp +++ b/src/corelib/kernel/qabstractitemmodel.cpp @@ -1043,12 +1043,32 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, /*! + \since 4.7 + + \fn int QModelIndex::rowCount() const + + Returns the number of children of this model index. + + \sa columnCount(), parent(), child(), sibling(), model() +*/ + +/*! + \since 4.7 + + \fn int QModelIndex::columnCount() const + + Returns the number of columns for the children of this model index. + + \sa rowCount(), parent(), child(), sibling(), model() +*/ + +/*! \fn QModelIndex QModelIndex::parent() const Returns the parent of the model index, or QModelIndex() if it has no parent. - \sa child(), sibling(), model() + \sa child(), sibling(), rowCount(), columnCount(), model() */ /*! diff --git a/src/corelib/kernel/qabstractitemmodel.h b/src/corelib/kernel/qabstractitemmodel.h index 63d9e6f..d91c383 100644 --- a/src/corelib/kernel/qabstractitemmodel.h +++ b/src/corelib/kernel/qabstractitemmodel.h @@ -68,6 +68,8 @@ public: inline int column() const { return c; } inline void *internalPointer() const { return p; } inline qint64 internalId() const { return reinterpret_cast(p); } + inline int rowCount() const; + inline int columnCount() const; inline QModelIndex parent() const; inline QModelIndex sibling(int row, int column) const; inline QModelIndex child(int row, int column) const; @@ -385,6 +387,12 @@ inline QModelIndex::QModelIndex(int arow, int acolumn, void *adata, const QAbstractItemModel *amodel) : r(arow), c(acolumn), p(adata), m(amodel) {} +inline int QModelIndex::rowCount() const +{ return m ? m->rowCount(*this) : 0; } + +inline int QModelIndex::columnCount() const +{ return m ? m->columnCount(*this) : 0; } + inline QModelIndex QModelIndex::parent() const { return m ? m->parent(*this) : QModelIndex(); } -- cgit v0.12