From 85285b7d02ea22cef49e7fe17702f1ab561cc7ba Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Wed, 12 Apr 2023 19:00:31 -0500 Subject: [PATCH] add newItem function to interface with QML In order to make sure QML can properly interact with Rust I'll use a function in the proxy model to interact with the actual model underneath in Rust. --- src/cpp/imagesqlmodel.cpp | 5 +++++ src/cpp/imagesqlmodel.h | 1 + src/qml/presenter/Library.qml | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cpp/imagesqlmodel.cpp b/src/cpp/imagesqlmodel.cpp index ccfab76..9f877f7 100644 --- a/src/cpp/imagesqlmodel.cpp +++ b/src/cpp/imagesqlmodel.cpp @@ -226,6 +226,11 @@ QModelIndex ImageProxyModel::idx(int row) { return idx; } +void ImageProxyModel::newItem(const QUrl &url) { + auto model = qobject_cast(sourceModel()); + model->newItem(url); +} + QVariantMap ImageProxyModel::getImage(const int &row) { auto model = qobject_cast(sourceModel()); QVariantMap image = model->getItem(mapToSource(index(row, 0)).row()); diff --git a/src/cpp/imagesqlmodel.h b/src/cpp/imagesqlmodel.h index ff31953..262cae5 100644 --- a/src/cpp/imagesqlmodel.h +++ b/src/cpp/imagesqlmodel.h @@ -62,6 +62,7 @@ public: public slots: Q_INVOKABLE QVariantMap getImage(const int &row); + Q_INVOKABLE void newItem(const QUrl &url); Q_INVOKABLE void deleteImage(const int &row); Q_INVOKABLE void deleteImages(const QVector &rows); diff --git a/src/qml/presenter/Library.qml b/src/qml/presenter/Library.qml index b7f3aaf..f329ce0 100644 --- a/src/qml/presenter/Library.qml +++ b/src/qml/presenter/Library.qml @@ -299,7 +299,7 @@ Item { } function addImg(url) { - imageProxyModel.imageModel.newItem(url); + imageProxyModel.newItem(url); selectedLibrary = "image"; imageLibrary.libraryList.currentIndex = imageProxyModel.imageModel.count(); console.log(imageProxyModel.getImage(imageLibrary.libraryList.currentIndex));