1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: MIT |
3 | |
4 | #include "gallery.h" |
5 | |
6 | #ifdef HAVE_GETTEXT |
7 | # include <locale> |
8 | # include <libintl.h> |
9 | #endif |
10 | |
11 | int main() |
12 | { |
13 | #ifdef HAVE_GETTEXT |
14 | bindtextdomain("gallery" , SRC_DIR "/lang/" ); |
15 | std::locale::global(std::locale("" )); |
16 | #endif |
17 | |
18 | auto demo = App::create(); |
19 | |
20 | auto row_data = std::make_shared< |
21 | slint::VectorModel<std::shared_ptr<slint::Model<slint::StandardListViewItem>>>>(); |
22 | |
23 | for (int r = 1; r < 101; r++) { |
24 | |
25 | auto items = std::make_shared<slint::VectorModel<slint::StandardListViewItem>>(); |
26 | |
27 | for (int c = 1; c < 5; c++) { |
28 | slint::SharedString text("item" ); |
29 | text = text + slint::SharedString::from_number(c) + slint::SharedString("." ) |
30 | + slint::SharedString::from_number(r); |
31 | items->push_back(slint::StandardListViewItem { text }); |
32 | } |
33 | |
34 | row_data->push_back(items); |
35 | } |
36 | |
37 | demo->global<TableViewPageAdapter>().set_row_data(row_data); |
38 | |
39 | demo->global<TableViewPageAdapter>().on_sort_ascending([row_data, |
40 | demo = slint::ComponentWeakHandle( |
41 | demo)](int index) { |
42 | auto demo_lock = demo.lock(); |
43 | (*demo_lock) |
44 | ->global<TableViewPageAdapter>() |
45 | .set_row_data(std::make_shared<slint::SortModel< |
46 | std::shared_ptr<slint::Model<slint::StandardListViewItem>>>>( |
47 | row_data, [index](auto lhs, auto rhs) { |
48 | auto c_lhs = lhs->row_data(index); |
49 | auto c_rhs = rhs->row_data(index); |
50 | |
51 | return c_lhs->text < c_rhs->text; |
52 | })); |
53 | }); |
54 | |
55 | demo->global<TableViewPageAdapter>().on_sort_descending([row_data, |
56 | demo = slint::ComponentWeakHandle( |
57 | demo)](int index) { |
58 | auto demo_lock = demo.lock(); |
59 | (*demo_lock)->global<TableViewPageAdapter>().set_row_data(row_data); |
60 | |
61 | (*demo_lock) |
62 | ->global<TableViewPageAdapter>() |
63 | .set_row_data(std::make_shared<slint::SortModel< |
64 | std::shared_ptr<slint::Model<slint::StandardListViewItem>>>>( |
65 | (*demo_lock)->global<TableViewPageAdapter>().get_row_data(), |
66 | [index](auto lhs, auto rhs) { |
67 | auto c_lhs = lhs->row_data(index); |
68 | auto c_rhs = rhs->row_data(index); |
69 | |
70 | return c_rhs->text < c_lhs->text; |
71 | })); |
72 | }); |
73 | |
74 | demo->run(); |
75 | } |
76 | |