From 0aa966e8b91d04cae077cbb002cfffc06d58b884 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Tue, 17 Sep 2024 06:20:06 -0500 Subject: [PATCH] clean up some things and add an internal get_song --- src/rust/songs/song_model.rs | 81 ++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/src/rust/songs/song_model.rs b/src/rust/songs/song_model.rs index 646daf8..322bab5 100644 --- a/src/rust/songs/song_model.rs +++ b/src/rust/songs/song_model.rs @@ -80,7 +80,7 @@ pub mod song_model { fn new_song(self: Pin<&mut SongModel>) -> bool; #[qinvokable] fn get_item( - self: Pin<&mut SongModel>, + self: &SongModel, index: i32, ) -> QMap_QString_QVariant; #[qinvokable] @@ -252,7 +252,7 @@ use diesel::{delete, insert_into, prelude::*, update}; use std::collections::HashMap; use std::pin::Pin; use std::slice::Iter; -use tracing::{debug, debug_span, error, info, instrument}; +use tracing::{debug, error}; use self::song_model::{ QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32, @@ -262,18 +262,18 @@ use self::song_model::{ #[derive(Clone, Debug)] pub struct Song { id: i32, - title: String, - lyrics: String, - author: String, - ccli: String, - audio: String, - verse_order: String, - background: String, - background_type: String, - horizontal_text_alignment: String, - vertical_text_alignment: String, - font: String, - font_size: i32, + pub title: String, + pub lyrics: String, + pub author: String, + pub ccli: String, + pub audio: String, + pub verse_order: String, + pub background: String, + pub background_type: String, + pub horizontal_text_alignment: String, + pub vertical_text_alignment: String, + pub font: String, + pub font_size: i32, } impl Default for Song { @@ -939,30 +939,31 @@ impl song_model::SongModel { } } - pub fn get_item( - self: Pin<&mut Self>, - index: i32, - ) -> QMap_QString_QVariant { + pub fn get_item(&self, index: i32) -> QMap_QString_QVariant { debug!(index); let mut qvariantmap = QMap_QString_QVariant::default(); let idx = self.index(index, 0, &QModelIndex::default()); if !idx.is_valid() { return qvariantmap; } - let role_names = self.as_ref().role_names(); + let role_names = self.role_names(); let role_names_iter = role_names.iter(); if let Some(song) = self.rust().songs.get(index as usize) { debug!(?song); for i in role_names_iter { qvariantmap.insert( QString::from(&i.1.to_string()), - self.as_ref().data(&idx, *i.0), + self.data(&idx, *i.0), ); } }; qvariantmap } + pub fn get_song(&self, index: i32) -> Option<&Song> { + self.rust().songs.get(index as usize) + } + pub fn get_lyric_list( self: Pin<&mut Self>, index: i32, @@ -1208,23 +1209,23 @@ impl song_model::SongModel { } } -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() - } -} +// 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() +// } +// }