From e1cb837249977ce0c430a98e7fc80f3bb2aedd06 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Tue, 17 Sep 2024 06:20:35 -0500 Subject: [PATCH] embedded song_model into the song_editor finally In order to embed a qobject from another file you need to find the generated .h file in the build path and make sure to include it. --- TODO.org | 3 ++ src/rust/songs/song_editor.rs | 55 +++++++++++++++++++++++++++++------ 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/TODO.org b/TODO.org index 35c95c1..ed90c8a 100644 --- a/TODO.org +++ b/TODO.org @@ -38,6 +38,9 @@ modified src/rust/service_item_model.rs #+end_src This represents an example of what it'd look like to add better types. If I can ensure to model things better I could leave out all the extra pieces in the ServiceItem struct and the Slide struct and include an ItemType. This would then let me jump to the appropriate db and get the right info for each item. + +I've got SlideType enums working + *** Move logic of changing slides to slide_model Since the slide_object is merely supposed to be the view of the current slide, deciding which slide to switch to should be entirely on the slide_model, not the slide_object. This way slide_object doesn't need to know anything about the which slide is next and instead have a function to update everything to the slide returned from slide_model's new slide. diff --git a/src/rust/songs/song_editor.rs b/src/rust/songs/song_editor.rs index f90ad3c..adba538 100644 --- a/src/rust/songs/song_editor.rs +++ b/src/rust/songs/song_editor.rs @@ -15,7 +15,9 @@ pub mod song_editor { include!("cxx-qt-lib/qlist.h"); type QList_QString = cxx_qt_lib::QList; - // type SongModel = super::song_model::qobject::SongModel; + include!("cxx-qt-gen/song_model.cxxqt.h"); + type SongModel = + crate::songs::song_model::song_model::SongModel; } unsafe extern "RustQt" { @@ -36,17 +38,20 @@ pub mod song_editor { #[qproperty(i32, font_size)] #[qproperty(bool, background_exists)] #[qproperty(bool, audio_exists)] - // #[qproperty(*mut SongModel, song_model)] + #[qproperty(*mut SongModel, song_model)] type SongEditor = super::SongEditorRust; #[qinvokable] fn check_verse_order(self: Pin<&mut SongEditor>); #[qinvokable] fn check_files(self: Pin<&mut SongEditor>); + #[qinvokable] + fn load_song(self: Pin<&mut SongEditor>, song_index: i32); } } -// use crate::songs::song_model::qobject::SongModel; +use crate::songs::song_model::song_model::SongModel; +use cxx_qt::CxxQtType; use cxx_qt_lib::QString; use std::{path::PathBuf, pin::Pin}; use tracing::debug; @@ -68,7 +73,7 @@ pub struct SongEditorRust { font_size: i32, background_exists: bool, audio_exists: bool, - // song_model: *mut SongModel, + song_model: *mut SongModel, } impl Default for SongEditorRust { @@ -89,20 +94,52 @@ impl Default for SongEditorRust { font_size: 50, background_exists: true, audio_exists: true, - // song_model: std::ptr::null_mut(), + song_model: std::ptr::null_mut(), } } } impl song_editor::SongEditor { fn idk(self: Pin<&mut Self>) { - // if let Some(model) = unsafe { self.song_model().as_mut() } { - // let pinned_model = unsafe { Pin::new_unchecked(model) }; - // pinned_model.update_ccli(0, QString::from("idk")); - // } + if let Some(model) = unsafe { self.song_model().as_mut() } { + let pinned_model = unsafe { Pin::new_unchecked(model) }; + pinned_model.update_ccli(0, QString::from("idk")); + } todo!(); } + fn load_song(mut self: Pin<&mut Self>, song_index: i32) { + if let Some(model) = unsafe { self.song_model().as_ref() } { + let pinned_model = unsafe { Pin::new_unchecked(model) }; + if let Some(song) = + pinned_model.as_ref().get_song(song_index) + { + // update internals + self.as_mut().set_title(QString::from(&song.title)); + self.as_mut().set_author(QString::from(&song.author)); + self.as_mut().set_ccli(QString::from(&song.ccli)); + self.as_mut().set_audio(QString::from(&song.audio)); + self.as_mut().set_lyrics(QString::from(&song.lyrics)); + self.as_mut().set_verse_order(QString::from( + &song.verse_order, + )); + self.as_mut() + .set_background(QString::from(&song.background)); + self.as_mut().set_background_type(QString::from( + &song.background_type, + )); + self.as_mut().set_font(QString::from(&song.font)); + self.as_mut().set_font_size(song.font_size); + self.as_mut().set_horizontal_text_alignment( + QString::from(&song.horizontal_text_alignment), + ); + self.as_mut().set_vertical_text_alignment( + QString::from(&song.vertical_text_alignment), + ); + } + } + } + pub fn check_verse_order(mut self: Pin<&mut Self>) { let vo = self.verse_order().to_string(); let split = vo.split(' ');