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.
This commit is contained in:
Chris Cochrun 2024-09-17 06:20:35 -05:00
parent 0aa966e8b9
commit e1cb837249
2 changed files with 49 additions and 9 deletions

View file

@ -15,7 +15,9 @@ pub mod song_editor {
include!("cxx-qt-lib/qlist.h");
type QList_QString = cxx_qt_lib::QList<QString>;
// 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(' ');