903 lines
39 KiB
C++
903 lines
39 KiB
C++
#include "Configuration.h"
|
||
#include "ui_Configuration.h"
|
||
#include <QStyleFactory>
|
||
#include <QMenu>
|
||
#include <QInputDialog>
|
||
#include <QScrollArea>
|
||
|
||
|
||
CConfiguration::CConfiguration(QWidget *parent) :
|
||
QWidget(parent),
|
||
ui(new Ui::CConfiguration)
|
||
{
|
||
ui->setupUi(this);
|
||
m_isConfirm = -1;
|
||
ui->widget_2->setProperty("flag", "configure");
|
||
ui->widget->setProperty("flag", "Title");
|
||
ui->widget_5->setProperty("flag", "normal");
|
||
|
||
|
||
QRegExp exp("[0-9\\.-]+$");
|
||
QValidator *Validator = new QRegExpValidator(exp);
|
||
ui->lineEdit_2->setValidator(Validator);
|
||
|
||
Init();
|
||
|
||
QHeaderView *pHeader=ui->treeView_Available->header();
|
||
pHeader->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||
pHeader->setStretchLastSection(false);
|
||
|
||
QHeaderView *pHeader2=ui->treeView_Relay->header();
|
||
pHeader2->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||
pHeader2->setStretchLastSection(false);
|
||
|
||
connect(ui->comboBox_WC,SIGNAL(currentTextChanged(const QString &)),this,SLOT(on_comboBox_WC_currentTextChanged2(const QString&)));
|
||
connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&)));
|
||
}
|
||
|
||
CConfiguration::~CConfiguration()
|
||
{
|
||
qDebug()<< "~CConfiguration" << endl;
|
||
// for(int i = 0;i < model_Available->rowCount() ;i++){
|
||
// model_Relay->removeRow(i);
|
||
// }
|
||
// for(int i = 0;i < model_Relay->rowCount() ;i++){
|
||
// model_Relay->removeRow(i);
|
||
// }
|
||
// delete model_Available;
|
||
// delete model_Relay;
|
||
// model_Relay = NULL;
|
||
// model_Available = NULL;
|
||
delete ui;
|
||
}
|
||
|
||
void CConfiguration::Init()
|
||
{
|
||
|
||
QString wherecon = "";
|
||
wherecon = QString("Enable = \"1\" ");
|
||
m_WorkCondition = g_SqliteDB->GetWorkCondition("t_WorkCondition",wherecon);
|
||
|
||
QStringList strWorkConditionList;
|
||
for (int i = 0; i < m_WorkCondition.size(); i++) {
|
||
strWorkConditionList << m_WorkCondition.at(i).WorkConditionName;
|
||
}
|
||
|
||
|
||
ui->treeView_Available->setContextMenuPolicy(Qt::CustomContextMenu);
|
||
ui->treeView_Available->setStyle(QStyleFactory::create("windows"));
|
||
model_Available = new QStandardItemModel(ui->treeView_Available); //创建模型指定父类
|
||
ui->treeView_Available->setModel(model_Available);
|
||
ui->treeView_Available->setHeaderHidden(true);
|
||
|
||
ui->treeView_Relay->setContextMenuPolicy(Qt::CustomContextMenu);
|
||
ui->treeView_Relay->setStyle(QStyleFactory::create("windows"));
|
||
model_Relay = new QStandardItemModel(ui->treeView_Relay); //创建模型指定父类
|
||
ui->treeView_Relay->setModel(model_Relay);
|
||
ui->treeView_Relay->setHeaderHidden(true);
|
||
|
||
QStandardItem* item1 = new QStandardItem("Operator");
|
||
QStandardItem* item2 = new QStandardItem("Operand");
|
||
model_Available->appendRow(item1);
|
||
model_Available->appendRow(item2);
|
||
|
||
QStandardItem *itemAnd = new QStandardItem(QString("logicAND(1)"));
|
||
itemAnd->setData(1,Qt::UserRole+1);
|
||
QStandardItem *itemOr = new QStandardItem(QString("logicOR"));
|
||
item1->appendRow(itemAnd);
|
||
item1->appendRow(itemOr);
|
||
|
||
|
||
QString name = QCoreApplication::applicationDirPath() + "\\config\\TriggerSettings.json";
|
||
QFile loadFile(name);
|
||
if(!loadFile.open(QIODevice::ReadOnly))
|
||
{
|
||
qDebug() << "could't open projects json";
|
||
return;
|
||
}
|
||
QString value = loadFile.readAll();
|
||
loadFile.close();
|
||
QJsonParseError parseJsonErr;
|
||
QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(), &parseJsonErr);
|
||
if (!(parseJsonErr.error == QJsonParseError::NoError)) {
|
||
QMessageBox::about(NULL, "提示", "读取文件错误!");
|
||
return;
|
||
}
|
||
ui->comboBox_WC->clear();
|
||
ui->comboBox_WC->addItems(strWorkConditionList);
|
||
QString strWC = ui->comboBox_WC->currentText();
|
||
qDebug() << strWC;
|
||
arrayTriggerConfig = document.array();
|
||
for (int i = 0; i < arrayTriggerConfig.size(); i++) {
|
||
if(strWC == arrayTriggerConfig.at(i)["workConditionName"].toString()){
|
||
QString strFirstDelaySeconds = arrayTriggerConfig.at(i)["FirstDelaySeconds"].toString();
|
||
QString strSecondDelaySeconds = arrayTriggerConfig.at(i)["SecondDelaySeconds"].toString();
|
||
QString strThirdDelaySeconds = arrayTriggerConfig.at(i)["ThirdDelaySeconds"].toString();
|
||
ui->lineEdit_2->setText(strSecondDelaySeconds);
|
||
|
||
QJsonArray TriggerSettings = arrayTriggerConfig.at(i)["triggerSettings"].toArray();
|
||
for (int j = 0; j < TriggerSettings.size(); j++){
|
||
QString channelName = TriggerSettings.at(j)["channelName"].toString();
|
||
QStandardItem *itemChannel = new QStandardItem(QString(channelName));
|
||
QJsonArray arrayConfig = TriggerSettings.at(j)["triggerConfig"].toArray();
|
||
if(arrayConfig.size() > 0){
|
||
item2->appendRow(itemChannel);
|
||
|
||
for (int k = 0; k < arrayConfig.size(); k++){
|
||
QString str = arrayConfig.at(k)["triggerEventName"].toString();
|
||
QStandardItem *item = NULL;
|
||
int xAlertOverEnabled = arrayConfig.at(k)["xAlertOverEnabled"].toInt();
|
||
int xAlertUnderEnabled = arrayConfig.at(k)["xAlertUnderEnabled"].toInt();
|
||
int xDangerOverEnabled = arrayConfig.at(k)["xDangerOverEnabled"].toInt();
|
||
int xDangerUnderEnabled = arrayConfig.at(k)["xDangerUnderEnabled"].toInt();
|
||
if(xAlertOverEnabled == 1){
|
||
item = new QStandardItem(QString(channelName + "-" + str + "-Over-"+"警报"));
|
||
itemChannel->appendRow(item);
|
||
}
|
||
if(xAlertUnderEnabled == 1){
|
||
item = new QStandardItem(QString(channelName + "-" + str + "-Under-"+"警报"));
|
||
itemChannel->appendRow(item);
|
||
}
|
||
if(xDangerOverEnabled == 1){
|
||
item = new QStandardItem(QString(channelName + "-" + str + "-Over-"+"危险"));
|
||
itemChannel->appendRow(item);
|
||
}
|
||
if(xDangerUnderEnabled == 1){
|
||
item = new QStandardItem(QString(channelName + "-" + str + "-Under-"+"危险"));
|
||
itemChannel->appendRow(item);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
LoadConfiguration();
|
||
|
||
}
|
||
|
||
void CConfiguration::LoadConfiguration()
|
||
{
|
||
QString name = QCoreApplication::applicationDirPath() + "\\config\\UnitConfigurations.json";
|
||
QFile loadFile(name);
|
||
if(!loadFile.open(QIODevice::ReadOnly))
|
||
{
|
||
qDebug() << "could't open projects json";
|
||
return;
|
||
}
|
||
QString value = loadFile.readAll();
|
||
loadFile.close();
|
||
QJsonParseError parseJsonErr;
|
||
QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(), &parseJsonErr);
|
||
if (!(parseJsonErr.error == QJsonParseError::NoError)) {
|
||
QMessageBox::about(NULL, "提示", "读取文件错误!");
|
||
return;
|
||
}
|
||
QString strWC = ui->comboBox_WC->currentText();
|
||
QJsonObject TriggerConfigObj = document.object();
|
||
QJsonArray arrayConfig = TriggerConfigObj["WorkConditionConfiguraitons"].toArray();
|
||
for (int i = 0; i < arrayConfig.size(); i++) {
|
||
m_vecWorkConditionObj.append(arrayConfig[i].toObject());
|
||
}
|
||
|
||
}
|
||
|
||
void CConfiguration::slotDeleteItem()
|
||
{
|
||
QModelIndex curIndex = ui->treeView_Relay->currentIndex();
|
||
//QModelIndex index = curIndex.sibling(curIndex.row(),0); //同一行第一列元素的index
|
||
if(curIndex.isValid())
|
||
{
|
||
QStandardItem* item = model_Relay->itemFromIndex(curIndex);
|
||
QString text = item->text();
|
||
qDebug() << text <<endl;
|
||
model_Relay->removeRow(curIndex.row(),curIndex.parent());
|
||
}
|
||
}
|
||
|
||
void CConfiguration::slotModifyItem()
|
||
{
|
||
QModelIndex curIndex = ui->treeView_Relay->currentIndex();
|
||
if(curIndex.isValid())
|
||
{
|
||
QStandardItem* item = model_Relay->itemFromIndex(curIndex);
|
||
if(item->rowCount() < 1){
|
||
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("选择错误!"));
|
||
return;
|
||
}
|
||
|
||
bool ok;
|
||
|
||
// 获取整数
|
||
QString strTips =QString("请输入0到%1之间的数值").arg(item->rowCount());
|
||
|
||
int value1 = QInputDialog::getInt(this, tr("输入整数对话框"), strTips, item->rowCount(), 1, 10, 1, &ok);
|
||
if(!ok) return;
|
||
|
||
if(value1 > item->rowCount() || value1 < 1){
|
||
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("请输入正确的数字!"));
|
||
return ;
|
||
}
|
||
QString text = item->text().left(item->text().length()-3);
|
||
item->setData(value1,Qt::UserRole+1);
|
||
QString str = QString("(%1)").arg(value1);
|
||
item->setText(text + str);
|
||
}
|
||
}
|
||
|
||
void CConfiguration::on_treeView_Relay_customContextMenuRequested(const QPoint &pos)
|
||
{
|
||
qDebug() << "on_treeView_Relay_customContextMenuRequested" <<endl;
|
||
QModelIndex curIndex = ui->treeView_Relay->indexAt(pos); //当前点击的元素的index
|
||
QModelIndex index = curIndex.sibling(curIndex.row(),0); //该行的第1列元素的index
|
||
QMenu menu(this);
|
||
if (index.isValid())
|
||
{
|
||
//添加一行菜单,进行展开
|
||
menu.addAction(QStringLiteral("删除"), this, SLOT(slotDeleteItem()));
|
||
menu.addAction(QStringLiteral("选择满足要求的任意条件数量"), this, SLOT(slotModifyItem()));
|
||
menu.addSeparator(); //添加一个分隔线
|
||
//menu.addAction(QStringLiteral("增加"), this, SLOT(slotTreeMenuCollapse(bool)));
|
||
}
|
||
menu.exec(QCursor::pos()); //显示菜单
|
||
}
|
||
|
||
QJsonArray CConfiguration::GetItem(QStandardItem *item,int MinimumNumber)
|
||
{
|
||
QJsonArray arrayAll;
|
||
QJsonObject jsonObj,inputObj,MinimumNumberObj;
|
||
QString strLogic;
|
||
if(item->hasChildren())
|
||
{
|
||
for(int i = 0;i < item->rowCount() ;i++)
|
||
{
|
||
QJsonArray array;
|
||
QStandardItem * childitem = item->child(i);
|
||
strLogic = childitem->text();
|
||
if(childitem->text().contains("logicOR") || childitem->text().contains("logicAND")){
|
||
QJsonArray inputArray;
|
||
if(childitem->hasChildren()){
|
||
for(int i = 0;i < childitem->rowCount() ;i++){
|
||
QStandardItem * childitem2 = childitem->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();
|
||
jsonObj["channelId"] = childitem2->text().split("-")[3];
|
||
inputArray.append(jsonObj);
|
||
}
|
||
}else{
|
||
QMessageBox::question(this, QStringLiteral("提示"), QStringLiteral("请选择正确的逻辑!"));
|
||
return arrayAll;
|
||
}
|
||
inputObj["Inputs"] = inputArray;
|
||
|
||
MinimumNumber = childitem->data(Qt::UserRole + 1).toInt();
|
||
qDebug()<< "MinimumNumber" <<MinimumNumber<< endl;
|
||
MinimumNumberObj["MinimumNumber"] = MinimumNumber;
|
||
inputObj["Combination"] = MinimumNumberObj;
|
||
arrayAll.append(inputObj);
|
||
//qDebug() << "m_array"<<m_array << childitem->data(1) << endl;
|
||
}
|
||
|
||
}
|
||
}
|
||
QJsonObject jsonObjLogic;
|
||
qDebug() << "strLogic" << strLogic.left(strLogic.length()-3) << endl;
|
||
jsonObjLogic[strLogic.left(strLogic.length()-3)] = arrayAll;
|
||
QJsonArray ret;
|
||
ret.append(jsonObjLogic);
|
||
return ret;
|
||
|
||
|
||
// QJsonArray arrayAll,inputArray;
|
||
// QJsonObject jsonObj,inputObj,MinimumNumberObj;
|
||
// if(item->hasChildren())
|
||
// {
|
||
// for(int i = 0;i < item->rowCount() ;i++)
|
||
// {
|
||
// QJsonArray array;
|
||
// QStandardItem * childitem = item->child(i);
|
||
// if(childitem->text().contains("logicOR") || childitem->text().contains("logicAND")){
|
||
// QJsonObject jsonObjLogic;
|
||
// MinimumNumber = childitem->data(Qt::UserRole + 1).toInt();
|
||
// jsonObjLogic[childitem->text().left(7)] = GetItem(childitem, MinimumNumber);
|
||
// m_array.append(jsonObjLogic);
|
||
// //qDebug() << "m_array"<<m_array << childitem->data(1) << endl;
|
||
|
||
// }else{
|
||
// if(childitem->text().contains("警报")){
|
||
// jsonObj["status"] = "alarm";
|
||
// }else if (childitem->text().contains("危险")) {
|
||
// jsonObj["status"] = "danger";
|
||
// }
|
||
// jsonObj["triggerFeatureName"] = childitem->text();
|
||
// jsonObj["nodeType"] = 1;
|
||
// jsonObj["displayTitle"] = childitem->text();
|
||
// jsonObj["channelId"] = childitem->text().split("-")[3];
|
||
// }
|
||
// if(!childitem->text().contains("logicOR") && !childitem->text().contains("logicAND")){
|
||
|
||
// inputArray.append(jsonObj);
|
||
// }
|
||
|
||
// if(!item->parent() && i + 1 == item->rowCount())
|
||
// {
|
||
// qDebug() << "No parent" << item->text()<< endl;
|
||
// return m_array;
|
||
// }else if(item->parent() && i + 1 == item->rowCount()){
|
||
// MinimumNumberObj["MinimumNumber"] = MinimumNumber;
|
||
// inputObj["Combination"] = MinimumNumberObj;
|
||
// inputObj["Inputs"] = inputArray;
|
||
// arrayAll.append(inputObj);
|
||
// return arrayAll;
|
||
// }
|
||
// }
|
||
// }
|
||
}
|
||
|
||
QJsonObject CConfiguration::SelectChannel(int channelNo)
|
||
{
|
||
QJsonObject ConfiguraitonsObj;
|
||
for (int i = 0; i < g_ChannelBaseInfo.size(); i++) {
|
||
if(g_ChannelBaseInfo[i].bordNo == 10 && g_ChannelBaseInfo[i].channelNoInBoard == channelNo){
|
||
ConfiguraitonsObj["BoardNo"] = g_ChannelBaseInfo[i].bordNo;
|
||
ConfiguraitonsObj["ChannelId"] = g_ChannelBaseInfo[i].channelID;
|
||
ConfiguraitonsObj["ChannelName"] = g_ChannelBaseInfo[i].channelName;
|
||
ConfiguraitonsObj["ChannelNoInBoard"] = g_ChannelBaseInfo[i].channelNoInBoard;
|
||
}
|
||
}
|
||
return ConfiguraitonsObj;
|
||
}
|
||
void CConfiguration::slotNetMgr(QString sAddr, const QVariant &msg)
|
||
{
|
||
QJsonObject objec = msg.value<QJsonObject>();
|
||
if(objec.contains("cmd"))
|
||
{
|
||
QJsonValue arrays_value = objec.take("cmd");
|
||
//qDebug()<<"cmd ="<<arrays_value.toString();
|
||
if(arrays_value.toString() == "110"){
|
||
bool Status = objec.take("success").toBool();
|
||
if(Status){
|
||
PushData();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void CConfiguration::on_pushButton_save_clicked()
|
||
{
|
||
g_NetMgr->DetectNet();
|
||
}
|
||
|
||
void CConfiguration::on_pushButton_confirm_clicked()
|
||
{
|
||
|
||
QJsonObject logicObj,ConfiguraitonsObj,ConfiguraitonsWCObj;
|
||
QJsonArray logicExpressArray,ConfiguraitonsArray;
|
||
int flag = -1;
|
||
if(ui->radioButton_1->isChecked()){
|
||
flag = 1;
|
||
ConfiguraitonsObj = SelectChannel(3);
|
||
|
||
}else if(ui->radioButton_2->isChecked()){
|
||
flag = 1;
|
||
ConfiguraitonsObj = SelectChannel(4);
|
||
|
||
}else if(ui->radioButton_3->isChecked()){
|
||
flag = 1;
|
||
ConfiguraitonsObj = SelectChannel(5);
|
||
|
||
}else if(ui->radioButton_4->isChecked()){
|
||
flag = 1;
|
||
ConfiguraitonsObj = SelectChannel(6);
|
||
|
||
}else if(ui->radioButton_5->isChecked()){
|
||
flag = 1;
|
||
ConfiguraitonsObj = SelectChannel(7);
|
||
|
||
}else if(ui->radioButton_6->isChecked()){
|
||
flag = 1;
|
||
ConfiguraitonsObj = SelectChannel(8);
|
||
|
||
}else if(ui->radioButton_7->isChecked()){
|
||
flag = 1;
|
||
ConfiguraitonsObj = SelectChannel(9);
|
||
|
||
}else if(ui->radioButton_8->isChecked()){
|
||
flag = 1;
|
||
ConfiguraitonsObj = SelectChannel(10);
|
||
|
||
}else if(ui->radioButton_9->isChecked()){
|
||
flag = 1;
|
||
ConfiguraitonsObj = SelectChannel(11);
|
||
|
||
}else if(ui->radioButton_10->isChecked()){
|
||
flag = 1;
|
||
ConfiguraitonsObj = SelectChannel(12);
|
||
}
|
||
|
||
if(flag == -1){
|
||
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("请先选择继电器!"));
|
||
return;
|
||
}
|
||
m_isConfirm = 1;
|
||
if(model_Relay->rowCount() > 1){
|
||
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("请选择正确的组态逻辑"));
|
||
return;
|
||
}
|
||
for(int i = 0;i < model_Relay->rowCount() ;i++)
|
||
{
|
||
QStandardItem *item = model_Relay->item(i);
|
||
qDebug() <<"item = " << item->text();
|
||
QJsonArray arrayAll = GetItem(model_Relay->item(i));
|
||
if(arrayAll.size() < 1)
|
||
return;
|
||
logicObj[item->text().left(7)] = arrayAll;
|
||
logicExpressArray.append(logicObj);
|
||
}
|
||
ConfiguraitonsObj["logicExpress"] = logicExpressArray;
|
||
ConfiguraitonsArray.append(ConfiguraitonsObj);
|
||
QJsonArray().swap(m_array);
|
||
QJsonArray().swap(m_arrayAll);
|
||
|
||
|
||
|
||
if(ui->lineEdit_2->text() == "")
|
||
ConfiguraitonsWCObj["SecondDelaySeconds"] = "0";
|
||
else
|
||
ConfiguraitonsWCObj["SecondDelaySeconds"] = ui->lineEdit_2->text();
|
||
|
||
|
||
|
||
QString strCurrentSN = "";
|
||
for (int i = 0; i < m_WorkCondition.size(); i++) {
|
||
if(m_WorkCondition[i].WorkConditionName == ui->comboBox_WC->currentText()){
|
||
ConfiguraitonsWCObj["SN"] = m_WorkCondition[i].SN;
|
||
strCurrentSN = m_WorkCondition[i].SN;
|
||
ConfiguraitonsWCObj["WorkConditionName"] = m_WorkCondition[i].WorkConditionName;
|
||
}
|
||
}
|
||
ConfiguraitonsWCObj["Configuraitons"] = ConfiguraitonsArray;
|
||
if(m_vecWorkConditionObj.size() > 0){
|
||
QVector<QJsonObject> vecWorkConditionObj = m_vecWorkConditionObj;
|
||
int flag = -1,flag2 = -1;
|
||
for (int i = 0; i < vecWorkConditionObj.size(); i++){
|
||
if(vecWorkConditionObj.at(i)["SN"].toString() == strCurrentSN){
|
||
flag = 1;
|
||
QJsonArray configuraitonsArray = vecWorkConditionObj.at(i)["Configuraitons"].toArray();
|
||
QJsonArray tempArray = configuraitonsArray;
|
||
for (int j = 0; j < configuraitonsArray.size(); j++) {
|
||
if(ConfiguraitonsObj["ChannelId"].toString() == configuraitonsArray.at(j)["ChannelId"].toString()){
|
||
flag2 = 1;
|
||
for (int ii = 0; ii < tempArray.size(); ii++) {
|
||
if(tempArray.at(ii)["ChannelId"].toString() == ConfiguraitonsObj["ChannelId"].toString()){
|
||
tempArray.removeAt(ii);
|
||
}
|
||
}
|
||
tempArray.append(ConfiguraitonsObj);
|
||
}
|
||
if(j + 1 == configuraitonsArray.size() && flag2 == -1){
|
||
tempArray.append(ConfiguraitonsObj);
|
||
}
|
||
}
|
||
ConfiguraitonsWCObj["Configuraitons"] = tempArray;
|
||
m_vecWorkConditionObj.removeAt(i);
|
||
m_vecWorkConditionObj.append(ConfiguraitonsWCObj);
|
||
}
|
||
if( i + 1 == vecWorkConditionObj.size() && flag == -1){
|
||
m_vecWorkConditionObj.append(ConfiguraitonsWCObj);
|
||
}
|
||
}
|
||
}else{
|
||
m_vecWorkConditionObj.append(ConfiguraitonsWCObj);
|
||
}
|
||
}
|
||
|
||
|
||
void CConfiguration::on_comboBox_WC_currentTextChanged2(const QString &arg1)
|
||
{
|
||
qDebug() << "on_comboBox_WC_currentTextChanged" << endl;
|
||
for(int i = 0;i < model_Available->rowCount() ;i++){
|
||
QStandardItem *item = model_Available->item(i);
|
||
if(item->text() == "Operand"){
|
||
if(item->hasChildren()){
|
||
for(int ii = 0;ii < item->rowCount() ;ii++){
|
||
item->removeRow(ii);
|
||
}
|
||
}
|
||
model_Available->removeRow(i);
|
||
}
|
||
}
|
||
for(int i = 0;i < model_Available->rowCount() ;i++){
|
||
model_Relay->removeRow(i);
|
||
}
|
||
|
||
QStandardItem* item2 = new QStandardItem("Operand");
|
||
model_Available->appendRow(item2);
|
||
for (int i = 0; i < arrayTriggerConfig.size(); i++) {
|
||
if(arg1 == arrayTriggerConfig.at(i)["workConditionName"].toString()){
|
||
QJsonArray TriggerSettings = arrayTriggerConfig.at(i)["triggerSettings"].toArray();
|
||
for (int j = 0; j < TriggerSettings.size(); j++){
|
||
QString channelName = TriggerSettings.at(j)["channelName"].toString();
|
||
QStandardItem *itemChannel = new QStandardItem(QString(channelName));
|
||
itemChannel->setDragEnabled(false);
|
||
itemChannel->setDropEnabled(false);
|
||
QJsonArray arrayConfig = TriggerSettings.at(j)["triggerConfig"].toArray();
|
||
if(arrayConfig.size() > 0){
|
||
item2->appendRow(itemChannel);
|
||
for (int k = 0; k < arrayConfig.size(); k++){
|
||
QString str = arrayConfig.at(k)["triggerEventName"].toString();
|
||
QStandardItem *item = NULL;
|
||
int xAlertOverEnabled = arrayConfig.at(k)["xAlertOverEnabled"].toInt();
|
||
int xAlertUnderEnabled = arrayConfig.at(k)["xAlertUnderEnabled"].toInt();
|
||
int xDangerOverEnabled = arrayConfig.at(k)["xDangerOverEnabled"].toInt();
|
||
int xDangerUnderEnabled = arrayConfig.at(k)["xDangerUnderEnabled"].toInt();
|
||
if(xAlertOverEnabled == 1){
|
||
item = new QStandardItem(QString(channelName + "-" + str + "-Over-"+"警报"));
|
||
itemChannel->appendRow(item);
|
||
}
|
||
if(xAlertUnderEnabled == 1){
|
||
item = new QStandardItem(QString(channelName + "-" + str + "-Under-"+"警报"));
|
||
itemChannel->appendRow(item);
|
||
}
|
||
if(xDangerOverEnabled == 1){
|
||
item = new QStandardItem(QString(channelName + "-" + str + "-Over-"+"危险"));
|
||
itemChannel->appendRow(item);
|
||
}
|
||
if(xDangerUnderEnabled == 1){
|
||
item = new QStandardItem(QString(channelName + "-" + str + "-Under-"+"危险"));
|
||
itemChannel->appendRow(item);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
void CConfiguration::PushData()
|
||
{
|
||
if(m_isConfirm == -1){
|
||
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("请先点击\"应用\"!"));
|
||
return ;
|
||
}
|
||
m_isConfirm = -1;
|
||
|
||
if(m_vecWorkConditionObj.size() > 0){
|
||
for (int i = 0; i < m_vecWorkConditionObj.size(); i++) {
|
||
m_WorkConditionConfiguraitonsArray.append(m_vecWorkConditionObj[i]);
|
||
}
|
||
}else{
|
||
m_WorkConditionConfiguraitonsArray.append(m_ConfiguraitonsWCObj);
|
||
}
|
||
|
||
|
||
QJsonObject WorkConditionConfiguraitonsObj;
|
||
WorkConditionConfiguraitonsObj["WorkConditionConfiguraitons"] = m_WorkConditionConfiguraitonsArray;
|
||
//qDebug() << WorkConditionConfiguraitonsObj << endl;
|
||
|
||
QJsonDocument jsonDoc;
|
||
jsonDoc.setObject(WorkConditionConfiguraitonsObj);
|
||
QString fileName = QCoreApplication::applicationDirPath() + "\\config\\UnitConfigurations.json";
|
||
|
||
QFile file(fileName);
|
||
file.open(QIODevice::WriteOnly);
|
||
file.write(jsonDoc.toJson());
|
||
file.close();
|
||
|
||
QJsonArray().swap(m_WorkConditionConfiguraitonsArray);
|
||
QJsonArray().swap(m_array);
|
||
QJsonArray().swap(m_ConfiguraitonsArray);
|
||
//QVector<QJsonObject>().swap(m_vecWorkConditionObj);
|
||
|
||
QString str = QString("ftp://%1/CIDW/qtconfig/%2").arg(IP).arg("UnitConfigurations.json");
|
||
g_FtpClient->SetServerInfo(str);
|
||
g_FtpClient->SetUserInfo("root","@#cidw!@123456");
|
||
g_FtpClient->UpLoadFile(fileName,"UnitConfigurations.json");
|
||
|
||
}
|
||
|
||
|
||
void CConfiguration::on_comboBox_WC_currentIndexChanged(const QString &arg1)
|
||
{
|
||
for (int i = 0; i < m_vecWorkConditionObj.size(); i++) {
|
||
QJsonObject tempObj = m_vecWorkConditionObj[i];
|
||
if(ui->comboBox_WC->currentText() == tempObj["WorkConditionName"].toString()){
|
||
QJsonArray tempArray = tempObj["Configuraitons"].toArray();
|
||
for (int j = 0;j < tempArray.size() ;j++ ) {
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
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){
|
||
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++){
|
||
// model_Relay->removeRow(i);
|
||
// }
|
||
// 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();
|
||
// for (int j = 0;j < tempArray.size() ;j++ ) {
|
||
// if(tempArray.at(j)["ChannelNoInBoard"] == ChannelNoInBoard){
|
||
// 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"));
|
||
// 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);
|
||
// itemOr->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);
|
||
// 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);
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
}
|
||
|
||
void CConfiguration::on_radioButton_1_clicked()
|
||
{
|
||
|
||
ViewRelay(3);
|
||
}
|
||
|
||
|
||
void CConfiguration::on_radioButton_2_clicked()
|
||
{
|
||
ViewRelay(4);
|
||
}
|
||
|
||
|
||
void CConfiguration::on_radioButton_3_clicked()
|
||
{
|
||
ViewRelay(5);
|
||
}
|
||
|
||
|
||
void CConfiguration::on_radioButton_4_clicked()
|
||
{
|
||
ViewRelay(6);
|
||
}
|
||
|
||
|
||
void CConfiguration::on_radioButton_5_clicked()
|
||
{
|
||
ViewRelay(7);
|
||
}
|
||
|
||
|
||
void CConfiguration::on_radioButton_6_clicked()
|
||
{
|
||
ViewRelay(8);
|
||
}
|
||
|
||
|
||
void CConfiguration::on_radioButton_8_clicked()
|
||
{
|
||
ViewRelay(10);
|
||
}
|
||
|
||
|
||
void CConfiguration::on_radioButton_7_clicked()
|
||
{
|
||
ViewRelay(9);
|
||
}
|
||
|
||
|
||
void CConfiguration::on_radioButton_9_clicked()
|
||
{
|
||
ViewRelay(11);
|
||
}
|
||
|
||
|
||
void CConfiguration::on_radioButton_10_clicked()
|
||
{
|
||
ViewRelay(12);
|
||
}
|
||
|
||
|
||
void CConfiguration::on_treeView_Available_pressed(const QModelIndex &index)
|
||
{
|
||
|
||
}
|
||
|