finished implementing selection for multiple items

Now with the help of better debugging, we can select multiple items
in the ServiceItemList.
This commit is contained in:
Chris Cochrun 2023-09-27 11:04:09 -05:00
parent 83d7249a8b
commit 39ceca74cd

View file

@ -398,7 +398,7 @@ mod service_item_model {
for service_item in
self.as_mut().service_items_mut().iter_mut()
{
// println!("service_item is deactivating {:?}", i);
debug!(deselecting = ?service_item);
service_item.selected = false;
}
if let Some(service_item) = self
@ -406,19 +406,7 @@ mod service_item_model {
.service_items_mut()
.get_mut(index as usize)
{
println!("selecting-item: {:?}", index);
println!(
"service_item_title: {:?}",
service_item.name
);
println!(
"service_item_background: {:?}",
service_item.background
);
println!(
"service_item_background_type: {:?}",
service_item.background_type
);
debug!(selecting_item = index, item = ?service_item);
service_item.selected = true;
self.as_mut().emit_data_changed(
tl,
@ -427,7 +415,7 @@ mod service_item_model {
);
// We use this signal generated by our signals enum to tell QML that
// the selected service_item has changed which is used to reposition views.
self.as_mut().emit_selected_changed();
// self.as_mut().emit_selected_changed();
true
} else {
false
@ -439,24 +427,38 @@ mod service_item_model {
mut self: Pin<&mut Self>,
final_index: i32,
) -> bool {
if let Some((current_index, current_item)) = self
// setup the roles we are using so that we can tell QML
// which properties to get again.
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.get_role(Role::SelectedRole));
if let Some(current_index) = self
.as_ref()
.service_items()
.iter()
.filter(|i| i.selected)
.enumerate()
.next()
.position(|i| i.selected == true)
{
// Here we will need to branch to get the selected items
debug!(first_item = ?current_index);
debug!(final_item = final_index);
if final_index == current_index {
false
// Let's return early to prevent needing to do anything else
if final_index == current_index as i32 {
return false;
}
let lower = final_index > current_index;
let lower = final_index > current_index as i32;
if lower {
let selected = self
let top_left = &self.as_ref().index(
current_index as i32,
0,
&QModelIndex::default(),
);
let bottom_right = &self.as_ref().index(
final_index,
0,
&QModelIndex::default(),
);
for (index, item) in self
.as_mut()
.service_items_mut()
.iter_mut()
@ -465,7 +467,46 @@ mod service_item_model {
i.0 >= current_index
&& i.0 <= final_index as usize
})
.map(|i| i.1.selected = true);
{
item.selected = true;
debug!(selected_item = ?item, index = index);
}
self.as_mut().emit_data_changed(
top_left,
bottom_right,
&vector_roles,
);
// self.as_mut().emit_selected_changed();
} else {
let top_left = &self.as_ref().index(
final_index,
0,
&QModelIndex::default(),
);
let bottom_right = &self.as_ref().index(
current_index as i32,
0,
&QModelIndex::default(),
);
for (index, item) in self
.as_mut()
.service_items_mut()
.iter_mut()
.enumerate()
.filter(|i| {
i.0 >= final_index as usize
&& i.0 <= current_index
})
{
item.selected = true;
debug!(selected_item = ?item, index = index);
}
self.as_mut().emit_data_changed(
top_left,
bottom_right,
&vector_roles,
);
// self.as_mut().emit_selected_changed();
}
true
@ -473,7 +514,38 @@ mod service_item_model {
// Here let's branch to select from the first item to the
// final item. Since we don't know which one is selected,
// assume that the first one is "selected"
error!("ERROR: couldn't find first selected item");
let top_left = &self.as_ref().index(
0,
0,
&QModelIndex::default(),
);
let bottom_right = &self.as_ref().index(
final_index,
0,
&QModelIndex::default(),
);
for (index, item) in self
.as_mut()
.service_items_mut()
.iter_mut()
.enumerate()
.filter(|i| i.0 <= final_index as usize)
{
item.selected = true;
debug!(selected_item = ?item, index = index);
}
self.as_mut().emit_data_changed(
top_left,
bottom_right,
&vector_roles,
);
// self.as_mut().emit_selected_changed();
debug!(
first_item = 0,
final_item = final_index,
"couldn't find first selected item"
);
false
}
}