修改组态logic层级
This commit is contained in:
parent
d32e5bfb55
commit
8085a2875b
@ -346,48 +346,135 @@ void CConfiguration::on_treeView_Relay_customContextMenuRequested(const QPoint &
|
|||||||
menu.exec(QCursor::pos()); //显示菜单
|
menu.exec(QCursor::pos()); //显示菜单
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 递归遍历 QTreeView 的节点,构建 JSON 结构
|
||||||
|
QJsonObject CConfiguration::createJsonFromTreeNode(QStandardItem *item) {
|
||||||
|
QJsonObject nodeObject,inputNodeObj;
|
||||||
|
QJsonArray inputNodeArray;
|
||||||
|
|
||||||
|
// 根据节点的类型判断是 logicOR、logicAND 还是叶子节点
|
||||||
|
QString nodeType = item->text();
|
||||||
|
if (nodeType.contains("logicOR") || nodeType.contains("logicAND")){
|
||||||
|
QJsonArray childrenArray;
|
||||||
|
|
||||||
|
// 遍历子节点
|
||||||
|
for (int i = 0; i < item->rowCount(); ++i) {
|
||||||
|
QStandardItem *childItem = item->child(i);
|
||||||
|
childrenArray.append(createJsonFromTreeNode(childItem));
|
||||||
|
}
|
||||||
|
// 添加 Combination 节点
|
||||||
|
QJsonObject combination;
|
||||||
|
int MinimumNumber = item->data(Qt::UserRole + 1).toInt();
|
||||||
|
if(nodeType.contains("logicOR"))
|
||||||
|
combination["MinimumNumber"] = 1;
|
||||||
|
else if(nodeType.contains("logicAND"))
|
||||||
|
combination["MinimumNumber"] = MinimumNumber;
|
||||||
|
inputNodeObj["Combination"] = combination;
|
||||||
|
// 将子节点数组存储在当前逻辑运算符节点下
|
||||||
|
inputNodeObj["Inputs"] = childrenArray;
|
||||||
|
inputNodeArray.append(inputNodeObj);
|
||||||
|
if(nodeType.contains("logicOR"))
|
||||||
|
nodeObject[nodeType] = inputNodeArray;
|
||||||
|
else if(nodeType.contains("logicAND"))
|
||||||
|
nodeObject[nodeType.left(nodeType.length()-3)] = inputNodeArray;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if(item->text().contains("警报")){
|
||||||
|
nodeObject["alarm"] = 1;
|
||||||
|
nodeObject["danger"] = 0;
|
||||||
|
}else if (item->text().contains("危险")) {
|
||||||
|
nodeObject["danger"] = 1;
|
||||||
|
nodeObject["alarm"] = 0;
|
||||||
|
}
|
||||||
|
nodeObject["triggerFeatureName"] = item->text();
|
||||||
|
nodeObject["nodeType"] = 1;
|
||||||
|
nodeObject["displayTitle"] = item->text();
|
||||||
|
for (int k = 0;k < g_ChannelBaseInfo.size(); k++) {
|
||||||
|
if(g_ChannelBaseInfo[k].channelName == item->text().split("-")[0]){
|
||||||
|
nodeObject["channelId"] = g_ChannelBaseInfo[k].channelID;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodeObject;
|
||||||
|
}
|
||||||
|
// 将生成的 JSON 保存到文件
|
||||||
|
void CConfiguration::saveJsonToFile(const QJsonObject &jsonObject, const QString &filePath) {
|
||||||
|
QJsonDocument jsonDoc(jsonObject);
|
||||||
|
QFile file(filePath);
|
||||||
|
if (file.open(QIODevice::WriteOnly)) {
|
||||||
|
file.write(jsonDoc.toJson(QJsonDocument::Indented));
|
||||||
|
file.close();
|
||||||
|
qDebug() << "JSON 文件已生成:" << filePath;
|
||||||
|
} else {
|
||||||
|
qDebug() << "无法打开文件以保存 JSON 数据";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 从 QTreeView 中生成 JSON 数据
|
||||||
|
QJsonObject CConfiguration::generateJsonFromTreeView(QTreeView *treeView) {
|
||||||
|
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(treeView->model());
|
||||||
|
if (!model) return QJsonObject();
|
||||||
|
|
||||||
|
QJsonArray rootArray;
|
||||||
|
|
||||||
|
// 遍历模型的每个根节点
|
||||||
|
for (int i = 0; i < model->rowCount(); ++i) {
|
||||||
|
QStandardItem *rootItem = model->item(i);
|
||||||
|
rootArray.append(createJsonFromTreeNode(rootItem));
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject root;
|
||||||
|
root["logicTree"] = rootArray; // 顶层使用 "logicTree" 作为键
|
||||||
|
return root;
|
||||||
|
}
|
||||||
QJsonArray CConfiguration::GetItem(QStandardItem *item,int MinimumNumber)
|
QJsonArray CConfiguration::GetItem(QStandardItem *item,int MinimumNumber)
|
||||||
{
|
{
|
||||||
QJsonArray arrayAll,arrayAll2;
|
QJsonArray arrjsonObjLogic,arrjsonObjLogic2;
|
||||||
QJsonObject jsonObj,inputObj,inputObj2,MinimumNumberObj;
|
|
||||||
QString strLogic;
|
QString strLogic;
|
||||||
|
QJsonArray ret;
|
||||||
|
QJsonArray arrItem;
|
||||||
|
QJsonObject logicObj,logicInputs;
|
||||||
|
QJsonArray tmplogic ;
|
||||||
if(item->hasChildren())
|
if(item->hasChildren())
|
||||||
{
|
{
|
||||||
for(int i = 0;i < item->rowCount() ;i++)
|
for(int i = 0;i < item->rowCount() ;i++)
|
||||||
{
|
{
|
||||||
QJsonArray array;
|
QJsonObject inputObj,logic_inputObj,inputObj2,jsonObj,MinimumNumberObj;
|
||||||
|
QJsonObject jsonObjLogic,jsonObjLogic2;
|
||||||
|
QJsonArray array,arrayAll,logic_arrayAll,arrayAll2;
|
||||||
|
QJsonArray inputArray,inputArray2;
|
||||||
QStandardItem * childitem = item->child(i);
|
QStandardItem * childitem = item->child(i);
|
||||||
strLogic = childitem->text();
|
strLogic = item->text();
|
||||||
if(childitem->text().contains("logicOR") || childitem->text().contains("logicAND")){
|
if(childitem->text().contains("logicOR") || childitem->text().contains("logicAND")){
|
||||||
QJsonArray inputArray,inputArray2;
|
|
||||||
if(childitem->hasChildren()){
|
if(childitem->hasChildren()){
|
||||||
for(int i = 0;i < childitem->rowCount() ;i++){
|
arrItem = GetItem(childitem, MinimumNumber);
|
||||||
QStandardItem * childitem2 = childitem->child(i);
|
qDebug() << "m_array0" << arrItem << endl;
|
||||||
if(childitem2->text().contains("警报")){
|
|
||||||
jsonObj["alarm"] = 1;
|
|
||||||
jsonObj["danger"] = 0;
|
|
||||||
}else if (childitem2->text().contains("危险")) {
|
|
||||||
jsonObj["danger"] = 1;
|
|
||||||
jsonObj["alarm"] = 0;
|
|
||||||
}
|
|
||||||
jsonObj["triggerFeatureName"] = childitem2->text();
|
|
||||||
jsonObj["nodeType"] = 1;
|
|
||||||
jsonObj["displayTitle"] = childitem2->text();
|
|
||||||
for (int k = 0;k < g_ChannelBaseInfo.size(); k++) {
|
|
||||||
if(g_ChannelBaseInfo[k].channelName == childitem2->text().split("-")[0]){
|
|
||||||
jsonObj["channelId"] = g_ChannelBaseInfo[k].channelID;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inputArray.append(jsonObj);
|
|
||||||
inputArray2.append(jsonObj);
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
QMessageBox::question(this, QStringLiteral("提示"), QStringLiteral("请选择正确的逻辑!"));
|
QMessageBox::question(this, QStringLiteral("提示"), QStringLiteral("请选择正确的逻辑!"));
|
||||||
return arrayAll;
|
return arrayAll;
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
for(int i = 0;i < item->rowCount() ;i++){
|
||||||
|
QStandardItem * childitem2 = item->child(i);
|
||||||
|
if(childitem2->text().contains("警报")){
|
||||||
|
jsonObj["alarm"] = 1;
|
||||||
|
jsonObj["danger"] = 0;
|
||||||
|
}else if (childitem2->text().contains("危险")) {
|
||||||
|
jsonObj["danger"] = 1;
|
||||||
|
jsonObj["alarm"] = 0;
|
||||||
|
}
|
||||||
|
jsonObj["triggerFeatureName"] = childitem2->text();
|
||||||
|
jsonObj["nodeType"] = 1;
|
||||||
|
jsonObj["displayTitle"] = childitem2->text();
|
||||||
|
for (int k = 0;k < g_ChannelBaseInfo.size(); k++) {
|
||||||
|
if(g_ChannelBaseInfo[k].channelName == childitem2->text().split("-")[0]){
|
||||||
|
jsonObj["channelId"] = g_ChannelBaseInfo[k].channelID;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inputArray.append(jsonObj);
|
||||||
|
inputArray2.append(jsonObj);
|
||||||
|
}
|
||||||
QString strTableName = " t_UnitConfiguration ";
|
QString strTableName = " t_UnitConfiguration ";
|
||||||
QVector<UnitConfiguration_t> vecUnitConfiguration = g_SqliteDB->GetUnitConfigurationInfo(strTableName);
|
QVector<UnitConfiguration_t> vecUnitConfiguration = g_SqliteDB->GetUnitConfigurationInfo(strTableName);
|
||||||
for (int i = 0; i < vecUnitConfiguration.size(); i++) {
|
for (int i = 0; i < vecUnitConfiguration.size(); i++) {
|
||||||
@ -407,19 +494,43 @@ QJsonArray CConfiguration::GetItem(QStandardItem *item,int MinimumNumber)
|
|||||||
inputObj2["Combination"] = MinimumNumberObj;
|
inputObj2["Combination"] = MinimumNumberObj;
|
||||||
arrayAll.append(inputObj);
|
arrayAll.append(inputObj);
|
||||||
arrayAll2.append(inputObj2);
|
arrayAll2.append(inputObj2);
|
||||||
|
qDebug() << "arrayAll==========" << arrayAll << endl;
|
||||||
|
qDebug() << "strLogic" << strLogic.left(strLogic.length()-3) << endl;
|
||||||
|
jsonObjLogic[strLogic.left(strLogic.length()-3)] = arrayAll;
|
||||||
|
jsonObjLogic2[strLogic.left(strLogic.length()-3)] = arrayAll2;
|
||||||
|
arrjsonObjLogic.append(jsonObjLogic);
|
||||||
|
arrjsonObjLogic2.append(jsonObjLogic2);
|
||||||
|
}
|
||||||
|
if((childitem->text().contains("logicOR") || childitem->text().contains("logicAND")) && item->parent()){
|
||||||
|
logicObj[strLogic] = arrItem;
|
||||||
|
qDebug() << "logicObj123" << logicObj << endl;
|
||||||
|
tmplogic.append(logicObj);
|
||||||
|
qDebug() << "tmplogic123" << tmplogic << endl;
|
||||||
|
}
|
||||||
|
if(!item->parent() && i + 1 == item->rowCount())
|
||||||
|
{
|
||||||
|
qDebug() << "No parent" << item->text() << endl;
|
||||||
|
qDebug() << "m_array1" << arrItem << endl;
|
||||||
|
return arrItem;
|
||||||
|
}else if(item->parent() && i + 1 == item->rowCount()){
|
||||||
|
qDebug() << "parent" << item->text() << endl;
|
||||||
|
MinimumNumberObj["MinimumNumber"] = 1;
|
||||||
|
logic_inputObj["Combination"] = MinimumNumberObj;
|
||||||
|
if(childitem->text().contains("logicOR") || childitem->text().contains("logicAND")){
|
||||||
|
logic_inputObj["Inputs"] = tmplogic;
|
||||||
|
}else{
|
||||||
|
logic_inputObj["Inputs"] = arrjsonObjLogic;
|
||||||
|
}
|
||||||
|
logic_arrayAll.append(logic_inputObj);
|
||||||
|
qDebug() << "arrayAll111" << logic_arrayAll << endl;
|
||||||
|
return logic_arrayAll;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QJsonObject jsonObjLogic,jsonObjLogic2;
|
m_deleteInputArray.append(arrjsonObjLogic2);
|
||||||
qDebug() << "strLogic" << strLogic.left(strLogic.length()-3) << endl;
|
qDebug() << "m_array2" << arrItem << endl;
|
||||||
jsonObjLogic[strLogic.left(strLogic.length()-3)] = arrayAll;
|
return arrItem;
|
||||||
jsonObjLogic2[strLogic.left(strLogic.length()-3)] = arrayAll2;
|
|
||||||
QJsonArray ret;
|
|
||||||
ret.append(jsonObjLogic);
|
|
||||||
m_deleteInputArray.append(jsonObjLogic2);
|
|
||||||
qDebug() << "m_array" << ret << endl;
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
|
|
||||||
// QJsonArray arrayAll,inputArray;
|
// QJsonArray arrayAll,inputArray;
|
||||||
@ -565,22 +676,36 @@ void CConfiguration::on_pushButton_confirm_clicked()
|
|||||||
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("请选择正确的组态逻辑"));
|
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("请选择正确的组态逻辑"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(int i = 0;i < model_Relay->rowCount() ;i++)
|
// for(int i = 0;i < model_Relay->rowCount() ;i++)
|
||||||
{
|
// {
|
||||||
QStandardItem *item = model_Relay->item(i);
|
// QStandardItem *item = model_Relay->item(i);
|
||||||
qDebug() <<"item = " << item->text();
|
// qDebug() <<"item = " << item->text();
|
||||||
QJsonArray arrayAll = GetItem(model_Relay->item(i));
|
// QJsonArray arrayAll = GetItem(model_Relay->item(i));
|
||||||
if(arrayAll.size() < 1)
|
// QJsonObject json = generateJsonFromTreeView(ui->treeView_Relay);
|
||||||
return;
|
// saveJsonToFile(json, "TreeViewToJSON.json");
|
||||||
logicObj[item->text().left(7)] = arrayAll;
|
// if(arrayAll.size() < 1)
|
||||||
logicObj2[item->text().left(7)] = m_deleteInputArray;
|
// return;
|
||||||
logicExpressArray.append(logicObj);
|
// logicObj[item->text().left(7)] = arrayAll;
|
||||||
logicExpressArray2.append(logicObj2);
|
// logicObj2[item->text().left(7)] = m_deleteInputArray;
|
||||||
}
|
// logicExpressArray.append(logicObj);
|
||||||
ConfiguraitonsObj2 = ConfiguraitonsObj;
|
// logicExpressArray2.append(logicObj2);
|
||||||
ConfiguraitonsObj["logicExpress"] = logicExpressArray;
|
// }
|
||||||
ConfiguraitonsObj2["logicExpress"] = logicExpressArray2;
|
QJsonArray rootArray;
|
||||||
|
|
||||||
|
// 遍历模型的每个根节点
|
||||||
|
for (int i = 0; i < model_Relay->rowCount(); ++i) {
|
||||||
|
QStandardItem *rootItem = model_Relay->item(i);
|
||||||
|
rootArray.append(createJsonFromTreeNode(rootItem));
|
||||||
|
// logicObj[rootItem->text().left(7)] = rootArray;
|
||||||
|
// logicObj2[rootItem->text().left(7)] = m_deleteInputArray;
|
||||||
|
// logicExpressArray.append(logicObj);
|
||||||
|
// logicExpressArray2.append(logicObj2);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfiguraitonsObj2 = ConfiguraitonsObj;
|
||||||
|
ConfiguraitonsObj["logicExpress"] = rootArray;
|
||||||
|
ConfiguraitonsObj2["logicExpress"] = logicExpressArray2;
|
||||||
|
saveJsonToFile(ConfiguraitonsObj, "TreeViewToJSON.json");
|
||||||
QString strTableName = " t_UnitConfiguration ";
|
QString strTableName = " t_UnitConfiguration ";
|
||||||
QVector<UnitConfiguration_t> vecUnitConfiguration = g_SqliteDB->GetUnitConfigurationInfo(strTableName);
|
QVector<UnitConfiguration_t> vecUnitConfiguration = g_SqliteDB->GetUnitConfigurationInfo(strTableName);
|
||||||
for (int i = 0; i < vecUnitConfiguration.size(); i++) {
|
for (int i = 0; i < vecUnitConfiguration.size(); i++) {
|
||||||
@ -915,10 +1040,62 @@ void CConfiguration::on_comboBox_WC_currentIndexChanged(const QString &arg1)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 递归解析 JSON 并构建树模型
|
||||||
|
void CConfiguration::populateTree(QStandardItem *parentItem, const QJsonObject &jsonObject) {
|
||||||
|
for (auto it = jsonObject.begin(); it != jsonObject.end(); ++it) {
|
||||||
|
QString key = it.key();
|
||||||
|
QJsonValue value = it.value();
|
||||||
|
|
||||||
|
if (key == "Combination") {
|
||||||
|
// // 添加 Combination 节点
|
||||||
|
// QJsonObject combination = value.toObject();
|
||||||
|
// int minNumber = combination["MinimumNumber"].toInt();
|
||||||
|
// QString combinationText = QString("Combination (MinimumNumber: %1)").arg(minNumber);
|
||||||
|
// QStandardItem *combinationItem = new QStandardItem(combinationText);
|
||||||
|
// parentItem->appendRow(combinationItem);
|
||||||
|
} else if (key == "Inputs" && value.isArray()) {
|
||||||
|
// 解析 Inputs 数组
|
||||||
|
QJsonArray inputsArray = value.toArray();
|
||||||
|
// QStandardItem *inputsItem = new QStandardItem("Inputs");
|
||||||
|
// parentItem->appendRow(inputsItem);
|
||||||
|
|
||||||
void CConfiguration::ViewRelay(int ChannelNoInBoard)
|
for (const QJsonValue &inputValue : inputsArray) {
|
||||||
{
|
if (inputValue.isObject()) {
|
||||||
|
populateTree(parentItem, inputValue.toObject());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (key.startsWith("logic")) {
|
||||||
|
// 处理 logicAND 或 logicOR 节点
|
||||||
|
QStandardItem *logicItem = new QStandardItem(key);
|
||||||
|
parentItem->appendRow(logicItem);
|
||||||
|
|
||||||
|
if (value.isArray()) {
|
||||||
|
QJsonArray logicArray = value.toArray();
|
||||||
|
for (const QJsonValue &logicValue : logicArray) {
|
||||||
|
if (logicValue.isObject()) {
|
||||||
|
QJsonObject logicCombination = logicValue["Combination"].toObject();
|
||||||
|
int MinimumNumber =logicCombination["MinimumNumber"].toInt();
|
||||||
|
qDebug() << "MinimumNumber" << MinimumNumber << endl;
|
||||||
|
logicItem->setData(MinimumNumber,Qt::UserRole+1);
|
||||||
|
if(key.contains("logicAND"))
|
||||||
|
logicItem->setText(QString("logicAND(%1)").arg(MinimumNumber));
|
||||||
|
populateTree(logicItem, logicValue.toObject());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (value.isObject()) {
|
||||||
|
// 如果是嵌套对象
|
||||||
|
QStandardItem *objectItem = new QStandardItem(key);
|
||||||
|
parentItem->appendRow(objectItem);
|
||||||
|
populateTree(objectItem, value.toObject());
|
||||||
|
} else if (key == "displayTitle") {
|
||||||
|
// 叶子节点:展示 displayTitle
|
||||||
|
QStandardItem *leafItem = new QStandardItem(value.toString());
|
||||||
|
parentItem->appendRow(leafItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void CConfiguration::ViewRelay(int ChannelNoInBoard){
|
||||||
model_Relay->clear();
|
model_Relay->clear();
|
||||||
ui->lineEdit_2->setText("");
|
ui->lineEdit_2->setText("");
|
||||||
QString strWorkConditonName = ui->comboBox_WC->currentText();
|
QString strWorkConditonName = ui->comboBox_WC->currentText();
|
||||||
@ -932,100 +1109,134 @@ void CConfiguration::ViewRelay(int ChannelNoInBoard)
|
|||||||
if(tempArray.at(j)["ChannelNoInBoard"] == ChannelNoInBoard){
|
if(tempArray.at(j)["ChannelNoInBoard"] == ChannelNoInBoard){
|
||||||
ui->lineEdit_delay->setText(tempArray.at(j)["DelaySeconds"].toString());
|
ui->lineEdit_delay->setText(tempArray.at(j)["DelaySeconds"].toString());
|
||||||
QJsonArray tempArray2 = tempArray.at(j)["logicExpress"].toArray();
|
QJsonArray tempArray2 = tempArray.at(j)["logicExpress"].toArray();
|
||||||
|
// 递归解析 JSON 数据并填充到模型中
|
||||||
for (int k = 0; k < tempArray2.size(); k++) {
|
for (int k = 0; k < tempArray2.size(); k++) {
|
||||||
QJsonObject tempObj2 = tempArray2[k].toObject();
|
QJsonObject tempObj2 = tempArray2[k].toObject();
|
||||||
if (tempObj2.contains(QStringLiteral("logicAND"))){
|
|
||||||
QJsonValue arrayValue = tempObj2.value(QStringLiteral("logicAND"));
|
|
||||||
QStandardItem *itemAnd = new QStandardItem(QString("logicAND"));
|
|
||||||
model_Relay->appendRow(itemAnd);
|
|
||||||
QJsonArray array = arrayValue.toArray();
|
|
||||||
for (int kk = 0; kk < array.size(); kk++) {
|
|
||||||
QJsonObject tempObj3 = array[kk].toObject();
|
|
||||||
if (tempObj3.contains(QStringLiteral("logicAND"))){
|
|
||||||
QJsonValue objValue = tempObj3.value(QStringLiteral("logicAND"));
|
|
||||||
|
|
||||||
QJsonObject Combination = objValue["Combination"].toObject();
|
|
||||||
int MinimumNumber = Combination["MinimumNumber"].toInt();
|
|
||||||
|
|
||||||
QStandardItem *itemAnd2 = new QStandardItem(QString("logicAND(%1)").arg(MinimumNumber));
|
|
||||||
itemAnd2->setData(MinimumNumber,Qt::UserRole+1);
|
|
||||||
itemAnd->appendRow(itemAnd2);
|
|
||||||
|
|
||||||
QJsonArray inputsArray = objValue["Inputs"].toArray();
|
|
||||||
for (int ii = 0; ii < inputsArray.size(); ii++) {
|
|
||||||
QStandardItem *item = new QStandardItem(QString(inputsArray.at(ii)["displayTitle"].toString()));
|
|
||||||
itemAnd2->appendRow(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tempObj3.contains(QStringLiteral("logicOR"))){
|
|
||||||
QJsonValue objValue = tempObj3.value(QStringLiteral("logicOR"));
|
|
||||||
QJsonObject Combination = objValue["Combination"].toObject();
|
|
||||||
int MinimumNumber = Combination["MinimumNumber"].toInt();
|
|
||||||
QStandardItem *itemOr2 = new QStandardItem(QString("logicOR(%1)").arg(MinimumNumber));
|
|
||||||
itemOr2->setData(MinimumNumber,Qt::UserRole+1);
|
|
||||||
itemAnd->appendRow(itemOr2);
|
|
||||||
|
|
||||||
QJsonArray arrValue2 = objValue.toArray();
|
|
||||||
for(int jj = 0; jj < arrValue2.size();jj++){
|
|
||||||
QJsonArray inputsArray = arrValue2.at(jj)["Inputs"].toArray();
|
|
||||||
for (int ii = 0; ii < inputsArray.size(); ii++) {
|
|
||||||
QStandardItem *item = new QStandardItem(QString(inputsArray.at(ii)["displayTitle"].toString()));
|
|
||||||
itemOr2->appendRow(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (tempObj2.contains(QStringLiteral("logicOR"))){
|
if (tempObj2.contains(QStringLiteral("logicOR"))){
|
||||||
QJsonValue arrayValue = tempObj2.value(QStringLiteral("logicOR"));
|
QJsonValue arrayValue = tempObj2.value(QStringLiteral("logicOR"));
|
||||||
QStandardItem *itemOr = new QStandardItem(QString("logicOR"));
|
QStandardItem *itemOr = new QStandardItem(QString("logicOR"));
|
||||||
model_Relay->appendRow(itemOr);
|
|
||||||
QJsonArray array = arrayValue.toArray();
|
QJsonArray array = arrayValue.toArray();
|
||||||
for (int kk = 0; kk < array.size(); kk++) {
|
for (int kk = 0; kk < array.size(); kk++) {
|
||||||
QJsonObject tempObj3 = array[k].toObject();
|
QJsonObject tempObj3 = array[k].toObject();
|
||||||
if (tempObj3.contains(QStringLiteral("logicAND"))){
|
populateTree(itemOr, tempObj3);
|
||||||
QJsonValue objValue = tempObj3.value(QStringLiteral("logicAND"));
|
|
||||||
QJsonArray array2 = objValue.toArray();
|
|
||||||
for (int jj = 0; jj < array2.size(); jj++) {
|
|
||||||
QJsonObject tempObj4 = array2[jj].toObject();
|
|
||||||
QJsonObject Combination = tempObj4["Combination"].toObject();
|
|
||||||
int MinimumNumber = Combination["MinimumNumber"].toInt();
|
|
||||||
QStandardItem *itemAnd2 = new QStandardItem(QString("logicAND(%1)").arg(MinimumNumber));
|
|
||||||
QJsonArray inputsArray = tempObj4["Inputs"].toArray();
|
|
||||||
for (int ii = 0; ii < inputsArray.size(); ii++) {
|
|
||||||
QStandardItem *item = new QStandardItem(QString(inputsArray.at(ii)["displayTitle"].toString()));
|
|
||||||
itemAnd2->appendRow(item);
|
|
||||||
}
|
|
||||||
itemAnd2->setData(MinimumNumber,Qt::UserRole+1);
|
|
||||||
itemOr->appendRow(itemAnd2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tempObj3.contains(QStringLiteral("logicOR"))){
|
|
||||||
QJsonValue objValue = tempObj3.value(QStringLiteral("logicOR"));
|
|
||||||
QJsonObject Combination = objValue["Combination"].toObject();
|
|
||||||
int MinimumNumber = Combination["MinimumNumber"].toInt();
|
|
||||||
QStandardItem *itemOr2 = new QStandardItem(QString("logicOR(%1)").arg(MinimumNumber));
|
|
||||||
itemOr2->setData(MinimumNumber,Qt::UserRole+1);
|
|
||||||
itemOr->appendRow(itemOr2);
|
|
||||||
|
|
||||||
QJsonArray arrValue2 = objValue.toArray();
|
|
||||||
for(int jj = 0; jj < arrValue2.size();jj++){
|
|
||||||
QJsonArray inputsArray = arrValue2.at(jj)["Inputs"].toArray();
|
|
||||||
for (int ii = 0; ii < inputsArray.size(); ii++) {
|
|
||||||
QStandardItem *item = new QStandardItem(QString(inputsArray.at(ii)["displayTitle"].toString()));
|
|
||||||
itemOr2->appendRow(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
model_Relay->appendRow(itemOr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
//void CConfiguration::ViewRelay(int ChannelNoInBoard)
|
||||||
|
//{
|
||||||
|
// model_Relay->clear();
|
||||||
|
// ui->lineEdit_2->setText("");
|
||||||
|
// QString strWorkConditonName = ui->comboBox_WC->currentText();
|
||||||
|
// for (int i = 0; i < m_vecWorkConditionObj.size(); i++) {
|
||||||
|
// QJsonObject tempObj = m_vecWorkConditionObj[i];
|
||||||
|
// if(strWorkConditonName == tempObj["WorkConditionName"].toString()){
|
||||||
|
// QJsonArray tempArray = tempObj["Configuraitons"].toArray();
|
||||||
|
// QString strSecondDelaySeconds = tempObj["SecondDelaySeconds"].toString();
|
||||||
|
// ui->lineEdit_2->setText(strSecondDelaySeconds);
|
||||||
|
// for (int j = 0;j < tempArray.size() ;j++ ) {
|
||||||
|
// if(tempArray.at(j)["ChannelNoInBoard"] == ChannelNoInBoard){
|
||||||
|
// ui->lineEdit_delay->setText(tempArray.at(j)["DelaySeconds"].toString());
|
||||||
|
// QJsonArray tempArray2 = tempArray.at(j)["logicExpress"].toArray();
|
||||||
|
// for (int k = 0; k < tempArray2.size(); k++) {
|
||||||
|
// QJsonObject tempObj2 = tempArray2[k].toObject();
|
||||||
|
// if (tempObj2.contains(QStringLiteral("logicAND"))){
|
||||||
|
// QJsonValue arrayValue = tempObj2.value(QStringLiteral("logicAND"));
|
||||||
|
// QStandardItem *itemAnd = new QStandardItem(QString("logicAND"));
|
||||||
|
// model_Relay->appendRow(itemAnd);
|
||||||
|
// QJsonArray array = arrayValue.toArray();
|
||||||
|
// for (int kk = 0; kk < array.size(); kk++) {
|
||||||
|
// QJsonObject tempObj3 = array[kk].toObject();
|
||||||
|
// if (tempObj3.contains(QStringLiteral("logicAND"))){
|
||||||
|
// QJsonValue objValue = tempObj3.value(QStringLiteral("logicAND"));
|
||||||
|
|
||||||
|
// QJsonObject Combination = objValue["Combination"].toObject();
|
||||||
|
// int MinimumNumber = Combination["MinimumNumber"].toInt();
|
||||||
|
|
||||||
|
// QStandardItem *itemAnd2 = new QStandardItem(QString("logicAND(%1)").arg(MinimumNumber));
|
||||||
|
// itemAnd2->setData(MinimumNumber,Qt::UserRole+1);
|
||||||
|
// itemAnd->appendRow(itemAnd2);
|
||||||
|
|
||||||
|
// QJsonArray inputsArray = objValue["Inputs"].toArray();
|
||||||
|
// for (int ii = 0; ii < inputsArray.size(); ii++) {
|
||||||
|
// QStandardItem *item = new QStandardItem(QString(inputsArray.at(ii)["displayTitle"].toString()));
|
||||||
|
// itemAnd2->appendRow(item);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (tempObj3.contains(QStringLiteral("logicOR"))){
|
||||||
|
// QJsonValue objValue = tempObj3.value(QStringLiteral("logicOR"));
|
||||||
|
// QJsonObject Combination = objValue["Combination"].toObject();
|
||||||
|
// int MinimumNumber = Combination["MinimumNumber"].toInt();
|
||||||
|
// QStandardItem *itemOr2 = new QStandardItem(QString("logicOR(%1)").arg(MinimumNumber));
|
||||||
|
// itemOr2->setData(MinimumNumber,Qt::UserRole+1);
|
||||||
|
// itemAnd->appendRow(itemOr2);
|
||||||
|
|
||||||
|
// QJsonArray arrValue2 = objValue.toArray();
|
||||||
|
// for(int jj = 0; jj < arrValue2.size();jj++){
|
||||||
|
// QJsonArray inputsArray = arrValue2.at(jj)["Inputs"].toArray();
|
||||||
|
// for (int ii = 0; ii < inputsArray.size(); ii++) {
|
||||||
|
// QStandardItem *item = new QStandardItem(QString(inputsArray.at(ii)["displayTitle"].toString()));
|
||||||
|
// itemOr2->appendRow(item);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
// if (tempObj2.contains(QStringLiteral("logicOR"))){
|
||||||
|
// QJsonValue arrayValue = tempObj2.value(QStringLiteral("logicOR"));
|
||||||
|
// QStandardItem *itemOr = new QStandardItem(QString("logicOR"));
|
||||||
|
// model_Relay->appendRow(itemOr);
|
||||||
|
// QJsonArray array = arrayValue.toArray();
|
||||||
|
// for (int kk = 0; kk < array.size(); kk++) {
|
||||||
|
// QJsonObject tempObj3 = array[k].toObject();
|
||||||
|
// if (tempObj3.contains(QStringLiteral("logicAND"))){
|
||||||
|
// QJsonValue objValue = tempObj3.value(QStringLiteral("logicAND"));
|
||||||
|
// QJsonArray array2 = objValue.toArray();
|
||||||
|
// for (int jj = 0; jj < array2.size(); jj++) {
|
||||||
|
// QJsonObject tempObj4 = array2[jj].toObject();
|
||||||
|
// QJsonObject Combination = tempObj4["Combination"].toObject();
|
||||||
|
// int MinimumNumber = Combination["MinimumNumber"].toInt();
|
||||||
|
// QStandardItem *itemAnd2 = new QStandardItem(QString("logicAND(%1)").arg(MinimumNumber));
|
||||||
|
// QJsonArray inputsArray = tempObj4["Inputs"].toArray();
|
||||||
|
// for (int ii = 0; ii < inputsArray.size(); ii++) {
|
||||||
|
// QStandardItem *item = new QStandardItem(QString(inputsArray.at(ii)["displayTitle"].toString()));
|
||||||
|
// itemAnd2->appendRow(item);
|
||||||
|
// }
|
||||||
|
// itemAnd2->setData(MinimumNumber,Qt::UserRole+1);
|
||||||
|
// itemOr->appendRow(itemAnd2);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (tempObj3.contains(QStringLiteral("logicOR"))){
|
||||||
|
// QJsonValue objValue = tempObj3.value(QStringLiteral("logicOR"));
|
||||||
|
// QJsonObject Combination = objValue["Combination"].toObject();
|
||||||
|
// int MinimumNumber = Combination["MinimumNumber"].toInt();
|
||||||
|
// QStandardItem *itemOr2 = new QStandardItem(QString("logicOR(%1)").arg(MinimumNumber));
|
||||||
|
// itemOr2->setData(MinimumNumber,Qt::UserRole+1);
|
||||||
|
// itemOr->appendRow(itemOr2);
|
||||||
|
|
||||||
|
// QJsonArray arrValue2 = objValue.toArray();
|
||||||
|
// for(int jj = 0; jj < arrValue2.size();jj++){
|
||||||
|
// QJsonArray inputsArray = arrValue2.at(jj)["Inputs"].toArray();
|
||||||
|
// for (int ii = 0; ii < inputsArray.size(); ii++) {
|
||||||
|
// QStandardItem *item = new QStandardItem(QString(inputsArray.at(ii)["displayTitle"].toString()));
|
||||||
|
// itemOr2->appendRow(item);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// for(int i = 0;i < model_Available->rowCount() ;i++){
|
// for(int i = 0;i < model_Available->rowCount() ;i++){
|
||||||
// model_Relay->removeRow(i);
|
// model_Relay->removeRow(i);
|
||||||
@ -1128,7 +1339,7 @@ void CConfiguration::ViewRelay(int ChannelNoInBoard)
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
void CConfiguration::on_radioButton_1_clicked()
|
void CConfiguration::on_radioButton_1_clicked()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -65,7 +65,9 @@ private:
|
|||||||
QStandardItemModel *model_Relay;
|
QStandardItemModel *model_Relay;
|
||||||
|
|
||||||
QVector<WorkCondition_t> m_WorkCondition;
|
QVector<WorkCondition_t> m_WorkCondition;
|
||||||
|
QJsonObject createJsonFromTreeNode(QStandardItem *item);
|
||||||
|
void saveJsonToFile(const QJsonObject &jsonObject, const QString &filePath);
|
||||||
|
QJsonObject generateJsonFromTreeView(QTreeView *treeView);
|
||||||
QJsonArray GetItem(QStandardItem *item,int MinimumNumber = -1);
|
QJsonArray GetItem(QStandardItem *item,int MinimumNumber = -1);
|
||||||
QJsonArray m_arrayAll;
|
QJsonArray m_arrayAll;
|
||||||
QJsonArray m_array;
|
QJsonArray m_array;
|
||||||
@ -85,6 +87,7 @@ private:
|
|||||||
QJsonObject SelectChannel(int channelNo);
|
QJsonObject SelectChannel(int channelNo);
|
||||||
void ViewRelay(int ChannelNoInBoard);
|
void ViewRelay(int ChannelNoInBoard);
|
||||||
void PushData();
|
void PushData();
|
||||||
|
void populateTree(QStandardItem *parentItem, const QJsonObject &jsonObject);
|
||||||
int m_isConfirm;
|
int m_isConfirm;
|
||||||
int m_curentRLY;
|
int m_curentRLY;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user