search function for all models... however...
There is some sort of problem. Somehow I sometimes get a signal 11 SEGV_MAPERR error and then it segfaults. *sigh*... So this function needs some help yet.
This commit is contained in:
parent
114ffb5bdc
commit
5b0462db65
4 changed files with 120 additions and 15 deletions
|
@ -90,6 +90,11 @@ mod presentation_model {
|
|||
index: i32,
|
||||
updated_page_count: i32,
|
||||
) -> bool;
|
||||
#[qinvokable]
|
||||
fn search(
|
||||
self: Pin<&mut PresentationModel>,
|
||||
search_term: QString,
|
||||
);
|
||||
}
|
||||
|
||||
impl cxx_qt::Threading for PresentationModel {}
|
||||
|
@ -205,6 +210,7 @@ pub struct PresentationModelRust {
|
|||
count: i32,
|
||||
highest_id: i32,
|
||||
presentations: Vec<Presentation>,
|
||||
inner_presentations: Vec<Presentation>,
|
||||
}
|
||||
|
||||
impl presentation_model::PresentationModel {
|
||||
|
@ -279,6 +285,10 @@ impl presentation_model::PresentationModel {
|
|||
.rust_mut()
|
||||
.presentations
|
||||
.remove(index as usize);
|
||||
self.as_mut()
|
||||
.rust_mut()
|
||||
.inner_presentations
|
||||
.remove(index as usize);
|
||||
self.as_mut().end_remove_rows();
|
||||
}
|
||||
println!(
|
||||
|
@ -410,7 +420,14 @@ impl presentation_model::PresentationModel {
|
|||
index,
|
||||
index,
|
||||
);
|
||||
self.as_mut().rust_mut().presentations.push(presentation);
|
||||
self.as_mut()
|
||||
.rust_mut()
|
||||
.presentations
|
||||
.push(presentation.clone());
|
||||
self.as_mut()
|
||||
.rust_mut()
|
||||
.inner_presentations
|
||||
.push(presentation);
|
||||
self.as_mut().end_insert_rows();
|
||||
}
|
||||
}
|
||||
|
@ -568,6 +585,29 @@ impl presentation_model::PresentationModel {
|
|||
}
|
||||
}
|
||||
|
||||
fn search(mut self: Pin<&mut Self>, search_term: QString) {
|
||||
let search_term = search_term.to_string().to_lowercase();
|
||||
debug!(search_term);
|
||||
let searched_presentations: Vec<Presentation> = self
|
||||
.inner_presentations
|
||||
.iter()
|
||||
.filter(|presentation| {
|
||||
presentation
|
||||
.title
|
||||
.to_lowercase()
|
||||
.contains(&search_term)
|
||||
})
|
||||
.cloned()
|
||||
.collect();
|
||||
debug!(search = ?&searched_presentations);
|
||||
unsafe {
|
||||
self.as_mut().begin_reset_model();
|
||||
self.as_mut().rust_mut().presentations =
|
||||
searched_presentations;
|
||||
self.as_mut().end_reset_model();
|
||||
}
|
||||
}
|
||||
|
||||
fn get_role(&self, role: PresRoles) -> i32 {
|
||||
match role {
|
||||
PresRoles::Id => 0,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue