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>2012-01-15 16:54:41 +0000
committerStijn Buys <ingar@osirion.org>2012-01-15 16:54:41 +0000
commit5b4f6c57feacefd121f71283d189b08880177462 (patch)
treee6522e16f01bb017cfe87b2bfb2c021284b14fdd /src/ui
parent47a0d9b5a128ef537693055da194e552476bc2f4 (diff)
Added ui::ListView::sort_reverse() method.
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/listview.cc20
-rw-r--r--src/ui/listview.h7
2 files changed, 27 insertions, 0 deletions
diff --git a/src/ui/listview.cc b/src/ui/listview.cc
index 5601bd7..99bcd3c 100644
--- a/src/ui/listview.cc
+++ b/src/ui/listview.cc
@@ -118,4 +118,24 @@ void ListView::sort()
children().sort(compare_listitems);
}
+bool compare_listitems_reverse(const Widget *first, const Widget *second)
+{
+ const ListItem *firstitem = dynamic_cast<const ListItem *>(first);
+ const ListItem *seconditem = dynamic_cast<const ListItem *>(second);
+ assert(firstitem && seconditem);
+
+ if (firstitem->sortkey() < seconditem->sortkey()) {
+ return false;
+ } else if (firstitem->sortkey() > seconditem->sortkey()) {
+ return true;
+ } else {
+ return (firstitem->sortkey().length() > seconditem->sortkey().length());
+ }
+}
+
+void ListView::sort_reverse()
+{
+ children().sort(compare_listitems_reverse);
+}
+
}
diff --git a/src/ui/listview.h b/src/ui/listview.h
index 81dd5a5..5a465f9 100644
--- a/src/ui/listview.h
+++ b/src/ui/listview.h
@@ -66,6 +66,13 @@ public:
*/
void sort();
+ /**
+ * @brief reverse sort child ListItems according to their sortkey
+ * Sort will fail with an assert error if the ListView
+ * contains any non-ListItem child widgets
+ */
+ void sort_reverse();
+
protected:
virtual void resize();