finish bay/measure save/load

This commit is contained in:
baiYue 2025-07-18 18:26:13 +08:00
parent 38c8bc51e3
commit 93892cc597
23 changed files with 935 additions and 157 deletions

View File

@ -31,8 +31,12 @@ class BayProperty:public AbstractProperty //间隔属性(待扩展)
{
Q_OBJECT
public:
BayProperty(QObject* parent)
BayProperty(QObject* parent = nullptr)
:AbstractProperty(parent){
dVoltage = 0.0;
dFla = 0.0; //电流
dCapacity = 0.0; //容量
sType = "normal";
}
virtual ~BayProperty(){};
public:
@ -185,9 +189,9 @@ class VariableProperty:public BaseProperty //收到的变量数据
{
Q_OBJECT
public:
VariableProperty(QObject* parent);
VariableProperty(QObject* parent = nullptr);
~VariableProperty();
modelDataInfo getPropertyValue() const;
modelDataInfo& getPropertyValue() const;
};
#endif // DATABASE_H

View File

@ -292,6 +292,8 @@ struct propertyStateInfo //属性
QString type; //属性类型
QVariant defaultValue; //默认值
int lengthPrecision = 999; //长度限制
int isVisibe = 1; //是否可见0不可见,1:可见,2:特殊项)
bool lock = false; //值手动改变时置true下次保存时恢复
};
Q_DECLARE_METATYPE(propertyStateInfo);
@ -568,6 +570,8 @@ struct MeasurementInfo //量测
QString channel; //设备端子
QString type; //量测类型
int size; //量测size
QUuid bayUuid; //所属间隔
QUuid componentUuid; //所属设备
};
//==================================================
@ -586,7 +590,6 @@ struct baseComponentInfo //基模图元数据
struct componentInfo //工程模图元数据
{
int id = 0;
QUuid uuid;
QString modelName;
QString nspath;
@ -659,6 +662,33 @@ struct stationInfo
bool is_local = true;
};
struct bayInfo
{
QUuid uuid;
QString name;
QString type;
double unom;
double fla;
double capacity;
QString description;
bool inService;
int nState;
QString grid;
QString zone;
QString station;
QJsonObject business;
QJsonObject fromUuid;
QJsonObject toUuid;
QJsonObject protect;
QJsonObject faultRec;
QJsonObject status;
QJsonObject dynSense;
QJsonObject instruct;
QJsonObject etc;
QList<QUuid> components;
};
/*struct busStability
{
int componentId = 0;

View File

@ -52,7 +52,7 @@ BaseProperty::BaseProperty(QObject* parent)
BaseProperty::~BaseProperty()
{
qDebug()<<"release by "<<uuid();
}
/*************************属性变量*************************/
@ -68,8 +68,7 @@ VariableProperty::~VariableProperty()
}
modelDataInfo VariableProperty::getPropertyValue() const
modelDataInfo& VariableProperty::getPropertyValue() const
{
ModelDataMap mapData = DataManager::instance().modelData();
return mapData[sModelName];
return DataManager::instance().modelData()[sModelName];
}

View File

@ -12,6 +12,7 @@ namespace Ui { class bayInfoDlg; }
QT_END_NAMESPACE
class MeasureSettingDlg;
class BayProperty;
class BayInfoDlg : public BaseContentDlg
{
@ -26,6 +27,7 @@ public:
void setUi();
void addMeasure(MeasurementInfo);
void addOtherMeasure(QStringList); //本间隔的其他量测
BaseProperty* getProperty() {return _itemProperty;}
public slots:
void onAddClicked();
void onDeleteClicked();
@ -34,6 +36,8 @@ private:
void initial();
private:
Ui::bayInfoDlg *ui;
BayProperty* _bayProperty; //当前间隔属性
BaseProperty* _itemProperty; //当前对象属性
MeasureSettingDlg* _measureDlg;
QList<measureAttributeType> _validType; //可用的属性列表
QMap<QString,MeasurementInfo> _mapMeasure; //量测列表

View File

@ -10,6 +10,7 @@ namespace Ui { class bayManagerContentDlg; }
QT_END_NAMESPACE
class BayProperty;
class QButtonGroup;
class BayManagerContentDlg : public QDialog
{
@ -26,6 +27,7 @@ public:
private:
Ui::bayManagerContentDlg *ui;
BayProperty* _pData;
QButtonGroup* _stateGroup;
};
#endif

View File

@ -40,7 +40,7 @@ public:
QVector<ModelProperty*> allConnectionProperty();
QMap<QUuid,GraphicsProjectModelItem*>& allItems();
bool addNodeItem(QUuid uuid,GraphicsProjectModelItem*);
void addNodeItem(QUuid id,/*int type,*/QPointF pos);
void addNodeItem(QUuid id,QPointF pos);
GraphicsProjectModelItem* nodeItem(QUuid uuid);
QVariant nodeData(QUuid nodeId, NodeRole role) const;
BaseProperty* addNodeData(QUuid id,int type,QString name,QString modelName); //对应component数据一个data可对应多个itemid,类型,名称,工程模名)
@ -79,6 +79,7 @@ public:
void generateProjectModel(const QString&,QList<GraphicsBaseModelItem*>,QList<GraphicsNonStandardItem*>); //由基模生成工程模
void addProjectItemByBaseData(DrawingPanel*,GraphicsBaseModelItem*,BaseProperty*); //从基模item生成工程模item
/*************************间隔*****************************/
void addBayItem(QUuid);
bool addBayItem(QUuid,ElectricBayItem*);
void addItemsToBay(QList<GraphicsBaseItem*>,ElectricBayItem*); //将对象添加到间隔
BayProperty* addBayData(QUuid uuid);
@ -90,6 +91,8 @@ public:
void addBayByData(BayProperty*); //基模bay生成工程模bay
void addTestData(); //生成测试基模
QJsonObject turnListToJson(QList<QUuid> lst,QString sInerTag,QString sOutTag); //将list转换为QJsonObject,<lst,内部标签,外部标签>
QList<QUuid> turnJsonArrToList(QJsonObject obj,QString sInner,QString sOut);
Q_SIGNALS:
void activatePage(const QString&); //激活当前model所在page
public:

View File

@ -25,7 +25,8 @@ public:
protected:
QVBoxLayout* _layout;
QWidget* createEditor(propertyStateInfo); //创建属性
private:
QMap<QString,propertyStateInfo> _curValue;
};
#endif

View File

@ -16,6 +16,7 @@ BaseInfoDlg::BaseInfoDlg(QWidget *parent)
_stateGroup = new QButtonGroup(this);
_stateGroup->addButton(ui->rb_inService,1);
_stateGroup->addButton(ui->rb_outService,0);
_stateGroup->setExclusive(true);
}
BaseInfoDlg::~BaseInfoDlg()

View File

@ -16,6 +16,8 @@ BayInfoDlg::BayInfoDlg(QWidget *parent)
: BaseContentDlg(parent)
, ui(new Ui::bayInfoDlg)
,_measureDlg(nullptr)
,_bayProperty(nullptr)
,_itemProperty(nullptr)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
@ -48,6 +50,7 @@ QMap<QString,propertyStateInfo> BayInfoDlg::getPropertyValue(BaseProperty* pPro)
{
QMap<QString,propertyStateInfo> map;
pPro->setDataChanged(true);
pPro->setMeasurement(_mapMeasure);
return map;
}
@ -55,7 +58,7 @@ QMap<QString,propertyStateInfo> BayInfoDlg::getPropertyValue(BaseProperty* pPro)
void BayInfoDlg::setPropertyValue(QVariant var)
{
_mapMeasure.clear();
ui->tableWidget_other->setRowCount(0);;
ui->tableWidget_other->setRowCount(0);
ui->tableWidget_local->setRowCount(0); //清空列表
ui->le_zhbh->clear();
ui->le_jk->clear();
@ -67,6 +70,7 @@ void BayInfoDlg::setPropertyValue(QVariant var)
BaseProperty* property = static_cast<BaseProperty*>(var.value<void*>());
if(property)
{
_itemProperty = property;
QList<measureAttributeType> lstType = DataBase::GetInstance()->getMeasureAttributeTypes();
auto map = property->getMeasurement();
@ -77,7 +81,7 @@ void BayInfoDlg::setPropertyValue(QVariant var)
}
//间隔处理
BayProperty* pBay = nullptr;
_bayProperty = nullptr;
QMap<QUuid,ElectricBayItem*> mapBay = _curModelController->allBayItem();
for(auto& item:mapBay){
AbstractProperty* pPro = item->getProperty();
@ -86,22 +90,22 @@ void BayInfoDlg::setPropertyValue(QVariant var)
QList<QUuid> lstCompo = pBayPro->getLstComponent(); //获取间隔下的component找到本component对应的间隔
for(auto& id:lstCompo){
if(id == property->uuid()){
pBay = pBayPro;
_bayProperty = pBayPro;
break;
}
}
}
}
if(pBay){
auto lstFrom = pBay->getLstFrom();
auto lstTo = pBay->getLstTo();
auto lstProtect = pBay->getLstProtect();
auto lstFaultRecord = pBay->getLstFaultRecord();
auto lstDynSense = pBay->getLstDynSense();
auto lstStatus = pBay->getLstStatus();
auto lstInstruct = pBay->getLstInstruct();
auto lstEtc = pBay->getLstEtc();
if(_bayProperty){
auto lstFrom = _bayProperty->getLstFrom();
auto lstTo = _bayProperty->getLstTo();
auto lstProtect = _bayProperty->getLstProtect();
auto lstFaultRecord = _bayProperty->getLstFaultRecord();
auto lstDynSense = _bayProperty->getLstDynSense();
auto lstStatus = _bayProperty->getLstStatus();
auto lstInstruct = _bayProperty->getLstInstruct();
auto lstEtc = _bayProperty->getLstEtc();
QStringList sLstFrom;
for(auto& fromId:lstFrom){
@ -168,7 +172,7 @@ void BayInfoDlg::setPropertyValue(QVariant var)
}
QList<BaseProperty*> lstOther;
QList<QUuid> lstCompo = pBay->getLstComponent();
QList<QUuid> lstCompo = _bayProperty->getLstComponent();
for(auto& compoId:lstCompo){
BaseProperty* pPro = BasePropertyManager::instance().findEntityData(compoId);
if(pPro){
@ -196,7 +200,7 @@ void BayInfoDlg::setPropertyValue(QVariant var)
ui->le_ztjc->setText(sLstStatus.join(""));
ui->le_qt->setText(sLstEtc.join(""));
ui->le_bayName->setText(pBay->tag());
ui->le_bayName->setText(_bayProperty->name());
addOtherMeasure(lstOtherMeasure);
}
}
@ -263,7 +267,14 @@ void BayInfoDlg::addMeasure(MeasurementInfo info)
QTableWidgetItem* sizeItem = new QTableWidgetItem(QString::number(info.size));
ui->tableWidget_local->setItem(row, 5, sizeItem);
if(_bayProperty && _itemProperty){
QUuid bayId = _bayProperty->uuid();
QUuid itemId = _itemProperty->uuid();
info.bayUuid = bayId;
info.componentUuid = itemId;
_mapMeasure.insert(info.name,info);
}
for(int i = 0;i < _validType.size();++i){
if(_validType.at(i).name == info.name){ //可用类型中移除该类型
_validType.removeAt(i);

View File

@ -1,3 +1,4 @@
#include <QButtonGroup>
#include "bayManagerContentDlg.h"
#include "baseProperty.h"
#include "ui_bayManagerContentDlg.h"
@ -20,6 +21,11 @@ BayManagerContentDlg::~BayManagerContentDlg()
void BayManagerContentDlg::initial()
{
_stateGroup = new QButtonGroup(this);
_stateGroup->addButton(ui->rbtn_in,1);
_stateGroup->addButton(ui->rbtn_out,0);
_stateGroup->setExclusive(true);
QStringList headerText;
headerText<<"选择"<<"名称";
ui->tw_zongHe->setContextMenuPolicy(Qt::CustomContextMenu);
@ -68,7 +74,7 @@ void BayManagerContentDlg::initial()
void BayManagerContentDlg::updateByProperty()
{
if(_pData){
ui->le_name->setText(_pData->tag());
ui->le_name->setText(_pData->name());
ui->tw_zongHe->setRowCount(0);
ui->tw_jianKong->setRowCount(0);
ui->tw_dongTai->setRowCount(0);

View File

@ -89,7 +89,7 @@ void BayManagerDlg::generatePage(QList<BayProperty*> lstBay)
pBay->updateByProperty();
int index = ui->stackedWidget->addWidget(pBay);
_contentData.insert(index,pBay);
QListWidgetItem* pItem = new QListWidgetItem(pData->tag());
QListWidgetItem* pItem = new QListWidgetItem(pData->name());
pItem->setData(Qt::UserRole+1,index);
ui->listWidget->addItem(pItem);
}

View File

@ -13,6 +13,7 @@
#include "topologyManager.h"
#include "projectDiagramNameInput.h"
#include "baseProperty.h"
#include "graphicsItem/electricBayItem.h"
DrawingPanel::DrawingPanel(PowerEntity* pEntity,QWidget *parent,DiagramMode mode)
: QWidget(parent)
@ -207,6 +208,20 @@ QJsonObject DrawingPanel::getDiagramInfo() const
arrConnect.append(connect);
}
obj["connections"] = arrConnect;
QJsonArray arrBay;
QMap<QUuid,ElectricBayItem*> mapBay = _pModel->allBayItem();
for(auto& bayItem:mapBay){
AbstractProperty* pPro = bayItem->getProperty();
BayProperty* pBay = dynamic_cast<BayProperty*>(pPro);
if(pBay)
{
QJsonObject bay;
bay["id"] = pBay->uuid().toString();
arrBay.append(bay);
}
}
obj["bays"] = arrBay;
}
return obj;
}
@ -256,6 +271,17 @@ void DrawingPanel::loadNodes(QJsonObject obj)
}
}
QJsonArray bayArr = obj["bays"].toArray();
for(QJsonValueRef bayJson:bayArr)
{
QJsonObject bay = bayJson.toObject();
QUuid id = QUuid(bay["id"].toString());
if(_pModel)
{
_pModel->addBayItem(id);
}
}
if(_mode == DM_run)
{
if(_pModel)

View File

@ -118,7 +118,7 @@ void FixedPortsModel::addNodeItem(QUuid id/*,int type*/,QPointF pos)
QMap<QUuid,BaseProperty*> mapData = BasePropertyManager::instance().getEntityData(); //加载的图形必定关联component(todo:完善判断条件,如判断拓扑节点)
if(mapData.contains(id))
{
pro = mapData[id];
pro = mapData.value(id);
if(pro)
{
int type = pro->graphicsType();
@ -209,7 +209,7 @@ BaseProperty* FixedPortsModel::addNodeData(QUuid id,int type,QString name,QStrin
if(pData != nullptr)
return pData;
VariableProperty* item = new VariableProperty(this);
VariableProperty* item = new VariableProperty();
//todo:关联到对应data
if(item)
@ -256,6 +256,14 @@ void FixedPortsModel::loadNodeDataFromDataBase()
if(pEntity){
createTopoTerminalsByData(pEntity,info.context);
}
QList<MeasurementInfo> lstMeasure = DataBase::GetInstance()->getMeasurement(info.uuid); //添加设备量测
QMap<QString,MeasurementInfo> mapMeasure;
for(auto& info:lstMeasure)
{
mapMeasure.insert(info.name,info);
}
pData->setMeasurement(mapMeasure);
}
QList<topologicInfo> lstTopo = DataBase::GetInstance()->getAllTopologics();
@ -266,6 +274,35 @@ void FixedPortsModel::loadNodeDataFromDataBase()
TopologyManager::instance().createConnection(QString::number(info.id),from_pin,to_pin,info.uuid_from.toString(),info.uuid_to.toString());
}
QList<bayInfo> lstBay = DataBase::GetInstance()->getAllBay();
for(auto& bay:lstBay)
{
BayProperty* pBay = addBayData(bay.uuid);
pBay->setName(bay.name);
pBay->setType(bay.type);
pBay->setLstComponent(bay.components);
pBay->setVoltage(bay.unom);
pBay->setFla(bay.fla);
pBay->setCapacity(bay.capacity);
pBay->setInService(bay.inService);
auto fromLst = turnJsonArrToList(bay.fromUuid,"id","ids");
pBay->setLstFrom(fromLst);
auto toLst = turnJsonArrToList(bay.toUuid,"id","ids");
pBay->setLstTo(toLst);
auto proptecLst = turnJsonArrToList(bay.protect,"id","ids");
pBay->setLstProtect(proptecLst);
auto falRecLst = turnJsonArrToList(bay.faultRec,"id","ids");
pBay->setLstFaultRecord(falRecLst);
auto dynSenLst = turnJsonArrToList(bay.dynSense,"id","ids");
pBay->setLstDynSense(dynSenLst);
auto staLst = turnJsonArrToList(bay.status,"id","ids");
pBay->setLstStatus(staLst);
auto insLst = turnJsonArrToList(bay.instruct,"id","ids");
pBay->setLstInstruct(insLst);
auto etcLst = turnJsonArrToList(bay.etc,"id","ids");
pBay->setLstEtc(etcLst);
}
_dataInitialised = true;
}
else
@ -462,6 +499,39 @@ QVariant FixedPortsModel::nodeData(QUuid nodeId, NodeRole role) const
void FixedPortsModel::saveNode(int nPageId)
{
for(auto& bay:_bayItem)
{
AbstractProperty* pro = bay->getProperty(); //间隔
BayProperty* pBay = dynamic_cast<BayProperty*>(pro);
if(pBay){
bool val = DataBase::GetInstance()->ifBayExist(pBay->uuid());
if(!val){
QJsonObject objFrom = turnListToJson(pBay->getLstFrom(),"id","ids");
QJsonObject objTo= turnListToJson(pBay->getLstTo(),"id","ids");
QJsonObject objProtec= turnListToJson(pBay->getLstProtect(),"id","ids");
QJsonObject objFalRec= turnListToJson(pBay->getLstFaultRecord(),"id","ids");
QJsonObject objStatus= turnListToJson(pBay->getLstStatus(),"id","ids");
QJsonObject objDynSen= turnListToJson(pBay->getLstDynSense(),"id","ids");
QJsonObject objIns= turnListToJson(pBay->getLstInstruct(),"id","ids");
QJsonObject objEtc= turnListToJson(pBay->getLstEtc(),"id","ids");
DataBase::GetInstance()->insertBay(pBay->uuid(),pBay->name(),pBay->getType(),pBay->getVoltage(),pBay->getFla(),pBay->getCapacity(),"1",pBay->getInService(),0,"1","1","1",QJsonObject(),objFrom,objTo,objProtec,objFalRec,objStatus,objDynSen,objIns,objEtc,pBay->getLstComponent());
}
else{
QJsonObject objFrom = turnListToJson(pBay->getLstFrom(),"id","ids");
QJsonObject objTo= turnListToJson(pBay->getLstTo(),"id","ids");
QJsonObject objProtec= turnListToJson(pBay->getLstProtect(),"id","ids");
QJsonObject objFalRec= turnListToJson(pBay->getLstFaultRecord(),"id","ids");
QJsonObject objStatus= turnListToJson(pBay->getLstStatus(),"id","ids");
QJsonObject objDynSen= turnListToJson(pBay->getLstDynSense(),"id","ids");
QJsonObject objIns= turnListToJson(pBay->getLstInstruct(),"id","ids");
QJsonObject objEtc= turnListToJson(pBay->getLstEtc(),"id","ids");
DataBase::GetInstance()->updateBay(pBay->uuid(),pBay->name(),pBay->getVoltage(),pBay->getFla(),pBay->getCapacity(),"",pBay->getInService(),0,QJsonObject(),objFrom,objTo,objProtec,objFalRec,objStatus,objDynSen,objIns,objEtc,pBay->getLstComponent());
}
}
}
QMap<QUuid,GraphicsProjectModelItem*> mapItems = allItems();
for(auto& pItem:mapItems)
{
@ -487,11 +557,12 @@ void FixedPortsModel::saveNode(int nPageId)
}
if(pData->dataChanged())
{
pData->setDataChanged(false);
bool exist = DataBase::GetInstance()->componentExist(pData->uuid().toString());
VariableProperty* pVariable = dynamic_cast<VariableProperty*>(pData);
if(pVariable)
{
modelDataInfo dataInfo = pVariable->getPropertyValue();
modelDataInfo& dataInfo = pVariable->getPropertyValue();
if(exist) //已存在更新
{
DataBase::GetInstance()->updateComponent(pData->uuid(),pData->tag(),pData->name(),pData->context());
@ -500,6 +571,13 @@ void FixedPortsModel::saveNode(int nPageId)
if(val.groupName == "component")
continue;
DataBase::GetInstance()->updateDynamicProperty(pData->uuid(),val);
if(val.mapInfo.contains(pData->uuid())){ //保存时将数据锁复原
auto& mapPro = val.mapInfo[pData->uuid()];
for(auto& pro:mapPro)
{
pro.lock = false;
}
}
}
}
else
@ -510,20 +588,74 @@ void FixedPortsModel::saveNode(int nPageId)
if(val.groupName == "component")
continue;
DataBase::GetInstance()->insertDynamicProperty(pData->uuid(),val);
if(val.mapInfo.contains(pData->uuid())){ //保存时将数据锁复原
auto& mapPro = val.mapInfo[pData->uuid()];
for(auto& pro:mapPro)
{
pro.lock = false;
}
}
}
}
QMap<QString,MeasurementInfo> mapMeasure = pData->getMeasurement(); //量测
QList<MeasurementInfo> lstDataBase = DataBase::GetInstance()->getMeasurement(pData->uuid()); //数据库中现有量测
for(auto& info:mapMeasure)
{
int tpe = 0; //todo:建立类型映射表
if(info.type == "遥测"){
tpe = 0;
}
else if(info.type == "遥信"){
tpe = 1;
}
else if(info.type == "遥控"){
tpe = 2;
}
else if(info.type == "遥调"){
tpe = 3;
}
else if(info.type == "整定值"){
tpe = 4;
}
QJsonObject obj;
obj["type"] = info.equipment;
obj["main_pos"] = info.channel;
bool val = DataBase::GetInstance()->ifMeasureExist(info.name,pData->uuid());
if(val){
DataBase::GetInstance()->updateMeasurement(info.name,tpe,obj,info.size,pData->uuid());
}
else{
DataBase::GetInstance()->insertMeasurement(info.name,info.tag,tpe,obj,info.size,info.bayUuid,info.componentUuid);
}
for(int i = 0;i < lstDataBase.size();++i) //从数据库记录中移除操作过的对象
{
if(lstDataBase[i].name == info.name){
lstDataBase.removeAt(i);
break;
}
}
}
for(auto& info:lstDataBase) //操作的记录小于数据库中的记录,删除库中多出的记录
{
DataBase::GetInstance()->delteMeasurement(info.name,info.componentUuid);
}
}
if(pData->type() == 8){
PowerConnection* pCon = TopologyManager::instance().connection(fromPin,toPin);
if(pCon){
int id = DataBase::GetInstance()->topologicExist(con.nSrcNodeId,con.nDestNodeId);
if(id == -1)
DataBase::GetInstance()->insertTopologic(con.nSrcNodeId,con.nDestNodeId,context,0,"",0);
}
}
}
}
}
//todo:savebay
}
void FixedPortsModel::onSignal_ifExits(QUuid id,const QString& str,int type,GraphicsProjectModelItem* pitem)
@ -1246,6 +1378,19 @@ void FixedPortsModel::addProjectItemByBaseData(DrawingPanel* pPanel,GraphicsBase
}
}
void FixedPortsModel::addBayItem(QUuid id)
{
QMap<QUuid,BayProperty*> mapData = BasePropertyManager::instance().getBayData(); //加载的图形必定关联component(todo:完善判断条件,如判断拓扑节点)
if(mapData.contains(id))
{
BayProperty* pro = mapData.value(id);
if(pro)
{
addBayByData(pro);
}
}
}
bool FixedPortsModel::addBayItem(QUuid id,ElectricBayItem* pBay)
{
if(_bayItem.contains(id))
@ -1281,7 +1426,7 @@ BayProperty* FixedPortsModel::addBayData(QUuid uuid)
if(pData != nullptr)
return pData;
BayProperty* item = new BayProperty(this);
BayProperty* item = new BayProperty();
if(item)
{
@ -1394,7 +1539,7 @@ void FixedPortsModel::addBayByData(BayProperty* pData)
auto pBay = new ElectricBayItem(rec);
pBay->setItemType(GIT_bay);
pBay->setProperty(pData);
pBay->setText(pData->tag());
pBay->setText(pData->name());
addBayItem(pData->uuid(),pBay);
getScene()->addItem(pBay);
}
@ -1477,3 +1622,34 @@ void FixedPortsModel::addTestData()
addItemsToBay(lst,pBay);
_scene->addItem(pBay);
}
QJsonObject FixedPortsModel::turnListToJson(QList<QUuid> lst,QString sInerTag,QString sOutTag)
{
QJsonObject o;
QJsonArray arr;
if(lst.isEmpty())
return QJsonObject();
for(auto id:lst)
{
QJsonObject obj;
obj[sInerTag] = id.toString();
arr.push_back(obj);
}
o[sOutTag] = arr;
return o;
}
QList<QUuid> FixedPortsModel::turnJsonArrToList(QJsonObject object,QString sInner,QString sOut)
{
QJsonArray jsonArray = object[sOut].toArray();
QList<QUuid> lst;
for (QJsonValueRef nodeJson : jsonArray)
{
QJsonObject node = nodeJson.toObject();
QUuid uid = QUuid(node[sInner].toString());
lst.append(uid);
}
return lst;
}

