From b40d9e11a64f4dd36bd2dea9b2d778f137210b74 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sat, 21 Jan 2023 07:23:33 -0600 Subject: [PATCH] adding of items now adds slides as well through signal/slot --- src/cpp/serviceitemmodel.cpp | 81 +++++-------------------------- src/cpp/serviceitemmodel.h | 20 +++----- src/cpp/slidemodel.cpp | 72 +++++++++++++++++++++++++++ src/cpp/slidemodel.h | 12 ++--- src/main.cpp | 12 +++-- src/qml/presenter/ServiceList.qml | 14 +++--- 6 files changed, 107 insertions(+), 104 deletions(-) diff --git a/src/cpp/serviceitemmodel.cpp b/src/cpp/serviceitemmodel.cpp index 8065b19..ff88a39 100644 --- a/src/cpp/serviceitemmodel.cpp +++ b/src/cpp/serviceitemmodel.cpp @@ -277,7 +277,7 @@ void ServiceItemModel::addItem(const QString &name, const QString &type, const QString &background, const QString &backgroundType, const QStringList &text, const QString &audio, const QString &font, const int &fontSize, - const int &slideNumber, SlideModel &slideModel) { + const int &slideNumber) { qDebug() << "*************************"; qDebug() << "Plain adding item: " << name; qDebug() << "*************************"; @@ -285,36 +285,9 @@ void ServiceItemModel::addItem(const QString &name, const QString &type, text, audio, font, fontSize, slideNumber); item->setSelected(false); item->setActive(false); - if (type == "song") { - for (int i = 0; i < text.size(); i++) { - if (backgroundType == "image") { - slideModel.addItem(text[i], type, background, "", audio, font, fontSize, - "horizontalTextAlignment", "verticalTextAlignment", - rowCount(), i, 0); - } else { - slideModel.addItem(text[i], type, "", background, audio, font, fontSize, - "horizontalTextAlignment", "verticalTextAlignment", - rowCount(), i, 0); - } - } - } else if (type == "presentation") { - for (int i = 0; i < slideNumber; i++) { - slideModel.addItem("", type, background, "", audio, font, fontSize, - "horizontalTextAlignment", "verticalTextAlignment", - rowCount(), i, slideNumber); - } - } else if (type == "video") { - slideModel.addItem("", type, "", background, - audio, font, fontSize, - "center", "center", - rowCount(), 0, 1); - } else { - slideModel.addItem("", type, background, "", - audio, font, fontSize, - "center", "center", - rowCount(), 0, 1); - } addItem(item); + emit itemAdded(rowCount() - 1, *item); + qDebug() << "EMITTED ITEM ADDED" << rowCount(); qDebug() << "#################################"; qDebug() << name << type << font << fontSize << slideNumber; qDebug() << "#################################"; @@ -376,8 +349,7 @@ void ServiceItemModel::insertItem(const int &index, const QString &name, const QString &type,const QString &background, const QString &backgroundType,const QStringList &text, const QString &audio, const QString &font, - const int &fontSize, const int &slideNumber, - SlideModel &slideModel) { + const int &fontSize, const int &slideNumber) { qDebug() << "*************************"; qDebug() << "Inserting serviceItem: " << name << " and index is " << index; qDebug() << "*************************"; @@ -385,43 +357,12 @@ void ServiceItemModel::insertItem(const int &index, const QString &name, text, audio, font, fontSize, slideNumber); item->setSelected(false); item->setActive(false); - int slideModelIdx = slideModel.findSlideIdFromServItm(index); - if (type == "song") { - for (int i = 0; i < text.size(); i++) { - if (backgroundType == "image") { - slideModel.insertItem(slideModelIdx, type, background, "", - text[i], audio, font, fontSize, - "center", "center", - rowCount(), i, 0); - } else { - slideModel.insertItem(slideModelIdx, type, "", background, - text[i], audio, font, fontSize, - "center", "center", - rowCount(), i, 0); - } - } - } else if (type == "presentation") { - for (int i = 0; i < slideNumber; i++) { - slideModel.insertItem(slideModelIdx, type, background, "", - "", audio, font, fontSize, - "center", "center", - rowCount(), i, slideNumber); - } - } else if (type == "video") { - slideModel.insertItem(slideModelIdx, type, "", background, "", - audio, font, fontSize, - "center", "center", - rowCount(), 0, 1); - } else { - slideModel.insertItem(slideModelIdx, type, background, "", "", - audio, font, fontSize, - "center", "center", - rowCount(), 0, 1); - } insertItem(index, item); + emit itemInserted(index, *item); + qDebug() << "EMITTED ITEM INSERTED"; qDebug() << "#################################"; qDebug() << "INSERTING SERVICE ITEM!"; - qDebug() << name << type << font << fontSize << slideNumber << index << slideModelIdx; + qDebug() << name << type << font << fontSize << slideNumber << index; qDebug() << "#################################"; } @@ -721,7 +662,7 @@ bool ServiceItemModel::save(QUrl file) { return false; } -bool ServiceItemModel::load(QUrl file, SlideModel &slideModel) { +bool ServiceItemModel::load(QUrl file) { qDebug() << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"; qDebug() << "Loading..."; qDebug() << "File path is: " << file.toString(); @@ -827,7 +768,7 @@ bool ServiceItemModel::load(QUrl file, SlideModel &slideModel) { item.value("backgroundType").toString(), item.value("text").toStringList(), realAudio, item.value("font").toString(), item.value("fontSize").toInt(), - item.value("slideNumber").toInt(), slideModel); + item.value("slideNumber").toInt()); } return true; @@ -843,7 +784,7 @@ void ServiceItemModel::clearAll() { } } -bool ServiceItemModel::loadLastSaved(SlideModel &slideModel) { +bool ServiceItemModel::loadLastSaved() { QSettings settings; - return load(settings.value("lastSaveFile").toUrl(), slideModel); + return load(settings.value("lastSaveFile").toUrl()); } diff --git a/src/cpp/serviceitemmodel.h b/src/cpp/serviceitemmodel.h index f7a7d5e..9c20b96 100644 --- a/src/cpp/serviceitemmodel.h +++ b/src/cpp/serviceitemmodel.h @@ -72,7 +72,7 @@ public: const QString &backgroundType, const QStringList &text, const QString &audio, const QString &font, const int &fontSize, - const int &slideNumber, SlideModel &slideModel); + const int &slideNumber); // Q_INVOKABLE void insertItem(const int &index, const QString &name, // const QString &type); // Q_INVOKABLE void insertItem(const int &index, const QString &name, @@ -93,8 +93,7 @@ public: const QString &type, const QString &background, const QString &backgroundType, const QStringList &text, const QString &audio, const QString &font, - const int &fontSize, const int &slideNumber, - SlideModel &slideModel); + const int &fontSize, const int &slideNumber); Q_INVOKABLE void removeItem(int index); Q_INVOKABLE bool moveRows(int sourceIndex, int destIndex, int count); Q_INVOKABLE bool moveDown(int index); @@ -107,19 +106,12 @@ public: Q_INVOKABLE void clearAll(); Q_INVOKABLE bool save(QUrl file); - Q_INVOKABLE bool load(QUrl file, SlideModel &slideModel); - Q_INVOKABLE bool loadLastSaved(SlideModel &slideModel); + Q_INVOKABLE bool load(QUrl file); + Q_INVOKABLE bool loadLastSaved(); signals: - void itemAdded(const int &index, const QString &type, - const QString &background, const QString &backgroundType, - const QStringList &text, const QString &audio, - const QString &font, const int &fontSize, const int &slideNumber); - - void itemInserted(const int &index, const QString &type, - const QString &background, const QString &backgroundType, - const QStringList &text, const QString &audio, - const QString &font, const int &fontSize, const int &slideNumber); + void itemAdded(const int &, const ServiceItem &); + void itemInserted(const int &, const ServiceItem &); private: diff --git a/src/cpp/slidemodel.cpp b/src/cpp/slidemodel.cpp index e6de0db..5917677 100644 --- a/src/cpp/slidemodel.cpp +++ b/src/cpp/slidemodel.cpp @@ -1,4 +1,5 @@ #include "slidemodel.h" +#include "serviceitem.h" #include "slide.h" #include #include @@ -476,3 +477,74 @@ int SlideModel::findSlideIdFromServItm(int index) { } return -1; } + +void SlideModel::addItemFromService(const int &index, const ServiceItem &item) { + qDebug() << "***INSERTING SLIDE FROM SERVICEITEM***"; + if (item.type() == "song") { + for (int i = 0; i < item.text().size(); i++) { + if (item.backgroundType() == "image") { + addItem(item.text()[i], item.type(), item.background(), "", + item.audio(), item.font(), item.fontSize(), "center", "center", + index, i, item.text().size()); + } else { + addItem(item.text()[i], item.type(), "", item.background(), + item.audio(), item.font(), item.fontSize(), "center", "center", + index, i, item.text().size()); + } + } + } else if (item.type() == "presentation") { + for (int i = 0; i < item.slideNumber(); i++) { + addItem("", item.type(), item.background(), "", + item.audio(), item.font(), item.fontSize(), + "center", "center", + index, i, item.slideNumber()); + } + } else if (item.type() == "video") { + addItem("", item.type(), "", item.background(), + item.audio(), item.font(), item.fontSize(), + "center", "center", + index, 0, 1); + } else { + addItem("", item.type(), item.background(), "", + item.audio(), item.font(), item.fontSize(), + "center", "center", + index, 0, 1); + } + +} + +void SlideModel::insertItemFromService(const int &index, const ServiceItem &item) { + qDebug() << "***INSERTING SLIDE FROM SERVICEITEM***"; + int slideId = findSlideIdFromServItm(index); + if (item.type() == "song") { + for (int i = 0; i < item.text().size(); i++) { + if (item.backgroundType() == "image") { + insertItem(slideId + i, item.type(), item.background(), "", item.text()[i], + item.audio(), item.font(), item.fontSize(), "center", "center", + index, i, item.text().size()); + } else { + insertItem(slideId + i, item.type(), "", item.background(), item.text()[i], + item.audio(), item.font(), item.fontSize(), "center", "center", + index, i, item.text().size()); + } + } + } else if (item.type() == "presentation") { + for (int i = 0; i < item.slideNumber(); i++) { + insertItem(slideId + i, item.type(), item.background(), "", + "", item.audio(), item.font(), item.fontSize(), + "center", "center", + index, i, item.slideNumber()); + } + } else if (item.type() == "video") { + insertItem(slideId, item.type(), "", item.background(), "", + item.audio(), item.font(), item.fontSize(), + "center", "center", + index, 0, 1); + } else { + insertItem(slideId, item.type(), item.background(), "", "", + item.audio(), item.font(), item.fontSize(), + "center", "center", + index, 0, 1); + } + +} diff --git a/src/cpp/slidemodel.h b/src/cpp/slidemodel.h index 2a9c1f3..d857241 100644 --- a/src/cpp/slidemodel.h +++ b/src/cpp/slidemodel.h @@ -1,6 +1,7 @@ #ifndef SLIDEMODEL_H #define SLIDEMODEL_H +#include "serviceitem.h" #include "slide.h" #include #include @@ -83,15 +84,8 @@ public: Q_INVOKABLE int findSlideIdFromServItm(int index); public slots: - void addItemFromService(const int &index, const QString &type, - const QString &background, const QString &backgroundType, - const QStringList &text, const QString &audio, - const QString &font, const int &fontSize, const int &slideNumber); - - void insertItemFromService(const int &index, const QString &type, - const QString &background, const QString &backgroundType, - const QStringList &text, const QString &audio, - const QString &font, const int &fontSize, const int &slideNumber); + void addItemFromService(const int &index, const ServiceItem &item); + void insertItemFromService(const int &index, const ServiceItem &item); private: QList m_items; diff --git a/src/main.cpp b/src/main.cpp index 4b7fc23..47dab03 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -139,10 +139,16 @@ int main(int argc, char *argv[]) QScopedPointer slideobject(new SlideObject); preswin->setSource(QUrl(QStringLiteral("qrc:qml/presenter/PresentationWindow.qml"))); - QObject::connect(serviceItemModel.get(), &ServiceItemModel::itemAdded, - slideModel.get(), &SlideModel::addItem()) + QObject::connect(serviceItemModel.get(), + SIGNAL(itemInserted(const int&, const ServiceItem&)), + slideModel.get(), + SLOT(insertItemFromService(const int&, const ServiceItem&))); + QObject::connect(serviceItemModel.get(), + SIGNAL(itemAdded(const int&, const ServiceItem&)), + slideModel.get(), + SLOT(addItemFromService(const int&, const ServiceItem&))); - bool loading = serviceItemModel.get()->loadLastSaved(*slideModel.get()); + bool loading = serviceItemModel.get()->loadLastSaved(); // apparently mpv needs this class set // let's register mpv as well diff --git a/src/qml/presenter/ServiceList.qml b/src/qml/presenter/ServiceList.qml index 76bab92..ef99ab9 100644 --- a/src/qml/presenter/ServiceList.qml +++ b/src/qml/presenter/ServiceList.qml @@ -520,7 +520,7 @@ Item { ServiceItemModel.insertItem(index, name, type, background, backgroundType, newtext, - audio, font, fontSize, newtext.length, SlideModel); + audio, font, fontSize, newtext.length); /* totalServiceItems++; */ return; } @@ -529,7 +529,7 @@ Item { ServiceItemModel.insertItem(index, name, type, background, backgroundType, "", - "", "", 0, dragItemSlideNumber, SlideModel); + "", "", 0, dragItemSlideNumber); /* totalServiceItems++; */ return; } @@ -537,7 +537,7 @@ Item { ServiceItemModel.insertItem(index, name, type, background, backgroundType, "", "", - "", 0, 0, SlideModel); + "", 0, 0); /* totalServiceItems++; */ } @@ -552,8 +552,7 @@ Item { console.log(lyrics); ServiceItemModel.addItem(name, type, background, backgroundType, lyrics, - audio, font, fontSize, lyrics.length(), - SlideModel); + audio, font, fontSize, lyrics.length()); /* totalServiceItems++; */ return; }; @@ -565,8 +564,7 @@ Item { ServiceItemModel.addItem(name, type, background, backgroundType, "", audio, font, fontSize, - dragSlideItemNumber, - SlideModel); + dragSlideItemNumber); /* totalServiceItems++; */ return; }; @@ -575,7 +573,7 @@ Item { ServiceItemModel.addItem(name, type, background, backgroundType, [""], "", - "", 0, 0, SlideModel); + "", 0, 0); /* totalServiceItems++; */ }