making presentation library work
This commit is contained in:
parent
96de8e3b00
commit
5713f40208
6 changed files with 78 additions and 46 deletions
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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<SongSqlModel>("org.presenter", 1, 0, "SongSqlModel");
|
||||
qmlRegisterType<VideoSqlModel>("org.presenter", 1, 0, "VideoSqlModel");
|
||||
qmlRegisterType<ImageSqlModel>("org.presenter", 1, 0, "ImageSqlModel");
|
||||
qmlRegisterType<PresSqlModel>("org.presenter", 1, 0, "PresSqlModel");
|
||||
qmlRegisterType<PresentationSqlModel>("org.presenter", 1, 0, "PresentationSqlModel");
|
||||
qmlRegisterType<ServiceItemModel>("org.presenter", 1, 0, "ServiceItemModel");
|
||||
qmlRegisterSingletonInstance("org.presenter", 1, 0, "SlideObject", slide.get());
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "pressqlmodel.h"
|
||||
#include "presentationsqlmodel.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
|
@ -17,15 +17,17 @@
|
|||
#include <qurl.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
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<int, QByteArray> PresSqlModel::roleNames() const
|
||||
QHash<int, QByteArray> PresentationSqlModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> names;
|
||||
names[Qt::UserRole] = "id";
|
||||
|
@ -74,8 +76,8 @@ QHash<int, QByteArray> 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);
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef PRESSQLMODEL_H
|
||||
#define PRESSQLMODEL_H
|
||||
#ifndef PRESENTATIONSQLMODEL_H
|
||||
#define PRESENTATIONSQLMODEL_H
|
||||
|
||||
#include <QSqlTableModel>
|
||||
#include <qobject.h>
|
||||
|
@ -8,7 +8,7 @@
|
|||
#include <qurl.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
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<int, QByteArray> roleNames() const override;
|
||||
|
@ -46,4 +46,4 @@ private:
|
|||
QUrl m_filePath;
|
||||
};
|
||||
|
||||
#endif //PRESSQLMODEL_H
|
||||
#endif //PRESENTATIONSQLMODEL_H
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ Controls.Page {
|
|||
id: imagesqlmodel
|
||||
}
|
||||
|
||||
PresSqlModel {
|
||||
PresentationSqlModel {
|
||||
id: pressqlmodel
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue