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" version = "0.1.0"
dependencies = [ dependencies = [
"bitvec", "bitvec",
"gio",
"gtk4", "gtk4",
"libadwaita", "libadwaita",
"tokio", "tokio",

View File

@ -8,7 +8,6 @@ edition = "2021"
[dependencies] [dependencies]
adw = { version = "0.7.0", package = "libadwaita", features = ["v1_4"] } adw = { version = "0.7.0", package = "libadwaita", features = ["v1_4"] }
bitvec = "1.0.1" bitvec = "1.0.1"
gio = {version = "0.20.0", features = ["v2_74"]} gtk4 = "0.9.0"
gtk4 = { version = "0.9.0"}
tokio = { version = "1.39.2", features = ["rt", "time", "rt-multi-thread", "macros", "sync"] } 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}, view_utils::signal_reduce_input_utils::{get_error_message, parse_fields},
}; };
use glib::clone;
extern crate gio;
use gio::ListStore;
use gtk::{ use gtk::{
prelude::{BoxExt, ButtonExt, Cast, CastNone, GridExt, ListItemExt, ListModelExt, SorterExt}, prelude::{BoxExt, ButtonExt, Cast, CastNone, GridExt, ListItemExt, ListModelExt},
Align, WrapMode, *, Align, WrapMode, *,
}; };
use gtk4 as gtk; use gtk4 as gtk;
@ -57,17 +51,27 @@ pub fn signal_reducing_page(wrapper: &Box) {
}) })
.collect(); .collect();
for (id, elem) in all_inputs.iter().enumerate() { let mut row_position = 0i32;
let row = id as i32 / 3;
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 calculate_button = Button::builder().label("Расчитать").build();
let result_table_headers_labels: [&str; 4] = ["f, МГц", "Xc, Ом", "Vп, мВ", "ζ"]; 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(); let model_for_events = model.clone();
for number in (0..=100).step_by(5) { 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 selection_model = NoSelection::new(Some(model));
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)
@ -95,14 +90,6 @@ 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();
@ -191,31 +178,12 @@ pub fn signal_reducing_page(wrapper: &Box) {
.vexpand(true) .vexpand(true)
.build(); .build();
calculate_button.connect_clicked(clone!( calculate_button.connect_clicked(move |_| match parse_fields(all_inputs.clone()) {
#[strong]
model_for_events,
move |_| match parse_fields(all_inputs.clone()) {
Ok(results) => { Ok(results) => {
values.set(results); values.set(results);
let new_elem = &Frequency::new(values.get().frequency); model_for_events.items_changed(0, 0, 18);
model_for_events.items_changed(18, 18, 0);
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) => { Err(error) => {
let error_kind: Option<&str> = get_error_message(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.set_text_label(error_kind);
info_bar.show_infobar(5u64); info_bar.show_infobar(5u64);
} }
} });
));
wrapper.append(&input_block); wrapper.append(&input_block);
wrapper.append(&calculate_button); wrapper.append(&calculate_button);