-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05040ec
commit fd30819
Showing
20 changed files
with
333 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
singleton ItemsOriginal 1.0 ItemsOriginal.qml | ||
singleton ItemsFooter 1.0 ItemsFooter.qml | ||
singleton MainEvent 1.0 MainEvent.qml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import QtQuick | ||
import FluentUI | ||
import "qrc:///example/qml/component" | ||
|
||
FluViewModel{ | ||
|
||
objectName: "SettingsViewModel" | ||
property int displayMode | ||
|
||
onInitData: { | ||
displayMode = FluNavigationViewType.Auto | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
singleton ItemsOriginal 1.0 ItemsOriginal.qml | ||
singleton ItemsFooter 1.0 ItemsFooter.qml | ||
singleton MainEvent 1.0 MainEvent.qml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import QtQuick 2.15 | ||
import FluentUI 1.0 | ||
import "qrc:///example/qml/component" | ||
|
||
FluViewModel{ | ||
|
||
objectName: "SettingsViewModel" | ||
property int displayMode | ||
|
||
onInitData: { | ||
displayMode = FluNavigationViewType.Auto | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#include "FluViewModel.h" | ||
|
||
#include <QQuickItem> | ||
#include "Def.h" | ||
|
||
ViewModelManager* ViewModelManager::m_instance = nullptr; | ||
|
||
ViewModelManager *ViewModelManager::getInstance() | ||
{ | ||
if(ViewModelManager::m_instance == nullptr){ | ||
ViewModelManager::m_instance = new ViewModelManager; | ||
} | ||
return ViewModelManager::m_instance; | ||
} | ||
|
||
Model::Model(QObject *parent) | ||
: QObject{parent} | ||
{ | ||
|
||
} | ||
|
||
Model::~Model() | ||
{ | ||
qDebug()<<"Model delete~"; | ||
} | ||
|
||
ViewModelManager::ViewModelManager(QObject *parent) | ||
: QObject{parent} | ||
{ | ||
|
||
} | ||
|
||
void ViewModelManager::insertViewModel(FluViewModel* value){ | ||
m_viewmodel.append(value); | ||
} | ||
|
||
void ViewModelManager::deleteViewModel(FluViewModel* value){ | ||
m_viewmodel.removeOne(value); | ||
} | ||
|
||
QObject* ViewModelManager::getModel(const QString& key){ | ||
return m_data.value(key); | ||
} | ||
|
||
void ViewModelManager::insert(const QString& key,QObject* value){ | ||
m_data.insert(key,value); | ||
} | ||
|
||
bool ViewModelManager::exist(const QString& key){ | ||
return m_data.contains(key); | ||
} | ||
|
||
void ViewModelManager::refreshViewModel(FluViewModel* viewModel,QString key,QVariant value){ | ||
foreach (auto item, m_viewmodel) { | ||
if(item->getKey() == viewModel->getKey()){ | ||
item->setProperty(key.toStdString().c_str(),value); | ||
} | ||
} | ||
} | ||
|
||
PropertyObserver::PropertyObserver(QString name,QObject* model,QObject *parent) | ||
: QObject{parent} | ||
{ | ||
_name = name; | ||
_model = model; | ||
_property = QQmlProperty(parent,_name); | ||
_property.connectNotifySignal(this,SLOT(_propertyChange())); | ||
} | ||
|
||
PropertyObserver::~PropertyObserver(){ | ||
qDebug()<<"PropertyObserver delete~"; | ||
} | ||
|
||
void PropertyObserver::_propertyChange(){ | ||
auto value = _property.read(); | ||
_model->setProperty(_name.toStdString().c_str(),value); | ||
ViewModelManager::getInstance()->refreshViewModel((FluViewModel*)parent(),_name,value); | ||
} | ||
|
||
FluViewModel::FluViewModel(QObject *parent) | ||
: QObject{parent} | ||
{ | ||
ViewModelManager::getInstance()->insertViewModel(this); | ||
scope(FluViewModelType::Scope::Window); | ||
} | ||
|
||
FluViewModel::~FluViewModel(){ | ||
ViewModelManager::getInstance()->deleteViewModel(this); | ||
} | ||
|
||
void FluViewModel::classBegin() | ||
{ | ||
} | ||
|
||
void FluViewModel::componentComplete() | ||
{ | ||
auto o = parent(); | ||
while (nullptr != o) { | ||
_window = o; | ||
o = o->parent(); | ||
} | ||
const QMetaObject* obj = metaObject(); | ||
if(_scope == FluViewModelType::Scope::Window){ | ||
_key = property("objectName_").toString()+QString::number(reinterpret_cast<qulonglong>(_window), 16); | ||
}else{ | ||
_key = property("objectName").toString(); | ||
} | ||
QObject * model; | ||
if(!ViewModelManager::getInstance()->exist(_key)){ | ||
if(_scope == FluViewModelType::Scope::Window){ | ||
model = new Model(_window); | ||
}else{ | ||
model = new Model(); | ||
} | ||
Q_EMIT initData(); | ||
for (int i = 0; i < obj->propertyCount(); ++i) { | ||
const QMetaProperty property = obj->property(i); | ||
QString propertyName = property.name(); | ||
auto value = property.read(this); | ||
model->setProperty(propertyName.toStdString().c_str(),value); | ||
new PropertyObserver(propertyName,model,this); | ||
} | ||
ViewModelManager::getInstance()->insert(_key,model); | ||
}else{ | ||
model = ViewModelManager::getInstance()->getModel(_key); | ||
for (int i = 0; i < obj->propertyCount(); ++i) { | ||
const QMetaProperty property = obj->property(i); | ||
QString propertyName = property.name(); | ||
new PropertyObserver(propertyName,model,this); | ||
} | ||
} | ||
foreach (auto key, model->dynamicPropertyNames()) { | ||
setProperty(key,model->property(key)); | ||
} | ||
} | ||
|
||
QString FluViewModel::getKey(){ | ||
return _key; | ||
} |
Oops, something went wrong.