using song_model now

This commit is contained in:
Chris Cochrun 2023-05-12 17:00:23 -05:00
parent 68b30877ed
commit 184ad4fe57
4 changed files with 76 additions and 19 deletions

View file

@ -722,7 +722,8 @@ QModelIndex SongSqlModel::idx(int row) {
SongProxyModel::SongProxyModel(QObject *parent)
:QSortFilterProxyModel(parent)
{
m_songModel = new SongSqlModel;
m_songModel = new SongModel;
m_songModel->setup();
// m_selectionModel = new QItemSelectionModel;
// m_selectionModel->setModel(this);
setSourceModel(m_songModel);
@ -731,7 +732,7 @@ SongProxyModel::SongProxyModel(QObject *parent)
setFilterCaseSensitivity(Qt::CaseInsensitive);
}
SongSqlModel *SongProxyModel::songModel() {
SongModel *SongProxyModel::songModel() {
return m_songModel;
}
@ -742,7 +743,7 @@ QModelIndex SongProxyModel::idx(int row) {
}
QModelIndex SongProxyModel::modelIndex(int row) {
QModelIndex idx = m_songModel->idx(mapToSource(index(row, 0)).row());
QModelIndex idx = m_songModel->index(mapToSource(index(row, 0)).row());
return idx;
}
@ -752,21 +753,21 @@ QStringList SongProxyModel::getLyricList(const int &row) {
}
QVariantMap SongProxyModel::getSong(const int &row) {
QVariantMap song = m_songModel->getSong(mapToSource(index(row, 0)).row());
QVariantMap song = m_songModel->getItem(mapToSource(index(row, 0)).row());
return song;
}
void SongProxyModel::deleteSong(const int &row) {
auto model = qobject_cast<SongSqlModel *>(sourceModel());
model->deleteSong(row);
auto model = qobject_cast<SongModel *>(sourceModel());
model->removeItem(row);
}
void SongProxyModel::deleteSongs(const QVector<int> &rows) {
auto model = qobject_cast<SongSqlModel *>(sourceModel());
auto model = qobject_cast<SongModel *>(sourceModel());
qDebug() << "DELETING!!!!!!!!!!!!!!!!!!!!!!!" << rows;
for (int i = rows.size() - 1; i >= 0; i--) {
qDebug() << "deleting" << rows.at(i);
model->deleteSong(rows.at(i));
model->removeItem(rows.at(i));
}
}

View file

@ -7,6 +7,7 @@
#include <qobjectdefs.h>
#include <qqml.h>
#include <qvariant.h>
#include "cxx-qt-gen/song_model.cxxqt.h"
class SongSqlModel : public QSqlTableModel
{
@ -113,14 +114,14 @@ private:
class SongProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(SongSqlModel *songModel READ songModel)
Q_PROPERTY(SongModel *songModel READ songModel)
// Q_PROPERTY(bool hasSelection READ hasSelection NOTIFY selectedChanged)
public:
explicit SongProxyModel(QObject *parent = nullptr);
~SongProxyModel() = default;
SongSqlModel *songModel();
SongModel *songModel();
Q_INVOKABLE QModelIndex idx(int row);
Q_INVOKABLE QModelIndex modelIndex(int row);
// Q_INVOKABLE bool selected(const int &row);
@ -142,7 +143,7 @@ signals:
// Q_INVOKABLE void selectedChanged(bool selected);
private:
SongSqlModel *m_songModel;
SongModel *m_songModel;
// QItemSelectionModel *m_selectionModel;
// bool m_selected;
};

View file

@ -435,7 +435,7 @@ Item {
function changeSong(index) {
clearSlides();
console.log(index);
song = songProxyModel.songModel.getSong(index);
song = songProxyModel.getSong(index);
console.log(song.lyrics);
songIndex = song.id;
@ -581,7 +581,7 @@ Item {
function changeSlideText(id) {
/* console.log("Here are the verses: " + verses); */
const verses = songProxyModel.songModel.getLyricList(id);
const verses = songProxyModel.getLyricList(id);
verses.forEach(slideEditor.appendVerse);
/* slideEditor.loadVideo(); */
}

View file

@ -5,6 +5,7 @@ mod song_model {
use crate::song_model::song_model::Song;
use diesel::sqlite::SqliteConnection;
use diesel::{delete, insert_into, prelude::*, update};
use std::collections::HashMap;
use std::path::{Path, PathBuf};
unsafe extern "C++" {
@ -92,7 +93,7 @@ mod song_model {
}
#[qinvokable]
pub fn test_database(mut self: Pin<&mut Self>) {
pub fn setup(mut self: Pin<&mut Self>) {
let db = &mut self.as_mut().get_db();
let results = songs
.load::<crate::models::Song>(db)
@ -306,17 +307,71 @@ mod song_model {
}
#[qinvokable]
pub fn get_lyric_list(mut self: Pin<&mut Self>, index: i32) -> QList_QString {
println!("{index}");
let lyric_list = QList_QString::default();
pub fn get_lyric_list(mut self: Pin<&mut Self>, index: i32) -> QStringList {
println!("LYRIC_LIST: {index}");
let mut lyric_list = QList_QString::default();
let idx = self.index(index, 0, &QModelIndex::default());
if !idx.is_valid() {
return lyric_list;
return QStringList::default();
}
if let Some(song) = self.rust().songs.get(index as usize) {
let raw_lyrics = song.lyrics.clone();
let vorder: Vec<&str> = song.verse_order.split(' ').collect();
let keywords = vec![
"Verse 1", "Verse 2", "Verse 3", "Verse 4", "Verse 5", "Verse 6", "Verse 7",
"Verse 8", "Chorus 1", "Chorus 2", "Chorus 3", "Chorus 4", "Bridge 1",
"Bridge 2", "Bridge 3", "Bridge 4", "Intro 1", "Intro 2", "Ending 1",
"Ending 2", "Other 1", "Other 2", "Other 3", "Other 4",
];
let mut first_item = true;
let mut lyric_map = HashMap::new();
let mut verse_title = String::from("");
let mut lyric = String::from("");
for (i, line) in raw_lyrics.split("\n").enumerate() {
if keywords.contains(&line) {
if i != 0 {
println!("{verse_title}");
println!("{lyric}");
lyric_map.insert(verse_title, lyric);
lyric = String::from("");
verse_title = line.to_string();
// println!("{line}");
// println!("\n");
} else {
verse_title = line.to_string();
// println!("{line}");
// println!("\n");
}
} else {
lyric.push_str(line);
lyric.push_str("\n");
}
}
println!("da-map: {:?}", lyric_map);
for verse in vorder {
let mut verse_name = "";
for word in keywords.clone() {
let end_verse = verse.get(1..).unwrap();
if word.get(..0).unwrap() == verse.get(..0).unwrap()
&& word.ends_with(end_verse)
{
verse_name = word;
println!("TITLE: {verse_name}");
}
}
if let Some(lyric) = lyric_map.get(verse_name) {
lyric_list.append(QString::from(lyric));
} else {
println!("NOT WORKING!");
};
}
for lyric in lyric_list.iter() {
println!("da-list: {:?}", lyric);
}
}
lyric_list
QStringList::from(&lyric_list)
}
fn get_role(&self, role: Role) -> i32 {