summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/Roster/RosterModel.cpp')
-rw-r--r--Swift/QtUI/Roster/RosterModel.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/Swift/QtUI/Roster/RosterModel.cpp b/Swift/QtUI/Roster/RosterModel.cpp
new file mode 100644
index 0000000..1df2117
--- /dev/null
+++ b/Swift/QtUI/Roster/RosterModel.cpp
@@ -0,0 +1,71 @@
+#include "RosterModel.h"
+
+namespace Swift {
+
+RosterModel::RosterModel() {
+}
+
+RosterModel::~RosterModel() {
+ delete tree_;
+}
+
+void RosterModel::setRoot(QtTreeWidgetItem* root) {
+ tree_ = root;
+ connect(tree_, SIGNAL(changed(QtTreeWidgetItem*)), this, SLOT(handleItemChanged(QtTreeWidgetItem*)));
+}
+
+
+void RosterModel::handleItemChanged(QtTreeWidgetItem* item) {
+ if (!item->isShown()) {
+ return;
+ }
+ Q_ASSERT(item);
+ QModelIndex modelIndex = index(item);
+ Q_ASSERT(modelIndex.isValid());
+ emit itemExpanded(modelIndex, item->isExpanded());
+ emit dataChanged(modelIndex, modelIndex);
+ emit layoutChanged();
+}
+
+int RosterModel::columnCount(const QModelIndex& parent) const {
+ Q_UNUSED(parent);
+ return 1;
+}
+
+QVariant RosterModel::data(const QModelIndex& index, int role) const {
+ QtTreeWidgetItem* item = index.isValid() ? static_cast<QtTreeWidgetItem*>(index.internalPointer()) : NULL;
+ return item ? item->data(role) : QVariant();
+}
+
+QModelIndex RosterModel::index(int row, int column, const QModelIndex& parent) const {
+ QtTreeWidgetItem* parentItem = parent.isValid() ? static_cast<QtTreeWidgetItem*>(parent.internalPointer()) : tree_;
+ Q_ASSERT(parentItem);
+
+ return row < parentItem->rowCount() ? createIndex(row, column, parentItem->getItem(row)) : QModelIndex();
+}
+
+QModelIndex RosterModel::index(QtTreeWidgetItem* item) const {
+ return createIndex(item->row(), 0, item);
+}
+
+QModelIndex RosterModel::parent(const QModelIndex& index) const {
+ if (!index.isValid()) {
+ return QModelIndex();
+ }
+
+ QtTreeWidgetItem* item = static_cast<QtTreeWidgetItem*>(index.internalPointer());
+ Q_ASSERT(item);
+
+ QtTreeWidgetItem* parentItem = item->getParentItem();
+ return parentItem == tree_ ? QModelIndex() : createIndex(parentItem->row(), 0, parentItem);
+
+}
+
+int RosterModel::rowCount(const QModelIndex& parent) const {
+ QtTreeWidgetItem* item = parent.isValid() ? static_cast<QtTreeWidgetItem*>(parent.internalPointer()) : tree_;
+ Q_ASSERT(item);
+
+ return item->rowCount();
+}
+
+} \ No newline at end of file