added a serviceitemmodel and working on implementing move and insert
This commit is contained in:
parent
2857ce6c2b
commit
105c958810
9 changed files with 396 additions and 159 deletions
8
TODO.org
8
TODO.org
|
@ -1,9 +1,9 @@
|
||||||
#+TITLE: Todo List
|
#+TITLE: Todo List
|
||||||
* Inbox
|
* Inbox
|
||||||
** TODO Need to make ListModel capable of bringing in a string list
|
** TODO Need to make ListModel capable of bringing in a string list [1/2] [50%]
|
||||||
|
- [X] Create a Model
|
||||||
|
- [ ] Create a class that we'll make a list of in the model
|
||||||
|
|
||||||
[[file:~/dev/church-presenter/src/qml/presenter/LeftDock.qml::/* showPassiveNotification(serviceItemList.currentIndex); */]]
|
** DONE Parse Lyrics to create a list of strings for slides
|
||||||
** TODO Parse Lyrics to create a list of strings for slides
|
|
||||||
SCHEDULED: <2022-03-23 Wed 10:00>
|
SCHEDULED: <2022-03-23 Wed 10:00>
|
||||||
|
|
||||||
[[file:~/dev/church-presenter/src/qml/presenter/LeftDock.qml::/* showPassiveNotification(serviceItemList.currentIndex); */]]
|
|
||||||
|
|
|
@ -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
|
||||||
|
serviceitemmodel.cpp serviceitemmodel.h
|
||||||
serviceitem.cpp serviceitem.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
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include <qstringliteral.h>
|
#include <qstringliteral.h>
|
||||||
|
|
||||||
#include "mpv/mpvobject.h"
|
#include "mpv/mpvobject.h"
|
||||||
|
#include "serviceitemmodel.h"
|
||||||
#include "songsqlmodel.h"
|
#include "songsqlmodel.h"
|
||||||
#include "videosqlmodel.h"
|
#include "videosqlmodel.h"
|
||||||
|
|
||||||
|
@ -89,6 +90,7 @@ int main(int argc, char *argv[])
|
||||||
//register our models
|
//register our models
|
||||||
qmlRegisterType<SongSqlModel>("org.presenter", 1, 0, "SongSqlModel");
|
qmlRegisterType<SongSqlModel>("org.presenter", 1, 0, "SongSqlModel");
|
||||||
qmlRegisterType<VideoSqlModel>("org.presenter", 1, 0, "VideoSqlModel");
|
qmlRegisterType<VideoSqlModel>("org.presenter", 1, 0, "VideoSqlModel");
|
||||||
|
qmlRegisterType<ServiceItemModel>("org.presenter", 1, 0, "ServiceItemModel");
|
||||||
|
|
||||||
connectToDatabase();
|
connectToDatabase();
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,9 @@ ColumnLayout {
|
||||||
onDropped: {
|
onDropped: {
|
||||||
appendItem(dragItemTitle,
|
appendItem(dragItemTitle,
|
||||||
dragItemType,
|
dragItemType,
|
||||||
dragItemText,
|
|
||||||
dragItemBackgroundType,
|
|
||||||
dragItemBackground,
|
dragItemBackground,
|
||||||
|
dragItemBackgroundType,
|
||||||
|
dragItemText,
|
||||||
dragItemIndex);
|
dragItemIndex);
|
||||||
}
|
}
|
||||||
keys: ["library"]
|
keys: ["library"]
|
||||||
|
@ -46,7 +46,7 @@ ColumnLayout {
|
||||||
ListView {
|
ListView {
|
||||||
id: serviceItemList
|
id: serviceItemList
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
model: serviceListModel
|
model: serviceItemModel
|
||||||
delegate: Kirigami.DelegateRecycler {
|
delegate: Kirigami.DelegateRecycler {
|
||||||
width: serviceItemList.width
|
width: serviceItemList.width
|
||||||
sourceComponent: itemDelegate
|
sourceComponent: itemDelegate
|
||||||
|
@ -108,7 +108,7 @@ ColumnLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
listItem: serviceItem
|
listItem: serviceItem
|
||||||
listView: serviceItemList
|
listView: serviceItemList
|
||||||
onMoveRequested: serviceListModel.move(oldIndex, newIndex, 1)
|
onMoveRequested: serviceItemModel.move(oldIndex, newIndex)
|
||||||
onClicked: {
|
onClicked: {
|
||||||
serviceItemList.currentIndex = index;
|
serviceItemList.currentIndex = index;
|
||||||
/* showPassiveNotification(serviceItemList.currentIndex); */
|
/* showPassiveNotification(serviceItemList.currentIndex); */
|
||||||
|
@ -147,56 +147,27 @@ ColumnLayout {
|
||||||
anchors.rightMargin: 0
|
anchors.rightMargin: 0
|
||||||
active: hovered || pressed
|
active: hovered || pressed
|
||||||
}
|
}
|
||||||
|
|
||||||
ListModel {
|
|
||||||
id: serviceListModel
|
|
||||||
ListElement {
|
|
||||||
name: "10,000 Reason"
|
|
||||||
type: "song"
|
|
||||||
text: "YIP YIP!"
|
|
||||||
backgroundType: "image"
|
|
||||||
background: "file:/home/chris/nextcloud/tfc/openlp/CMG - Nature King 21.jpg"
|
|
||||||
}
|
|
||||||
ListElement {
|
|
||||||
name: "Marvelous Light"
|
|
||||||
type: "song"
|
|
||||||
text: "HALLELUJAH!"
|
|
||||||
backgroundType: "video"
|
|
||||||
background: "file:/home/chris/nextcloud/tfc/openlp/Fire Embers_Loop.mp4"
|
|
||||||
}
|
|
||||||
ListElement {
|
|
||||||
name: "Test"
|
|
||||||
type: "video"
|
|
||||||
text: ""
|
|
||||||
backgroundType: "video"
|
|
||||||
background: "file:/home/chris/nextcloud/tfc/openlp/videos/test.mp4"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addItem(index, name, type, text, backgroundType, background, itemID) {
|
function addItem(index, name, type,
|
||||||
serviceListModel.insert(index, {
|
background, backgroundType, text, itemID) {
|
||||||
"name": name,
|
serviceItemModel.insertItem(index, name,
|
||||||
"type": type,
|
type, text, background,
|
||||||
"text": text,
|
backgroundType)
|
||||||
"backgroundType": backgroundType,
|
|
||||||
"background": background})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendItem(name, type, text, backgroundType, background, itemID) {
|
function appendItem(name, type, background, backgroundType, text, itemID) {
|
||||||
serviceListModel.append({
|
let lyrics;
|
||||||
"name": name,
|
|
||||||
"type": type,
|
|
||||||
"text": text,
|
|
||||||
"backgroundType": backgroundType,
|
|
||||||
"background": background});
|
|
||||||
|
|
||||||
if (type == "song") {
|
if (type == "song") {
|
||||||
const lyrics = songsqlmodel.getLyricList(itemID);
|
lyrics = songsqlmodel.getLyricList(itemID);
|
||||||
/* print(lyrics); */
|
print(lyrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
print(background);
|
||||||
}
|
print(backgroundType);
|
||||||
|
|
||||||
|
serviceItemModel.addItem(name, type, background,
|
||||||
|
backgroundType, lyrics);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -129,6 +129,10 @@ Controls.Page {
|
||||||
id: videosqlmodel
|
id: videosqlmodel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServiceItemModel {
|
||||||
|
id: serviceItemModel
|
||||||
|
}
|
||||||
|
|
||||||
function changeSlideType(type) {
|
function changeSlideType(type) {
|
||||||
presentation.itemType = type;
|
presentation.itemType = type;
|
||||||
if (slideItem)
|
if (slideItem)
|
||||||
|
|
|
@ -1,88 +1,96 @@
|
||||||
#include "serviceitem.h"
|
#include "serviceitem.h"
|
||||||
#include <qvariant.h>
|
|
||||||
|
|
||||||
ServiceItem::ServiceItem(QObject *parent)
|
ServiceItem::ServiceItem(QObject *parent)
|
||||||
: QAbstractListModel(parent)
|
: QObject{parent}
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ServiceItem::rowCount(const QModelIndex &parent) const
|
ServiceItem::ServiceItem(const QString &name, const QString &type, QObject *parent)
|
||||||
|
: QObject(parent),m_name(name),m_type(type)
|
||||||
{
|
{
|
||||||
// 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
|
ServiceItem::ServiceItem(const QString &name, const QString &type, const QString &background,
|
||||||
|
const QString &backgroundType, QObject *parent)
|
||||||
|
: QObject(parent),m_name(name),m_type(type),m_background(background),m_backgroundType(backgroundType)
|
||||||
{
|
{
|
||||||
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 {
|
ServiceItem::ServiceItem(const QString &name, const QString &type, const QString &background,
|
||||||
static QHash<int, QByteArray> mapping {
|
const QString &backgroundType, const QStringList &text, QObject *parent)
|
||||||
{NameRole, "name"},
|
: QObject(parent),m_name(name),m_type(type),m_background(background),m_backgroundType(backgroundType),m_text(text)
|
||||||
{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!
|
}
|
||||||
|
|
||||||
|
QString ServiceItem::name() const {
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ServiceItem::type() const {
|
||||||
|
return m_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ServiceItem::background() const
|
||||||
|
{
|
||||||
|
return m_background;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ServiceItem::backgroundType() const
|
||||||
|
{
|
||||||
|
return m_backgroundType;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList ServiceItem::text() const
|
||||||
|
{
|
||||||
|
return m_text;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceItem::setName(QString name)
|
||||||
|
{
|
||||||
|
if (m_name == name)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_name = name;
|
||||||
|
emit nameChanged(m_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceItem::setType(QString type)
|
||||||
|
{
|
||||||
|
if (m_type == type)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_type = type;
|
||||||
|
emit typeChanged(m_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceItem::setBackground(QString background)
|
||||||
|
{
|
||||||
|
if (m_background == background)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_background = background;
|
||||||
|
emit backgroundChanged(m_background);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceItem::setBackgroundType(QString backgroundType)
|
||||||
|
{
|
||||||
|
if (m_backgroundType == backgroundType)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_backgroundType = backgroundType;
|
||||||
|
emit backgroundTypeChanged(m_backgroundType);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceItem::setText(QStringList text)
|
||||||
|
{
|
||||||
|
if (m_text == text)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_text = text;
|
||||||
|
emit textChanged(m_text);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +1,51 @@
|
||||||
#ifndef SERVICEITEM_H
|
#ifndef SERVICEITEM_H
|
||||||
#define SERVICEITEM_H
|
#define SERVICEITEM_H
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QObject>
|
||||||
#include <qnamespace.h>
|
#include <qobject.h>
|
||||||
|
|
||||||
struct Data {
|
class ServiceItem : public QObject
|
||||||
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
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||||
|
Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
|
||||||
|
Q_PROPERTY(QString background READ background WRITE setBackground NOTIFY backgroundChanged)
|
||||||
|
Q_PROPERTY(QString backgroundType READ backgroundType WRITE setBackgroundType NOTIFY backgroundTypeChanged)
|
||||||
|
Q_PROPERTY(QStringList text READ text WRITE setText NOTIFY textChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ServiceItem(QObject *parent = nullptr);
|
explicit ServiceItem(QObject *parent = nullptr);
|
||||||
|
ServiceItem(const QString &name, const QString &type, QObject * parent = nullptr);
|
||||||
|
ServiceItem(const QString &name, const QString &type, const QString &background,
|
||||||
|
const QString &backgroundType, QObject * parent = nullptr);
|
||||||
|
ServiceItem(const QString &name, const QString &type, const QString &background,
|
||||||
|
const QString &backgroundType, const QStringList &text, QObject * parent = nullptr);
|
||||||
|
|
||||||
enum Roles {
|
QString name() const;
|
||||||
NameRole = Qt::UserRole,
|
QString type() const;
|
||||||
TypeRole,
|
QString background() const;
|
||||||
BackgroundRole,
|
QString backgroundType() const;
|
||||||
BackgroundTypeRole,
|
QStringList text() const;
|
||||||
TextRole,
|
|
||||||
SlidesRole
|
|
||||||
};
|
|
||||||
|
|
||||||
// Basic functionality:
|
void setName(QString name);
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
void setType(QString type);
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
void setBackground(QString background);
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
void setBackgroundType(QString backgroundType);
|
||||||
|
void setText(QStringList text);
|
||||||
|
|
||||||
// Editable:
|
signals:
|
||||||
bool setData(const QModelIndex &index, const QVariant &value,
|
void nameChanged(QString name);
|
||||||
int role = Qt::EditRole) override;
|
void typeChanged(QString type);
|
||||||
|
void backgroundChanged(QString background);
|
||||||
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
void backgroundTypeChanged(QString backgroundType);
|
||||||
|
void textChanged(QStringList text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector<Data> m_data;
|
QString m_name;
|
||||||
|
QString m_type;
|
||||||
|
QString m_background;
|
||||||
|
QString m_backgroundType;
|
||||||
|
QStringList m_text;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SERVICEITEM_H
|
#endif // SERVICEITEM_H
|
||||||
|
|
190
src/serviceitemmodel.cpp
Normal file
190
src/serviceitemmodel.cpp
Normal file
|
@ -0,0 +1,190 @@
|
||||||
|
#include "serviceitemmodel.h"
|
||||||
|
#include "serviceitem.h"
|
||||||
|
#include <qabstractitemmodel.h>
|
||||||
|
#include <qnamespace.h>
|
||||||
|
#include <qvariant.h>
|
||||||
|
#include <qdebug.h>
|
||||||
|
|
||||||
|
ServiceItemModel::ServiceItemModel(QObject *parent)
|
||||||
|
: QAbstractListModel(parent) {
|
||||||
|
addItem(new ServiceItem("10,000 Resons", "song",
|
||||||
|
"file:/home/chris/nextcloud/tfc/openlp/CMG - Nature King 21.jpg",
|
||||||
|
"image", QStringList("Yip Yip")));
|
||||||
|
addItem(new ServiceItem("Marvelous Light", "song",
|
||||||
|
"file:/home/chris/nextcloud/tfc/openlp/Fire Embers_Loop.mp4",
|
||||||
|
"video", QStringList("Hallelujah!")));
|
||||||
|
addItem(new ServiceItem("BP Text", "video",
|
||||||
|
"file:/home/chris/nextcloud/tfc/openlp/videos/test.mp4",
|
||||||
|
"video", QStringList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
int ServiceItemModel::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_items.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ServiceItemModel::data(const QModelIndex &index, int role) const {
|
||||||
|
if (!index.isValid())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
ServiceItem *item = m_items[index.row()];
|
||||||
|
switch (role) {
|
||||||
|
case NameRole:
|
||||||
|
return item->name();
|
||||||
|
case TypeRole:
|
||||||
|
return item->type();
|
||||||
|
case BackgroundRole:
|
||||||
|
return item->background();
|
||||||
|
case BackgroundTypeRole:
|
||||||
|
return item->backgroundType();
|
||||||
|
case TextRole:
|
||||||
|
return item->text();
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> ServiceItemModel::roleNames() const {
|
||||||
|
static QHash<int, QByteArray> mapping{{NameRole, "name"},
|
||||||
|
{TypeRole, "type"},
|
||||||
|
{BackgroundRole, "background"},
|
||||||
|
{BackgroundTypeRole, "backgroundType"},
|
||||||
|
{TextRole, "text"}};
|
||||||
|
|
||||||
|
return mapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServiceItemModel::setData(const QModelIndex &index, const QVariant &value,
|
||||||
|
int role) {
|
||||||
|
|
||||||
|
ServiceItem *item = m_items[index.row()];
|
||||||
|
bool somethingChanged = false;
|
||||||
|
|
||||||
|
switch (role) {
|
||||||
|
case NameRole:
|
||||||
|
if (item->name() != value.toString()) {
|
||||||
|
item->setName(value.toString());
|
||||||
|
somethingChanged = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TypeRole:
|
||||||
|
if (item->type() != value.toString()) {
|
||||||
|
item->setType(value.toString());
|
||||||
|
somethingChanged = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BackgroundRole:
|
||||||
|
if (item->background() != value.toString()) {
|
||||||
|
item->setBackground(value.toString());
|
||||||
|
somethingChanged = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BackgroundTypeRole:
|
||||||
|
if (item->backgroundType() != value.toString()) {
|
||||||
|
item->setBackgroundType(value.toString());
|
||||||
|
somethingChanged = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TextRole:
|
||||||
|
if (item->text() != value.toStringList()) {
|
||||||
|
item->setText(value.toStringList());
|
||||||
|
somethingChanged = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
if (somethingChanged) {
|
||||||
|
emit dataChanged(index, index, QVector<int>() << role);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags ServiceItemModel::flags(const QModelIndex &index) const {
|
||||||
|
if (!index.isValid())
|
||||||
|
return Qt::NoItemFlags;
|
||||||
|
|
||||||
|
return Qt::ItemIsEditable; // FIXME: Implement me!
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceItemModel::addItem(ServiceItem *item) {
|
||||||
|
const int index = m_items.size();
|
||||||
|
beginInsertRows(QModelIndex(), index, index);
|
||||||
|
m_items.append(item);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceItemModel::insertItem(const int &index, ServiceItem *item) {
|
||||||
|
beginInsertRows(this->index(index), index, index);
|
||||||
|
m_items.insert(index, item);
|
||||||
|
endInsertRows();
|
||||||
|
qDebug() << "Success";
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceItemModel::addItem(const QString &name, const QString &type) {
|
||||||
|
ServiceItem *item = new ServiceItem(name, type);
|
||||||
|
addItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceItemModel::addItem(const QString &name, const QString &type,
|
||||||
|
const QString &background, const QString &backgroundType) {
|
||||||
|
ServiceItem *item = new ServiceItem(name, type, background, backgroundType);
|
||||||
|
addItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceItemModel::addItem(const QString &name, const QString &type,
|
||||||
|
const QString &background, const QString &backgroundType,
|
||||||
|
const QStringList &text) {
|
||||||
|
ServiceItem *item = new ServiceItem(name, type, background, backgroundType, text);
|
||||||
|
addItem(item);
|
||||||
|
qDebug() << name << type << background;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceItemModel::insertItem(const int &index, const QString &name, const QString &type) {
|
||||||
|
ServiceItem *item = new ServiceItem(name, type);
|
||||||
|
insertItem(index, item);
|
||||||
|
qDebug() << name << type;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceItemModel::insertItem(const int &index, const QString &name, const QString &type,
|
||||||
|
const QString &background, const QString &backgroundType) {
|
||||||
|
ServiceItem *item = new ServiceItem(name, type, background, backgroundType);
|
||||||
|
insertItem(index, item);
|
||||||
|
qDebug() << name << type << background;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceItemModel::insertItem(const int &index, const QString &name, const QString &type,
|
||||||
|
const QString &background, const QString &backgroundType,
|
||||||
|
const QStringList &text) {
|
||||||
|
ServiceItem *item = new ServiceItem(name, type, background, backgroundType, text);
|
||||||
|
insertItem(index, item);
|
||||||
|
qDebug() << name << type << background;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceItemModel::removeItem(int index) {
|
||||||
|
beginRemoveRows(QModelIndex(), index, index);
|
||||||
|
m_items.removeAt(index);
|
||||||
|
endRemoveRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServiceItemModel::move(int sourceIndex, int destIndex) {
|
||||||
|
qDebug() << "starting move";
|
||||||
|
QModelIndex parent = index(sourceIndex).parent();
|
||||||
|
bool begsuc = beginMoveRows(parent, sourceIndex, sourceIndex, parent, destIndex);
|
||||||
|
qDebug() << begsuc;
|
||||||
|
if (!begsuc) {
|
||||||
|
qDebug() << "Failed to start moving rows";
|
||||||
|
m_items.move(sourceIndex, destIndex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// bool success = moveRow(index(sourceIndex).parent(), sourceIndex, index(destIndex).parent(), destIndex);
|
||||||
|
endMoveRows();
|
||||||
|
// qDebug() << success;
|
||||||
|
return true;
|
||||||
|
}
|
64
src/serviceitemmodel.h
Normal file
64
src/serviceitemmodel.h
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
#ifndef SERVICEITEMMODEL_H
|
||||||
|
#define SERVICEITEMMODEL_H
|
||||||
|
|
||||||
|
#include "serviceitem.h"
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
#include <qabstractitemmodel.h>
|
||||||
|
#include <qnamespace.h>
|
||||||
|
#include <qobjectdefs.h>
|
||||||
|
#include <qsize.h>
|
||||||
|
|
||||||
|
class ServiceItemModel : public QAbstractListModel {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ServiceItemModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
enum Roles {
|
||||||
|
NameRole = Qt::UserRole,
|
||||||
|
TypeRole,
|
||||||
|
BackgroundRole,
|
||||||
|
BackgroundTypeRole,
|
||||||
|
TextRole
|
||||||
|
};
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
// Helper methods
|
||||||
|
void addItem(ServiceItem *item);
|
||||||
|
void insertItem(const int &index, ServiceItem *item);
|
||||||
|
Q_INVOKABLE void addItem(const QString &name, const QString &type);
|
||||||
|
// Q_INVOKABLE void addItem(const QString &name, const QString &type,
|
||||||
|
// const QString &background);
|
||||||
|
Q_INVOKABLE void addItem(const QString &name, const QString &type,
|
||||||
|
const QString &background,
|
||||||
|
const QString &backgroundType);
|
||||||
|
Q_INVOKABLE void addItem(const QString &name, const QString &type,
|
||||||
|
const QString &background,
|
||||||
|
const QString &backgroundType,
|
||||||
|
const QStringList &text);
|
||||||
|
Q_INVOKABLE void insertItem(const int &index, const QString &name,
|
||||||
|
const QString &type);
|
||||||
|
Q_INVOKABLE void insertItem(const int &index, const QString &name,
|
||||||
|
const QString &type, const QString &background,
|
||||||
|
const QString &backgroundType);
|
||||||
|
Q_INVOKABLE void insertItem(const int &index, const QString &name,
|
||||||
|
const QString &type, const QString &background,
|
||||||
|
const QString &backgroundType, const QStringList &text);
|
||||||
|
Q_INVOKABLE void removeItem(int index);
|
||||||
|
Q_INVOKABLE bool move(int sourceIndex, int destIndex);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<ServiceItem *> m_items;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SERVICEITEMMODEL_H
|
Loading…
Add table
Add a link
Reference in a new issue