got a working lyriclist, now adding serviceitem
This commit is contained in:
parent
fe32ccc3bb
commit
2857ce6c2b
4 changed files with 183 additions and 40 deletions
|
@ -4,6 +4,7 @@ target_sources(presenter
|
||||||
PRIVATE
|
PRIVATE
|
||||||
main.cpp resources.qrc
|
main.cpp resources.qrc
|
||||||
songsqlmodel.cpp songsqlmodel.h
|
songsqlmodel.cpp songsqlmodel.h
|
||||||
|
serviceitem.cpp serviceitem.h
|
||||||
videosqlmodel.cpp videosqlmodel.h
|
videosqlmodel.cpp videosqlmodel.h
|
||||||
mpv/mpvobject.h mpv/mpvobject.cpp
|
mpv/mpvobject.h mpv/mpvobject.cpp
|
||||||
mpv/qthelper.hpp mpv/mpvhelpers.h
|
mpv/qthelper.hpp mpv/mpvhelpers.h
|
||||||
|
|
88
src/serviceitem.cpp
Normal file
88
src/serviceitem.cpp
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
#include "serviceitem.h"
|
||||||
|
#include <qvariant.h>
|
||||||
|
|
||||||
|
ServiceItem::ServiceItem(QObject *parent)
|
||||||
|
: QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int ServiceItem::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
// For list models only the root node (an invalid parent) should return the list's size. For all
|
||||||
|
// other (valid) parents, rowCount() should return 0 so that it does not become a tree model.
|
||||||
|
if (parent.isValid())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// FIXME: Implement me!
|
||||||
|
return m_data.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ServiceItem::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (!index.isValid())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
const Data &data = m_data.at(index.row());
|
||||||
|
switch (role) {
|
||||||
|
case NameRole:
|
||||||
|
return data.name;
|
||||||
|
case TypeRole:
|
||||||
|
return data.type;
|
||||||
|
case BackgroundRole:
|
||||||
|
return data.background;
|
||||||
|
case BackgroundTypeRole:
|
||||||
|
return data.backgroundType;
|
||||||
|
case TextRole:
|
||||||
|
return data.text;
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> ServiceItem::roleNames() const {
|
||||||
|
static QHash<int, QByteArray> mapping {
|
||||||
|
{NameRole, "name"},
|
||||||
|
{TypeRole, "type"},
|
||||||
|
{BackgroundRole, "background"},
|
||||||
|
{BackgroundTypeRole, "backgroundType"},
|
||||||
|
{TextRole, "text"}
|
||||||
|
};
|
||||||
|
|
||||||
|
return mapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServiceItem::setData(const QModelIndex &index,
|
||||||
|
const QVariant &value,
|
||||||
|
int role) {
|
||||||
|
const Data &oldData = m_data.at(index.row());
|
||||||
|
const QVariant newData = data(index, role);
|
||||||
|
if (newData != value) {
|
||||||
|
// FIXME: Implement me!
|
||||||
|
switch (role) {
|
||||||
|
case NameRole:
|
||||||
|
m_data.at(index.row()).name = newData.toString();
|
||||||
|
case TypeRole:
|
||||||
|
return data.type;
|
||||||
|
case BackgroundRole:
|
||||||
|
return data.background;
|
||||||
|
case BackgroundTypeRole:
|
||||||
|
return data.backgroundType;
|
||||||
|
case TextRole:
|
||||||
|
return data.text;
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
oldData = newData;
|
||||||
|
emit dataChanged(index, index, QVector<int>() << role);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags ServiceItem::flags(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
if (!index.isValid())
|
||||||
|
return Qt::NoItemFlags;
|
||||||
|
|
||||||
|
return Qt::ItemIsEditable; // FIXME: Implement me!
|
||||||
|
}
|
54
src/serviceitem.h
Normal file
54
src/serviceitem.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#ifndef SERVICEITEM_H
|
||||||
|
#define SERVICEITEM_H
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
#include <qnamespace.h>
|
||||||
|
|
||||||
|
struct Data {
|
||||||
|
Data() {}
|
||||||
|
Data( const QString& name,
|
||||||
|
const QString& type,
|
||||||
|
const QString& background,
|
||||||
|
const QString& backgroundType,
|
||||||
|
const QStringList& text)
|
||||||
|
: name(name), type(type), background(background),
|
||||||
|
backgroundType(backgroundType), text(text) {}
|
||||||
|
QString name;
|
||||||
|
QString type;
|
||||||
|
QString background;
|
||||||
|
QString backgroundType;
|
||||||
|
QStringList text;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ServiceItem : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ServiceItem(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
enum Roles {
|
||||||
|
NameRole = Qt::UserRole,
|
||||||
|
TypeRole,
|
||||||
|
BackgroundRole,
|
||||||
|
BackgroundTypeRole,
|
||||||
|
TextRole,
|
||||||
|
SlidesRole
|
||||||
|
};
|
||||||
|
|
||||||
|
// Basic functionality:
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
|
// Editable:
|
||||||
|
bool setData(const QModelIndex &index, const QVariant &value,
|
||||||
|
int role = Qt::EditRole) override;
|
||||||
|
|
||||||
|
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVector<Data> m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SERVICEITEM_H
|
|
@ -11,6 +11,7 @@
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
#include <qglobal.h>
|
#include <qglobal.h>
|
||||||
#include <qobjectdefs.h>
|
#include <qobjectdefs.h>
|
||||||
|
#include <qregexp.h>
|
||||||
#include <qsqlquery.h>
|
#include <qsqlquery.h>
|
||||||
#include <qsqlrecord.h>
|
#include <qsqlrecord.h>
|
||||||
|
|
||||||
|
@ -142,61 +143,60 @@ QStringList SongSqlModel::getLyricList(const int &row) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList rawLyrics = recordData.value("lyrics").toString().split("\n");
|
QStringList rawLyrics = recordData.value("lyrics").toString().split("\n");
|
||||||
qDebug() << rawLyrics;
|
|
||||||
|
|
||||||
QStringList lyrics;
|
QStringList lyrics;
|
||||||
// qDebug() << lyrics;
|
|
||||||
|
|
||||||
QStringList vorder = recordData.value("vorder").toString().split(" ");
|
QStringList vorder = recordData.value("vorder").toString().split(" ");
|
||||||
qDebug() << vorder;
|
qDebug() << vorder;
|
||||||
|
|
||||||
int endIndex;
|
|
||||||
QString line;
|
|
||||||
QStringList keywords = {"Verse 1", "Verse 2", "Verse 3", "Verse 4",
|
QStringList keywords = {"Verse 1", "Verse 2", "Verse 3", "Verse 4",
|
||||||
"Verse 5", "Verse 6", "Verse 7", "Verse 8",
|
"Verse 5", "Verse 6", "Verse 7", "Verse 8",
|
||||||
"Chorus 1", "Chorus 2", "Chorus 3", "Chorus 4",
|
"Chorus 1", "Chorus 2", "Chorus 3", "Chorus 4",
|
||||||
"Bridge 1", "Bridge 2", "Bridge 3", "Bridge 4",
|
"Bridge 1", "Bridge 2", "Bridge 3", "Bridge 4",
|
||||||
"Intro 1", "Outro 2", "Ending 1", "Other 1"};
|
"Intro 1", "Intro 2", "Ending 1", "Ending 2",
|
||||||
|
"Other 1", "Other 2", "Other 3", "Other 4"};
|
||||||
|
|
||||||
foreach (const QString &vstr, vorder) {
|
bool recordVerse;
|
||||||
int startIndex;
|
bool firstItem = true;
|
||||||
QString verse;
|
QString verse;
|
||||||
qDebug() << vstr;
|
QString vtitle;
|
||||||
foreach (line, rawLyrics) {
|
QString line;
|
||||||
|
QMap<QString, QString> verses;
|
||||||
|
|
||||||
|
// This first function pulls out each verse into our verses map
|
||||||
|
foreach (line, rawLyrics) {
|
||||||
|
if (firstItem) {
|
||||||
if (keywords.contains(line)) {
|
if (keywords.contains(line)) {
|
||||||
if (line.startsWith(vstr.at(0)) && line.endsWith(vstr.at(1))) {
|
recordVerse = true;
|
||||||
qDebug() << vstr << line;
|
firstItem = false;
|
||||||
startIndex = rawLyrics.indexOf(line);
|
vtitle = line;
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
qDebug() << "Break out";
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
qDebug() << line;
|
} else if (keywords.contains(line)) {
|
||||||
// verse.append(line + "\n");
|
verses.insert(vtitle, verse);
|
||||||
// qDebug() << verse;
|
verse.clear();
|
||||||
|
vtitle = line;
|
||||||
|
recordVerse = false;
|
||||||
|
} else if (rawLyrics.endsWith(line)) {
|
||||||
|
verses.insert(vtitle, verse);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
// lyrics.append(verse);
|
if (recordVerse) {
|
||||||
// qDebug() << verse;
|
verse.append(line.trimmed() + "\n");
|
||||||
|
}
|
||||||
|
recordVerse = true;
|
||||||
}
|
}
|
||||||
// foreach (line, rawLyrics) {
|
qDebug() << verses;
|
||||||
// if (line.trimmed() == "Chorus 1") {
|
|
||||||
// startIndex = rawLyrics.indexOf(line) + 1;
|
|
||||||
// // qDebug() << line;
|
|
||||||
// // qDebug() << startIndex;
|
|
||||||
// }
|
|
||||||
// if (line.trimmed() == "Verse 1") {
|
|
||||||
// endIndex = rawLyrics.indexOf(line);
|
|
||||||
// // qDebug() << endIndex;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// if (rawLyrics.indexOf(line) == startIndex - 1) {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// verse.append(line + "\n");
|
|
||||||
// // qDebug() << verse;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
// this function appends the verse that matches the verse order from the map
|
||||||
|
foreach (const QString &vstr, vorder) {
|
||||||
|
foreach (line, rawLyrics) {
|
||||||
|
if (line.startsWith(vstr.at(0)) && line.endsWith(vstr.at(1))) {
|
||||||
|
lyrics.append(verses[line]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << lyrics;
|
||||||
|
|
||||||
return lyrics;
|
return lyrics;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue