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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue