From 5713f402085b491817fd99bef21388c8d9843c84 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 23 Sep 2022 05:41:36 -0500 Subject: [PATCH] making presentation library work --- src/CMakeLists.txt | 1 + src/main.cpp | 4 +- ...ssqlmodel.cpp => presentationsqlmodel.cpp} | 61 ++++++++++--------- ...{pressqlmodel.h => presentationsqlmodel.h} | 16 ++--- src/qml/presenter/Library.qml | 40 ++++++++++-- src/qml/presenter/MainWindow.qml | 2 +- 6 files changed, 78 insertions(+), 46 deletions(-) rename src/{pressqlmodel.cpp => presentationsqlmodel.cpp} (69%) rename src/{pressqlmodel.h => presentationsqlmodel.h} (71%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 708ac08..3133497 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,6 +9,7 @@ target_sources(presenter slide.cpp slide.h videosqlmodel.cpp videosqlmodel.h imagesqlmodel.cpp imagesqlmodel.h + presentationsqlmodel.cpp presentationsqlmodel.h mpv/mpvobject.h mpv/mpvobject.cpp mpv/qthelper.hpp mpv/mpvhelpers.h ) diff --git a/src/main.cpp b/src/main.cpp index 429295c..68d4e6a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,7 +38,7 @@ #include "songsqlmodel.h" #include "videosqlmodel.h" #include "imagesqlmodel.h" -#include "pressqlmodel.h" +#include "presentationsqlmodel.h" #include "slide.h" static void connectToDatabase() { @@ -106,7 +106,7 @@ int main(int argc, char *argv[]) qmlRegisterType("org.presenter", 1, 0, "SongSqlModel"); qmlRegisterType("org.presenter", 1, 0, "VideoSqlModel"); qmlRegisterType("org.presenter", 1, 0, "ImageSqlModel"); - qmlRegisterType("org.presenter", 1, 0, "PresSqlModel"); + qmlRegisterType("org.presenter", 1, 0, "PresentationSqlModel"); qmlRegisterType("org.presenter", 1, 0, "ServiceItemModel"); qmlRegisterSingletonInstance("org.presenter", 1, 0, "SlideObject", slide.get()); diff --git a/src/pressqlmodel.cpp b/src/presentationsqlmodel.cpp similarity index 69% rename from src/pressqlmodel.cpp rename to src/presentationsqlmodel.cpp index b7d42c6..f0f538f 100644 --- a/src/pressqlmodel.cpp +++ b/src/presentationsqlmodel.cpp @@ -1,4 +1,4 @@ -#include "pressqlmodel.h" +#include "presentationsqlmodel.h" #include #include @@ -17,15 +17,17 @@ #include #include -static const char *presTableName = "presentation"; +static const char *presentationsTableName = "presentations"; -static void createPresTable() +static void createPresentationTable() { - if(QSqlDatabase::database().tables().contains(presTableName)) { + QSqlQuery query; + if(QSqlDatabase::database().tables().contains(presentationsTableName)) { + // query.exec("DROP TABLE 'presentations'"); + // qDebug() << query.lastQuery(); return; } - QSqlQuery query; if (!query.exec("CREATE TABLE IF NOT EXISTS 'presentations' (" " 'id' INTEGER NOT NULL," " 'title' TEXT NOT NULL," @@ -37,25 +39,25 @@ static void createPresTable() qDebug() << query.lastQuery(); qDebug() << "inserting into presentations"; - query.exec("INSERT INTO presentations (title, filePath) VALUES ('Dec 180', 'file:///home/chris/nextcloud/tfc/openlp/5 slides-2.pdf')"); + query.exec("INSERT INTO presentations (title, filePath) VALUES ('Dec 180', 'file:///home/chris/nextcloud/tfc/openlp/5 slides-1.pdf')"); qDebug() << query.lastQuery(); query.exec("INSERT INTO presentations (title, filePath) VALUES ('No TFC', " - "'file:///home/chris/nextcloud/tfc/openlp/5 slides-1.pdf')"); + "'file:///home/chris/nextcloud/tfc/openlp/5 slides-2.pdf')"); query.exec("select * from presentations"); qDebug() << query.lastQuery(); } -PresSqlModel::PresSqlModel(QObject *parent) : QSqlTableModel(parent) { - qDebug() << "creating pres table"; - createPresTable(); - setTable(pressTableName); +PresentationSqlModel::PresentationSqlModel(QObject *parent) : QSqlTableModel(parent) { + qDebug() << "creating presentation table"; + createPresentationTable(); + setTable(presentationsTableName); setEditStrategy(QSqlTableModel::OnManualSubmit); // make sure to call select else the model won't fill select(); } -QVariant PresSqlModel::data(const QModelIndex &index, int role) const { +QVariant PresentationSqlModel::data(const QModelIndex &index, int role) const { if (role < Qt::UserRole) { return QSqlTableModel::data(index, role); } @@ -65,7 +67,7 @@ QVariant PresSqlModel::data(const QModelIndex &index, int role) const { return sqlRecord.value(role - Qt::UserRole); } -QHash PresSqlModel::roleNames() const +QHash PresentationSqlModel::roleNames() const { QHash names; names[Qt::UserRole] = "id"; @@ -74,8 +76,8 @@ QHash PresSqlModel::roleNames() const return names; } -void PresSqlModel::newPres(const QUrl &filePath) { - qDebug() << "adding new pres"; +void PresentationSqlModel::newPresentation(const QUrl &filePath) { + qDebug() << "adding new presentation"; int rows = rowCount(); qDebug() << rows; @@ -92,7 +94,7 @@ void PresSqlModel::newPres(const QUrl &filePath) { }; } -void PresSqlModel::deletePres(const int &row) { +void PresentationSqlModel::deletePresentation(const int &row) { QSqlRecord recordData = record(row); if (recordData.isEmpty()) return; @@ -101,15 +103,15 @@ void PresSqlModel::deletePres(const int &row) { submitAll(); } -int PresSqlModel::id() const { +int PresentationSqlModel::id() const { return m_id; } -QString PresSqlModel::title() const { +QString PresentationSqlModel::title() const { return m_title; } -void PresSqlModel::setTitle(const QString &title) { +void PresentationSqlModel::setTitle(const QString &title) { if (title == m_title) return; @@ -120,7 +122,7 @@ void PresSqlModel::setTitle(const QString &title) { } // This function is for updating the title from outside the delegate -void PresSqlModel::updateTitle(const int &row, const QString &title) { +void PresentationSqlModel::updateTitle(const int &row, const QString &title) { qDebug() << "Row is " << row; QSqlRecord rowdata = record(row); qDebug() << rowdata; @@ -131,11 +133,11 @@ void PresSqlModel::updateTitle(const int &row, const QString &title) { emit titleChanged(); } -QUrl PresSqlModel::filePath() const { +QUrl PresentationSqlModel::filePath() const { return m_filePath; } -void PresSqlModel::setFilePath(const QUrl &filePath) { +void PresentationSqlModel::setFilePath(const QUrl &filePath) { if (filePath == m_filePath) return; @@ -146,7 +148,7 @@ void PresSqlModel::setFilePath(const QUrl &filePath) { } // This function is for updating the filepath from outside the delegate -void PresSqlModel::updateFilePath(const int &row, const QUrl &filePath) { +void PresentationSqlModel::updateFilePath(const int &row, const QUrl &filePath) { qDebug() << "Row is " << row; QSqlRecord rowdata = record(row); qDebug() << rowdata; @@ -157,16 +159,15 @@ void PresSqlModel::updateFilePath(const int &row, const QUrl &filePath) { emit filePathChanged(); } -// Here we grab the presentation from it's row id -QVariantMap PresSqlModel::getPres(const int &row) { +QVariantMap PresentationSqlModel::getPresentation(const int &row) { // qDebug() << "Row we are getting is " << row; - // QUrl pres; + // QUrl presentation; // QSqlRecord rec = record(row); // qDebug() << rec.value("filePath").toUrl(); - // // pres.append(rec.value("title")); - // // pres.append(rec.value("filePath")); - // pres = rec.value("filePath").toUrl(); - // return pres; + // // presentation.append(rec.value("title")); + // // presentation.append(rec.value("filePath")); + // presentation = rec.value("filePath").toUrl(); + // return presentation; QVariantMap data; const QModelIndex idx = this->index(row,0); diff --git a/src/pressqlmodel.h b/src/presentationsqlmodel.h similarity index 71% rename from src/pressqlmodel.h rename to src/presentationsqlmodel.h index 1d73408..39fe00a 100644 --- a/src/pressqlmodel.h +++ b/src/presentationsqlmodel.h @@ -1,5 +1,5 @@ -#ifndef PRESSQLMODEL_H -#define PRESSQLMODEL_H +#ifndef PRESENTATIONSQLMODEL_H +#define PRESENTATIONSQLMODEL_H #include #include @@ -8,7 +8,7 @@ #include #include -class PresSqlModel : public QSqlTableModel +class PresentationSqlModel : public QSqlTableModel { Q_OBJECT Q_PROPERTY(int id READ id) @@ -17,7 +17,7 @@ class PresSqlModel : public QSqlTableModel QML_ELEMENT public: - PresSqlModel(QObject *parent = 0); + PresentationSqlModel(QObject *parent = 0); int id() const; QString title() const; @@ -29,9 +29,9 @@ public: Q_INVOKABLE void updateTitle(const int &row, const QString &title); Q_INVOKABLE void updateFilePath(const int &row, const QUrl &filePath); - Q_INVOKABLE void newPres(const QUrl &filePath); - Q_INVOKABLE void deletePres(const int &row); - Q_INVOKABLE QVariantMap getPres(const int &row); + Q_INVOKABLE void newPresentation(const QUrl &filePath); + Q_INVOKABLE void deletePresentation(const int &row); + Q_INVOKABLE QVariantMap getPresentation(const int &row); QVariant data(const QModelIndex &index, int role) const override; QHash roleNames() const override; @@ -46,4 +46,4 @@ private: QUrl m_filePath; }; -#endif //PRESSQLMODEL_H +#endif //PRESENTATIONSQLMODEL_H diff --git a/src/qml/presenter/Library.qml b/src/qml/presenter/Library.qml index c1f0ac0..c0be45c 100644 --- a/src/qml/presenter/Library.qml +++ b/src/qml/presenter/Library.qml @@ -692,8 +692,38 @@ Item { color: Kirigami.Theme.backgroundColor Controls.Label { - anchors.centerIn: parent + id: presentationLabel + anchors.right: presentationCount.left + anchors.rightMargin: 15 + anchors.verticalCenter: parent.verticalCenter text: "Presentations" + elide: Text.ElideRight + } + + Controls.Label { + id: presentationCount + anchors {right: presentationDrawerArrow.left + verticalCenter: presentationLabel.verticalCenter + rightMargin: 10} + text: pressqlmodel.rowCount() + font.pixelSize: 15 + color: Kirigami.Theme.disabledTextColor + } + + Kirigami.Icon { + id: presentationDrawerArrow + anchors {right: parent.right + verticalCenter: presentationCount.verticalCenter + rightMargin: 10} + source: "arrow-down" + rotation: selectedLibrary == "presentations" ? 0 : 180 + + Behavior on rotation { + NumberAnimation { + easing.type: Easing.OutCubic + duration: 300 + } + } } MouseArea { @@ -747,14 +777,14 @@ Item { id: presDelegate Item{ implicitWidth: ListView.view.width - height: selectedLibrary == "press" ? 50 : 0 + height: selectedLibrary == "presentations" ? 50 : 0 Kirigami.BasicListItem { id: presListItem property bool rightMenu: false implicitWidth: presentationLibraryList.width - height: selectedLibrary == "press" ? 50 : 0 + height: selectedLibrary == "presentations" ? 50 : 0 clip: true label: title /* subtitle: author */ @@ -833,7 +863,7 @@ Item { rightClickPresMenu.popup() else{ presentationLibraryList.currentIndex = index - const pres = pressqlmodel.getPres(presentationLibraryList.currentIndex); + const pres = pressqlmodel.getPresentation(presentationLibraryList.currentIndex); if (!editMode) editMode = true; editType = "pres"; @@ -849,7 +879,7 @@ Item { y: presClickHandler.mouseY + 10 Kirigami.Action { text: "delete" - onTriggered: pressqlmodel.deletePres(index) + onTriggered: pressqlmodel.deletePresentation(index) } } } diff --git a/src/qml/presenter/MainWindow.qml b/src/qml/presenter/MainWindow.qml index 848d891..d784152 100644 --- a/src/qml/presenter/MainWindow.qml +++ b/src/qml/presenter/MainWindow.qml @@ -115,7 +115,7 @@ Controls.Page { id: imagesqlmodel } - PresSqlModel { + PresentationSqlModel { id: pressqlmodel }