diff options
author | Kevin Smith <git@kismith.co.uk> | 2009-07-26 12:39:50 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2009-07-26 12:39:50 (GMT) |
commit | a28d92f3458218d6effbfdd9a42bf8fbe8b8aa72 (patch) | |
tree | f666c221dcc899704bb80f67afe383e58b780669 /Swift/QtUI/Roster/RosterModel.cpp | |
parent | c4660f404c9a0dbf1c00a20baacfc738d93eaff5 (diff) | |
download | swift-contrib-a28d92f3458218d6effbfdd9a42bf8fbe8b8aa72.zip swift-contrib-a28d92f3458218d6effbfdd9a42bf8fbe8b8aa72.tar.bz2 |
Begin to assage Swift model into Qt Model/View.
Diffstat (limited to 'Swift/QtUI/Roster/RosterModel.cpp')
-rw-r--r-- | Swift/QtUI/Roster/RosterModel.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Swift/QtUI/Roster/RosterModel.cpp b/Swift/QtUI/Roster/RosterModel.cpp new file mode 100644 index 0000000..2c9a2cc --- /dev/null +++ b/Swift/QtUI/Roster/RosterModel.cpp @@ -0,0 +1,56 @@ +#include "RosterModel.h" + +namespace Swift { + +RosterModel::RosterModel(RosterItem* tree) { + tree_ = tree; +} + +RosterModel::~RosterModel() { + +} + +int RosterModel::columnCount(const QModelIndex& parent) const { + Q_UNUSED(parent); + return 1; +} + +QVariant RosterModel::data(const QModelIndex& index, int role) const { + if (!index.isValid()) { + return QVariant(); + } + return QVariant("bob"); +} + +QModelIndex RosterModel::index(int row, int column, const QModelIndex& parent) const { + RosterItem* parentItem = parent.isValid() ? static_cast<RosterItem*>(parent.internalPointer()) : tree_; + Q_ASSERT(parentItem); + + return row < parentItem->rowCount() ? createIndex(row, column, parentItem->getItem(row)) : QModelIndex(); +} + +QModelIndex RosterModel::parent(const QModelIndex& index) const { + if (!index.isValid()) { + return QModelIndex(); + } + + RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); + Q_ASSERT(item); + + RosterItem* parentItem = item->getParentItem(); + return parentItem == tree_ ? QModelIndex() : createIndex(parentItem->getParentItem()->rowOf(parentItem), 0, parentItem); + +} + +int RosterModel::rowCount(const QModelIndex& parent) const { + if (!parent.isValid()) { + return 0; + } + + RosterItem* item = static_cast<RosterItem*>(parent.internalPointer()); + Q_ASSERT(item); + + return item->rowCount(); +} + +}
\ No newline at end of file |