diff --git a/common/include/baseProperty.h b/common/include/baseProperty.h index 4278fbb..f48b0cd 100644 --- a/common/include/baseProperty.h +++ b/common/include/baseProperty.h @@ -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 diff --git a/common/include/global.h b/common/include/global.h index 45b3141..69c5293 100644 --- a/common/include/global.h +++ b/common/include/global.h @@ -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 components; +}; + + /*struct busStability { int componentId = 0; diff --git a/common/source/baseProperty.cpp b/common/source/baseProperty.cpp index c265fd3..43a88f0 100644 --- a/common/source/baseProperty.cpp +++ b/common/source/baseProperty.cpp @@ -52,7 +52,7 @@ BaseProperty::BaseProperty(QObject* parent) BaseProperty::~BaseProperty() { - + qDebug()<<"release by "< _validType; //可用的属性列表 QMap _mapMeasure; //量测列表 diff --git a/diagramCavas/include/bayManagerContentDlg.h b/diagramCavas/include/bayManagerContentDlg.h index 482d334..e64c748 100644 --- a/diagramCavas/include/bayManagerContentDlg.h +++ b/diagramCavas/include/bayManagerContentDlg.h @@ -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 diff --git a/diagramCavas/include/graphicsDataModel/fixedPortsModel.h b/diagramCavas/include/graphicsDataModel/fixedPortsModel.h index 1c4fdb7..9c3b050 100644 --- a/diagramCavas/include/graphicsDataModel/fixedPortsModel.h +++ b/diagramCavas/include/graphicsDataModel/fixedPortsModel.h @@ -40,7 +40,7 @@ public: QVector allConnectionProperty(); QMap& 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可对应多个item(id,类型,名称,工程模名) @@ -79,6 +79,7 @@ public: void generateProjectModel(const QString&,QList,QList); //由基模生成工程模 void addProjectItemByBaseData(DrawingPanel*,GraphicsBaseModelItem*,BaseProperty*); //从基模item生成工程模item /*************************间隔*****************************/ + void addBayItem(QUuid); bool addBayItem(QUuid,ElectricBayItem*); void addItemsToBay(QList,ElectricBayItem*); //将对象添加到间隔 BayProperty* addBayData(QUuid uuid); @@ -90,6 +91,8 @@ public: void addBayByData(BayProperty*); //基模bay生成工程模bay void addTestData(); //生成测试基模 + QJsonObject turnListToJson(QList lst,QString sInerTag,QString sOutTag); //将list转换为QJsonObject, + QList turnJsonArrToList(QJsonObject obj,QString sInner,QString sOut); Q_SIGNALS: void activatePage(const QString&); //激活当前model所在page public: diff --git a/diagramCavas/include/propertyContentDlg.h b/diagramCavas/include/propertyContentDlg.h index 6a3b1a2..72981df 100644 --- a/diagramCavas/include/propertyContentDlg.h +++ b/diagramCavas/include/propertyContentDlg.h @@ -25,7 +25,8 @@ public: protected: QVBoxLayout* _layout; QWidget* createEditor(propertyStateInfo); //创建属性 - +private: + QMap _curValue; }; #endif diff --git a/diagramCavas/source/baseInfoDlg.cpp b/diagramCavas/source/baseInfoDlg.cpp index 53ff95e..47cc12f 100644 --- a/diagramCavas/source/baseInfoDlg.cpp +++ b/diagramCavas/source/baseInfoDlg.cpp @@ -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() diff --git a/diagramCavas/source/bayInfoDlg.cpp b/diagramCavas/source/bayInfoDlg.cpp index 2374f0a..d1612d2 100644 --- a/diagramCavas/source/bayInfoDlg.cpp +++ b/diagramCavas/source/bayInfoDlg.cpp @@ -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 BayInfoDlg::getPropertyValue(BaseProperty* pPro) { QMap map; + pPro->setDataChanged(true); pPro->setMeasurement(_mapMeasure); return map; } @@ -55,7 +58,7 @@ QMap 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(var.value()); if(property) { + _itemProperty = property; QList lstType = DataBase::GetInstance()->getMeasureAttributeTypes(); auto map = property->getMeasurement(); @@ -77,7 +81,7 @@ void BayInfoDlg::setPropertyValue(QVariant var) } //间隔处理 - BayProperty* pBay = nullptr; + _bayProperty = nullptr; QMap mapBay = _curModelController->allBayItem(); for(auto& item:mapBay){ AbstractProperty* pPro = item->getProperty(); @@ -86,22 +90,22 @@ void BayInfoDlg::setPropertyValue(QVariant var) QList 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 lstOther; - QList lstCompo = pBay->getLstComponent(); + QList 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); - _mapMeasure.insert(info.name,info); + 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); diff --git a/diagramCavas/source/bayManagerContentDlg.cpp b/diagramCavas/source/bayManagerContentDlg.cpp index c156e7d..64b09ec 100644 --- a/diagramCavas/source/bayManagerContentDlg.cpp +++ b/diagramCavas/source/bayManagerContentDlg.cpp @@ -1,3 +1,4 @@ +#include #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); diff --git a/diagramCavas/source/bayManagerDlg.cpp b/diagramCavas/source/bayManagerDlg.cpp index aff7355..f8aed81 100644 --- a/diagramCavas/source/bayManagerDlg.cpp +++ b/diagramCavas/source/bayManagerDlg.cpp @@ -89,7 +89,7 @@ void BayManagerDlg::generatePage(QList 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); } diff --git a/diagramCavas/source/drawingPanel.cpp b/diagramCavas/source/drawingPanel.cpp index 05ee246..44ab441 100644 --- a/diagramCavas/source/drawingPanel.cpp +++ b/diagramCavas/source/drawingPanel.cpp @@ -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 mapBay = _pModel->allBayItem(); + for(auto& bayItem:mapBay){ + AbstractProperty* pPro = bayItem->getProperty(); + BayProperty* pBay = dynamic_cast(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) diff --git a/diagramCavas/source/graphicsDataModel/fixedPortsModel.cpp b/diagramCavas/source/graphicsDataModel/fixedPortsModel.cpp index 5032522..b1d964b 100644 --- a/diagramCavas/source/graphicsDataModel/fixedPortsModel.cpp +++ b/diagramCavas/source/graphicsDataModel/fixedPortsModel.cpp @@ -118,7 +118,7 @@ void FixedPortsModel::addNodeItem(QUuid id/*,int type*/,QPointF pos) QMap 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 lstMeasure = DataBase::GetInstance()->getMeasurement(info.uuid); //添加设备量测 + QMap mapMeasure; + for(auto& info:lstMeasure) + { + mapMeasure.insert(info.name,info); + } + pData->setMeasurement(mapMeasure); } QList 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 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(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 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(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 mapMeasure = pData->getMeasurement(); //量测 + + QList 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){ - DataBase::GetInstance()->insertTopologic(con.nSrcNodeId,con.nDestNodeId,context,0,"",0); + 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 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 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 FixedPortsModel::turnJsonArrToList(QJsonObject object,QString sInner,QString sOut) +{ + QJsonArray jsonArray = object[sOut].toArray(); + + QList lst; + for (QJsonValueRef nodeJson : jsonArray) + { + QJsonObject node = nodeJson.toObject(); + QUuid uid = QUuid(node[sInner].toString()); + lst.append(uid); + } + return lst; +} + diff --git a/diagramCavas/source/measureSettingDlg.cpp b/diagramCavas/source/measureSettingDlg.cpp index 2a95f7d..f97e9b7 100644 --- a/diagramCavas/source/measureSettingDlg.cpp +++ b/diagramCavas/source/measureSettingDlg.cpp @@ -64,6 +64,10 @@ void MeasureSettingDlg::showDlg() } ui->cb_equip->addItems(lstDevice); + BaseProperty* pro = _pBay->getProperty(); + if(pro){ + ui->cb_equip->setCurrentText(pro->tag()); + } } } diff --git a/diagramCavas/source/propertyContentDlg.cpp b/diagramCavas/source/propertyContentDlg.cpp index 64a35b8..f9efdba 100644 --- a/diagramCavas/source/propertyContentDlg.cpp +++ b/diagramCavas/source/propertyContentDlg.cpp @@ -240,12 +240,24 @@ QMap 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 map = var.value>(); + _curValue = map; for(auto &info:map) { propertyContentInfo pro = _mapPro[info.name]; diff --git a/diagramCavas/source/statusBar.cpp b/diagramCavas/source/statusBar.cpp index 2123ffe..e06c505 100644 --- a/diagramCavas/source/statusBar.cpp +++ b/diagramCavas/source/statusBar.cpp @@ -27,7 +27,7 @@ void StatusBar::initial() void StatusBar::setButtonVisible(bool val) { - setVisible(m_pButtonGenerate); + m_pButtonGenerate->setVisible(val); } void StatusBar::onScaleLevelChanged(double f) diff --git a/diagramCavas/source/util/baseSelector.cpp b/diagramCavas/source/util/baseSelector.cpp index e5097e9..cd83582 100644 --- a/diagramCavas/source/util/baseSelector.cpp +++ b/diagramCavas/source/util/baseSelector.cpp @@ -443,9 +443,12 @@ void BaseSelector::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, Design { if(item->getItemType() == GIT_bay) //间隔暂时返回 return; - QString modelName = item->getModelName(); //todo:additem时填写模型类型 - QUuid uuid = item->itemId(); - _model->showModelDlg(modelName,uuid,item); + ModelProperty* pro = item->getProperty(); + if(pro){ + QString modelName = pro->modelName(); + QUuid uuid = item->itemId(); + _model->showModelDlg(modelName,uuid,item); + } } } } diff --git a/diagramUtils/include/dataBase.h b/diagramUtils/include/dataBase.h index ee3cd9a..e6994db 100644 --- a/diagramUtils/include/dataBase.h +++ b/diagramUtils/include/dataBase.h @@ -41,7 +41,7 @@ public: QList getAllStation(); QList 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 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 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 components); + bayInfo getBay(QUuid uuid); + QList 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 getMeasurement(QUuid componentId); /*********************************************************************************/ bool deleteComponentById(int id); - void select(); - void parallelUpdate(); QJsonObject QstringToJson(QString jsonString); + QList parseUuidArray(const QString& pgArray); //转化UUID[]类型 public: //***********元模 bool getAttributeGroup(); //获取属性组信息 @@ -118,7 +128,9 @@ public: QMap getModelInfo(const QString&); //获取模型信息 QMap getPublicInfo(); //获取公共属性组信息 QMap getProjectModelGroupInfo(const QString&); //获取指定工程模所有属性组信息<属性组名,属性信息> - QMap selectGroupProperty(const QString& tableName,QMap mapPro); //返回属性组表中的信息 + QMap selectGroupPropertyByState(const QString& tableName,QMap mapPro); //返回属性组表中的信息 + PropertyValueInfo selectGroupPropertyByValue(const QString& tableName,QUuid uuid,PropertyValueInfo value); //通过已有结构更新数据 + QList getMeasureAttributeTypes(); //获取所有量测属性 private: QMap _attributeGroup; //属性组的组 diff --git a/diagramUtils/source/basePropertyManager.cpp b/diagramUtils/source/basePropertyManager.cpp index a6ceb7d..88201ef 100644 --- a/diagramUtils/source/basePropertyManager.cpp +++ b/diagramUtils/source/basePropertyManager.cpp @@ -17,7 +17,8 @@ BasePropertyManager::BasePropertyManager(QObject *parent) BasePropertyManager::~BasePropertyManager() { - + qDeleteAll(m_entityData); + qDeleteAll(m_bayData); } void BasePropertyManager::insertEntityData(QUuid uid,BaseProperty* p) diff --git a/diagramUtils/source/dataBase.cpp b/diagramUtils/source/dataBase.cpp index 5bcd98a..73002ae 100644 --- a/diagramUtils/source/dataBase.cpp +++ b/diagramUtils/source/dataBase.cpp @@ -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 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 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 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 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 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 DataBase::getAllBay() +{ + QList 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 DataBase::getMeasurement(QUuid componentId) +{ + QList 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 DataBase::parseUuidArray(const QString& pgArray) +{ + QList 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 DataBase::getProjectModelGroupInfo(const QString& s } } -QMap DataBase::selectGroupProperty(const QString& tableName,QMap mapPro) +QMap DataBase::selectGroupPropertyByState(const QString& tableName,QMap mapPro) { QStringList paramList; for(auto &pro:mapPro) @@ -1920,6 +2335,7 @@ QMap 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 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 DataBase::getMeasureAttributeTypes() { QList lst; diff --git a/diagramUtils/source/dataManager.cpp b/diagramUtils/source/dataManager.cpp index e48bcdf..473f945 100644 --- a/diagramUtils/source/dataManager.cpp +++ b/diagramUtils/source/dataManager.cpp @@ -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,94 +118,117 @@ void DataManager::initialModelState(bool refresh) void DataManager::initialModelData(bool refresh) { QMap model = DataBase::GetInstance()->getAllProjectModel(); - if(refresh) - { - _modleDataInfo.clear(); - } - QMap::Iterator iter; - for(iter = model.begin();iter != model.end(); ++iter) //遍历模型 - { - modelDataInfo modelInfo; - modelInfo.modelType = iter.value(); //模型类型 - modelInfo.modelName = iter.key(); - - QMap mapState = DataBase::GetInstance()->getModelInfo(iter.key()); - QMap mapPublic = DataBase::GetInstance()->getPublicInfo(); //公共属性组 - QMap::Iterator it; - - for(it = mapPublic.begin();it != mapPublic.end();++it) //遍历公共属性组 + if(!refresh){ + QMap::Iterator iter; + for(iter = model.begin();iter != model.end(); ++iter) //遍历模型 { - groupStateValue groupValue; - groupValue.groupName = it.key(); - groupValue.tableName = it->tableName; - QJsonArray nodesJsonArray = it->propertyState["checkState"].toArray(); + modelDataInfo modelInfo; + modelInfo.modelType = iter.value(); //模型类型 + modelInfo.modelName = iter.key(); - QMap mapPro; - for (QJsonValueRef nodeJson : nodesJsonArray) //每个属性的状态信息 + QMap mapState = DataBase::GetInstance()->getModelInfo(iter.key()); + QMap mapPublic = DataBase::GetInstance()->getPublicInfo(); //公共属性组 + QMap::Iterator it; + + for(it = mapPublic.begin();it != mapPublic.end();++it) //遍历公共属性组 { - propertyStateInfo propertyInfo; + groupStateValue groupValue; + groupValue.groupName = it.key(); + groupValue.tableName = it->tableName; + QJsonArray nodesJsonArray = it->propertyState["checkState"].toArray(); - QJsonObject node = nodeJson.toObject(); - QString propertyName = node["name"].toString(); - int nState = node["checked"].toInt(); - QString dataType = node["type"].toString(); - QVariant defaultValue = node["defaultValue"].toVariant(); - - propertyInfo.name = propertyName; - propertyInfo.type = dataType; - if(nState) + QMap mapPro; + for (QJsonValueRef nodeJson : nodesJsonArray) //每个属性的状态信息 { - mapPro.insert(propertyName,propertyInfo); + 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 nIsVisible = node["isVisible"].toInt(); + + propertyInfo.name = propertyName; + propertyInfo.type = dataType; + propertyInfo.isVisibe = nIsVisible; + if(nState) + { + mapPro.insert(propertyName,propertyInfo); + } } + if(!mapPro.contains("global_uuid")) //不包含uuid则手动添加 + { + propertyStateInfo uuidInfo; + uuidInfo.name = "global_uuid"; //全局id未添加到属性状态中,手动添加 + mapPro.insert("global_uuid",uuidInfo); + } + + groupValue.mapInfo = DataBase::GetInstance()->selectGroupPropertyByState(it->tableName,mapPro); //返回表中属性值 + + modelInfo.groupInfo.insert(it.key(),groupValue); } - if(!mapPro.contains("global_uuid")) //不包含uuid则手动添加 + + for(it = mapState.begin();it != mapState.end();++it) //遍历模型属性组 { + groupStateValue groupValue; + groupValue.groupName = it.key(); + groupValue.tableName = it->tableName; + QJsonArray nodesJsonArray = it->propertyState["checkState"].toArray(); + + QMap mapPro; + 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 nIsVisible = node["isVisible"].toInt(); + + propertyInfo.name = propertyName; + propertyInfo.type = dataType; + propertyInfo.isVisibe = nIsVisible; + if(nState) + { + mapPro.insert(propertyName,propertyInfo); + } + } propertyStateInfo uuidInfo; uuidInfo.name = "global_uuid"; //全局id未添加到属性状态中,手动添加 mapPro.insert("global_uuid",uuidInfo); + + groupValue.mapInfo = DataBase::GetInstance()->selectGroupPropertyByState(it->tableName,mapPro); //返回表中属性值 + + modelInfo.groupInfo.insert(it.key(),groupValue); } - - groupValue.mapInfo = DataBase::GetInstance()->selectGroupProperty(it->tableName,mapPro); //返回表中属性值 - - modelInfo.groupInfo.insert(it.key(),groupValue); + _modleDataInfo.insert(iter.key(),modelInfo); } - - for(it = mapState.begin();it != mapState.end();++it) //遍历模型属性组 + _dataInitialised = true; + } + else + { + for(auto itMod = _modleDataInfo.begin();itMod != _modleDataInfo.end();itMod++) //模型 { - groupStateValue groupValue; - groupValue.groupName = it.key(); - groupValue.tableName = it->tableName; - QJsonArray nodesJsonArray = it->propertyState["checkState"].toArray(); - - QMap mapPro; - for (QJsonValueRef nodeJson : nodesJsonArray) //每个属性的状态信息 + for(auto itGroup = itMod->groupInfo.begin();itGroup != itMod->groupInfo.end();itGroup++) //属性组 { - 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(); - - propertyInfo.name = propertyName; - propertyInfo.type = dataType; - if(nState) + for(auto itComponent = itGroup->mapInfo.begin();itComponent != itGroup->mapInfo.end();itComponent++) //设备 { - mapPro.insert(propertyName,propertyInfo); + //获取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; + } + } } } - propertyStateInfo uuidInfo; - uuidInfo.name = "global_uuid"; //全局id未添加到属性状态中,手动添加 - mapPro.insert("global_uuid",uuidInfo); - - groupValue.mapInfo = DataBase::GetInstance()->selectGroupProperty(it->tableName,mapPro); //返回表中属性值 - - 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 mapPro) diff --git a/diagramUtils/source/projectModelManager.cpp b/diagramUtils/source/projectModelManager.cpp index 2a5cfa0..0844e01 100644 --- a/diagramUtils/source/projectModelManager.cpp +++ b/diagramUtils/source/projectModelManager.cpp @@ -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); } } diff --git a/source/diagramView.cpp b/source/diagramView.cpp index 8fdd498..7473813 100644 --- a/source/diagramView.cpp +++ b/source/diagramView.cpp @@ -32,15 +32,16 @@ void DiagramView::initial() // 设置模型的列数 _pModel->setColumnCount(1); - QList pageList; + //QList pageList; QList 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);