videosProxyModel working

This commit is contained in:
Chris Cochrun 2023-02-17 15:33:50 -06:00
parent c7b35f2b44
commit cc501873c1
3 changed files with 29 additions and 10 deletions

View file

@ -106,12 +106,16 @@ void VideoSqlModel::newVideo(const QUrl &filePath) {
} }
void VideoSqlModel::deleteVideo(const int &row) { void VideoSqlModel::deleteVideo(const int &row) {
const QModelIndex parent = QModelIndex();
QSqlRecord recordData = record(row); QSqlRecord recordData = record(row);
if (recordData.isEmpty()) if (recordData.isEmpty())
return; return;
// emit beginRemoveRows(parent, row, row);
// emit beginResetModel();
removeRow(row); removeRow(row);
submitAll(); submitAll();
// emit endRemoveRows();
// emit endResetModel();
} }
int VideoSqlModel::id() const { int VideoSqlModel::id() const {
@ -320,13 +324,24 @@ QVariantMap VideoSqlModel::getVideo(const int &row) {
VideoProxyModel::VideoProxyModel(QObject *parent) VideoProxyModel::VideoProxyModel(QObject *parent)
:QSortFilterProxyModel(parent) :QSortFilterProxyModel(parent)
{ {
VideoSqlModel *videoModel = new VideoSqlModel; m_videoModel = new VideoSqlModel();
setSourceModel(videoModel); setSourceModel(m_videoModel);
setDynamicSortFilter(true); setDynamicSortFilter(true);
setFilterRole(Qt::UserRole + 1); setFilterRole(Qt::UserRole + 1);
setFilterCaseSensitivity(Qt::CaseInsensitive); setFilterCaseSensitivity(Qt::CaseInsensitive);
} }
QVariantMap VideoProxyModel::getVideo(const int &row) { VideoSqlModel *VideoProxyModel::videoModel() {
return QVariantMap(); return m_videoModel;
}
QVariantMap VideoProxyModel::getVideo(const int &row) {
auto model = qobject_cast<VideoSqlModel *>(sourceModel());
QVariantMap video = model->getVideo(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());
} }

View file

@ -68,12 +68,20 @@ private:
class VideoProxyModel : public QSortFilterProxyModel class VideoProxyModel : public QSortFilterProxyModel
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(VideoSqlModel *videoModel READ videoModel)
public: public:
explicit VideoProxyModel(QObject *parent = nullptr); explicit VideoProxyModel(QObject *parent = nullptr);
~VideoProxyModel() = default;
VideoSqlModel *videoModel();
public slots: public slots:
Q_INVOKABLE QVariantMap getVideo(const int &row); Q_INVOKABLE QVariantMap getVideo(const int &row);
Q_INVOKABLE void deleteVideo(const int &row);
private:
VideoSqlModel *m_videoModel;
}; };
#endif //VIDEOSQLMODEL_H #endif //VIDEOSQLMODEL_H

View file

@ -133,13 +133,9 @@ Controls.Page {
} }
SongProxyModel { id: songProxyModel } SongProxyModel { id: songProxyModel }
VideoProxyModel { id: videoProxyModel }
ImageProxyModel { id: imageProxyModel } ImageProxyModel { id: imageProxyModel }
PresentationProxyModel { id: presProxyModel } PresentationProxyModel { id: presProxyModel }
SongSqlModel { id: songSqlModel } VideoProxyModel { id: videoProxyModel }
VideoSqlModel { id: videoSqlModel }
ImageSqlModel { id: imageSqlModel }
PresentationSqlModel { id: presSqlModel }
ServiceThing { id: serviceThing } ServiceThing { id: serviceThing }
FileHelper { id: fileHelper } FileHelper { id: fileHelper }