Compare commits

..

5 Commits

3 changed files with 62 additions and 27 deletions

1
Cargo.lock generated
View File

@ -470,6 +470,7 @@ name = "laboratory_works"
version = "0.1.0"
dependencies = [
"bitvec",
"gio",
"gtk4",
"libadwaita",
"tokio",

View File

@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
adw = { version = "0.7.0", package = "libadwaita", features = ["v1_4"] }
bitvec = "1.0.1"
gtk4 = "0.9.0"
gio = {version = "0.20.0", features = ["v2_74"]}
gtk4 = { version = "0.9.0"}
tokio = { version = "1.39.2", features = ["rt", "time", "rt-multi-thread", "macros", "sync"] }

View File

@ -14,8 +14,14 @@ use crate::{
view_utils::signal_reduce_input_utils::{get_error_message, parse_fields},
};
use glib::clone;
extern crate gio;
use gio::ListStore;
use gtk::{
prelude::{BoxExt, ButtonExt, Cast, CastNone, GridExt, ListItemExt, ListModelExt},
prelude::{BoxExt, ButtonExt, Cast, CastNone, GridExt, ListItemExt, ListModelExt, SorterExt},
Align, WrapMode, *,
};
use gtk4 as gtk;
@ -51,27 +57,17 @@ pub fn signal_reducing_page(wrapper: &Box) {
})
.collect();
let mut row_position = 0i32;
for (id, elem) in all_inputs.iter().enumerate() {
if id % 3 == 0 {
row_position += 1;
}
let row = id as i32 / 3;
input_block.attach(
elem.clone().get(),
(id as i32) - (3 * row_position),
row_position,
1,
1,
);
input_block.attach(elem.get(), (id as i32) - (3 * row), row, 1, 1);
}
let calculate_button = Button::builder().label("Расчитать").build();
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();
for number in (0..=100).step_by(5) {
@ -82,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()
.reorderable(true)
@ -90,6 +95,14 @@ pub fn signal_reducing_page(wrapper: &Box) {
.model(&selection_model)
.build();
result_table.connect_activate(clone!(
#[strong]
numeric_sorter,
move |_, _| {
numeric_sorter.changed(SorterChange::Different);
}
));
for label in result_table_headers_labels {
let factory = SignalListItemFactory::new();
@ -178,20 +191,40 @@ pub fn signal_reducing_page(wrapper: &Box) {
.vexpand(true)
.build();
calculate_button.connect_clicked(move |_| match parse_fields(all_inputs.clone()) {
Ok(results) => {
values.set(results);
calculate_button.connect_clicked(clone!(
#[strong]
model_for_events,
move |_| match parse_fields(all_inputs.clone()) {
Ok(results) => {
values.set(results);
model_for_events.items_changed(0, 0, 18);
model_for_events.items_changed(18, 18, 0);
}
Err(error) => {
let error_kind: Option<&str> = get_error_message(error);
let new_elem = &Frequency::new(values.get().frequency);
info_bar.set_text_label(error_kind);
info_bar.show_infobar(5u64);
let exist_elem_pos = model_for_events.find_with_equal_func(|elem| {
elem.downcast_ref::<Frequency>().unwrap().frequency() == new_elem.frequency()
});
match exist_elem_pos {
Some(_) => {
info_bar.set_text_label(Some("Данная частота уже была задана."));
info_bar.show_infobar(5u64);
}
None => {
model_for_events.append(&Frequency::new(values.get().frequency));
model_for_events.items_changed(0, 0, 1);
model_for_events.items_changed(1, 1, 0);
}
}
}
Err(error) => {
let error_kind: Option<&str> = get_error_message(error);
info_bar.set_text_label(error_kind);
info_bar.show_infobar(5u64);
}
}
});
));
wrapper.append(&input_block);
wrapper.append(&calculate_button);