diff options
Diffstat (limited to 'Swift/QtUI/Roster/RosterModel.cpp')
-rw-r--r-- | Swift/QtUI/Roster/RosterModel.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/Swift/QtUI/Roster/RosterModel.cpp b/Swift/QtUI/Roster/RosterModel.cpp index f322792..30d8135 100644 --- a/Swift/QtUI/Roster/RosterModel.cpp +++ b/Swift/QtUI/Roster/RosterModel.cpp @@ -11,16 +11,23 @@ RosterModel::~RosterModel() { void RosterModel::setRoot(QtTreeWidgetItem* root) { tree_ = root; - connect(tree_, SIGNAL(changed()), this, SLOT(handleItemChanged())); + connect(tree_, SIGNAL(changed(QtTreeWidgetItem*)), this, SLOT(handleItemChanged(QtTreeWidgetItem*))); } -void RosterModel::handleItemChanged() { - //FIXME: This is just a lazy hack to cause the view to refresh until it works. - // Then I'll replace it with the proper implementation. - //printf("Changed\n"); +void RosterModel::handleItemChanged(QtTreeWidgetItem* item) { + if (!item->isShown()) { + return; + } + //these two lines should be redundant, but... reset(); emit layoutChanged(); + //These lines don't seem to be enough + Q_ASSERT(item); + QModelIndex modelIndex = index(item); + emit itemExpanded(modelIndex, item->isExpanded()); + emit dataChanged(modelIndex, modelIndex); + } int RosterModel::columnCount(const QModelIndex& parent) const { @@ -40,6 +47,19 @@ QModelIndex RosterModel::index(int row, int column, const QModelIndex& parent) c return row < parentItem->rowCount() ? createIndex(row, column, parentItem->getItem(row)) : QModelIndex(); } +QModelIndex RosterModel::index(QtTreeWidgetItem* item) const { + QtTreeWidgetItem* parentItem = item->getParentItem(); + Q_ASSERT(parentItem); + QModelIndex parentIndex = parent(item); + return index(item->row(), 0, parentIndex); +} + +QModelIndex RosterModel::parent(QtTreeWidgetItem* item) const { + QtTreeWidgetItem* parentItem = item->getParentItem(); + return parentItem == tree_ ? QModelIndex() : index(parentItem->row(), 0, parent(parentItem)); +} + + QModelIndex RosterModel::parent(const QModelIndex& index) const { if (!index.isValid()) { return QModelIndex(); |