diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/listview.cc | 20 | ||||
-rw-r--r-- | src/ui/listview.h | 7 |
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(); |