This commit is contained in:
zhuzichu 2023-11-02 11:34:02 +08:00
parent 636dddaa84
commit 20852ac6bf
3 changed files with 11 additions and 7 deletions

View File

@ -139,7 +139,7 @@ target_include_directories(example PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/component
)
#FluentUI.h
#FluentUI.h
if(FLUENTUI_BUILD_STATIC_LIB)
target_include_directories(example PRIVATE
${CMAKE_SOURCE_DIR}/src

View File

@ -35,7 +35,9 @@ bool ViewModelManager::exist(const QString& key){
void ViewModelManager::refreshViewModel(FluViewModel* viewModel,QString key,QVariant value){
foreach (auto item, _viewmodel) {
if(item->getKey() == viewModel->getKey()){
item->enablePropertyChange = false;
item->setProperty(key.toStdString().c_str(),value);
item->enablePropertyChange = true;
}
}
}
@ -51,14 +53,16 @@ PropertyObserver::~PropertyObserver(){
}
void PropertyObserver::_propertyChange(){
auto viewModel = (FluViewModel*)parent();
if(viewModel->enablePropertyChange){
auto value = _property.read();
_model->setProperty(_name.toStdString().c_str(),value);
ViewModelManager::getInstance()->refreshViewModel((FluViewModel*)parent(),_name,value);
ViewModelManager::getInstance()->refreshViewModel(viewModel,_name,value);
}
}
FluViewModel::FluViewModel(QObject *parent):QObject{parent}{
scope(FluViewModelType::Scope::Window);
target(nullptr);
ViewModelManager::getInstance()->insertViewModel(this);
}
@ -77,7 +81,7 @@ void FluViewModel::componentComplete(){
}
const QMetaObject* obj = metaObject();
if(_scope == FluViewModelType::Scope::Window){
_key = property("objectName_").toString()+QString::number(reinterpret_cast<qulonglong>(_window), 16);
_key = property("objectName").toString()+"-"+QString::number(reinterpret_cast<qulonglong>(_window), 16);
}else{
_key = property("objectName").toString();
}

View File

@ -20,7 +20,6 @@ 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);
@ -29,6 +28,7 @@ public:
void componentComplete() override;
Q_SIGNAL void initData();
QString getKey();
bool enablePropertyChange = true;
private:
QObject* _window = nullptr;
QString _key = "";