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.
This commit is contained in:
parent
b2a87b76b6
commit
85285b7d02
3 changed files with 7 additions and 1 deletions
|
@ -226,6 +226,11 @@ QModelIndex ImageProxyModel::idx(int row) {
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImageProxyModel::newItem(const QUrl &url) {
|
||||||
|
auto model = qobject_cast<ImageModel *>(sourceModel());
|
||||||
|
model->newItem(url);
|
||||||
|
}
|
||||||
|
|
||||||
QVariantMap ImageProxyModel::getImage(const int &row) {
|
QVariantMap ImageProxyModel::getImage(const int &row) {
|
||||||
auto model = qobject_cast<ImageModel *>(sourceModel());
|
auto model = qobject_cast<ImageModel *>(sourceModel());
|
||||||
QVariantMap image = model->getItem(mapToSource(index(row, 0)).row());
|
QVariantMap image = model->getItem(mapToSource(index(row, 0)).row());
|
||||||
|
|
|
@ -62,6 +62,7 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
Q_INVOKABLE QVariantMap getImage(const int &row);
|
Q_INVOKABLE QVariantMap getImage(const int &row);
|
||||||
|
Q_INVOKABLE void newItem(const QUrl &url);
|
||||||
Q_INVOKABLE void deleteImage(const int &row);
|
Q_INVOKABLE void deleteImage(const int &row);
|
||||||
Q_INVOKABLE void deleteImages(const QVector<int> &rows);
|
Q_INVOKABLE void deleteImages(const QVector<int> &rows);
|
||||||
|
|
||||||
|
|
|
@ -299,7 +299,7 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addImg(url) {
|
function addImg(url) {
|
||||||
imageProxyModel.imageModel.newItem(url);
|
imageProxyModel.newItem(url);
|
||||||
selectedLibrary = "image";
|
selectedLibrary = "image";
|
||||||
imageLibrary.libraryList.currentIndex = imageProxyModel.imageModel.count();
|
imageLibrary.libraryList.currentIndex = imageProxyModel.imageModel.count();
|
||||||
console.log(imageProxyModel.getImage(imageLibrary.libraryList.currentIndex));
|
console.log(imageProxyModel.getImage(imageLibrary.libraryList.currentIndex));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue