using video_model.rs and presentation_model.rs
These are hopefully a better alternative than the cpp counterparts after some more time
This commit is contained in:
parent
020e812bce
commit
9d05a7e655
8 changed files with 75 additions and 28 deletions
|
@ -243,14 +243,15 @@ QVariantMap PresentationSqlModel::getPresentation(const int &row) {
|
||||||
PresentationProxyModel::PresentationProxyModel(QObject *parent)
|
PresentationProxyModel::PresentationProxyModel(QObject *parent)
|
||||||
:QSortFilterProxyModel(parent)
|
:QSortFilterProxyModel(parent)
|
||||||
{
|
{
|
||||||
m_presentationModel = new PresentationSqlModel;
|
m_presentationModel = new PresentationModel;
|
||||||
|
m_presentationModel->testDatabase();
|
||||||
setSourceModel(m_presentationModel);
|
setSourceModel(m_presentationModel);
|
||||||
setDynamicSortFilter(true);
|
setDynamicSortFilter(true);
|
||||||
setFilterRole(Qt::UserRole + 1);
|
setFilterRole(Qt::UserRole + 1);
|
||||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
PresentationSqlModel *PresentationProxyModel::presentationModel() {
|
PresentationModel *PresentationProxyModel::presentationModel() {
|
||||||
return m_presentationModel;
|
return m_presentationModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,21 +262,21 @@ QModelIndex PresentationProxyModel::idx(int row) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap PresentationProxyModel::getPresentation(const int &row) {
|
QVariantMap PresentationProxyModel::getPresentation(const int &row) {
|
||||||
auto model = qobject_cast<PresentationSqlModel *>(sourceModel());
|
auto model = qobject_cast<PresentationModel *>(sourceModel());
|
||||||
QVariantMap presentation = model->getPresentation(mapToSource(index(row, 0)).row());
|
QVariantMap presentation = model->getItem(mapToSource(index(row, 0)).row());
|
||||||
return presentation;
|
return presentation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PresentationProxyModel::deletePresentation(const int &row) {
|
void PresentationProxyModel::deletePresentation(const int &row) {
|
||||||
auto model = qobject_cast<PresentationSqlModel *>(sourceModel());
|
auto model = qobject_cast<PresentationModel *>(sourceModel());
|
||||||
model->deletePresentation(row);
|
model->removeItem(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PresentationProxyModel::deletePresentations(const QVector<int> &rows) {
|
void PresentationProxyModel::deletePresentations(const QVector<int> &rows) {
|
||||||
auto model = qobject_cast<PresentationSqlModel *>(sourceModel());
|
auto model = qobject_cast<PresentationModel *>(sourceModel());
|
||||||
qDebug() << "DELETING!!!!!!!!!!!!!!!!!!!!!!!" << rows;
|
qDebug() << "DELETING!!!!!!!!!!!!!!!!!!!!!!!" << rows;
|
||||||
for (int i = rows.size() - 1; i >= 0; i--) {
|
for (int i = rows.size() - 1; i >= 0; i--) {
|
||||||
qDebug() << "deleting" << rows.at(i);
|
qDebug() << "deleting" << rows.at(i);
|
||||||
model->deletePresentation(rows.at(i));
|
model->removeItem(rows.at(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include <qqml.h>
|
#include <qqml.h>
|
||||||
#include <qurl.h>
|
#include <qurl.h>
|
||||||
#include <qvariant.h>
|
#include <qvariant.h>
|
||||||
|
#include "cxx-qt-gen/presentation_model.cxxqt.h"
|
||||||
|
|
||||||
|
|
||||||
class PresentationSqlModel : public QSqlTableModel
|
class PresentationSqlModel : public QSqlTableModel
|
||||||
{
|
{
|
||||||
|
@ -57,13 +59,13 @@ private:
|
||||||
class PresentationProxyModel : public QSortFilterProxyModel
|
class PresentationProxyModel : public QSortFilterProxyModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(PresentationSqlModel *presentationModel READ presentationModel)
|
Q_PROPERTY(PresentationModel *presentationModel READ presentationModel)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PresentationProxyModel(QObject *parent = nullptr);
|
explicit PresentationProxyModel(QObject *parent = nullptr);
|
||||||
~PresentationProxyModel() = default;
|
~PresentationProxyModel() = default;
|
||||||
|
|
||||||
PresentationSqlModel *presentationModel();
|
PresentationModel *presentationModel();
|
||||||
Q_INVOKABLE QModelIndex idx(int row);
|
Q_INVOKABLE QModelIndex idx(int row);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -72,7 +74,7 @@ public slots:
|
||||||
Q_INVOKABLE void deletePresentations(const QVector<int> &row);
|
Q_INVOKABLE void deletePresentations(const QVector<int> &row);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PresentationSqlModel *m_presentationModel;
|
PresentationModel *m_presentationModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //PRESENTATIONSQLMODEL_H
|
#endif //PRESENTATIONSQLMODEL_H
|
||||||
|
|
|
@ -324,14 +324,15 @@ QVariantMap VideoSqlModel::getVideo(const int &row) {
|
||||||
VideoProxyModel::VideoProxyModel(QObject *parent)
|
VideoProxyModel::VideoProxyModel(QObject *parent)
|
||||||
:QSortFilterProxyModel(parent)
|
:QSortFilterProxyModel(parent)
|
||||||
{
|
{
|
||||||
m_videoModel = new VideoSqlModel();
|
m_videoModel = new VideoModel();
|
||||||
|
m_videoModel->testDatabase();
|
||||||
setSourceModel(m_videoModel);
|
setSourceModel(m_videoModel);
|
||||||
setDynamicSortFilter(true);
|
setDynamicSortFilter(true);
|
||||||
setFilterRole(Qt::UserRole + 1);
|
setFilterRole(Qt::UserRole + 1);
|
||||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoSqlModel *VideoProxyModel::videoModel() {
|
VideoModel *VideoProxyModel::videoModel() {
|
||||||
return m_videoModel;
|
return m_videoModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,21 +343,21 @@ QModelIndex VideoProxyModel::idx(int row) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap VideoProxyModel::getVideo(const int &row) {
|
QVariantMap VideoProxyModel::getVideo(const int &row) {
|
||||||
auto model = qobject_cast<VideoSqlModel *>(sourceModel());
|
auto model = qobject_cast<VideoModel *>(sourceModel());
|
||||||
QVariantMap video = model->getVideo(mapToSource(index(row, 0)).row());
|
QVariantMap video = model->getItem(mapToSource(index(row, 0)).row());
|
||||||
return video;
|
return video;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoProxyModel::deleteVideo(const int &row) {
|
void VideoProxyModel::deleteVideo(const int &row) {
|
||||||
auto model = qobject_cast<VideoSqlModel *>(sourceModel());
|
auto model = qobject_cast<VideoModel *>(sourceModel());
|
||||||
model->deleteVideo(mapToSource(index(row,0)).row());
|
model->removeItem(mapToSource(index(row,0)).row());
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoProxyModel::deleteVideos(const QVector<int> &rows) {
|
void VideoProxyModel::deleteVideos(const QVector<int> &rows) {
|
||||||
auto model = qobject_cast<VideoSqlModel *>(sourceModel());
|
auto model = qobject_cast<VideoModel *>(sourceModel());
|
||||||
qDebug() << "DELETING!!!!!!!!!!!!!!!!!!!!!!!" << rows;
|
qDebug() << "DELETING!!!!!!!!!!!!!!!!!!!!!!!" << rows;
|
||||||
for (int i = rows.size() - 1; i >= 0; i--) {
|
for (int i = rows.size() - 1; i >= 0; i--) {
|
||||||
qDebug() << "deleting" << rows.at(i);
|
qDebug() << "deleting" << rows.at(i);
|
||||||
model->deleteVideo(rows.at(i));
|
model->removeItem(rows.at(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <qqml.h>
|
#include <qqml.h>
|
||||||
#include <qurl.h>
|
#include <qurl.h>
|
||||||
#include <qvariant.h>
|
#include <qvariant.h>
|
||||||
|
#include "cxx-qt-gen/video_model.cxxqt.h"
|
||||||
|
|
||||||
class VideoSqlModel : public QSqlTableModel
|
class VideoSqlModel : public QSqlTableModel
|
||||||
{
|
{
|
||||||
|
@ -68,13 +69,13 @@ private:
|
||||||
class VideoProxyModel : public QSortFilterProxyModel
|
class VideoProxyModel : public QSortFilterProxyModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(VideoSqlModel *videoModel READ videoModel)
|
Q_PROPERTY(VideoModel *videoModel READ videoModel)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit VideoProxyModel(QObject *parent = nullptr);
|
explicit VideoProxyModel(QObject *parent = nullptr);
|
||||||
~VideoProxyModel() = default;
|
~VideoProxyModel() = default;
|
||||||
|
|
||||||
VideoSqlModel *videoModel();
|
VideoModel *videoModel();
|
||||||
Q_INVOKABLE QModelIndex idx(int row);
|
Q_INVOKABLE QModelIndex idx(int row);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -83,7 +84,7 @@ public slots:
|
||||||
Q_INVOKABLE void deleteVideos(const QVector<int> &row);
|
Q_INVOKABLE void deleteVideos(const QVector<int> &row);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VideoSqlModel *m_videoModel;
|
VideoModel *m_videoModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //VIDEOSQLMODEL_H
|
#endif //VIDEOSQLMODEL_H
|
||||||
|
|
|
@ -65,7 +65,7 @@ Item {
|
||||||
itemIcon: "folder-videos-symbolic"
|
itemIcon: "folder-videos-symbolic"
|
||||||
itemSubtitle: {
|
itemSubtitle: {
|
||||||
if (fileValidation)
|
if (fileValidation)
|
||||||
model.filePath;
|
model.path;
|
||||||
else
|
else
|
||||||
"file is missing"
|
"file is missing"
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ ColumnLayout {
|
||||||
anchors {left: libraryLabel.right
|
anchors {left: libraryLabel.right
|
||||||
verticalCenter: libraryLabel.verticalCenter
|
verticalCenter: libraryLabel.verticalCenter
|
||||||
leftMargin: 15}
|
leftMargin: 15}
|
||||||
text: innerModel.rowCount()
|
text: libraryType == "song" ? innerModel.rowCount() : innerModel.count()
|
||||||
color: Kirigami.Theme.disabledTextColor
|
color: Kirigami.Theme.disabledTextColor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,7 @@ Item {
|
||||||
function updateLoop(value) {
|
function updateLoop(value) {
|
||||||
/* changeStartTime(value, false); */
|
/* changeStartTime(value, false); */
|
||||||
videosqlmodel.updateLoop(video.id, value);
|
videosqlmodel.updateLoop(video.id, value);
|
||||||
video.loop = value;
|
/* video.loop = value; */
|
||||||
showPassiveNotification("Loop changed to: " + video.loop);
|
showPassiveNotification("Loop changed to: " + video.loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ mod video_model {
|
||||||
use crate::schema::videos::dsl::*;
|
use crate::schema::videos::dsl::*;
|
||||||
use crate::video_model::video_model::Video;
|
use crate::video_model::video_model::Video;
|
||||||
use diesel::sqlite::SqliteConnection;
|
use diesel::sqlite::SqliteConnection;
|
||||||
use diesel::{delete, insert_into, prelude::*};
|
use diesel::{delete, insert_into, prelude::*, update};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
|
@ -65,8 +65,6 @@ mod video_model {
|
||||||
LoopingRole,
|
LoopingRole,
|
||||||
}
|
}
|
||||||
|
|
||||||
// use crate::entities::{videos, prelude::Videos};
|
|
||||||
// use sea_orm::{ConnectionTrait, Database, DbBackend, DbErr, Statement, ActiveValue};
|
|
||||||
impl qobject::VideoModel {
|
impl qobject::VideoModel {
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn clear(mut self: Pin<&mut Self>) {
|
pub fn clear(mut self: Pin<&mut Self>) {
|
||||||
|
@ -256,6 +254,50 @@ mod video_model {
|
||||||
_ => 0,
|
_ => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[qinvokable]
|
||||||
|
pub fn update_loop(mut self: Pin<&mut Self>, index: i32, loop_value: bool) -> bool {
|
||||||
|
let mut vector_roles = QVector_i32::default();
|
||||||
|
vector_roles.append(self.as_ref().get_role(Role::LoopingRole));
|
||||||
|
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
||||||
|
|
||||||
|
let db = &mut self.as_mut().get_db();
|
||||||
|
let result = update(videos.filter(id.eq(index)))
|
||||||
|
.set(looping.eq(loop_value))
|
||||||
|
.execute(db);
|
||||||
|
match result {
|
||||||
|
Ok(_i) => {
|
||||||
|
let video = self.as_mut().videos_mut().get_mut(index as usize).unwrap();
|
||||||
|
video.looping = loop_value;
|
||||||
|
self.as_mut()
|
||||||
|
.emit_data_changed(model_index, model_index, &vector_roles);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
Err(_e) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[qinvokable]
|
||||||
|
pub fn update_title(mut self: Pin<&mut Self>, index: i32, updated_title: QString) -> bool {
|
||||||
|
let mut vector_roles = QVector_i32::default();
|
||||||
|
vector_roles.append(self.as_ref().get_role(Role::TitleRole));
|
||||||
|
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
||||||
|
|
||||||
|
let db = &mut self.as_mut().get_db();
|
||||||
|
let result = update(videos.filter(id.eq(index)))
|
||||||
|
.set(title.eq(updated_title.to_string()))
|
||||||
|
.execute(db);
|
||||||
|
match result {
|
||||||
|
Ok(_i) => {
|
||||||
|
let video = self.as_mut().videos_mut().get_mut(index as usize).unwrap();
|
||||||
|
video.title = updated_title;
|
||||||
|
self.as_mut()
|
||||||
|
.emit_data_changed(model_index, model_index, &vector_roles);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
Err(_e) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Rust bindings for C++ functions of the base class (QAbstractItemModel)
|
// Create Rust bindings for C++ functions of the base class (QAbstractItemModel)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue