136 lines
4.7 KiB
C++
136 lines
4.7 KiB
C++
#include <QJsonArray>
|
||
#include "dataManager.h"
|
||
#include "dataBase.h"
|
||
|
||
DataManager& DataManager::instance()
|
||
{
|
||
//采用静态局部变量的方式,静态局部变量的初始化是在第一次访问时,以后的调用不会多次初始化,并且生命周期和程序一致
|
||
static DataManager instance;
|
||
return instance;
|
||
}
|
||
|
||
DataManager::DataManager(QObject *parent)
|
||
: QObject(parent)
|
||
{
|
||
_stateInitialised = false;
|
||
_dataInitialised = false;
|
||
}
|
||
|
||
DataManager::~DataManager()
|
||
{
|
||
|
||
}
|
||
|
||
void DataManager::initialModelState()
|
||
{
|
||
QMap<QString,int> model = DataBase::GetInstance()->getAllProjectModel();
|
||
|
||
QMap<QString,int>::Iterator iter;
|
||
for(iter = model.begin();iter != model.end(); ++iter) //遍历模型
|
||
{
|
||
modelStateInfo modelInfo;
|
||
modelInfo.modelType = iter.value(); //模型类型
|
||
|
||
groupStateInfo groupInfo;
|
||
QMap<QString,propertyGroupState> mapState = DataBase::GetInstance()->getModelInfo(iter.key());
|
||
|
||
QMap<QString,propertyGroupState>::Iterator it;
|
||
for(it = mapState.begin();it != mapState.end();++it) //遍历模型属性组
|
||
{
|
||
groupInfo.groupName = it.key();
|
||
groupInfo.tableName = it->tableName;
|
||
QJsonArray nodesJsonArray = it->propertyState["checkState"].toArray();
|
||
|
||
for (QJsonValueRef nodeJson : nodesJsonArray) //每个属性的状态信息
|
||
{
|
||
propertyStateInfo propertyInfo;
|
||
|
||
QJsonObject node = nodeJson.toObject();
|
||
QString propertyName = node["name"].toString();
|
||
int nState = node["checked"].toInt();
|
||
QString dataType = node["type"].toString();
|
||
QVariant defaultValue = node["defaultValue"].toVariant();
|
||
int lengthPrecision = node["lengthPrecision"].toInt();
|
||
if(nState)
|
||
{
|
||
//todo:别名赋值
|
||
propertyInfo.name = propertyName;
|
||
propertyInfo.type = dataType;
|
||
propertyInfo.defaultValue = defaultValue;
|
||
propertyInfo.lengthPrecision = lengthPrecision;
|
||
|
||
groupInfo.info.insert(propertyName,propertyInfo);
|
||
}
|
||
}
|
||
modelInfo.groupInfo.insert(it.key(),groupInfo);
|
||
}
|
||
_modelStateInfo.insert(iter.key(),modelInfo);
|
||
}
|
||
_stateInitialised = true;
|
||
}
|
||
|
||
void DataManager::initialModelData()
|
||
{
|
||
QMap<QString,int> model = DataBase::GetInstance()->getAllProjectModel();
|
||
|
||
QMap<QString,int>::Iterator iter;
|
||
for(iter = model.begin();iter != model.end(); ++iter) //遍历模型
|
||
{
|
||
modelDataInfo modelInfo;
|
||
modelInfo.modelType = iter.value(); //模型类型
|
||
|
||
QMap<QString,propertyGroupState> mapState = DataBase::GetInstance()->getModelInfo(iter.key());
|
||
|
||
QMap<QString,propertyGroupState>::Iterator it;
|
||
for(it = mapState.begin();it != mapState.end();++it) //遍历模型属性组
|
||
{
|
||
groupStateValue groupValue;
|
||
groupValue.groupName = it.key();
|
||
QJsonArray nodesJsonArray = it->propertyState["checkState"].toArray();
|
||
|
||
QStringList lstParam; //需检索的属性组中属性名列表
|
||
|
||
for (QJsonValueRef nodeJson : nodesJsonArray) //每个属性的状态信息
|
||
{
|
||
propertyStateInfo propertyInfo;
|
||
|
||
QJsonObject node = nodeJson.toObject();
|
||
QString propertyName = node["name"].toString();
|
||
int nState = node["checked"].toInt();
|
||
QString dataType = node["type"].toString();
|
||
QVariant defaultValue = node["defaultValue"].toVariant();
|
||
|
||
if(nState)
|
||
{
|
||
lstParam.append(propertyName);
|
||
}
|
||
}
|
||
lstParam.append("global_uuid"); //全局id未添加到属性状态中,手动选择
|
||
groupValue.mapInfo = DataBase::GetInstance()->selectGroupProperty(it->tableName,lstParam); //返回表中属性值
|
||
|
||
modelInfo.groupInfo.insert(it.key(),groupValue);
|
||
}
|
||
_modleDataInfo.insert(iter.key(),modelInfo);
|
||
}
|
||
_dataInitialised = true;
|
||
}
|
||
|
||
void DataManager::updateModelData(const QString& sModel,QUuid uuid,const QString& sGroup,QMap<QString,propertyStateInfo> mapPro)
|
||
{
|
||
_modleDataInfo[sModel].groupInfo[sGroup].mapInfo[uuid] = mapPro; //暂用设定值直接替换旧属性,待测试
|
||
}
|
||
|
||
ModleStateMap& DataManager::modelState()
|
||
{
|
||
if(!_stateInitialised)
|
||
initialModelState();
|
||
return _modelStateInfo;
|
||
}
|
||
|
||
ModelDataMap& DataManager::modelData()
|
||
{
|
||
if(!_dataInitialised)
|
||
initialModelData();
|
||
return _modleDataInfo;
|
||
}
|