delete all selected items
This commit is contained in:
parent
dead3a16bc
commit
3d09157be8
2 changed files with 25 additions and 19 deletions
|
@ -288,7 +288,7 @@ Item {
|
||||||
}
|
}
|
||||||
Kirigami.Action {
|
Kirigami.Action {
|
||||||
text: "Delete"
|
text: "Delete"
|
||||||
onTriggered: removeItem(index)
|
onTriggered: removeItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
Controls.MenuSeparator {}
|
Controls.MenuSeparator {}
|
||||||
|
|
|
@ -113,7 +113,7 @@ mod service_item_model {
|
||||||
fn clear(self: Pin<&mut ServiceItemModel>);
|
fn clear(self: Pin<&mut ServiceItemModel>);
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
fn remove_item(self: Pin<&mut ServiceItemModel>, index: i32);
|
fn remove_items(self: Pin<&mut ServiceItemModel>);
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
fn add_item(
|
fn add_item(
|
||||||
|
@ -411,26 +411,32 @@ impl service_item_model::ServiceItemModel {
|
||||||
self.as_mut().cleared();
|
self.as_mut().cleared();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) {
|
pub fn remove_items(mut self: Pin<&mut Self>) {
|
||||||
if index < 0 || (index as usize) >= self.service_items.len() {
|
let mut indices = vec![];
|
||||||
return;
|
let mut items = self.service_items.clone();
|
||||||
|
for (index, item) in items.iter_mut().enumerate().filter(|(y, x)| x.selected) {
|
||||||
|
let index = index as i32;
|
||||||
|
indices.push(index);
|
||||||
}
|
}
|
||||||
|
debug!(vec = ?indices);
|
||||||
|
for index in indices.iter().rev() {
|
||||||
|
debug!(index);
|
||||||
unsafe {
|
unsafe {
|
||||||
self.as_mut().begin_remove_rows(
|
self.as_mut().begin_remove_rows(
|
||||||
&QModelIndex::default(),
|
&QModelIndex::default(),
|
||||||
index,
|
*index,
|
||||||
index,
|
*index,
|
||||||
);
|
);
|
||||||
self.as_mut()
|
self.as_mut()
|
||||||
.rust_mut()
|
.rust_mut()
|
||||||
.service_items
|
.service_items
|
||||||
.remove(index as usize);
|
.remove(*index as usize);
|
||||||
self.as_mut().end_remove_rows();
|
self.as_mut().end_remove_rows();
|
||||||
}
|
}
|
||||||
let item = self.as_mut().get_item(index);
|
let item = self.as_mut().get_item(*index);
|
||||||
self.as_mut().item_removed(&index, &item);
|
self.as_mut().item_removed(&index, &item);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_item(
|
pub fn add_item(
|
||||||
mut self: Pin<&mut Self>,
|
mut self: Pin<&mut Self>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue