finish load project model

This commit is contained in:
baiYue 2025-04-09 16:20:34 +08:00
parent 29ab9aa5f4
commit c9244b57fd
17 changed files with 184 additions and 107 deletions

View File

@ -29,8 +29,8 @@ enum GraphicsItemType
enum AbstractItemType //工程模关联的对象类型 enum AbstractItemType //工程模关联的对象类型
{ {
AIT_bus = 1, AIT_motor = 1,
AIT_motor AIT_bus
}; };
class corresbondItem //类型关联函数 class corresbondItem //类型关联函数

View File

@ -1,5 +1,5 @@
#include "global.h" #include "global.h"
QMap<AbstractItemType,GraphicsItemType> corresbondItem::linkType = { QMap<AbstractItemType,GraphicsItemType> corresbondItem::linkType = {
{AIT_bus,GIT_bus}, {AIT_motor,GIT_itemRect},{AIT_bus,GIT_bus},
}; };

View File

@ -38,7 +38,7 @@ public:
void setTopWidget(DrawingPanel* p) {_widget = p;} void setTopWidget(DrawingPanel* p) {_widget = p;}
QWidget* getTopWidget(); QWidget* getTopWidget();
void showModelDlg(const QString&,QUuid); //点击时显示指定模型的dlg、指定item的数据(模型名对象Uuid) void showModelDlg(const QString&,QUuid,GraphicsBaseItem*); //点击时显示指定模型的dlg、指定item的数据(模型名对象Uuid,触发事件的item)
void initialPropertyDlg(); //初始化属性设置dlg每个模型拥各自的dlg void initialPropertyDlg(); //初始化属性设置dlg每个模型拥各自的dlg
void generatePropertyDlg(const QString&); void generatePropertyDlg(const QString&);
Q_SIGNALS: Q_SIGNALS:
@ -64,6 +64,7 @@ private:
QTimer* _timer; QTimer* _timer;
QMap<QString,modelStateInfo> _modelStateInfo; //模型结构信息 QMap<QString,modelStateInfo> _modelStateInfo; //模型结构信息
QMap<QString,modelDataInfo> _modelDataInfo; //模型数据信息
public: public:
static bool _dataInitialised; static bool _dataInitialised;
static QMap<QUuid,BaseProperty*> _nodeData; //一个data可对应多个item static QMap<QUuid,BaseProperty*> _nodeData; //一个data可对应多个item

View File

@ -12,7 +12,7 @@ public:
ElectricSvgItemRect(const QRect &rect, QGraphicsItem *parent = 0); ElectricSvgItemRect(const QRect &rect, QGraphicsItem *parent = 0);
virtual ~ElectricSvgItemRect(); virtual ~ElectricSvgItemRect();
virtual void updateByProperty(); //virtual void updateByProperty();
protected: protected:
virtual void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*); virtual void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*);

View File

@ -586,9 +586,8 @@ class VariableProperty:public BaseProperty //收到的变量数据
public: public:
VariableProperty(QObject* parent); VariableProperty(QObject* parent);
~VariableProperty(); ~VariableProperty();
QMap<QString,VariableMap>& getMapGroup() {return _MapGroup;}
private: modelDataInfo getPropertyValue() const;
QMap<QString,VariableMap> _MapGroup; //<属性组,属性集>
}; };
#endif #endif

View File

@ -11,6 +11,8 @@ QT_BEGIN_NAMESPACE
namespace Ui { class itemPropertyDlg; } namespace Ui { class itemPropertyDlg; }
QT_END_NAMESPACE QT_END_NAMESPACE
class GraphicsBaseItem;
struct PropertyInfo struct PropertyInfo
{ {
double resistance = 0; //电阻 DEFAULT 2, double resistance = 0; //电阻 DEFAULT 2,
@ -34,7 +36,7 @@ public:
void initial(); void initial();
void loadGroupButton(QMap<QString,groupStateInfo>); //加载属性组列表 void loadGroupButton(QMap<QString,groupStateInfo>); //加载属性组列表
void createGroupView(const QString&); //创建属性页 void createGroupView(const QString&); //创建属性页
void showDlg(modelDataInfo,QUuid); //显示属性页面 void showDlg(modelDataInfo,QUuid,GraphicsBaseItem*); //显示属性页面
signals: signals:
void PropertyChange(const PropertyInfo); void PropertyChange(const PropertyInfo);
public slots: public slots:
@ -53,6 +55,7 @@ private:
QMap<QString,groupStateValue> groupValue_; //属性数据 QMap<QString,groupStateValue> groupValue_; //属性数据
QUuid curUuid_; //当前显示对象的uuid QUuid curUuid_; //当前显示对象的uuid
QString _curModel; //当前模型名 QString _curModel; //当前模型名
GraphicsBaseItem* _curItem;
}; };
#endif #endif

