clean up some things and add an internal get_song
This commit is contained in:
parent
922f1b3456
commit
0aa966e8b9
1 changed files with 41 additions and 40 deletions
|
@ -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()
|
||||
// }
|
||||
// }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue