#ifndef FLUVIEWMODEL_H #define FLUVIEWMODEL_H #include #include #include #include #include "stdafx.h" 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); Q_PROPERTY_AUTO(QObject*,target); QML_NAMED_ELEMENT(FluViewModel) public: explicit FluViewModel(QObject *parent = nullptr); ~FluViewModel(); void classBegin() override; void componentComplete() override; Q_SIGNAL void initData(); QString getKey(); private: QObject* _window = nullptr; QString _key; }; class PropertyObserver: public QObject{ Q_OBJECT public: explicit PropertyObserver(QString name,QObject* model,QObject *parent = nullptr); ~PropertyObserver(); private: Q_SLOT void _propertyChange(); private: QString _name; QQmlProperty _property; QObject* _model; }; class ViewModelManager:public QObject{ Q_OBJECT private: explicit ViewModelManager(QObject *parent = nullptr); public: static ViewModelManager *getInstance(); 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: static ViewModelManager* m_instance; QMap m_data; QList m_viewmodel; }; #endif // FLUVIEWMODEL_H