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
|
@ -75,6 +75,8 @@ mod image_model {
|
||||||
self: Pin<&mut ImageModel>,
|
self: Pin<&mut ImageModel>,
|
||||||
index: i32,
|
index: i32,
|
||||||
) -> QMap_QString_QVariant;
|
) -> QMap_QString_QVariant;
|
||||||
|
#[qinvokable]
|
||||||
|
fn search(self: Pin<&mut ImageModel>, search_term: QString);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl cxx_qt::Threading for ImageModel {}
|
impl cxx_qt::Threading for ImageModel {}
|
||||||
|
@ -161,6 +163,7 @@ use diesel::sqlite::SqliteConnection;
|
||||||
use diesel::{delete, insert_into, prelude::*, update};
|
use diesel::{delete, insert_into, prelude::*, update};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
use tracing::debug;
|
||||||
|
|
||||||
use self::image_model::{
|
use self::image_model::{
|
||||||
ImageRoles, QHash_i32_QByteArray, QMap_QString_QVariant,
|
ImageRoles, QHash_i32_QByteArray, QMap_QString_QVariant,
|
||||||
|
@ -171,8 +174,8 @@ use self::image_model::{
|
||||||
/// Idk what this is but it's cool
|
/// Idk what this is but it's cool
|
||||||
pub struct Image {
|
pub struct Image {
|
||||||
id: i32,
|
id: i32,
|
||||||
title: QString,
|
title: String,
|
||||||
path: QString,
|
path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
|
@ -180,6 +183,7 @@ pub struct ImageModelRust {
|
||||||
count: i32,
|
count: i32,
|
||||||
highest_id: i32,
|
highest_id: i32,
|
||||||
images: Vec<Image>,
|
images: Vec<Image>,
|
||||||
|
inner_images: Vec<Image>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl image_model::ImageModel {
|
impl image_model::ImageModel {
|
||||||
|
@ -211,8 +215,8 @@ impl image_model::ImageModel {
|
||||||
|
|
||||||
let img = self::Image {
|
let img = self::Image {
|
||||||
id: image.id,
|
id: image.id,
|
||||||
title: QString::from(&image.title),
|
title: image.title,
|
||||||
path: QString::from(&image.path),
|
path: image.path,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.as_mut().add_image(img);
|
self.as_mut().add_image(img);
|
||||||
|
@ -245,6 +249,10 @@ impl image_model::ImageModel {
|
||||||
.rust_mut()
|
.rust_mut()
|
||||||
.images
|
.images
|
||||||
.remove(index as usize);
|
.remove(index as usize);
|
||||||
|
self.as_mut()
|
||||||
|
.rust_mut()
|
||||||
|
.inner_images
|
||||||
|
.remove(index as usize);
|
||||||
self.as_mut().end_remove_rows();
|
self.as_mut().end_remove_rows();
|
||||||
}
|
}
|
||||||
println!("removed-item-at-index: {:?}", image_id);
|
println!("removed-item-at-index: {:?}", image_id);
|
||||||
|
@ -297,8 +305,8 @@ impl image_model::ImageModel {
|
||||||
// println!("{:?}", db);
|
// println!("{:?}", db);
|
||||||
let image = self::Image {
|
let image = self::Image {
|
||||||
id: image_id,
|
id: image_id,
|
||||||
title: image_title.clone(),
|
title: image_title.clone().to_string(),
|
||||||
path: image_path.clone(),
|
path: image_path.clone().to_string(),
|
||||||
};
|
};
|
||||||
println!("{:?}", image);
|
println!("{:?}", image);
|
||||||
|
|
||||||
|
@ -335,7 +343,8 @@ impl image_model::ImageModel {
|
||||||
index,
|
index,
|
||||||
index,
|
index,
|
||||||
);
|
);
|
||||||
self.as_mut().rust_mut().images.push(image);
|
self.as_mut().rust_mut().images.push(image.clone());
|
||||||
|
self.as_mut().rust_mut().inner_images.push(image);
|
||||||
self.as_mut().end_insert_rows();
|
self.as_mut().end_insert_rows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -364,7 +373,7 @@ impl image_model::ImageModel {
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.filter(|x| x.id == index)
|
.filter(|x| x.id == index)
|
||||||
{
|
{
|
||||||
image.title = updated_title.clone();
|
image.title = updated_title.clone().to_string();
|
||||||
println!("rust-title: {:?}", image.title);
|
println!("rust-title: {:?}", image.title);
|
||||||
}
|
}
|
||||||
self.as_mut().data_changed(
|
self.as_mut().data_changed(
|
||||||
|
@ -402,7 +411,8 @@ impl image_model::ImageModel {
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.filter(|x| x.id == index)
|
.filter(|x| x.id == index)
|
||||||
{
|
{
|
||||||
image.path = updated_file_path.clone();
|
image.path =
|
||||||
|
updated_file_path.clone().to_string();
|
||||||
println!("rust-title: {:?}", image.path);
|
println!("rust-title: {:?}", image.path);
|
||||||
}
|
}
|
||||||
self.as_mut().data_changed(
|
self.as_mut().data_changed(
|
||||||
|
@ -439,6 +449,25 @@ impl image_model::ImageModel {
|
||||||
qvariantmap
|
qvariantmap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn search(mut self: Pin<&mut Self>, search_term: QString) {
|
||||||
|
let search_term = search_term.to_string().to_lowercase();
|
||||||
|
debug!(search_term);
|
||||||
|
let searched_images: Vec<Image> = self
|
||||||
|
.inner_images
|
||||||
|
.iter()
|
||||||
|
.filter(|image| {
|
||||||
|
image.title.to_lowercase().contains(&search_term)
|
||||||
|
})
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
debug!(search = ?&searched_images);
|
||||||
|
unsafe {
|
||||||
|
self.as_mut().begin_reset_model();
|
||||||
|
self.as_mut().rust_mut().images = searched_images;
|
||||||
|
self.as_mut().end_reset_model();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn get_role_id(&self, role: ImageRoles) -> i32 {
|
fn get_role_id(&self, role: ImageRoles) -> i32 {
|
||||||
match role {
|
match role {
|
||||||
ImageRoles::Id => 0,
|
ImageRoles::Id => 0,
|
||||||
|
@ -456,8 +485,12 @@ impl image_model::ImageModel {
|
||||||
if let Some(image) = self.images.get(index.row() as usize) {
|
if let Some(image) = self.images.get(index.row() as usize) {
|
||||||
return match role {
|
return match role {
|
||||||
ImageRoles::Id => QVariant::from(&image.id),
|
ImageRoles::Id => QVariant::from(&image.id),
|
||||||
ImageRoles::Title => QVariant::from(&image.title),
|
ImageRoles::Title => {
|
||||||
ImageRoles::Path => QVariant::from(&image.path),
|
QVariant::from(&QString::from(&image.title))
|
||||||
|
}
|
||||||
|
ImageRoles::Path => {
|
||||||
|
QVariant::from(&QString::from(&image.path))
|
||||||
|
}
|
||||||
_ => QVariant::default(),
|
_ => QVariant::default(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,11 @@ mod presentation_model {
|
||||||
index: i32,
|
index: i32,
|
||||||
updated_page_count: i32,
|
updated_page_count: i32,
|
||||||
) -> bool;
|
) -> bool;
|
||||||
|
#[qinvokable]
|
||||||
|
fn search(
|
||||||
|
self: Pin<&mut PresentationModel>,
|
||||||
|
search_term: QString,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl cxx_qt::Threading for PresentationModel {}
|
impl cxx_qt::Threading for PresentationModel {}
|
||||||
|
@ -205,6 +210,7 @@ pub struct PresentationModelRust {
|
||||||
count: i32,
|
count: i32,
|
||||||
highest_id: i32,
|
highest_id: i32,
|
||||||
presentations: Vec<Presentation>,
|
presentations: Vec<Presentation>,
|
||||||
|
inner_presentations: Vec<Presentation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl presentation_model::PresentationModel {
|
impl presentation_model::PresentationModel {
|
||||||
|
@ -279,6 +285,10 @@ impl presentation_model::PresentationModel {
|
||||||
.rust_mut()
|
.rust_mut()
|
||||||
.presentations
|
.presentations
|
||||||
.remove(index as usize);
|
.remove(index as usize);
|
||||||
|
self.as_mut()
|
||||||
|
.rust_mut()
|
||||||
|
.inner_presentations
|
||||||
|
.remove(index as usize);
|
||||||
self.as_mut().end_remove_rows();
|
self.as_mut().end_remove_rows();
|
||||||
}
|
}
|
||||||
println!(
|
println!(
|
||||||
|
@ -410,7 +420,14 @@ impl presentation_model::PresentationModel {
|
||||||
index,
|
index,
|
||||||
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();
|
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 {
|
fn get_role(&self, role: PresRoles) -> i32 {
|
||||||
match role {
|
match role {
|
||||||
PresRoles::Id => 0,
|
PresRoles::Id => 0,
|
||||||
|
|
|
@ -355,7 +355,6 @@ impl song_model::SongModel {
|
||||||
println!("--------------------------------------");
|
println!("--------------------------------------");
|
||||||
println!("{:?}", self.as_mut().songs);
|
println!("{:?}", self.as_mut().songs);
|
||||||
println!("--------------------------------------");
|
println!("--------------------------------------");
|
||||||
self.as_mut().rust_mut().inner_songs = self.songs.clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) -> bool {
|
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) -> bool {
|
||||||
|
@ -380,6 +379,10 @@ impl song_model::SongModel {
|
||||||
.rust_mut()
|
.rust_mut()
|
||||||
.songs
|
.songs
|
||||||
.remove(index as usize);
|
.remove(index as usize);
|
||||||
|
self.as_mut()
|
||||||
|
.rust_mut()
|
||||||
|
.inner_songs
|
||||||
|
.remove(index as usize);
|
||||||
self.as_mut().end_remove_rows();
|
self.as_mut().end_remove_rows();
|
||||||
}
|
}
|
||||||
println!("removed-item-at-index: {:?}", song_id);
|
println!("removed-item-at-index: {:?}", song_id);
|
||||||
|
@ -464,7 +467,8 @@ impl song_model::SongModel {
|
||||||
index,
|
index,
|
||||||
index,
|
index,
|
||||||
);
|
);
|
||||||
self.as_mut().rust_mut().songs.push(song);
|
self.as_mut().rust_mut().songs.push(song.clone());
|
||||||
|
self.as_mut().rust_mut().inner_songs.push(song);
|
||||||
self.as_mut().end_insert_rows();
|
self.as_mut().end_insert_rows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,8 @@ mod video_model {
|
||||||
index: i32,
|
index: i32,
|
||||||
updated_end_time: f32,
|
updated_end_time: f32,
|
||||||
) -> bool;
|
) -> bool;
|
||||||
|
#[qinvokable]
|
||||||
|
fn search(self: Pin<&mut VideoModel>, search_term: QString);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl cxx_qt::Threading for VideoModel {}
|
impl cxx_qt::Threading for VideoModel {}
|
||||||
|
@ -185,6 +187,7 @@ use diesel::sqlite::SqliteConnection;
|
||||||
use diesel::{delete, insert_into, prelude::*, update};
|
use diesel::{delete, insert_into, prelude::*, update};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
use tracing::debug;
|
||||||
|
|
||||||
use self::video_model::{
|
use self::video_model::{
|
||||||
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
|
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
|
||||||
|
@ -206,6 +209,7 @@ pub struct VideoModelRust {
|
||||||
count: i32,
|
count: i32,
|
||||||
highest_id: i32,
|
highest_id: i32,
|
||||||
videos: Vec<self::Video>,
|
videos: Vec<self::Video>,
|
||||||
|
inner_videos: Vec<self::Video>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl video_model::VideoModel {
|
impl video_model::VideoModel {
|
||||||
|
@ -275,6 +279,10 @@ impl video_model::VideoModel {
|
||||||
.rust_mut()
|
.rust_mut()
|
||||||
.videos
|
.videos
|
||||||
.remove(index as usize);
|
.remove(index as usize);
|
||||||
|
self.as_mut()
|
||||||
|
.rust_mut()
|
||||||
|
.inner_videos
|
||||||
|
.remove(index as usize);
|
||||||
self.as_mut().end_remove_rows();
|
self.as_mut().end_remove_rows();
|
||||||
}
|
}
|
||||||
println!("removed-item-at-index: {:?}", video_id);
|
println!("removed-item-at-index: {:?}", video_id);
|
||||||
|
@ -373,7 +381,8 @@ impl video_model::VideoModel {
|
||||||
index,
|
index,
|
||||||
index,
|
index,
|
||||||
);
|
);
|
||||||
self.as_mut().rust_mut().videos.push(video);
|
self.as_mut().rust_mut().videos.push(video.clone());
|
||||||
|
self.as_mut().rust_mut().inner_videos.push(video);
|
||||||
self.as_mut().end_insert_rows();
|
self.as_mut().end_insert_rows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -608,6 +617,25 @@ impl video_model::VideoModel {
|
||||||
Err(_e) => false,
|
Err(_e) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn search(mut self: Pin<&mut Self>, search_term: QString) {
|
||||||
|
let search_term = search_term.to_string().to_lowercase();
|
||||||
|
debug!(search_term);
|
||||||
|
let searched_videos: Vec<Video> = self
|
||||||
|
.inner_videos
|
||||||
|
.iter()
|
||||||
|
.filter(|video| {
|
||||||
|
video.title.to_lowercase().contains(&search_term)
|
||||||
|
})
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
debug!(search = ?&searched_videos);
|
||||||
|
unsafe {
|
||||||
|
self.as_mut().begin_reset_model();
|
||||||
|
self.as_mut().rust_mut().videos = searched_videos;
|
||||||
|
self.as_mut().end_reset_model();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// QAbstractListModel implementation
|
// QAbstractListModel implementation
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue