mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-23 19:20:59 +08:00
69 lines
1.6 KiB
C
69 lines
1.6 KiB
C
|
#ifndef FLUVIEWMODEL_H
|
||
|
#define FLUVIEWMODEL_H
|
||
|
|
||
|
#include <QQuickItem>
|
||
|
#include <QtQml/qqml.h>
|
||
|
#include <QQuickWindow>
|
||
|
#include <QQmlProperty>
|
||
|
#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<QString,QObject*> m_data;
|
||
|
QList<FluViewModel*> m_viewmodel;
|
||
|
};
|
||
|
|
||
|
#endif // FLUVIEWMODEL_H
|