View File

@ -26,7 +26,7 @@ private:
QMap<QString,propertyContentInfo> _mapPro; QMap<QString,propertyContentInfo> _mapPro;
private: private:
QFormLayout* createFormLayout(); QFormLayout* createFormLayout(QWidget* parent);
}; };
#endif #endif

View File

@ -27,6 +27,7 @@ FixedPortsModel::FixedPortsModel()
_timer = new QTimer(this); _timer = new QTimer(this);
_modelStateInfo = DataManager::instance().modelState(); _modelStateInfo = DataManager::instance().modelState();
_modelDataInfo = DataManager::instance().modelData();
initialPropertyDlg(); initialPropertyDlg();
connect(_timer,SIGNAL(timeout()),this,SLOT(onTimeOut())); connect(_timer,SIGNAL(timeout()),this,SLOT(onTimeOut()));
connect(_Interface,&HttpInterface::sendPointData,this,&FixedPortsModel::onSignal_GetPointData); connect(_Interface,&HttpInterface::sendPointData,this,&FixedPortsModel::onSignal_GetPointData);
@ -140,25 +141,9 @@ BaseProperty* FixedPortsModel::addNodeData(QUuid id,int type,QString name,QStrin
{ {
if(_nodeData.contains(id)) if(_nodeData.contains(id))
return nullptr; return nullptr;
modelStateInfo modelInfo;
for(auto &model:_modelStateInfo){ //找到对象对应的工程模
if(model.modelName == modelName){
modelInfo = model;
break;
}
}
VariableProperty* item = new VariableProperty(this); VariableProperty* item = new VariableProperty(this);
QMap<QString,VariableMap>& propertyGroup = item->getMapGroup(); //todo:关联到对应data
for(auto &groupInfo:modelInfo.groupInfo)
{
VariableMap map;
for(auto &pro:groupInfo.info)
{
map.insert(pro.name,pro.defaultValue); //添加属性信息
}
propertyGroup.insert(groupInfo.groupName,map);
}
if(item) if(item)
{ {
@ -195,28 +180,6 @@ void FixedPortsModel::loadNodeDataFromDataBase()
pData->setStation(info.station); pData->setStation(info.station);
pData->setDataChanged(false); pData->setDataChanged(false);
VariableProperty* pPro = dynamic_cast<VariableProperty*>(pData);
if(pPro)
{
QMap<QString,VariableMap>& mapVariableGroup = pPro->getMapGroup();
ModelDataMap mapData = DataManager::instance().modelData();
QMap<QString,groupStateValue> mapGroup = mapData[info.modelName].groupInfo; //取得该模型下的所有属性组
QMap<QString,groupStateValue>::Iterator iter;
for(iter = mapGroup.begin();iter != mapGroup.end();++iter)
{
VariableMap varMap;
PropertyValueInfo valueInfo = iter->mapInfo[info.uuid];
PropertyValueInfo::Iterator it;
for(it = valueInfo.begin(); it != valueInfo.end();++it)
{
varMap.insert(it.key(),it->defaultValue);
}
mapVariableGroup.insert(iter.key(),varMap);
}
}
if(info.type == GIT_itemTri) if(info.type == GIT_itemTri)
{ {
@ -224,7 +187,7 @@ void FixedPortsModel::loadNodeDataFromDataBase()
} }
else if(info.type == GIT_itemRect) else if(info.type == GIT_itemRect)
{ {
busStability bility = DataBase::GetInstance()->getBusStabilityById(info.id); //busStability bility = DataBase::GetInstance()->getBusStabilityById(info.id);
/*ElectricSvgItemRect_Property* pPro = dynamic_cast<ElectricSvgItemRect_Property*>(pData); /*ElectricSvgItemRect_Property* pPro = dynamic_cast<ElectricSvgItemRect_Property*>(pData);
if(pPro) if(pPro)
{ {
@ -464,31 +427,25 @@ void FixedPortsModel::saveNode(int nPageId)
if(pData->dataChanged()) if(pData->dataChanged())
{ {
bool exist = DataBase::GetInstance()->componentExist(pData->uuid().toString()); bool exist = DataBase::GetInstance()->componentExist(pData->uuid().toString());
if(exist) //已存在更新 VariableProperty* pVariable = dynamic_cast<VariableProperty*>(pData);
if(pVariable)
{ {
DataBase::GetInstance()->updateComponent(pData->uuid(),pData->tag(),pData->name(),pData->context()); modelDataInfo dataInfo = pVariable->getPropertyValue();
int type = pData->type(); if(exist) //已存在更新
if(type == GIT_itemRect)
{ {
/*ElectricSvgItemRect_Property* pro = dynamic_cast<ElectricSvgItemRect_Property*>(pData); DataBase::GetInstance()->updateComponent(pData->uuid(),pData->tag(),pData->name(),pData->context());
if(pro) for(auto &val:dataInfo.groupInfo)
{ {
DataBase::GetInstance()->updateBus_stability(pro->component_id(),pro->getResistance(),pro->getAnchor_v(),pro->getUv_alarm(),pro->getOv_alarm(),pro->getAnchor_i(),pro->getUi_alarm(),pro->getOi_alarm(),1); DataBase::GetInstance()->updateDynamicProperty(pData->uuid(),val);
}*/ }
} }
} else
else
{
DataBase::GetInstance()->insertComponent(pData->uuid(),pData->modelName(),pData->path(),pData->tag(),pData->name(),pData->description(),pData->grid(),pData->zone(),pData->station(),pData->type(),true,pData->state(),pData->connectedBus(),pData->label(),pData->context(),nPageId,1);
int type = pData->type();
if(type == GIT_itemRect)
{ {
/*ElectricSvgItemRect_Property* pro = dynamic_cast<ElectricSvgItemRect_Property*>(pData); DataBase::GetInstance()->insertComponent(pData->uuid(),pData->modelName(),pData->path(),pData->tag(),pData->name(),pData->description(),pData->grid(),pData->zone(),pData->station(),pData->type(),true,pData->state(),pData->connectedBus(),pData->label(),pData->context(),nPageId,1);
if(pro) for(auto &val:dataInfo.groupInfo)
{ {
componentInfo info = DataBase::GetInstance()->getComponentInfoByUuid(pData->uuid().toString()); DataBase::GetInstance()->insertDynamicProperty(pData->uuid(),val);
DataBase::GetInstance()->insertBus_stability(info.id,pro->getResistance(),pro->getAnchor_v(),pro->getUv_alarm(),pro->getOv_alarm(),pro->getAnchor_i(),pro->getUi_alarm(),pro->getOi_alarm(),1); }
}*/
} }
} }
} }
@ -592,14 +549,14 @@ QWidget* FixedPortsModel::getTopWidget()
return dynamic_cast<QWidget*>(_widget); return dynamic_cast<QWidget*>(_widget);
} }
void FixedPortsModel::showModelDlg(const QString& sName,QUuid uuid) void FixedPortsModel::showModelDlg(const QString& sName,QUuid uuid,GraphicsBaseItem* pItem)
{ {
modelStateInfo stateInfo = _modelStateInfo[sName]; modelStateInfo stateInfo = _modelStateInfo[sName];
ModelDataMap mapData = DataManager::instance().modelData(); ModelDataMap mapData = DataManager::instance().modelData();
ItemPropertyDlg* pDlg = dynamic_cast<ItemPropertyDlg*>(stateInfo._PropertyDlg); ItemPropertyDlg* pDlg = dynamic_cast<ItemPropertyDlg*>(stateInfo._PropertyDlg);
if(pDlg) if(pDlg)
{ {
pDlg->showDlg(mapData[sName],uuid); pDlg->showDlg(mapData[sName],uuid,pItem);
} }
else else
qDebug()<<"showModelDlg err"; qDebug()<<"showModelDlg err";
@ -625,6 +582,7 @@ void FixedPortsModel::generatePropertyDlg(const QString& sModel)
if(dlg) if(dlg)
{ {
dlg->loadGroupButton(info.groupInfo); dlg->loadGroupButton(info.groupInfo);
_modelStateInfo[sModel]._PropertyDlg = dlg;
} }
} }
} }

View File

@ -71,7 +71,7 @@ void ElectricSvgItemRect::paint(QPainter* painter, const QStyleOptionGraphicsIte
} }
void ElectricSvgItemRect::updateByProperty() /*void ElectricSvgItemRect::updateByProperty()
{ {
} }*/

View File

@ -3,6 +3,7 @@
#include "graphicsItem/handleText.h" #include "graphicsItem/handleText.h"
#include "graphicsItem/itemPort.h" #include "graphicsItem/itemPort.h"
#include "graphicsItem/electricConnectLineItem.h" #include "graphicsItem/electricConnectLineItem.h"
#include "dataManager.h"
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QJsonArray> #include <QJsonArray>
@ -330,3 +331,9 @@ VariableProperty::~VariableProperty()
{ {
} }
modelDataInfo VariableProperty::getPropertyValue() const
{
ModelDataMap mapData = DataManager::instance().modelData();
return mapData[sModelName];
}

View File

@ -1,13 +1,16 @@
#include "itemPropertyDlg.h" #include "itemPropertyDlg.h"
#include "propertyContentDlg.h" #include "propertyContentDlg.h"
#include "dataManager.h" #include "dataManager.h"
#include "graphicsItem/graphicsBaseItem.h"
#include "ui_itemPropertyDlg.h" #include "ui_itemPropertyDlg.h"
#include <QMessageBox>
ItemPropertyDlg::ItemPropertyDlg(QWidget *parent) ItemPropertyDlg::ItemPropertyDlg(QWidget *parent)
: QDialog(parent) : QDialog(parent)
, ui(new Ui::itemPropertyDlg) , ui(new Ui::itemPropertyDlg)
,layout_(nullptr) ,layout_(nullptr)
,btnGroup_(nullptr) ,btnGroup_(nullptr)
,_curItem(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags()); this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
@ -43,11 +46,25 @@ void ItemPropertyDlg::loadGroupButton(QMap<QString,groupStateInfo> map)
onGroupSelected(info.groupName); onGroupSelected(info.groupName);
}); });
} }
layout_->addStretch();
} }
void ItemPropertyDlg::onOkClicked() void ItemPropertyDlg::onOkClicked()
{ {
//todo:将属性页中的值读取到当前uuid对象 //todo:将属性页中的值读取到当前uuid对象
if(_curItem)
{
if(_curItem->getProperty() == nullptr)
{
//todo:弹出输入框输入名称
QMessageBox::information(NULL, QString("提示"), QString::fromWCharArray(L"对象未命名"));
return;
}
else
{
curUuid_ = _curItem->getProperty()->uuid(); //使用数据uuid数据唯一,item不唯一
}
}
QMap<QString, QWidget*>::Iterator iter; QMap<QString, QWidget*>::Iterator iter;
for(iter = groupViews_.begin();iter != groupViews_.end();++iter) for(iter = groupViews_.begin();iter != groupViews_.end();++iter)
{ {
@ -92,11 +109,12 @@ void ItemPropertyDlg::createGroupView(const QString& str)
ui->stackedWidget->addWidget(contentDlg); ui->stackedWidget->addWidget(contentDlg);
} }
void ItemPropertyDlg::showDlg(modelDataInfo dataInfo,QUuid uuid) void ItemPropertyDlg::showDlg(modelDataInfo dataInfo,QUuid uuid,GraphicsBaseItem* pItem)
{ {
groupValue_ = dataInfo.groupInfo; groupValue_ = dataInfo.groupInfo;
curUuid_ = uuid; curUuid_ = uuid;
_curModel = dataInfo.modelName; _curModel = dataInfo.modelName;
_curItem = pItem;
QString firstName = groupInfo_.constBegin().key(); QString firstName = groupInfo_.constBegin().key();
onGroupSelected(firstName); //打开默认显示第一个属性组 onGroupSelected(firstName); //打开默认显示第一个属性组
show(); show();

View File

@ -10,7 +10,8 @@ PropertyContentDlg::PropertyContentDlg(QWidget *parent)
: QDialog(parent) : QDialog(parent)
,_layout(nullptr) ,_layout(nullptr)
{ {
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags()); setWindowFlags(Qt::Widget);
//this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
_layout = new QVBoxLayout(this); _layout = new QVBoxLayout(this);
} }
@ -23,11 +24,11 @@ void PropertyContentDlg::createGroupView(groupStateInfo infos)
{ {
QScrollArea* scrollArea = new QScrollArea(this); QScrollArea* scrollArea = new QScrollArea(this);
QWidget* content = new QWidget(); QWidget* content = new QWidget();
QFormLayout* formLayout = createFormLayout(); QFormLayout* formLayout = createFormLayout(content);
// 动态生成字段 // 动态生成字段
for(auto& info:infos.info) { for(auto& info:infos.info) {
QLabel* label = new QLabel(info.name); QLabel* label = new QLabel(info.name,this);
QWidget* editor = createEditor(info); QWidget* editor = createEditor(info);
formLayout->addRow(label, editor); formLayout->addRow(label, editor);
} }
@ -334,9 +335,9 @@ void PropertyContentDlg::setPropertyValue(QMap<QString,propertyStateInfo> map)
} }
} }
QFormLayout* PropertyContentDlg::createFormLayout() QFormLayout* PropertyContentDlg::createFormLayout(QWidget* parent)
{ {
QFormLayout* layout = new QFormLayout; QFormLayout* layout = new QFormLayout(parent);
layout->setHorizontalSpacing(20); // 标签与控件间距 layout->setHorizontalSpacing(20); // 标签与控件间距
layout->setVerticalSpacing(12); // 行间距 layout->setVerticalSpacing(12); // 行间距
layout->setLabelAlignment(Qt::AlignRight); // 标签右对齐 layout->setLabelAlignment(Qt::AlignRight); // 标签右对齐

View File

@ -373,7 +373,7 @@ void BaseSelector::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, Design
{ {
QString modelName = item->getModelName(); //todo:additem时填写模型类型 QString modelName = item->getModelName(); //todo:additem时填写模型类型
QUuid uuid = item->itemId(); QUuid uuid = item->itemId();
_model->showModelDlg(modelName,uuid); _model->showModelDlg(modelName,uuid,item);
} }
} }
} }

View File

@ -91,12 +91,21 @@
<string notr="true">background-color: rgb(219, 219, 219);</string> <string notr="true">background-color: rgb(219, 219, 219);</string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>4</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item> <item>
<widget class="QPushButton" name="btn_ok"> <widget class="QPushButton" name="btn_ok">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>0</height> <height>20</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
@ -107,7 +116,7 @@
</property> </property>
<property name="font"> <property name="font">
<font> <font>
<pointsize>14</pointsize> <pointsize>11</pointsize>
</font> </font>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
@ -120,6 +129,12 @@
</item> </item>
<item> <item>
<widget class="QPushButton" name="btn_cancel"> <widget class="QPushButton" name="btn_cancel">
<property name="minimumSize">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>80</width> <width>80</width>
@ -128,7 +143,7 @@
</property> </property>
<property name="font"> <property name="font">
<font> <font>
<pointsize>14</pointsize> <pointsize>11</pointsize>
</font> </font>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">

View File

@ -38,6 +38,8 @@ public:
/*********************************************************************************/ /*********************************************************************************/
bool updateComponent(QUuid uuid,QString tag,QString name,QJsonObject context); bool updateComponent(QUuid uuid,QString tag,QString name,QJsonObject context);
bool insertComponent(QUuid uuid,QString modelName,QString nspath,QString tag,QString name,QString description,QString grid,QString zone,QString station,int type,bool inService,int state,QJsonObject connected_bus,QJsonObject label,QJsonObject context,int page_id,int op); bool insertComponent(QUuid uuid,QString modelName,QString nspath,QString tag,QString name,QString description,QString grid,QString zone,QString station,int type,bool inService,int state,QJsonObject connected_bus,QJsonObject label,QJsonObject context,int page_id,int op);
bool insertDynamicProperty(QUuid uuid,groupStateValue groupValue);
bool updateDynamicProperty(QUuid uuid,groupStateValue groupValue);
componentInfo getComponentInfoByUuid(QString uuid); componentInfo getComponentInfoByUuid(QString uuid);
QList<componentInfo> getAllComponents(); QList<componentInfo> getAllComponents();
bool componentExist(QString uuid); bool componentExist(QString uuid);
@ -87,7 +89,7 @@ public:
QMap<QString,int> getAllProjectModel(); //获取所有工程模<名称,图元类型> QMap<QString,int> getAllProjectModel(); //获取所有工程模<名称,图元类型>
QMap<QString,propertyGroupState> getModelInfo(const QString&); //获取模型信息 QMap<QString,propertyGroupState> getModelInfo(const QString&); //获取模型信息
QMap<QString,projectManager> getProjectModelGroupInfo(const QString&); //获取指定工程模所有属性组信息<属性组名,属性信息> QMap<QString,projectManager> getProjectModelGroupInfo(const QString&); //获取指定工程模所有属性组信息<属性组名,属性信息>
QMap<QUuid,PropertyValueInfo> selectGroupProperty(const QString& tableName,const QStringList& paramList); //返回属性组表中的信息 QMap<QUuid,PropertyValueInfo> selectGroupProperty(const QString& tableName,QMap<QString,propertyStateInfo> mapPro); //返回属性组表中的信息
private: private:
QMap<int,attributeGroup> _attributeGroup; //属性组的组 QMap<int,attributeGroup> _attributeGroup; //属性组的组
QMap<int,dataType> _dataType; //数据类型组 QMap<int,dataType> _dataType; //数据类型组

View File

@ -294,6 +294,60 @@ bool DataBase::updateComponent(QUuid uuid,QString tag,QString name,QJsonObject c
return false; return false;
} }
bool DataBase::insertDynamicProperty(QUuid uuid,groupStateValue groupValue)
{
QString strPros;
QString strPronouns;
QVariantList params;
params.append(uuid);
params.append(groupValue.groupName);
for(auto &pro:groupValue.mapInfo[uuid])
{
strPros += QString(",")+pro.name;
strPronouns += QString(",?");
params.append(pro.defaultValue);
}
QString strSQL = QString("INSERT INTO %1(global_uuid, attribute_group%2) VALUES (?, ?%3)").arg(groupValue.tableName,strPros,strPronouns);
try
{
executeSQL(strSQL,false,params);
return true;
}
catch (const std::exception& e)
{
LOG_ERROR("DB", QString("Insert dynamic table fail"));
return false;
}
}
bool DataBase::updateDynamicProperty(QUuid uuid,groupStateValue groupValue)
{
QStringList setClauses;
QVariantList params;
for(auto &pro:groupValue.mapInfo[uuid])
{
setClauses.append(QString("%1 = ?").arg(pro.name));
params.append(pro.defaultValue);
}
QString strSQL = QString("UPDATE 1% SET %2 WHERE global_uuid = 3%").arg(groupValue.tableName).arg(setClauses.join(",")).arg(uuid.toString());
try
{
executeSQL(strSQL,false,params);
return true;
}
catch (const std::exception& e)
{
LOG_ERROR("DB", QString("Update table %1 fail").arg(groupValue.tableName));
return false;
}
}
bool DataBase::insertPage(QString tag,QString name,int status,QJsonObject label,QJsonObject context,QString description,int op) bool DataBase::insertPage(QString tag,QString name,int status,QJsonObject label,QJsonObject context,QString description,int op)
{ {
if(db.open()) if(db.open())
@ -574,7 +628,7 @@ QList<componentInfo> DataBase::getAllComponents()
{ {
QSqlQuery qry(db); QSqlQuery qry(db);
qry.prepare("SELECT id, global_uuid, tag, name, grid, zone, station, type, context, page_id, op FROM component"); qry.prepare("SELECT id, global_uuid, model_name,tag, name, grid, zone, station, type, context, page_id, op FROM component");
bool res = qry.exec(); bool res = qry.exec();
QString str = qry.lastQuery(); QString str = qry.lastQuery();
if(!res) if(!res)
@ -589,16 +643,17 @@ QList<componentInfo> DataBase::getAllComponents()
componentInfo inf; componentInfo inf;
inf.id = qry.value(0).toInt(); inf.id = qry.value(0).toInt();
inf.uuid = QUuid(qry.value(1).toString()); inf.uuid = QUuid(qry.value(1).toString());
inf.tag = qry.value(2).toString(); inf.modelName = qry.value(2).toString();
inf.name = qry.value(3).toString(); inf.tag = qry.value(3).toString();
inf.grid = qry.value(4).toString(); inf.name = qry.value(4).toString();
inf.zone = qry.value(5).toString(); inf.grid = qry.value(5).toString();
inf.station = qry.value(6).toString(); inf.zone = qry.value(6).toString();
inf.type = qry.value(7).toInt(); inf.station = qry.value(7).toString();
QString str = qry.value(8).toString(); inf.type = qry.value(8).toInt();
QString str = qry.value(9).toString();
inf.context = QstringToJson(str); inf.context = QstringToJson(str);
inf.page_id = qry.value(9).toInt(); inf.page_id = qry.value(10).toInt();
inf.op = qry.value(10).toInt(); inf.op = qry.value(11).toInt();
lst.push_back(inf); lst.push_back(inf);
} }
qry.clear(); qry.clear();
@ -1406,8 +1461,13 @@ QMap<QString,projectManager> DataBase::getProjectModelGroupInfo(const QString& s
} }
} }
QMap<QUuid,PropertyValueInfo> DataBase::selectGroupProperty(const QString& tableName,const QStringList& paramList) QMap<QUuid,PropertyValueInfo> DataBase::selectGroupProperty(const QString& tableName,QMap<QString,propertyStateInfo> mapPro)
{ {
QStringList paramList;
for(auto &pro:mapPro)
{
paramList.append(pro.name);
}
QString strSQL = QString("SELECT %1 FROM %2").arg(paramList.join(", ")).arg(tableName); QString strSQL = QString("SELECT %1 FROM %2").arg(paramList.join(", ")).arg(tableName);
QMap<QUuid,PropertyValueInfo> map; QMap<QUuid,PropertyValueInfo> map;
PropertyValueInfo info; PropertyValueInfo info;
@ -1418,16 +1478,18 @@ QMap<QUuid,PropertyValueInfo> DataBase::selectGroupProperty(const QString& table
while (query.next()) while (query.next())
{ {
QUuid uuid; QUuid uuid;
for(auto &param:paramList) for(auto &proVal:mapPro)
{ {
propertyStateInfo pro; propertyStateInfo pro;
if(param == "global_uuid") if(proVal.name == "global_uuid") //剔除uuid所属的临时对象
{ {
uuid = QUuid(query.value(param).toString()); uuid = QUuid(query.value(proVal.name).toString());
continue; continue;
} }
pro.defaultValue = query.value(param).toString(); pro.name = proVal.name;
info.insert(param,pro); pro.type = proVal.type;
pro.defaultValue = query.value(proVal.name );
info.insert(proVal.name ,pro);
} }
map.insert(uuid,info); map.insert(uuid,info);
} }

View File

@ -30,13 +30,14 @@ void DataManager::initialModelState()
{ {
modelStateInfo modelInfo; modelStateInfo modelInfo;
modelInfo.modelType = iter.value(); //模型类型 modelInfo.modelType = iter.value(); //模型类型
modelInfo.modelName = iter.key();
groupStateInfo groupInfo;
QMap<QString,propertyGroupState> mapState = DataBase::GetInstance()->getModelInfo(iter.key()); QMap<QString,propertyGroupState> mapState = DataBase::GetInstance()->getModelInfo(iter.key());
QMap<QString,propertyGroupState>::Iterator it; QMap<QString,propertyGroupState>::Iterator it;
for(it = mapState.begin();it != mapState.end();++it) //遍历模型属性组 for(it = mapState.begin();it != mapState.end();++it) //遍历模型属性组
{ {
groupStateInfo groupInfo;
groupInfo.groupName = it.key(); groupInfo.groupName = it.key();
groupInfo.tableName = it->tableName; groupInfo.tableName = it->tableName;
QJsonArray nodesJsonArray = it->propertyState["checkState"].toArray(); QJsonArray nodesJsonArray = it->propertyState["checkState"].toArray();
@ -78,6 +79,7 @@ void DataManager::initialModelData()
{ {
modelDataInfo modelInfo; modelDataInfo modelInfo;
modelInfo.modelType = iter.value(); //模型类型 modelInfo.modelType = iter.value(); //模型类型
modelInfo.modelName = iter.key();
QMap<QString,propertyGroupState> mapState = DataBase::GetInstance()->getModelInfo(iter.key()); QMap<QString,propertyGroupState> mapState = DataBase::GetInstance()->getModelInfo(iter.key());
@ -86,10 +88,10 @@ void DataManager::initialModelData()
{ {
groupStateValue groupValue; groupStateValue groupValue;
groupValue.groupName = it.key(); groupValue.groupName = it.key();
groupValue.tableName = it->tableName;
QJsonArray nodesJsonArray = it->propertyState["checkState"].toArray(); QJsonArray nodesJsonArray = it->propertyState["checkState"].toArray();
QStringList lstParam; //需检索的属性组中属性名列表 QMap<QString,propertyStateInfo> mapPro;
for (QJsonValueRef nodeJson : nodesJsonArray) //每个属性的状态信息 for (QJsonValueRef nodeJson : nodesJsonArray) //每个属性的状态信息
{ {
propertyStateInfo propertyInfo; propertyStateInfo propertyInfo;
@ -100,13 +102,18 @@ void DataManager::initialModelData()
QString dataType = node["type"].toString(); QString dataType = node["type"].toString();
QVariant defaultValue = node["defaultValue"].toVariant(); QVariant defaultValue = node["defaultValue"].toVariant();
propertyInfo.name = propertyName;
propertyInfo.type = dataType;
if(nState) if(nState)
{ {
lstParam.append(propertyName); mapPro.insert(propertyName,propertyInfo);
} }
} }
lstParam.append("global_uuid"); //全局id未添加到属性状态中手动选择 propertyStateInfo uuidInfo;
groupValue.mapInfo = DataBase::GetInstance()->selectGroupProperty(it->tableName,lstParam); //返回表中属性值 uuidInfo.name = "global_uuid"; //全局id未添加到属性状态中手动添加
mapPro.insert("global_uuid",uuidInfo);
groupValue.mapInfo = DataBase::GetInstance()->selectGroupProperty(it->tableName,mapPro); //返回表中属性值
modelInfo.groupInfo.insert(it.key(),groupValue); modelInfo.groupInfo.insert(it.key(),groupValue);
} }
@ -117,7 +124,11 @@ void DataManager::initialModelData()
void DataManager::updateModelData(const QString& sModel,QUuid uuid,const QString& sGroup,QMap<QString,propertyStateInfo> mapPro) void DataManager::updateModelData(const QString& sModel,QUuid uuid,const QString& sGroup,QMap<QString,propertyStateInfo> mapPro)
{ {
_modleDataInfo[sModel].groupInfo[sGroup].mapInfo[uuid] = mapPro; //暂用设定值直接替换旧属性,待测试 if(_modleDataInfo[sModel].groupInfo[sGroup].mapInfo.contains(uuid))
_modleDataInfo[sModel].groupInfo[sGroup].mapInfo[uuid] = mapPro; //暂用设定值直接替换旧属性,待测试
else{ //新增
_modleDataInfo[sModel].groupInfo[sGroup].mapInfo.insert(uuid,mapPro);
}
} }
ModleStateMap& DataManager::modelState() ModleStateMap& DataManager::modelState()