the image_model.rs is working
The basic functions are all working properly. Now the model works by using diesel to connect the sql database and retrieve all the items and organize them. Then it'll ensure any additions and deletions are correct and happen first on the database before adding them to the model. There is still a C++ proxyModel inbetween QML and Rust, but this proxyModel interfaces with the Rust model instead of the C++ SqlTableModel.
This commit is contained in:
parent
caed6e6367
commit
fc2d0492fa
9 changed files with 170 additions and 79 deletions
|
@ -208,14 +208,15 @@ QVariantMap ImageSqlModel::getImage(const int &row) {
|
|||
ImageProxyModel::ImageProxyModel(QObject *parent)
|
||||
:QSortFilterProxyModel(parent)
|
||||
{
|
||||
m_imageModel = new ImageSqlModel;
|
||||
m_imageModel = new ImageModel;
|
||||
m_imageModel->testDatabase();
|
||||
setSourceModel(m_imageModel);
|
||||
setDynamicSortFilter(true);
|
||||
setFilterRole(Qt::UserRole + 1);
|
||||
setFilterRole(1);
|
||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
ImageSqlModel *ImageProxyModel::imageModel() {
|
||||
ImageModel *ImageProxyModel::imageModel() {
|
||||
return m_imageModel;
|
||||
}
|
||||
|
||||
|
@ -226,21 +227,21 @@ QModelIndex ImageProxyModel::idx(int row) {
|
|||
}
|
||||
|
||||
QVariantMap ImageProxyModel::getImage(const int &row) {
|
||||
auto model = qobject_cast<ImageSqlModel *>(sourceModel());
|
||||
QVariantMap image = model->getImage(mapToSource(index(row, 0)).row());
|
||||
auto model = qobject_cast<ImageModel *>(sourceModel());
|
||||
QVariantMap image = model->getItem(mapToSource(index(row, 0)).row());
|
||||
return image;
|
||||
}
|
||||
|
||||
void ImageProxyModel::deleteImage(const int &row) {
|
||||
auto model = qobject_cast<ImageSqlModel *>(sourceModel());
|
||||
model->deleteImage(row);
|
||||
auto model = qobject_cast<ImageModel *>(sourceModel());
|
||||
model->removeItem(row);
|
||||
}
|
||||
|
||||
void ImageProxyModel::deleteImages(const QVector<int> &rows) {
|
||||
auto model = qobject_cast<ImageSqlModel *>(sourceModel());
|
||||
auto model = qobject_cast<ImageModel *>(sourceModel());
|
||||
qDebug() << "DELETING!!!!!!!!!!!!!!!!!!!!!!!" << rows;
|
||||
for (int i = rows.size() - 1; i >= 0; i--) {
|
||||
qDebug() << "deleting" << rows.at(i);
|
||||
model->deleteImage(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/image_model.cxxqt.h"
|
||||
|
||||
class ImageSqlModel : public QSqlTableModel
|
||||
{
|
||||
|
@ -50,13 +51,13 @@ private:
|
|||
class ImageProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(ImageSqlModel *imageModel READ imageModel)
|
||||
Q_PROPERTY(ImageModel *imageModel READ imageModel)
|
||||
|
||||
public:
|
||||
explicit ImageProxyModel(QObject *parent = nullptr);
|
||||
~ImageProxyModel() = default;
|
||||
|
||||
ImageSqlModel *imageModel();
|
||||
ImageModel *imageModel();
|
||||
Q_INVOKABLE QModelIndex idx(int row);
|
||||
|
||||
public slots:
|
||||
|
@ -65,7 +66,7 @@ public slots:
|
|||
Q_INVOKABLE void deleteImages(const QVector<int> &rows);
|
||||
|
||||
private:
|
||||
ImageSqlModel *m_imageModel;
|
||||
ImageModel *m_imageModel;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue