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)
|
||||
:QSortFilterProxyModel(parent)
|
||||
{
|
||||
m_presentationModel = new PresentationSqlModel;
|
||||
m_presentationModel = new PresentationModel;
|
||||
m_presentationModel->testDatabase();
|
||||
setSourceModel(m_presentationModel);
|
||||
setDynamicSortFilter(true);
|
||||
setFilterRole(Qt::UserRole + 1);
|
||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
PresentationSqlModel *PresentationProxyModel::presentationModel() {
|
||||
PresentationModel *PresentationProxyModel::presentationModel() {
|
||||
return m_presentationModel;
|
||||
}
|
||||
|
||||
|
@ -261,21 +262,21 @@ QModelIndex PresentationProxyModel::idx(int row) {
|
|||
}
|
||||
|
||||
QVariantMap PresentationProxyModel::getPresentation(const int &row) {
|
||||
auto model = qobject_cast<PresentationSqlModel *>(sourceModel());
|
||||
QVariantMap presentation = model->getPresentation(mapToSource(index(row, 0)).row());
|
||||
auto model = qobject_cast<PresentationModel *>(sourceModel());
|
||||
QVariantMap presentation = model->getItem(mapToSource(index(row, 0)).row());
|
||||
return presentation;
|
||||
}
|
||||
|
||||
void PresentationProxyModel::deletePresentation(const int &row) {
|
||||
auto model = qobject_cast<PresentationSqlModel *>(sourceModel());
|
||||
model->deletePresentation(row);
|
||||
auto model = qobject_cast<PresentationModel *>(sourceModel());
|
||||
model->removeItem(row);
|
||||
}
|
||||
|
||||
void PresentationProxyModel::deletePresentations(const QVector<int> &rows) {
|
||||
auto model = qobject_cast<PresentationSqlModel *>(sourceModel());
|
||||
auto model = qobject_cast<PresentationModel *>(sourceModel());
|
||||
qDebug() << "DELETING!!!!!!!!!!!!!!!!!!!!!!!" << rows;
|
||||
for (int i = rows.size() - 1; i >= 0; i--) {
|
||||
qDebug() << "deleting" << rows.at(i);
|
||||
model->deletePresentation(rows.at(i));
|
||||
model->removeItem(rows.at(i));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <qqml.h>
|
||||
#include <qurl.h>
|
||||
#include <qvariant.h>
|
||||
#include "cxx-qt-gen/presentation_model.cxxqt.h"
|
||||
|
||||
|
||||
class PresentationSqlModel : public QSqlTableModel
|
||||
{
|
||||
|
@ -57,13 +59,13 @@ private:
|
|||
class PresentationProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(PresentationSqlModel *presentationModel READ presentationModel)
|
||||
Q_PROPERTY(PresentationModel *presentationModel READ presentationModel)
|
||||
|
||||
public:
|
||||
explicit PresentationProxyModel(QObject *parent = nullptr);
|
||||
~PresentationProxyModel() = default;
|
||||
|
||||
PresentationSqlModel *presentationModel();
|
||||
PresentationModel *presentationModel();
|
||||
Q_INVOKABLE QModelIndex idx(int row);
|
||||
|
||||
public slots:
|
||||
|
@ -72,7 +74,7 @@ public slots:
|
|||
Q_INVOKABLE void deletePresentations(const QVector<int> &row);
|
||||
|
||||
private:
|
||||
PresentationSqlModel *m_presentationModel;
|
||||
PresentationModel *m_presentationModel;
|
||||
};
|
||||
|
||||
#endif //PRESENTATIONSQLMODEL_H
|
||||
|
|
|
@ -324,14 +324,15 @@ QVariantMap VideoSqlModel::getVideo(const int &row) {
|
|||
VideoProxyModel::VideoProxyModel(QObject *parent)
|
||||
:QSortFilterProxyModel(parent)
|
||||
{
|
||||
m_videoModel = new VideoSqlModel();
|
||||
m_videoModel = new VideoModel();
|
||||
m_videoModel->testDatabase();
|
||||
setSourceModel(m_videoModel);
|
||||
setDynamicSortFilter(true);
|
||||
setFilterRole(Qt::UserRole + 1);
|
||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
VideoSqlModel *VideoProxyModel::videoModel() {
|
||||
VideoModel *VideoProxyModel::videoModel() {
|
||||
return m_videoModel;
|
||||
}
|
||||
|
||||
|
@ -342,21 +343,21 @@ QModelIndex VideoProxyModel::idx(int row) {
|
|||
}
|
||||
|
||||
QVariantMap VideoProxyModel::getVideo(const int &row) {
|
||||
auto model = qobject_cast<VideoSqlModel *>(sourceModel());
|
||||
QVariantMap video = model->getVideo(mapToSource(index(row, 0)).row());
|
||||
auto model = qobject_cast<VideoModel *>(sourceModel());
|
||||
QVariantMap video = model->getItem(mapToSource(index(row, 0)).row());
|
||||
return video;
|
||||
}
|
||||
|
||||
void VideoProxyModel::deleteVideo(const int &row) {
|
||||
auto model = qobject_cast<VideoSqlModel *>(sourceModel());
|
||||
model->deleteVideo(mapToSource(index(row,0)).row());
|
||||
auto model = qobject_cast<VideoModel *>(sourceModel());
|
||||
model->removeItem(mapToSource(index(row,0)).row());
|
||||
}
|
||||
|
||||
void VideoProxyModel::deleteVideos(const QVector<int> &rows) {
|
||||
auto model = qobject_cast<VideoSqlModel *>(sourceModel());
|
||||
auto model = qobject_cast<VideoModel *>(sourceModel());
|
||||
qDebug() << "DELETING!!!!!!!!!!!!!!!!!!!!!!!" << rows;
|
||||
for (int i = rows.size() - 1; i >= 0; i--) {
|
||||
qDebug() << "deleting" << rows.at(i);
|
||||
model->deleteVideo(rows.at(i));
|
||||
model->removeItem(rows.at(i));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <qqml.h>
|
||||
#include <qurl.h>
|
||||
#include <qvariant.h>
|
||||
#include "cxx-qt-gen/video_model.cxxqt.h"
|
||||
|
||||
class VideoSqlModel : public QSqlTableModel
|
||||
{
|
||||
|
@ -68,13 +69,13 @@ private:
|
|||
class VideoProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(VideoSqlModel *videoModel READ videoModel)
|
||||
Q_PROPERTY(VideoModel *videoModel READ videoModel)
|
||||
|
||||
public:
|
||||
explicit VideoProxyModel(QObject *parent = nullptr);
|
||||
~VideoProxyModel() = default;
|
||||
|
||||
VideoSqlModel *videoModel();
|
||||
VideoModel *videoModel();
|
||||
Q_INVOKABLE QModelIndex idx(int row);
|
||||
|
||||
public slots:
|
||||
|
@ -83,7 +84,7 @@ public slots:
|
|||
Q_INVOKABLE void deleteVideos(const QVector<int> &row);
|
||||
|
||||
private:
|
||||
VideoSqlModel *m_videoModel;
|
||||
VideoModel *m_videoModel;
|
||||
};
|
||||
|
||||
#endif //VIDEOSQLMODEL_H
|
||||
|
|
|
@ -65,7 +65,7 @@ Item {
|
|||
itemIcon: "folder-videos-symbolic"
|
||||
itemSubtitle: {
|
||||
if (fileValidation)
|
||||
model.filePath;
|
||||
model.path;
|
||||
else
|
||||
"file is missing"
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ ColumnLayout {
|
|||
anchors {left: libraryLabel.right
|
||||
verticalCenter: libraryLabel.verticalCenter
|
||||
leftMargin: 15}
|
||||
text: innerModel.rowCount()
|
||||
text: libraryType == "song" ? innerModel.rowCount() : innerModel.count()
|
||||
color: Kirigami.Theme.disabledTextColor
|
||||
}
|
||||
|
||||
|
|
|
@ -266,7 +266,7 @@ Item {
|
|||
function updateLoop(value) {
|
||||
/* changeStartTime(value, false); */
|
||||
videosqlmodel.updateLoop(video.id, value);
|
||||
video.loop = value;
|
||||
/* video.loop = value; */
|
||||
showPassiveNotification("Loop changed to: " + video.loop);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ mod video_model {
|
|||
use crate::schema::videos::dsl::*;
|
||||
use crate::video_model::video_model::Video;
|
||||
use diesel::sqlite::SqliteConnection;
|
||||
use diesel::{delete, insert_into, prelude::*};
|
||||
use diesel::{delete, insert_into, prelude::*, update};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
unsafe extern "C++" {
|
||||
|
@ -65,8 +65,6 @@ mod video_model {
|
|||
LoopingRole,
|
||||
}
|
||||
|
||||
// use crate::entities::{videos, prelude::Videos};
|
||||
// use sea_orm::{ConnectionTrait, Database, DbBackend, DbErr, Statement, ActiveValue};
|
||||
impl qobject::VideoModel {
|
||||
#[qinvokable]
|
||||
pub fn clear(mut self: Pin<&mut Self>) {
|
||||
|
@ -256,6 +254,50 @@ mod video_model {
|
|||
_ => 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue