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
|
||||
main.cpp resources.qrc
|
||||
songsqlmodel.cpp songsqlmodel.h
|
||||
serviceitem.cpp serviceitem.h
|
||||
videosqlmodel.cpp videosqlmodel.h
|
||||
mpv/mpvobject.h mpv/mpvobject.cpp
|
||||
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 <qglobal.h>
|
||||
#include <qobjectdefs.h>
|
||||
#include <qregexp.h>
|
||||
#include <qsqlquery.h>
|
||||
#include <qsqlrecord.h>
|
||||
|
||||
|
@ -142,61 +143,60 @@ QStringList SongSqlModel::getLyricList(const int &row) {
|
|||
}
|
||||
|
||||
QStringList rawLyrics = recordData.value("lyrics").toString().split("\n");
|
||||
qDebug() << rawLyrics;
|
||||
|
||||
QStringList lyrics;
|
||||
// qDebug() << lyrics;
|
||||
|
||||
QStringList vorder = recordData.value("vorder").toString().split(" ");
|
||||
qDebug() << vorder;
|
||||
|
||||
int endIndex;
|
||||
QString line;
|
||||
QStringList keywords = {"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", "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) {
|
||||
int startIndex;
|
||||
bool recordVerse;
|
||||
bool firstItem = true;
|
||||
QString verse;
|
||||
qDebug() << vstr;
|
||||
QString vtitle;
|
||||
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 (line.startsWith(vstr.at(0)) && line.endsWith(vstr.at(1))) {
|
||||
qDebug() << vstr << line;
|
||||
startIndex = rawLyrics.indexOf(line);
|
||||
recordVerse = true;
|
||||
firstItem = false;
|
||||
vtitle = line;
|
||||
continue;
|
||||
}
|
||||
qDebug() << "Break out";
|
||||
} else if (keywords.contains(line)) {
|
||||
verses.insert(vtitle, verse);
|
||||
verse.clear();
|
||||
vtitle = line;
|
||||
recordVerse = false;
|
||||
} else if (rawLyrics.endsWith(line)) {
|
||||
verses.insert(vtitle, verse);
|
||||
break;
|
||||
}
|
||||
qDebug() << line;
|
||||
// verse.append(line + "\n");
|
||||
// qDebug() << verse;
|
||||
if (recordVerse) {
|
||||
verse.append(line.trimmed() + "\n");
|
||||
}
|
||||
// lyrics.append(verse);
|
||||
// qDebug() << verse;
|
||||
recordVerse = true;
|
||||
}
|
||||
// foreach (line, rawLyrics) {
|
||||
// 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;
|
||||
// }
|
||||
qDebug() << verses;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue