summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.cpp26
-rw-r--r--Swift/QtUI/Roster/RosterModel.cpp27
-rw-r--r--Swift/QtUI/Roster/RosterModel.h2
3 files changed, 20 insertions, 35 deletions
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp
index 997c1f6..6ace3df 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.cpp
+++ b/Swift/QtUI/Roster/QtTreeWidget.cpp
@@ -100,32 +100,16 @@ void QtTreeWidget::handleCollapsed(const QModelIndex& index) {
}
void QtTreeWidget::handleModelItemExpanded(const QModelIndex& index, bool shouldExpand) {
- if (this->isExpanded(index) == shouldExpand) {
+ if (!index.isValid()) {
return;
}
- //setExpanded(index, shouldExpand);
- if (shouldExpand) {
- expand(index);
- emit expanded(index);
- } else {
- collapse(index);
- emit collapsed(index);
+ bool alreadyRight = this->isExpanded(index) == shouldExpand;
+ if (alreadyRight) {
+ return;
}
+ setExpanded(index, shouldExpand);
}
-// void QtTreeWidget::handleDataChanged(const QModelIndex& topLeft, const QModelIndex& /*bottomRight*/) {
-// //in our model, this is only thrown with topLeft == bottomRight
-// if (!topLeft.isValid()) {
-// return;
-// }
-// QtTreeWidgetItem* qtItem = static_cast<QtTreeWidgetItem*>(topLeft.internalPointer());
-// if (qtItem) {
-// setExpanded(topLeft, qtItem->isExpanded());
-// //qDebug() << "Item changed, passing expanded state to view: " << qtItem->isExpanded() << " giving an expanded state of " << isExpanded(topLeft);
-// }
-
-// }
-
void QtTreeWidget::drawBranches(QPainter*, const QRect&, const QModelIndex&) const {
}
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);
diff --git a/Swift/QtUI/Roster/RosterModel.h b/Swift/QtUI/Roster/RosterModel.h
index 10aeccd..4d9e03c 100644
--- a/Swift/QtUI/Roster/RosterModel.h
+++ b/Swift/QtUI/Roster/RosterModel.h
@@ -39,7 +39,6 @@ namespace Swift {
private:
void handleDataChanged(RosterItem* item);
void handleChildrenChanged(GroupRosterItem* item);
- void handleGroupAdded(GroupRosterItem* group);
RosterItem* getItem(const QModelIndex& index) const;
QColor intToColor(int color) const;
QColor getTextColor(RosterItem* item) const;
@@ -49,6 +48,7 @@ namespace Swift {
QString getStatusText(RosterItem* item) const;
QIcon getPresenceIcon(RosterItem* item) const;
int getChildCount(RosterItem* item) const;
+ void reLayout();
Roster* roster_;
QtTreeWidget* view_;
};