feat(sorter): add sorter model

This commit is contained in:
doryan 2024-08-12 12:16:28 +04:00
parent 3041e821a7
commit 28c569d547

View File

@ -67,7 +67,7 @@ pub fn signal_reducing_page(wrapper: &Box) {
let result_table_headers_labels: [&str; 4] = ["f, МГц", "Xc, Ом", "Vп, мВ", "ζ"]; let result_table_headers_labels: [&str; 4] = ["f, МГц", "Xc, Ом", "Vп, мВ", "ζ"];
let model = gio::ListStore::new::<Frequency>(); let model = ListStore::new::<Frequency>();
let model_for_events = model.clone(); let model_for_events = model.clone();
for number in (0..=100).step_by(5) { for number in (0..=100).step_by(5) {
@ -78,7 +78,16 @@ pub fn signal_reducing_page(wrapper: &Box) {
} }
} }
let selection_model = NoSelection::new(Some(model)); let numeric_sorter = CustomSorter::new(|a, b| {
let a = a.downcast_ref::<Frequency>().unwrap().frequency();
let b = b.downcast_ref::<Frequency>().unwrap().frequency();
a.total_cmp(&b).into()
});
let sorted_model = SortListModel::new(Some(model), Some(numeric_sorter.clone()));
let selection_model = NoSelection::new(Some(sorted_model));
let result_table = ColumnView::builder() let result_table = ColumnView::builder()
.reorderable(true) .reorderable(true)
@ -86,6 +95,14 @@ pub fn signal_reducing_page(wrapper: &Box) {
.model(&selection_model) .model(&selection_model)
.build(); .build();
result_table.connect_activate(clone!(
#[strong]
numeric_sorter,
move |_, _| {
numeric_sorter.changed(SorterChange::Different);
}
));
for label in result_table_headers_labels { for label in result_table_headers_labels {
let factory = SignalListItemFactory::new(); let factory = SignalListItemFactory::new();