From 93c94e19dbfa766bcba4aef97518a9a4b2dc789d Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Wed, 23 Mar 2022 14:46:28 -0500 Subject: [PATCH] Fixed the song textarea from removing blank lines --- TODO.org | 1 + src/qml/presenter/LeftDock.qml | 18 +++++++++++++----- src/qml/presenter/Library.qml | 1 + src/qml/presenter/MainWindow.qml | 1 + src/qml/presenter/SongEditor.qml | 16 +++++++++++++--- src/songsqlmodel.cpp | 21 +++++++++++++++++++++ src/songsqlmodel.h | 1 + 7 files changed, 51 insertions(+), 8 deletions(-) diff --git a/TODO.org b/TODO.org index 7d565fd..e1c2689 100644 --- a/TODO.org +++ b/TODO.org @@ -4,5 +4,6 @@ [[file:~/dev/church-presenter/src/qml/presenter/LeftDock.qml::/* showPassiveNotification(serviceItemList.currentIndex); */]] ** TODO Parse Lyrics to create a list of strings for slides +SCHEDULED: <2022-03-23 Wed 10:00> [[file:~/dev/church-presenter/src/qml/presenter/LeftDock.qml::/* showPassiveNotification(serviceItemList.currentIndex); */]] diff --git a/src/qml/presenter/LeftDock.qml b/src/qml/presenter/LeftDock.qml index 1ead689..dfd9fb2 100644 --- a/src/qml/presenter/LeftDock.qml +++ b/src/qml/presenter/LeftDock.qml @@ -38,7 +38,8 @@ ColumnLayout { dragItemType, dragItemText, dragItemBackgroundType, - dragItemBackground); + dragItemBackground, + dragItemIndex); } keys: ["library"] @@ -126,7 +127,8 @@ ColumnLayout { dragItemType, dragItemText, dragItemBackgroundType, - dragItemBackground); + dragItemBackground, + dragItemIndex); } keys: ["library"] } @@ -173,7 +175,7 @@ ColumnLayout { } } - function addItem(index, name, type, text, backgroundType, background) { + function addItem(index, name, type, text, backgroundType, background, itemID) { serviceListModel.insert(index, { "name": name, "type": type, @@ -182,13 +184,19 @@ ColumnLayout { "background": background}) } - function appendItem(name, type, text, backgroundType, background) { + function appendItem(name, type, text, backgroundType, background, itemID) { serviceListModel.append({ "name": name, "type": type, "text": text, "backgroundType": backgroundType, - "background": background}) + "background": background}); + + if (type == "song") { + const lyrics = songsqlmodel.getLyricList(itemID); + print(lyrics); + } + } } diff --git a/src/qml/presenter/Library.qml b/src/qml/presenter/Library.qml index e0013b9..cb6b7b2 100644 --- a/src/qml/presenter/Library.qml +++ b/src/qml/presenter/Library.qml @@ -208,6 +208,7 @@ Item { target: songListItem onActiveChanged: { if (songDragHandler.drag.active) { + dragItemIndex = index; dragItemTitle = title; dragItemType = "song"; dragItemBackgroundType = backgroundType; diff --git a/src/qml/presenter/MainWindow.qml b/src/qml/presenter/MainWindow.qml index 6df4a87..7fd86e7 100644 --- a/src/qml/presenter/MainWindow.qml +++ b/src/qml/presenter/MainWindow.qml @@ -18,6 +18,7 @@ Controls.Page { /* property var video */ + property int dragItemIndex property string dragItemTitle: "" property string dragItemType: "" property string dragItemText: "" diff --git a/src/qml/presenter/SongEditor.qml b/src/qml/presenter/SongEditor.qml index 2b5fd47..28c0db4 100644 --- a/src/qml/presenter/SongEditor.qml +++ b/src/qml/presenter/SongEditor.qml @@ -177,13 +177,14 @@ Item { placeholderText: "Put lyrics here..." persistentSelection: true text: songLyrics - textFormat: TextEdit.MarkdownText + textFormat: TextEdit.PlainText padding: 10 onEditingFinished: { - updateLyrics(text); + updateLyrics(lyricsEditor.getText(0,lyricsEditor.length)); editorTimer.running = false; } onPressed: editorTimer.running = true + /* Component.onCompleted: text = songsqlmodel.getLyrics(songIndex); */ } } Controls.TextField { @@ -215,6 +216,12 @@ Item { Layout.rightMargin: 20 Layout.leftMargin: 20 } + Controls.Button { + text: "update lyrics" + onClicked: { + print(lyricsEditor.getText(0,lyricsEditor.length)); + } + } } } } @@ -224,7 +231,9 @@ Item { interval: 1000 repeat: true running: false - onTriggered: updateLyrics(lyricsEditor.text) + onTriggered: { + updateLyrics(lyricsEditor.getText(0,lyricsEditor.length)); + } } FileDialog { @@ -282,6 +291,7 @@ Item { function updateLyrics(lyrics) { songsqlmodel.updateLyrics(songIndex, lyrics); + print(lyrics); } function updateTitle(title) { diff --git a/src/songsqlmodel.cpp b/src/songsqlmodel.cpp index c21850d..2cf777e 100644 --- a/src/songsqlmodel.cpp +++ b/src/songsqlmodel.cpp @@ -9,7 +9,9 @@ #include #include #include +#include #include +#include #include static const char *songsTableName = "songs"; @@ -131,6 +133,23 @@ QVariantList SongSqlModel::getSong(const int &row) { return song; } +QStringList SongSqlModel::getLyricList(const int &row) { + QSqlRecord recordData = record(row); + if (recordData.isEmpty()) { + qDebug() << "this is not a song"; + QStringList empty; + return empty; + } + + QString rawLyrics = recordData.value("lyrics").toString(); + qDebug() << rawLyrics; + + QStringList lyrics = rawLyrics.split("\n"); + qDebug() << lyrics; + + return lyrics; +} + int SongSqlModel::id() const { return m_id; } @@ -203,7 +222,9 @@ void SongSqlModel::setLyrics(const QString &lyrics) { void SongSqlModel::updateLyrics(const int &row, const QString &lyrics) { qDebug() << "Row is " << row; QSqlRecord rowdata = record(row); + qDebug() << lyrics; rowdata.setValue("lyrics", lyrics); + qDebug() << rowdata.value("lyrics"); setRecord(row, rowdata); submitAll(); emit lyricsChanged(); diff --git a/src/songsqlmodel.h b/src/songsqlmodel.h index a3ecde9..09045c1 100644 --- a/src/songsqlmodel.h +++ b/src/songsqlmodel.h @@ -54,6 +54,7 @@ public: Q_INVOKABLE void newSong(); Q_INVOKABLE void deleteSong(const int &row); Q_INVOKABLE QVariantList getSong(const int &row); + Q_INVOKABLE QStringList getLyricList(const int &row); QVariant data(const QModelIndex &index, int role) const override; QHash roleNames() const override;