summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/Roster')
-rw-r--r--Swift/QtUI/Roster/QtTreeWidgetItem.cpp41
-rw-r--r--Swift/QtUI/Roster/QtTreeWidgetItem.h9
2 files changed, 47 insertions, 3 deletions
diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp
index 00a84f3..ae6d58d 100644
--- a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp
+++ b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp
@@ -2,6 +2,7 @@
#include "Swift/QtUI/Roster/QtTreeWidget.h"
#include <qdebug.h>
+#include <QtAlgorithms>
namespace Swift {
@@ -119,13 +120,33 @@ void QtTreeWidgetItem::removeChild(QtTreeWidgetItem* child) {
handleChanged(this);
}
+void bubbleSort(QList<QtTreeWidgetItem*>& list) {
+ for (int i = 0; i < list.size(); i++) {
+ for (int j = i + 1; j < list.size(); j++) {
+ if (*(list[j]) < *(list[j - 1])) {
+ QtTreeWidgetItem* lower = list[j];
+ list[j] = list[j - 1];
+ list[j - 1] = lower;
+ }
+ }
+ }
+}
+
void QtTreeWidgetItem::handleChanged(QtTreeWidgetItem* child) {
+ /*We don't use the much faster qStableSort because it causes changed(child) and all sorts of nasty recursion*/
+ //qStableSort(children_.begin(), children_.end(), itemLessThan);
+ bubbleSort(children_);
shownChildren_.clear();
for (int i = 0; i < children_.size(); i++) {
if (children_[i]->isShown()) {
shownChildren_.append(children_[i]);
}
}
+
+ qDebug() << "List sorted, now:";
+ for (int i = 0; i < shownChildren_.size(); i++) {
+ qDebug() << (int)(shownChildren_[i]->getStatusShow()) << ":" << shownChildren_[i]->getName();
+ }
emit changed(child);
}
@@ -179,7 +200,7 @@ QIcon QtTreeWidgetItem::getPresenceIcon() {
return QIcon(":/icons/" + iconString + ".png");
}
-bool QtTreeWidgetItem::isContact() {
+bool QtTreeWidgetItem::isContact() const {
return children_.size() == 0;
}
@@ -187,4 +208,22 @@ bool QtTreeWidgetItem::isExpanded() {
return expanded_;
}
+bool QtTreeWidgetItem::operator<(const QtTreeWidgetItem& item) const {
+ if (isContact()) {
+ if (!item.isContact()) {
+ return false;
+ }
+ return getStatusShow() == item.getStatusShow() ? getName().toLower() < item.getName().toLower() : getStatusShow() < item.getStatusShow();
+ } else {
+ if (item.isContact()) {
+ return true;
+ }
+ return getName().toLower() < item.getName().toLower();
+ }
+}
+
+//bool itemLessThan(const QtTreeWidgetItem& left, const QtTreeWidgetItem& right) {
+// return left < right;
+//}
+
}
diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.h b/Swift/QtUI/Roster/QtTreeWidgetItem.h
index 7a459d5..8b69ae2 100644
--- a/Swift/QtUI/Roster/QtTreeWidgetItem.h
+++ b/Swift/QtUI/Roster/QtTreeWidgetItem.h
@@ -48,12 +48,15 @@ class QtTreeWidgetItem : public QObject, public TreeWidgetItem {
void hide();
void show();
bool isShown();
- bool isContact();
+ bool isContact() const;
bool isExpanded();
+ QString getName() const {return displayName_;};
+ StatusShow::Type getStatusShow() const {return statusShowType_;};
QWidget* getCollapsedRosterWidget();
QWidget* getExpandedRosterWidget();
-
+ bool operator<(const QtTreeWidgetItem& item) const;
+
signals:
void changed(QtTreeWidgetItem*);
private slots:
@@ -72,6 +75,8 @@ class QtTreeWidgetItem : public QObject, public TreeWidgetItem {
StatusShow::Type statusShowType_;
};
+//bool itemLessThan(const QtTreeWidgetItem& left, const QtTreeWidgetItem& right);
+
}
#endif