From baf6ad1f48ef08187f50247115c09a3612ebeec3 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 8 Nov 2010 23:33:49 +0000 Subject: added sorting of listview items --- src/ui/listview.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/ui/listview.cc') 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(*low); + ListItem *highitem = dynamic_cast(*high); + assert(lowitem && highitem); + if (highitem->sortkey() < lowitem->sortkey()) { + Widget *t = (*low); + (*low) = (*high); + (*high) = t; + } + } + } +} + } -- cgit v1.2.3