View File

@ -64,6 +64,10 @@ void MeasureSettingDlg::showDlg()
}
ui->cb_equip->addItems(lstDevice);
BaseProperty* pro = _pBay->getProperty();
if(pro){
ui->cb_equip->setCurrentText(pro->tag());
}
}
}

View File

@ -240,12 +240,24 @@ QMap<QString,propertyStateInfo> PropertyContentDlg::getPropertyValue(BasePropert
map.insert(pro.proName,info);
}
}
for(auto it = map.begin();it != map.end();++it) //值被手动改变过,锁定(保存后解除锁定
{
if(_curValue.contains(it.key()))
{
if(it->defaultValue != _curValue.value(it.key()).defaultValue)
{
it->lock = true;
}
}
}
return map;
}
void PropertyContentDlg::setPropertyValue(QVariant var)
{
QMap<QString,propertyStateInfo> map = var.value<QMap<QString,propertyStateInfo>>();
_curValue = map;
for(auto &info:map)
{
propertyContentInfo pro = _mapPro[info.name];

View File

@ -27,7 +27,7 @@ void StatusBar::initial()
void StatusBar::setButtonVisible(bool val)
{
setVisible(m_pButtonGenerate);
m_pButtonGenerate->setVisible(val);
}
void StatusBar::onScaleLevelChanged(double f)

View File

@ -443,12 +443,15 @@ void BaseSelector::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, Design
{
if(item->getItemType() == GIT_bay) //间隔暂时返回
return;
QString modelName = item->getModelName(); //todo:additem时填写模型类型
ModelProperty* pro = item->getProperty();
if(pro){
QString modelName = pro->modelName();
QUuid uuid = item->itemId();
_model->showModelDlg(modelName,uuid,item);
}
}
}
}
else if(sceneMode == DM_baseModel)
{
QList<QGraphicsItem *> items = scene->selectedItems();

View File

@ -41,7 +41,7 @@ public:
QList<stationInfo> getAllStation();
QList<topologicInfo> getAllTopologics();
int topologicExist(QUuid fromPin,QUuid toPin);
int topologicExist(QUuid fromItem,QUuid toItem);
topologicInfo getTopologicById(int id);
bool deleteTopologic(QUuid fromPin,QUuid toPin);
/*********************************************************************************/
@ -61,13 +61,23 @@ public:
QJsonObject getPageContextByName(QString name);
QList<pageInfo> getAllPage();
/*********************************************************************************/
bool insertMeasurement(QString tag,QString name,int type,QJsonObject dataSource,int size,int bayId,QUuid componentId);
bool insertBay(QUuid uuid,QString name,QString type,double unom,double fla,double capacity,QString description,bool inService,int nState,QString grid,QString zone,QString station,QJsonObject business,QJsonObject fromUuid,QJsonObject toUuid,QJsonObject protect,QJsonObject faultRec,QJsonObject status,QJsonObject dynSense,QJsonObject instruct,QJsonObject etc,QList<QUuid> components);
bool updateBay(QUuid uuid,QString name,double unom,double fla,double capacity,QString description,bool inService,int nState,QJsonObject business,QJsonObject fromUuid,QJsonObject toUuid,QJsonObject protect,QJsonObject faultRec,QJsonObject status,QJsonObject dynSense,QJsonObject instruct,QJsonObject etc,QList<QUuid> components);
bayInfo getBay(QUuid uuid);
QList<bayInfo> getAllBay();
bool ifBayExist(QUuid uuid);
bool deleteBay(QUuid uuid);
/*********************************************************************************/
bool insertMeasurement(QString name,QString tag,int type,QJsonObject dataSource,int size,QUuid bayId,QUuid componentId);
bool updateMeasurement(QString name,int type,QJsonObject dataSource,int size,QUuid componentId);
bool delteMeasurement(QString name,QUuid componentId);
bool ifMeasureExist(QString name,QUuid componentId);
QList<MeasurementInfo> getMeasurement(QUuid componentId);
/*********************************************************************************/
bool deleteComponentById(int id);
void select();
void parallelUpdate();
QJsonObject QstringToJson(QString jsonString);
QList<QUuid> parseUuidArray(const QString& pgArray); //转化UUID[]类型
public:
//***********元模
bool getAttributeGroup(); //获取属性组信息
@ -118,7 +128,9 @@ public:
QMap<QString,propertyGroupState> getModelInfo(const QString&); //获取模型信息
QMap<QString,propertyGroupState> getPublicInfo(); //获取公共属性组信息
QMap<QString,projectManager> getProjectModelGroupInfo(const QString&); //获取指定工程模所有属性组信息<属性组名,属性信息>
QMap<QUuid,PropertyValueInfo> selectGroupProperty(const QString& tableName,QMap<QString,propertyStateInfo> mapPro); //返回属性组表中的信息
QMap<QUuid,PropertyValueInfo> selectGroupPropertyByState(const QString& tableName,QMap<QString,propertyStateInfo> mapPro); //返回属性组表中的信息
PropertyValueInfo selectGroupPropertyByValue(const QString& tableName,QUuid uuid,PropertyValueInfo value); //通过已有结构更新数据
QList<measureAttributeType> getMeasureAttributeTypes(); //获取所有量测属性
private:
QMap<int,attributeGroup> _attributeGroup; //属性组的组

View File

@ -17,7 +17,8 @@ BasePropertyManager::BasePropertyManager(QObject *parent)
BasePropertyManager::~BasePropertyManager()
{
qDeleteAll(m_entityData);
qDeleteAll(m_bayData);
}
void BasePropertyManager::insertEntityData(QUuid uid,BaseProperty* p)

View File

@ -333,8 +333,9 @@ bool DataBase::updateDynamicProperty(QUuid uuid,groupStateValue groupValue)
setClauses.append(QString("%1 = ?").arg(pro.name));
params.append(pro.defaultValue);
}
params.append(uuid);
QString strSQL = QString("UPDATE 1% SET %2 WHERE global_uuid = 3%").arg(groupValue.tableName).arg(setClauses.join(",")).arg(uuid.toString());
QString strSQL = QString("UPDATE %1 SET %2 WHERE global_uuid = ?").arg(groupValue.tableName).arg(setClauses.join(","));
try
{
@ -660,12 +661,12 @@ QList<topologicInfo> DataBase::getAllTopologics()
}
}
int DataBase::topologicExist(QUuid fromPin,QUuid toPin)
int DataBase::topologicExist(QUuid fromItem,QUuid toItem)
{
QString strSQL = "SELECT id FROM topologic WHERE from_pin = ? AND to_pin = ?";
QString strSQL = "SELECT id FROM topologic WHERE uuid_from = ? AND uuid_to = ?";
QVariantList params;
params.append(fromPin.toString());
params.append(toPin.toString());
params.append(fromItem.toString());
params.append(toItem.toString());
try
{
@ -754,18 +755,17 @@ componentInfo DataBase::getComponentInfoByUuid(QString uuid)
{
while (qry.next())
{
inf.id = qry.value(0).toInt();
inf.uuid = QUuid(qry.value(1).toString());
inf.modelName = qry.value(2).toString();
inf.tag = qry.value(3).toString();
inf.name = qry.value(4).toString();
inf.grid = qry.value(5).toString();
inf.zone = qry.value(6).toString();
inf.station = qry.value(7).toString();
inf.type = qry.value(8).toInt();
QString str = qry.value(9).toString();
inf.uuid = QUuid(qry.value(0).toString());
inf.modelName = qry.value(1).toString();
inf.tag = qry.value(2).toString();
inf.name = qry.value(3).toString();
inf.grid = qry.value(4).toString();
inf.zone = qry.value(5).toString();
inf.station = qry.value(6).toString();
inf.type = qry.value(7).toInt();
QString str = qry.value(8).toString();
inf.context = QstringToJson(str);
inf.op = qry.value(10).toInt();
inf.op = qry.value(9).toInt();
qry.clear();
}
}
@ -780,7 +780,7 @@ QList<componentInfo> DataBase::getAllComponents()
{
QSqlQuery qry(db);
qry.prepare("SELECT id, global_uuid, model_name,tag, name, grid, zone, station, type, context, op FROM component");
qry.prepare("SELECT global_uuid, model_name,tag, name, grid, zone, station, type, context, op FROM component");
bool res = qry.exec();
QString str = qry.lastQuery();
if(!res)
@ -793,18 +793,17 @@ QList<componentInfo> DataBase::getAllComponents()
while (qry.next())
{
componentInfo inf;
inf.id = qry.value(0).toInt();
inf.uuid = QUuid(qry.value(1).toString());
inf.modelName = qry.value(2).toString();
inf.tag = qry.value(3).toString();
inf.name = qry.value(4).toString();
inf.grid = qry.value(5).toString();
inf.zone = qry.value(6).toString();
inf.station = qry.value(7).toString();
inf.type = qry.value(8).toInt();
QString str = qry.value(9).toString();
inf.uuid = QUuid(qry.value(0).toString());
inf.modelName = qry.value(1).toString();
inf.tag = qry.value(2).toString();
inf.name = qry.value(3).toString();
inf.grid = qry.value(4).toString();
inf.zone = qry.value(5).toString();
inf.station = qry.value(6).toString();
inf.type = qry.value(7).toInt();
QString str = qry.value(8).toString();
inf.context = QstringToJson(str);
inf.op = qry.value(10).toInt();
inf.op = qry.value(9).toInt();
lst.push_back(inf);
}
qry.clear();
@ -819,7 +818,7 @@ bool DataBase::componentExist(QString uuid)
{
QSqlQuery qry(db);
qry.prepare("SELECT id FROM component WHERE global_uuid = ?");
qry.prepare("SELECT global_uuid FROM component WHERE global_uuid = ?");
qry.bindValue(0,uuid);
bool res = qry.exec();
QString str = qry.lastQuery();
@ -1056,11 +1055,307 @@ bool DataBase::deleteComponentById(int id)
else
return false;
}
/*****************************************************************************/
bool DataBase::insertBay(QUuid uuid,QString name,QString type,double unom,double fla,double capacity,QString description,bool inService,int nState,QString grid,QString zone,
QString station,QJsonObject business,QJsonObject fromUuid,QJsonObject toUuid,QJsonObject protect,QJsonObject faultRec,QJsonObject status,QJsonObject dynSense,
QJsonObject instruct,QJsonObject etc,QList<QUuid> components)
{
QJsonDocument businessDoc(business);
QString strBusiness = businessDoc.toJson(QJsonDocument::Compact);
QJsonDocument fromUuidDoc(fromUuid);
QString strFromUuid = fromUuidDoc.toJson(QJsonDocument::Compact);
QJsonDocument toUuidDoc(toUuid);
QString strToUuid = toUuidDoc.toJson(QJsonDocument::Compact);
QJsonDocument protectDoc(protect);
QString strProtect = protectDoc.toJson(QJsonDocument::Compact);
QJsonDocument faultRecDoc(faultRec);
QString strFaultRec = faultRecDoc.toJson(QJsonDocument::Compact);
QJsonDocument statusDoc(status);
QString strStatus = statusDoc.toJson(QJsonDocument::Compact);
QJsonDocument dynSenseDoc(dynSense);
QString strDynSense = dynSenseDoc.toJson(QJsonDocument::Compact);
QJsonDocument instructDoc(instruct);
QString strInstruct = instructDoc.toJson(QJsonDocument::Compact);
QJsonDocument etcDoc(etc);
QString strEtc = etcDoc.toJson(QJsonDocument::Compact);
QString strSQL = "INSERT INTO bay(bay_uuid, name, type, unom, fla, capacity, description, in_service, state, grid, zone, station, business, from_uuids, to_uuids, dev_protect, dev_fault_record, dev_status, dev_dyn_sense, dev_instruct, dev_etc, components) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
QStringList uuidStrings;
for (const QUuid &uuid : components) {
// 使用WithoutBraces确保无花括号符合PG数组元素格式
uuidStrings << "\"" + uuid.toString(QUuid::WithoutBraces) + "\"";
}
QString arrayUuid = "{" + uuidStrings.join(",") + "}";
QVariantList params;
params.append(uuid.toString());
params.append(name);
params.append(type);
params.append(unom);
params.append(fla);
params.append(capacity);
params.append(description);
params.append(inService);
params.append(nState);
params.append(grid);
params.append(zone);
params.append(station);
params.append(strBusiness);
params.append(strFromUuid);
params.append(strToUuid);
params.append(strProtect);
params.append(strFaultRec);
params.append(strStatus);
params.append(strDynSense);
params.append(strInstruct);
params.append(strEtc);
params.append(arrayUuid);
try
{
executeSQL(strSQL,false,params);
return true;
}
catch (const std::exception& e)
{
LOG_ERROR("DB", QString("Insert bay fail"));
return false;
}
}
bool DataBase::updateBay(QUuid uuid,QString name,double unom,double fla,double capacity,QString description,bool inService,int nState,QJsonObject business,
QJsonObject fromUuid,QJsonObject toUuid,QJsonObject protect,QJsonObject faultRec,QJsonObject status,QJsonObject dynSense,QJsonObject instruct,
QJsonObject etc,QList<QUuid> components)
{
QJsonDocument businessDoc(business);
QString strBusiness = businessDoc.toJson(QJsonDocument::Compact);
QJsonDocument fromUuidDoc(fromUuid);
QString strFromUuid = fromUuidDoc.toJson(QJsonDocument::Compact);
QJsonDocument toUuidDoc(toUuid);
QString strToUuid = toUuidDoc.toJson(QJsonDocument::Compact);
QJsonDocument protectDoc(protect);
QString strProtect = protectDoc.toJson(QJsonDocument::Compact);
QJsonDocument faultRecDoc(faultRec);
QString strFaultRec = faultRecDoc.toJson(QJsonDocument::Compact);
QJsonDocument statusDoc(status);
QString strStatus = statusDoc.toJson(QJsonDocument::Compact);
QJsonDocument dynSenseDoc(dynSense);
QString strDynSense = dynSenseDoc.toJson(QJsonDocument::Compact);
QJsonDocument instructDoc(instruct);
QString strInstruct = instructDoc.toJson(QJsonDocument::Compact);
QJsonDocument etcDoc(etc);
QString strEtc = etcDoc.toJson(QJsonDocument::Compact);
QStringList uuidStrings;
for (const QUuid &uuid : components) {
// 使用WithoutBraces确保无花括号符合PG数组元素格式
uuidStrings << "\"" + uuid.toString(QUuid::WithoutBraces) + "\"";
}
QString arrayUuid = "{" + uuidStrings.join(",") + "}";
QString strSQL = "UPDATE bay SET name = ?,unom = ?,fla = ?,capacity = ?,description = ?,in_service = ?, state = ?, business = ?,from_uuids = ?,to_uuids = ?,dev_protect = ?,dev_fault_record = ?, dev_status = ?,dev_dyn_sense = ?,dev_instruct = ?,dev_etc = ?,components = ? WHERE bay_uuid = ?";
QVariantList params;
params.append(name);
params.append(unom);
params.append(fla);
params.append(capacity);
params.append(description);
params.append(inService);
params.append(nState);
params.append(strBusiness);
params.append(strFromUuid);
params.append(strToUuid);
params.append(strProtect);
params.append(strFaultRec);
params.append(strStatus);
params.append(strDynSense);
params.append(strInstruct);
params.append(strEtc);
params.append(arrayUuid);
params.append(uuid);
try
{
executeSQL(strSQL,false,params);
return true;
}
catch (const std::exception& e)
{
LOG_ERROR("DB", QString("Update bay fail"));
return false;
}
}
bayInfo DataBase::getBay(QUuid uuid)
{
bayInfo info;
QString strSQL = "SELECT bay_uuid, name, type, unom, fla, capacity, description, in_service, state, grid, zone, station, business, from_uuids, to_uuids, dev_protect, dev_fault_record, dev_status, dev_dyn_sense, dev_instruct, dev_etc, components FROM bay WHERE bay_uuid = ?";
QVariantList params;
params.append(uuid);
try
{
QSqlQuery query = executeSQL(strSQL,false,params);
while (query.next())
{
info.uuid = QUuid(query.value(0).toString());
info.name = query.value(1).toString();
info.type = query.value(2).toString();
info.unom = query.value(3).toDouble();
info.fla = query.value(4).toDouble();
info.capacity = query.value(5).toDouble();
info.description = query.value(6).toString();
info.inService = query.value(7).toBool();
info.nState = query.value(8).toInt();
info.grid = query.value(9).toString();
info.zone = query.value(10).toString();
info.station = query.value(11).toString();
QString strBusi = query.value(12).toString();
info.business = QstringToJson(strBusi);
QString strFrom = query.value(13).toString();
info.fromUuid = QstringToJson(strFrom);
QString strTo = query.value(14).toString();
info.toUuid = QstringToJson(strTo);
QString strProtect = query.value(15).toString();
info.protect = QstringToJson(strProtect);
QString strFaultRec= query.value(16).toString();
info.faultRec = QstringToJson(strFaultRec);
QString strStatus= query.value(17).toString();
info.status = QstringToJson(strStatus);
QString strDynSense= query.value(18).toString();
info.dynSense = QstringToJson(strDynSense);
QString strInstructe= query.value(19).toString();
info.instruct = QstringToJson(strInstructe);
QString strEtc= query.value(20).toString();
info.etc = QstringToJson(strEtc);
QString rawData = query.value(21).toString();
info.components = parseUuidArray(rawData);
}
query.clear();
return info;
}
catch (const std::exception& e)
{
return info;
}
}
QList<bayInfo> DataBase::getAllBay()
{
QList<bayInfo> lstInfo;
QString strSQL = "SELECT bay_uuid, name, type, unom, fla, capacity, description, in_service, state, grid, zone, station, business, from_uuids, to_uuids, dev_protect, dev_fault_record, dev_status, dev_dyn_sense, dev_instruct, dev_etc, components FROM bay";
try
{
QSqlQuery query = executeSQL(strSQL);
while (query.next())
{
bayInfo info;
info.uuid = QUuid(query.value(0).toString());
info.name = query.value(1).toString();
info.type = query.value(2).toString();
info.unom = query.value(3).toDouble();
info.fla = query.value(4).toDouble();
info.capacity = query.value(5).toDouble();
info.description = query.value(6).toString();
info.inService = query.value(7).toBool();
info.nState = query.value(8).toInt();
info.grid = query.value(9).toString();
info.zone = query.value(10).toString();
info.station = query.value(11).toString();
QString strBusi = query.value(12).toString();
info.business = QstringToJson(strBusi);
QString strFrom = query.value(13).toString();
info.fromUuid = QstringToJson(strFrom);
QString strTo = query.value(14).toString();
info.toUuid = QstringToJson(strTo);
QString strProtect = query.value(15).toString();
info.protect = QstringToJson(strProtect);
QString strFaultRec= query.value(16).toString();
info.faultRec = QstringToJson(strFaultRec);
QString strStatus= query.value(17).toString();
info.status = QstringToJson(strStatus);
QString strDynSense= query.value(18).toString();
info.dynSense = QstringToJson(strDynSense);
QString strInstructe= query.value(19).toString();
info.instruct = QstringToJson(strInstructe);
QString strEtc= query.value(20).toString();
info.etc = QstringToJson(strEtc);
QString rawData = query.value(21).toString();
info.components = parseUuidArray(rawData);
lstInfo.append(info);
}
query.clear();
return lstInfo;
}
catch (const std::exception& e)
{
return lstInfo;
}
}
bool DataBase::ifBayExist(QUuid uuid)
{
QString strSQL = "SELECT bay_uuid FROM bay WHERE bay_uuid = ?";
QVariantList params;
params.append(uuid);
try
{
QSqlQuery query = executeSQL(strSQL,false,params);
while (query.next())
{
return true;
}
}
catch (const std::exception& e)
{
return false;
}
return false;
}
bool DataBase::deleteBay(QUuid uuid)
{
QString strSQL = "DELETE FROM bay WHERE bay_uuid = ?";
QVariantList params;
params.append(uuid);
try
{
executeSQL(strSQL,false,params);
LOG_INFO("DB", QString("Delete bay %1 success").arg(uuid.toString()));
return true;
}
catch (const std::exception& e)
{
LOG_ERROR("DB", QString("Delete bay %1 failed").arg(uuid.toString()));
return false;
}
}
/*****************************************************************************/
bool DataBase::insertMeasurement(QString tag,QString name,int type,QJsonObject dataSource,int size,int bayId,QUuid componentId)
bool DataBase::insertMeasurement(QString name,QString tag,int type,QJsonObject dataSource,int size,QUuid bayId,QUuid componentId)
{
QString strSQL = "INSERT INTO measurement(tag, name, type, data_source, size, bay_id, component_id) VALUES (?, ?, ?, ?, ?, ?, ?)";
QString strSQL = "INSERT INTO measurement(tag, name, type, data_source, size, bay_uuid, component_uuid) VALUES (?, ?, ?, ?, ?, ?, ?)";
QJsonDocument dataDoc(dataSource);
QString strData = dataDoc.toJson(QJsonDocument::Compact);
@ -1084,18 +1379,109 @@ bool DataBase::insertMeasurement(QString tag,QString name,int type,QJsonObject d
return false;
}
}
bool DataBase::updateMeasurement(QString name,int type,QJsonObject dataSource,int size,QUuid componentId)
{
QJsonDocument dataDoc(dataSource);
QString strData = dataDoc.toJson(QJsonDocument::Compact);
QString strSQL = "UPDATE measurement SET type = ?,data_source = ?,size = ? WHERE name = ? AND component_uuid = ?";
QVariantList params;
params.append(type);
params.append(strData);
params.append(size);
params.append(name);
params.append(componentId);
try
{
executeSQL(strSQL,false,params);
return true;
}
catch (const std::exception& e)
{
LOG_ERROR("DB", QString("Update measurement %1 fail").arg(name));
return false;
}
}
bool DataBase::delteMeasurement(QString name,QUuid componentId)
{
QString strSQL = "DELETE FROM measurement WHERE name = ? AND component_uuid = ?";
QVariantList params;
params.append(name);
params.append(componentId);
try
{
executeSQL(strSQL,false,params);
LOG_INFO("DB", QString("Delete measurement %1 success").arg(name));
return true;
}
catch (const std::exception& e)
{
LOG_ERROR("DB", QString("Delete measurement %1 failed").arg(name));
return false;
}
}
bool DataBase::ifMeasureExist(QString name,QUuid componentId)
{
QString strSQL = "SELECT id FROM measurement WHERE name = ? AND component_uuid = ?";
QVariantList params;
params.append(name);
params.append(componentId);
try
{
QSqlQuery query = executeSQL(strSQL,false,params);
while (query.next())
{
return true;
}
}
catch (const std::exception& e)
{
return false;
}
return false;
}
QList<MeasurementInfo> DataBase::getMeasurement(QUuid componentId)
{
QList<MeasurementInfo> lst;
QString strSQL = "SELECT tag, name, type, data_source, size, bay_uuid, component_uuid FROM measurement WHERE component_uuid = ?";
QVariantList params;
params.append(componentId);
try
{
QSqlQuery query = executeSQL(strSQL,false,params);
while (query.next())
{
MeasurementInfo info;
info.tag = query.value(0).toString();
info.name = query.value(1).toString();
info.type = query.value(2).toString();
QString con = query.value(3).toString();
QJsonObject obj = QstringToJson(con);
info.equipment = obj["type"].toString();
info.channel = obj["main_pos"].toString();
info.size = query.value(4).toInt();
info.bayUuid = QUuid(query.value(5).toString());
info.componentUuid = QUuid(query.value(6).toString());
lst.append(info);
}
query.clear();
return lst;
}
catch (const std::exception& e)
{
return lst;
}
}
/*****************************************************************************/
void DataBase::select()
{
}
void DataBase::parallelUpdate()
{
}
void DataBase::readXML()
{
if (m_sFileName.isEmpty())
@ -1173,6 +1559,35 @@ QJsonObject DataBase::QstringToJson(QString jsonString)
QJsonObject jsonObject = jsonDocument.object();
return jsonObject;
}
QList<QUuid> DataBase::parseUuidArray(const QString& pgArray)
{
QList<QUuid> uuids;
if (pgArray.isEmpty() || pgArray == "{}")
return uuids;
// 移除花括号并分割元素
QStringList parts = pgArray.mid(1, pgArray.size() - 2).split(",");
for (QString& part : parts) {
part = part.trimmed();
// 处理带双引号的元素
if (part.startsWith('"') && part.endsWith('"')) {
part = part.mid(1, part.size() - 2);
}
// 处理 NULL 值(转为空 QUuid
if (part == "NULL") {
uuids << QUuid();
} else {
uuids << QUuid(part);
}
}
return uuids;
}
//=================================元模=============================================//
bool DataBase::getAttributeGroup()
{
@ -1889,7 +2304,7 @@ QMap<QString,projectManager> DataBase::getProjectModelGroupInfo(const QString& s
}
}
QMap<QUuid,PropertyValueInfo> DataBase::selectGroupProperty(const QString& tableName,QMap<QString,propertyStateInfo> mapPro)
QMap<QUuid,PropertyValueInfo> DataBase::selectGroupPropertyByState(const QString& tableName,QMap<QString,propertyStateInfo> mapPro)
{
QStringList paramList;
for(auto &pro:mapPro)
@ -1920,6 +2335,7 @@ QMap<QUuid,PropertyValueInfo> DataBase::selectGroupProperty(const QString& table
}
pro.name = proVal.name;
pro.type = proVal.type;
pro.isVisibe = proVal.isVisibe;
pro.defaultValue = query.value(proVal.name );
info.insert(proVal.name ,pro);
}
@ -1934,6 +2350,43 @@ QMap<QUuid,PropertyValueInfo> DataBase::selectGroupProperty(const QString& table
}
}
PropertyValueInfo DataBase::selectGroupPropertyByValue(const QString& tableName,QUuid uuid,PropertyValueInfo value)
{
PropertyValueInfo map;
QStringList paramList;
for(auto &pro:value)
{
paramList.append(pro.name);
}
QString strSQL = QString("SELECT %1 FROM %2 WHERE global_uuid = ?").arg(paramList.join(", ")).arg(tableName);
QVariantList params;
params.append(uuid);
try
{
QSqlQuery query = executeSQL(strSQL,false,params);
while (query.next())
{
QUuid uuid;
for(auto &proVal:value)
{
propertyStateInfo pro;
pro.name = proVal.name;
pro.type = proVal.type;
pro.isVisibe = proVal.isVisibe;
pro.defaultValue = query.value(proVal.name );
map.insert(proVal.name,pro);
}
}
query.clear();
return map;
}
catch (const std::exception& e)
{
return map;
}
}
QList<measureAttributeType> DataBase::getMeasureAttributeTypes()
{
QList<measureAttributeType> lst;

View File

@ -62,12 +62,14 @@ void DataManager::initialModelState(bool refresh)
QString dataType = node["type"].toString();
QVariant defaultValue = node["defaultValue"].toVariant();
int lengthPrecision = node["lengthPrecision"].toInt();
int nIsVisible = node["isVisible"].toInt();
if(nState)
{
propertyInfo.name = propertyName;
propertyInfo.type = dataType;
propertyInfo.defaultValue = defaultValue;
propertyInfo.lengthPrecision = lengthPrecision;
propertyInfo.isVisibe = nIsVisible;
groupInfo.info.insert(propertyName,propertyInfo);
}
@ -92,6 +94,7 @@ void DataManager::initialModelState(bool refresh)
QString dataType = node["type"].toString();
QVariant defaultValue = node["defaultValue"].toVariant();
int lengthPrecision = node["lengthPrecision"].toInt();
int nIsVisible = node["isVisible"].toInt();
if(nState)
{
//todo:别名赋值
@ -99,6 +102,7 @@ void DataManager::initialModelState(bool refresh)
propertyInfo.type = dataType;
propertyInfo.defaultValue = defaultValue;
propertyInfo.lengthPrecision = lengthPrecision;
propertyInfo.isVisibe = nIsVisible;
groupInfo.info.insert(propertyName,propertyInfo);
}
@ -114,10 +118,7 @@ void DataManager::initialModelState(bool refresh)
void DataManager::initialModelData(bool refresh)
{
QMap<QString,int> model = DataBase::GetInstance()->getAllProjectModel();
if(refresh)
{
_modleDataInfo.clear();
}
if(!refresh){
QMap<QString,int>::Iterator iter;
for(iter = model.begin();iter != model.end(); ++iter) //遍历模型
{
@ -146,9 +147,11 @@ void DataManager::initialModelData(bool refresh)
int nState = node["checked"].toInt();
QString dataType = node["type"].toString();
QVariant defaultValue = node["defaultValue"].toVariant();
int nIsVisible = node["isVisible"].toInt();
propertyInfo.name = propertyName;
propertyInfo.type = dataType;
propertyInfo.isVisibe = nIsVisible;
if(nState)
{
mapPro.insert(propertyName,propertyInfo);
@ -161,7 +164,7 @@ void DataManager::initialModelData(bool refresh)
mapPro.insert("global_uuid",uuidInfo);
}
groupValue.mapInfo = DataBase::GetInstance()->selectGroupProperty(it->tableName,mapPro); //返回表中属性值
groupValue.mapInfo = DataBase::GetInstance()->selectGroupPropertyByState(it->tableName,mapPro); //返回表中属性值
modelInfo.groupInfo.insert(it.key(),groupValue);
}
@ -183,9 +186,11 @@ void DataManager::initialModelData(bool refresh)
int nState = node["checked"].toInt();
QString dataType = node["type"].toString();
QVariant defaultValue = node["defaultValue"].toVariant();
int nIsVisible = node["isVisible"].toInt();
propertyInfo.name = propertyName;
propertyInfo.type = dataType;
propertyInfo.isVisibe = nIsVisible;
if(nState)
{
mapPro.insert(propertyName,propertyInfo);
@ -195,13 +200,35 @@ void DataManager::initialModelData(bool refresh)
uuidInfo.name = "global_uuid"; //全局id未添加到属性状态中手动添加
mapPro.insert("global_uuid",uuidInfo);
groupValue.mapInfo = DataBase::GetInstance()->selectGroupProperty(it->tableName,mapPro); //返回表中属性值
groupValue.mapInfo = DataBase::GetInstance()->selectGroupPropertyByState(it->tableName,mapPro); //返回表中属性值
modelInfo.groupInfo.insert(it.key(),groupValue);
}
_modleDataInfo.insert(iter.key(),modelInfo);
}
_dataInitialised = true;
}
else
{
for(auto itMod = _modleDataInfo.begin();itMod != _modleDataInfo.end();itMod++) //模型
{
for(auto itGroup = itMod->groupInfo.begin();itGroup != itMod->groupInfo.end();itGroup++) //属性组
{
for(auto itComponent = itGroup->mapInfo.begin();itComponent != itGroup->mapInfo.end();itComponent++) //设备
{
//获取component对应id的属性
PropertyValueInfo info = DataBase::GetInstance()->selectGroupPropertyByValue(itGroup->tableName,itComponent.key(),itComponent.value());
for(auto itPro = itComponent->begin(); itPro != itComponent->end();itPro++) //属性
{
if(info.contains(itPro.key())){
if(!itPro->lock)
itPro->defaultValue = info.value(itPro.key()).defaultValue;
}
}
}
}
}
}
}
void DataManager::updateModelData(const QString& sModel,QUuid uuid,const QString& sGroup,QMap<QString,propertyStateInfo> mapPro)

View File

@ -401,6 +401,8 @@ QStringList ProjectModelManager::getAttributeList(const QString& sM,const QStrin
{
if(mt.modelTypeId == metaId && mt.attributeGroupId == groupId)
{
if(attMap[mt.attributeId].isVisible == 2) //2为特殊属性不加入选择
continue;
lst.append(attMap[mt.attributeId].attribute);
}
}

View File

@ -32,15 +32,16 @@ void DiagramView::initial()
// 设置模型的列数
_pModel->setColumnCount(1);
QList<QStandardItem*> pageList;
//QList<QStandardItem*> pageList;
QList<pageInfo> lst = DataBase::GetInstance()->getAllPage();
for(auto info:lst)
{
QStandardItem* pItem = new QStandardItem(info.name);
pItem->setData(info.id,Qt::UserRole);
pageList.append(pItem);
//pageList.append(pItem);
_pModel->appendRow(pItem);
}
_pModel->appendRow(pageList);
//_pModel->appendRow(pageList);
// 创建树视图
ui->treeView->setModel(_pModel);