diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 66bf71d7..d8f03e04 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -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 diff --git a/src/FluViewModel.cpp b/src/FluViewModel.cpp index abb6dc1f..3742b645 100644 --- a/src/FluViewModel.cpp +++ b/src/FluViewModel.cpp @@ -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 value = _property.read(); - _model->setProperty(_name.toStdString().c_str(),value); - ViewModelManager::getInstance()->refreshViewModel((FluViewModel*)parent(),_name,value); + auto viewModel = (FluViewModel*)parent(); + if(viewModel->enablePropertyChange){ + auto value = _property.read(); + _model->setProperty(_name.toStdString().c_str(),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(_window), 16); + _key = property("objectName").toString()+"-"+QString::number(reinterpret_cast(_window), 16); }else{ _key = property("objectName").toString(); } diff --git a/src/FluViewModel.h b/src/FluViewModel.h index 924372d1..93bb9bf3 100644 --- a/src/FluViewModel.h +++ b/src/FluViewModel.h @@ -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 = "";