library is showing items and searching is working again
This commit is contained in:
parent
b61e05a423
commit
f197099346
4 changed files with 106 additions and 43 deletions
|
@ -160,6 +160,8 @@ pub mod song_model {
|
|||
index: i32,
|
||||
updated_audio: QString,
|
||||
) -> bool;
|
||||
#[qinvokable]
|
||||
fn search(self: Pin<&mut SongModel>, search_term: QString);
|
||||
}
|
||||
|
||||
impl cxx_qt::Threading for SongModel {}
|
||||
|
@ -249,7 +251,8 @@ use diesel::sqlite::SqliteConnection;
|
|||
use diesel::{delete, insert_into, prelude::*, update};
|
||||
use std::collections::HashMap;
|
||||
use std::pin::Pin;
|
||||
use tracing::{debug, error};
|
||||
use std::slice::Iter;
|
||||
use tracing::{debug, debug_span, error, info, instrument};
|
||||
|
||||
use self::song_model::{
|
||||
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
|
||||
|
@ -290,6 +293,7 @@ pub struct SongModelRust {
|
|||
count: i32,
|
||||
highest_id: i32,
|
||||
songs: Vec<Song>,
|
||||
inner_songs: Vec<Song>,
|
||||
}
|
||||
|
||||
impl song_model::SongModel {
|
||||
|
@ -351,6 +355,7 @@ impl song_model::SongModel {
|
|||
println!("--------------------------------------");
|
||||
println!("{:?}", self.as_mut().songs);
|
||||
println!("--------------------------------------");
|
||||
self.as_mut().rust_mut().inner_songs = self.songs.clone();
|
||||
}
|
||||
|
||||
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) -> bool {
|
||||
|
@ -1053,6 +1058,25 @@ impl song_model::SongModel {
|
|||
QStringList::from(&lyric_list)
|
||||
}
|
||||
|
||||
fn search(mut self: Pin<&mut Self>, search_term: QString) {
|
||||
let search_term = search_term.to_string().to_lowercase();
|
||||
debug!(search_term);
|
||||
let searched_songs: Vec<Song> = self
|
||||
.inner_songs
|
||||
.iter()
|
||||
.filter(|song| {
|
||||
song.title.to_lowercase().contains(&search_term)
|
||||
})
|
||||
.cloned()
|
||||
.collect();
|
||||
debug!(search = ?&searched_songs);
|
||||
unsafe {
|
||||
self.as_mut().begin_reset_model();
|
||||
self.as_mut().rust_mut().songs = searched_songs;
|
||||
self.as_mut().end_reset_model();
|
||||
}
|
||||
}
|
||||
|
||||
fn get_role(&self, role: SongRoles) -> i32 {
|
||||
match role {
|
||||
SongRoles::Id => 0,
|
||||
|
@ -1179,3 +1203,24 @@ impl song_model::SongModel {
|
|||
cnt
|
||||
}
|
||||
}
|
||||
|
||||
impl song_model::SongRoles {
|
||||
fn iter() -> Iter<'static, SongRoles> {
|
||||
static SONGROLES: [SongRoles; 13] = [
|
||||
SongRoles::Id,
|
||||
SongRoles::Title,
|
||||
SongRoles::Lyrics,
|
||||
SongRoles::Author,
|
||||
SongRoles::Ccli,
|
||||
SongRoles::Audio,
|
||||
SongRoles::VerseOrder,
|
||||
SongRoles::Background,
|
||||
SongRoles::BackgroundType,
|
||||
SongRoles::HorizontalTextAlignment,
|
||||
SongRoles::VerticalTextAlignment,
|
||||
SongRoles::Font,
|
||||
SongRoles::FontSize,
|
||||
];
|
||||
SONGROLES.iter()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue