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;
|
fn new_song(self: Pin<&mut SongModel>) -> bool;
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
fn get_item(
|
fn get_item(
|
||||||
self: Pin<&mut SongModel>,
|
self: &SongModel,
|
||||||
index: i32,
|
index: i32,
|
||||||
) -> QMap_QString_QVariant;
|
) -> QMap_QString_QVariant;
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
|
@ -252,7 +252,7 @@ use diesel::{delete, insert_into, prelude::*, update};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::slice::Iter;
|
use std::slice::Iter;
|
||||||
use tracing::{debug, debug_span, error, info, instrument};
|
use tracing::{debug, error};
|
||||||
|
|
||||||
use self::song_model::{
|
use self::song_model::{
|
||||||
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
|
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
|
||||||
|
@ -262,18 +262,18 @@ use self::song_model::{
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Song {
|
pub struct Song {
|
||||||
id: i32,
|
id: i32,
|
||||||
title: String,
|
pub title: String,
|
||||||
lyrics: String,
|
pub lyrics: String,
|
||||||
author: String,
|
pub author: String,
|
||||||
ccli: String,
|
pub ccli: String,
|
||||||
audio: String,
|
pub audio: String,
|
||||||
verse_order: String,
|
pub verse_order: String,
|
||||||
background: String,
|
pub background: String,
|
||||||
background_type: String,
|
pub background_type: String,
|
||||||
horizontal_text_alignment: String,
|
pub horizontal_text_alignment: String,
|
||||||
vertical_text_alignment: String,
|
pub vertical_text_alignment: String,
|
||||||
font: String,
|
pub font: String,
|
||||||
font_size: i32,
|
pub font_size: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Song {
|
impl Default for Song {
|
||||||
|
@ -939,30 +939,31 @@ impl song_model::SongModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_item(
|
pub fn get_item(&self, index: i32) -> QMap_QString_QVariant {
|
||||||
self: Pin<&mut Self>,
|
|
||||||
index: i32,
|
|
||||||
) -> QMap_QString_QVariant {
|
|
||||||
debug!(index);
|
debug!(index);
|
||||||
let mut qvariantmap = QMap_QString_QVariant::default();
|
let mut qvariantmap = QMap_QString_QVariant::default();
|
||||||
let idx = self.index(index, 0, &QModelIndex::default());
|
let idx = self.index(index, 0, &QModelIndex::default());
|
||||||
if !idx.is_valid() {
|
if !idx.is_valid() {
|
||||||
return qvariantmap;
|
return qvariantmap;
|
||||||
}
|
}
|
||||||
let role_names = self.as_ref().role_names();
|
let role_names = self.role_names();
|
||||||
let role_names_iter = role_names.iter();
|
let role_names_iter = role_names.iter();
|
||||||
if let Some(song) = self.rust().songs.get(index as usize) {
|
if let Some(song) = self.rust().songs.get(index as usize) {
|
||||||
debug!(?song);
|
debug!(?song);
|
||||||
for i in role_names_iter {
|
for i in role_names_iter {
|
||||||
qvariantmap.insert(
|
qvariantmap.insert(
|
||||||
QString::from(&i.1.to_string()),
|
QString::from(&i.1.to_string()),
|
||||||
self.as_ref().data(&idx, *i.0),
|
self.data(&idx, *i.0),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
qvariantmap
|
qvariantmap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_song(&self, index: i32) -> Option<&Song> {
|
||||||
|
self.rust().songs.get(index as usize)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_lyric_list(
|
pub fn get_lyric_list(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
index: i32,
|
index: i32,
|
||||||
|
@ -1208,23 +1209,23 @@ impl song_model::SongModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl song_model::SongRoles {
|
// impl song_model::SongRoles {
|
||||||
fn iter() -> Iter<'static, SongRoles> {
|
// fn iter() -> Iter<'static, SongRoles> {
|
||||||
static SONGROLES: [SongRoles; 13] = [
|
// static SONGROLES: [SongRoles; 13] = [
|
||||||
SongRoles::Id,
|
// SongRoles::Id,
|
||||||
SongRoles::Title,
|
// SongRoles::Title,
|
||||||
SongRoles::Lyrics,
|
// SongRoles::Lyrics,
|
||||||
SongRoles::Author,
|
// SongRoles::Author,
|
||||||
SongRoles::Ccli,
|
// SongRoles::Ccli,
|
||||||
SongRoles::Audio,
|
// SongRoles::Audio,
|
||||||
SongRoles::VerseOrder,
|
// SongRoles::VerseOrder,
|
||||||
SongRoles::Background,
|
// SongRoles::Background,
|
||||||
SongRoles::BackgroundType,
|
// SongRoles::BackgroundType,
|
||||||
SongRoles::HorizontalTextAlignment,
|
// SongRoles::HorizontalTextAlignment,
|
||||||
SongRoles::VerticalTextAlignment,
|
// SongRoles::VerticalTextAlignment,
|
||||||
SongRoles::Font,
|
// SongRoles::Font,
|
||||||
SongRoles::FontSize,
|
// SongRoles::FontSize,
|
||||||
];
|
// ];
|
||||||
SONGROLES.iter()
|
// SONGROLES.iter()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue