From 8efabbdf68bc4e524274a88cec2ff2f0b543d6ad Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Wed, 17 May 2023 10:11:33 -0500 Subject: [PATCH] maintenance: adding all models as types for direct access If each model is registered as a QML type, we can pass the model back to QML from each proxy model to have more direct access to it. This enables us to use it's functions and properties better. --- src/cpp/songsqlmodel.cpp | 4 ++++ src/cpp/songsqlmodel.h | 1 + src/main.cpp | 14 ++++++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/cpp/songsqlmodel.cpp b/src/cpp/songsqlmodel.cpp index 4f758fd..1132928 100644 --- a/src/cpp/songsqlmodel.cpp +++ b/src/cpp/songsqlmodel.cpp @@ -757,6 +757,10 @@ QVariantMap SongProxyModel::getSong(const int &row) { return song; } +void SongProxyModel::newSong() { + m_songModel->newSong(); +} + void SongProxyModel::deleteSong(const int &row) { auto model = qobject_cast(sourceModel()); model->removeItem(row); diff --git a/src/cpp/songsqlmodel.h b/src/cpp/songsqlmodel.h index a2db8b6..929cb02 100644 --- a/src/cpp/songsqlmodel.h +++ b/src/cpp/songsqlmodel.h @@ -131,6 +131,7 @@ public: public slots: Q_INVOKABLE QVariantMap getSong(const int &row); + Q_INVOKABLE void newSong(); Q_INVOKABLE void deleteSong(const int &row); Q_INVOKABLE void deleteSongs(const QVector &rows); Q_INVOKABLE QStringList getLyricList(const int &row); diff --git a/src/main.cpp b/src/main.cpp index 600dd38..1f0f22e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,6 +56,9 @@ #include "cxx-qt-gen/settings.cxxqt.h" #include "cxx-qt-gen/ytdl.cxxqt.h" #include "cxx-qt-gen/presentation_model.cxxqt.h" +#include "cxx-qt-gen/song_model.cxxqt.h" +#include "cxx-qt-gen/video_model.cxxqt.h" +#include "cxx-qt-gen/image_model.cxxqt.h" // #include "cxx-qt-gen/image_model.cxxqt.h" static QWindow *windowFromEngine(QQmlApplicationEngine *engine) @@ -202,11 +205,14 @@ int main(int argc, char *argv[]) qmlRegisterType("org.presenter", 1, 0, "VideoProxyModel"); qmlRegisterType("org.presenter", 1, 0, "ImageProxyModel"); qmlRegisterType("org.presenter", 1, 0, "PresentationProxyModel"); + qmlRegisterType("org.presenter", 1, 0, "SongModel"); + qmlRegisterType("org.presenter", 1, 0, "VideoModel"); + qmlRegisterType("org.presenter", 1, 0, "ImageModel"); qmlRegisterType("org.presenter", 1, 0, "PresentationModel"); - qmlRegisterType("org.presenter", 1, 0, "SongSqlModel"); - qmlRegisterType("org.presenter", 1, 0, "VideoSqlModel"); - qmlRegisterType("org.presenter", 1, 0, "ImageSqlModel"); - qmlRegisterType("org.presenter", 1, 0, "PresentationSqlModel"); + // qmlRegisterType("org.presenter", 1, 0, "SongSqlModel"); + // qmlRegisterType("org.presenter", 1, 0, "VideoSqlModel"); + // qmlRegisterType("org.presenter", 1, 0, "ImageSqlModel"); + // qmlRegisterType("org.presenter", 1, 0, "PresentationSqlModel"); qmlRegisterType("org.presenter", 1, 0, "FileHelper"); qmlRegisterType("org.presenter", 1, 0, "Ytdl"); qmlRegisterType("org.presenter", 1, 0, "ServiceThing");