Fixed the song textarea from removing blank lines

This commit is contained in:
Chris Cochrun 2022-03-23 14:46:28 -05:00
parent 7f69726c47
commit 93c94e19db
7 changed files with 51 additions and 8 deletions

View file

@ -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); */]]

View file

@ -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);
}
}
}

View file

@ -208,6 +208,7 @@ Item {
target: songListItem
onActiveChanged: {
if (songDragHandler.drag.active) {
dragItemIndex = index;
dragItemTitle = title;
dragItemType = "song";
dragItemBackgroundType = backgroundType;

View file

@ -18,6 +18,7 @@ Controls.Page {
/* property var video */
property int dragItemIndex
property string dragItemTitle: ""
property string dragItemType: ""
property string dragItemText: ""

View file

@ -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) {

View file

@ -9,7 +9,9 @@
#include <QSqlDatabase>
#include <qabstractitemmodel.h>
#include <qdebug.h>
#include <qglobal.h>
#include <qobjectdefs.h>
#include <qsqlquery.h>
#include <qsqlrecord.h>
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();

View file

@ -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<int, QByteArray> roleNames() const override;