summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-08-20 16:03:24 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-08-20 16:03:24 (GMT)
commit84835e9ed81d215511a0393d371ff9bf3ddf4953 (patch)
tree2c676478be904edbe1a6dc3c6f82c79d20edb1bf /Swift/QtUI
parent54859f64709f297b97bb48367759479d58f991fe (diff)
downloadswift-84835e9ed81d215511a0393d371ff9bf3ddf4953.zip
swift-84835e9ed81d215511a0393d371ff9bf3ddf4953.tar.bz2
Sort bookmark list.
Resolves: #454
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/ChatList/ChatListGroupItem.h10
-rw-r--r--Swift/QtUI/ChatList/ChatListItem.h3
-rw-r--r--Swift/QtUI/ChatList/ChatListMUCItem.cpp2
-rw-r--r--Swift/QtUI/ChatList/ChatListMUCItem.h2
4 files changed, 12 insertions, 5 deletions
diff --git a/Swift/QtUI/ChatList/ChatListGroupItem.h b/Swift/QtUI/ChatList/ChatListGroupItem.h
index 2fc99df..389410a 100644
--- a/Swift/QtUI/ChatList/ChatListGroupItem.h
+++ b/Swift/QtUI/ChatList/ChatListGroupItem.h
@@ -14,13 +14,19 @@ namespace Swift {
class ChatListGroupItem : public ChatListItem {
public:
ChatListGroupItem(const QString& name, ChatListGroupItem* parent) : ChatListItem(parent), name_(name) {};
- void addItem(ChatListItem* item) {items_.push_back(item);};
+ void addItem(ChatListItem* item) {items_.push_back(item); qStableSort(items_.begin(), items_.end(), pointerItemLessThan);};
void remove(int index) {items_.removeAt(index);};
int rowCount() {return items_.size();};
ChatListItem* item(int i) {return items_[i];};
int row(ChatListItem* item) {return items_.indexOf(item);};
- QVariant data(int role) {return (role == Qt::DisplayRole) ? name_ : QVariant();};
+ QVariant data(int role) const {return (role == Qt::DisplayRole) ? name_ : QVariant();};
private:
+ static bool pointerItemLessThan(const ChatListItem* first, const ChatListItem* second) {
+ QString myName = first->data(Qt::DisplayRole).toString().toLower();
+ QString theirName = second->data(Qt::DisplayRole).toString().toLower();
+ return myName < theirName;
+ }
+
QString name_;
QList<ChatListItem*> items_;
};
diff --git a/Swift/QtUI/ChatList/ChatListItem.h b/Swift/QtUI/ChatList/ChatListItem.h
index 57a85da..e7be614 100644
--- a/Swift/QtUI/ChatList/ChatListItem.h
+++ b/Swift/QtUI/ChatList/ChatListItem.h
@@ -7,6 +7,7 @@
#pragma once
#include <QVariant>
+#include <qdebug.h>
namespace Swift {
class ChatListGroupItem;
@@ -16,7 +17,7 @@ namespace Swift {
virtual ~ChatListItem() {}
ChatListGroupItem* parent() {return parent_;};
- virtual QVariant data(int role) = 0;
+ virtual QVariant data(int role) const = 0;
private:
ChatListGroupItem* parent_;
diff --git a/Swift/QtUI/ChatList/ChatListMUCItem.cpp b/Swift/QtUI/ChatList/ChatListMUCItem.cpp
index 370956e..e374ed5 100644
--- a/Swift/QtUI/ChatList/ChatListMUCItem.cpp
+++ b/Swift/QtUI/ChatList/ChatListMUCItem.cpp
@@ -17,7 +17,7 @@ const MUCBookmark& ChatListMUCItem::getBookmark() {
return bookmark_;
}
-QVariant ChatListMUCItem::data(int role) {
+QVariant ChatListMUCItem::data(int role) const {
switch (role) {
case Qt::DisplayRole: return P2QSTRING(bookmark_.getName());
case DetailTextRole: return P2QSTRING(bookmark_.getRoom().toString());
diff --git a/Swift/QtUI/ChatList/ChatListMUCItem.h b/Swift/QtUI/ChatList/ChatListMUCItem.h
index f5e3242..068f5d6 100644
--- a/Swift/QtUI/ChatList/ChatListMUCItem.h
+++ b/Swift/QtUI/ChatList/ChatListMUCItem.h
@@ -25,7 +25,7 @@ namespace Swift {
public:
ChatListMUCItem(const MUCBookmark& bookmark, ChatListGroupItem* parent);
const MUCBookmark& getBookmark();
- QVariant data(int role);
+ QVariant data(int role) const;
private:
MUCBookmark bookmark_;
QList<ChatListItem*> items_;