2023-09-12 18:45:15 +08:00
|
|
|
#ifndef FLUVIEWMODEL_H
|
|
|
|
#define FLUVIEWMODEL_H
|
|
|
|
|
|
|
|
#include <QQuickItem>
|
|
|
|
#include <QtQml/qqml.h>
|
|
|
|
#include <QQuickWindow>
|
|
|
|
#include <QQmlProperty>
|
|
|
|
#include "stdafx.h"
|
2023-09-13 15:11:22 +08:00
|
|
|
#include "singleton.h"
|
2023-09-12 18:45:15 +08:00
|
|
|
|
|
|
|
class Model : public QObject{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit Model(QObject *parent = nullptr);
|
|
|
|
~Model();
|
|
|
|
};
|
|
|
|
|
|
|
|
class FluViewModel : public QObject, public QQmlParserStatus
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_INTERFACES(QQmlParserStatus)
|
|
|
|
Q_PROPERTY_AUTO(int,scope);
|
|
|
|
QML_NAMED_ELEMENT(FluViewModel)
|
|
|
|
public:
|
|
|
|
explicit FluViewModel(QObject *parent = nullptr);
|
|
|
|
~FluViewModel();
|
|
|
|
void classBegin() override;
|
|
|
|
void componentComplete() override;
|
|
|
|
Q_SIGNAL void initData();
|
|
|
|
QString getKey();
|
2023-11-02 11:34:02 +08:00
|
|
|
bool enablePropertyChange = true;
|
2023-09-12 18:45:15 +08:00
|
|
|
private:
|
|
|
|
QObject* _window = nullptr;
|
2023-09-17 20:36:33 +08:00
|
|
|
QString _key = "";
|
2023-09-12 18:45:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class PropertyObserver: public QObject{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit PropertyObserver(QString name,QObject* model,QObject *parent = nullptr);
|
|
|
|
~PropertyObserver();
|
|
|
|
private:
|
|
|
|
Q_SLOT void _propertyChange();
|
|
|
|
private:
|
2023-09-17 20:36:33 +08:00
|
|
|
QString _name = "";
|
2023-09-12 18:45:15 +08:00
|
|
|
QQmlProperty _property;
|
2023-09-17 20:36:33 +08:00
|
|
|
QObject* _model = nullptr;
|
2023-09-12 18:45:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ViewModelManager:public QObject{
|
|
|
|
Q_OBJECT
|
|
|
|
private:
|
|
|
|
explicit ViewModelManager(QObject *parent = nullptr);
|
|
|
|
public:
|
2024-01-04 00:08:34 +08:00
|
|
|
SINGLETON(ViewModelManager)
|
2023-09-12 18:45:15 +08:00
|
|
|
bool exist(const QString& key);
|
|
|
|
void insert(const QString& key,QObject* value);
|
|
|
|
QObject* getModel(const QString& key);
|
|
|
|
void insertViewModel(FluViewModel* value);
|
|
|
|
void deleteViewModel(FluViewModel* value);
|
|
|
|
void refreshViewModel(FluViewModel* viewModel,QString key,QVariant value);
|
|
|
|
private:
|
2023-09-13 15:11:22 +08:00
|
|
|
QMap<QString,QObject*> _data;
|
|
|
|
QList<FluViewModel*> _viewmodel;
|
2023-09-12 18:45:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // FLUVIEWMODEL_H
|