Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
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();