summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-05-26 16:29:44 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-05-26 17:24:07 (GMT)
commite497af7cd28d2cf58d81ed8fd351b5d5ccfa56a4 (patch)
treee2fbb5b2c5f4b5fe3aa884bf551379ac2c6478c8 /Swift/QtUI/Roster/RosterModel.cpp
parentc77cbf3d4cdcfce47639006f023715483f6f0dc1 (diff)
downloadswift-e497af7cd28d2cf58d81ed8fd351b5d5ccfa56a4.zip
swift-e497af7cd28d2cf58d81ed8fd351b5d5ccfa56a4.tar.bz2
Don't let roster groups open and close on their own.
Resolves: #368
Diffstat (limited to 'Swift/QtUI/Roster/RosterModel.cpp')
-rw-r--r--Swift/QtUI/Roster/RosterModel.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/Swift/QtUI/Roster/RosterModel.cpp b/Swift/QtUI/Roster/RosterModel.cpp
index 12cedda..e5a938e 100644
--- a/Swift/QtUI/Roster/RosterModel.cpp
+++ b/Swift/QtUI/Roster/RosterModel.cpp
@@ -33,31 +33,26 @@ void RosterModel::setRoster(Roster* roster) {
if (!roster_) return;
roster->onChildrenChanged.connect(boost::bind(&RosterModel::handleChildrenChanged, this, _1));
roster->onDataChanged.connect(boost::bind(&RosterModel::handleDataChanged, this, _1));
- roster->onGroupAdded.connect(boost::bind(&RosterModel::handleGroupAdded, this, _1));
- emit layoutChanged();
-}
-
-void RosterModel::handleGroupAdded(GroupRosterItem* group) {
- emit itemExpanded(index(group), group->isExpanded());
+ reLayout();
}
-void RosterModel::handleChildrenChanged(GroupRosterItem* group) {
- foreach (RosterItem* item, group->getDisplayedChildren()) {
+void RosterModel::reLayout() {
+ emit layoutChanged();
+ foreach (RosterItem* item, roster_->getRoot()->getDisplayedChildren()) {
GroupRosterItem* child = dynamic_cast<GroupRosterItem*>(item);
if (!child) continue;
emit itemExpanded(index(child), child->isExpanded());
}
- emit layoutChanged();
+}
+
+void RosterModel::handleChildrenChanged(GroupRosterItem* /*group*/) {
+ reLayout();
}
void RosterModel::handleDataChanged(RosterItem* item) {
Q_ASSERT(item);
QModelIndex modelIndex = index(item);
if (modelIndex.isValid()) {
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
- if (group) {
- emit itemExpanded(modelIndex, group->isExpanded());
- }
emit dataChanged(modelIndex, modelIndex);
}
}
@@ -167,6 +162,12 @@ QModelIndex RosterModel::index(int row, int column, const QModelIndex& parent) c
QModelIndex RosterModel::index(RosterItem* item) const {
GroupRosterItem* parent = item->getParent();
+ /* Recursive check that it's ok to create such an item
+ Assuming there are more contacts in a group than groups in a
+ group, this could save a decent chunk of search time at startup.*/
+ if (parent != roster_->getRoot() && !index(parent).isValid()) {
+ return QModelIndex();
+ }
for (size_t i = 0; i < parent->getDisplayedChildren().size(); i++) {
if (parent->getDisplayedChildren()[i] == item) {
return createIndex(i, 0, item);