Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-11-08 23:33:49 +0000
committerStijn Buys <ingar@osirion.org>2010-11-08 23:33:49 +0000
commitbaf6ad1f48ef08187f50247115c09a3612ebeec3 (patch)
treec3c81f530c09b027f9880c8434df82a033a33323 /src/ui
parent106d0cb0cf884dd7a2920564852c001e13af1568 (diff)
added sorting of listview items
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/listitem.h9
-rw-r--r--src/ui/listview.cc18
-rw-r--r--src/ui/listview.h3
3 files changed, 30 insertions, 0 deletions
diff --git a/src/ui/listitem.h b/src/ui/listitem.h
index 3c9efea..5795917 100644
--- a/src/ui/listitem.h
+++ b/src/ui/listitem.h
@@ -35,6 +35,10 @@ public:
return listitem_item;
}
+ inline const std::string & sortkey() const {
+ return listitem_sortkey;
+ }
+
inline void set_info(const core::Info *info) {
listitem_info = info;
}
@@ -42,6 +46,10 @@ public:
inline void set_item(const core::Item *item) {
listitem_item = item;
}
+
+ inline void set_sortkey(const std::string sortkey) {
+ listitem_sortkey.assign(sortkey);
+ }
void select();
@@ -59,6 +67,7 @@ protected:
private:
const core::Info *listitem_info;
const core::Item *listitem_item;
+ std::string listitem_sortkey;
};
} // namespace ui
diff --git a/src/ui/listview.cc b/src/ui/listview.cc
index fc75806..70ecf8f 100644
--- a/src/ui/listview.cc
+++ b/src/ui/listview.cc
@@ -97,4 +97,22 @@ bool ListView::on_emit(Widget *sender, const Event event, void *data)
return false;
}
+void ListView::sort()
+{
+ // bubble sort - there's a reason for using it here
+ for (Children::iterator low = children().begin(); low != children().end(); low++) {
+ Children::iterator high = low;
+ for (high++; high != children().end(); high++) {
+ ListItem *lowitem = dynamic_cast<ListItem *>(*low);
+ ListItem *highitem = dynamic_cast<ListItem *>(*high);
+ assert(lowitem && highitem);
+ if (highitem->sortkey() < lowitem->sortkey()) {
+ Widget *t = (*low);
+ (*low) = (*high);
+ (*high) = t;
+ }
+ }
+ }
+}
+
}
diff --git a/src/ui/listview.h b/src/ui/listview.h
index a0c185b..f752ac2 100644
--- a/src/ui/listview.h
+++ b/src/ui/listview.h
@@ -59,6 +59,9 @@ public:
/// set selection to nothing
void deselect();
+ /// sort child ListItems according to their sortkey
+ void sort();
+
protected:
virtual void resize();