Compare commits

..

No commits in common. "24b60e74a03c96c4097d65ba422437a5a7b360c5" and "0d2987a9686b168ba20de76f53422ff301fb1132" have entirely different histories.

3 changed files with 29 additions and 64 deletions

1
Cargo.lock generated
View File

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

View File

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

View File

@ -14,14 +14,8 @@ 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, SorterExt},
prelude::{BoxExt, ButtonExt, Cast, CastNone, GridExt, ListItemExt, ListModelExt},
Align, WrapMode, *,
};
use gtk4 as gtk;
@ -57,17 +51,27 @@ pub fn signal_reducing_page(wrapper: &Box) {
})
.collect();
for (id, elem) in all_inputs.iter().enumerate() {
let row = id as i32 / 3;
let mut row_position = 0i32;
input_block.attach(elem.get(), (id as i32) - (3 * row), row, 1, 1);
for (id, elem) in all_inputs.iter().enumerate() {
if id % 3 == 0 {
row_position += 1;
}
input_block.attach(
elem.clone().get(),
(id as i32) - (3 * row_position),
row_position,
1,
1,
);
}
let calculate_button = Button::builder().label("Расчитать").build();
let result_table_headers_labels: [&str; 4] = ["f, МГц", "Xc, Ом", "Vп, мВ", "ζ"];
let model = ListStore::new::<Frequency>();
let model = gio::ListStore::new::<Frequency>();
let model_for_events = model.clone();
for number in (0..=100).step_by(5) {
@ -78,16 +82,7 @@ pub fn signal_reducing_page(wrapper: &Box) {
}
}
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 selection_model = NoSelection::new(Some(model));
let result_table = ColumnView::builder()
.reorderable(true)
@ -95,14 +90,6 @@ 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();
@ -191,31 +178,12 @@ pub fn signal_reducing_page(wrapper: &Box) {
.vexpand(true)
.build();
calculate_button.connect_clicked(clone!(
#[strong]
model_for_events,
move |_| match parse_fields(all_inputs.clone()) {
calculate_button.connect_clicked(move |_| match parse_fields(all_inputs.clone()) {
Ok(results) => {
values.set(results);
let new_elem = &Frequency::new(values.get().frequency);
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);
}
}
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);
@ -223,8 +191,7 @@ pub fn signal_reducing_page(wrapper: &Box) {
info_bar.set_text_label(error_kind);
info_bar.show_infobar(5u64);
}
}
));
});
wrapper.append(&input_block);
wrapper.append(&calculate_button);