diff --git a/HanddleAI/HandleAiUi-new/front/pages/configSettingWidget.h b/HanddleAI/HandleAiUi-new/front/pages/configSettingWidget.h index 32ab0fdc..8fff5d1d 100644 --- a/HanddleAI/HandleAiUi-new/front/pages/configSettingWidget.h +++ b/HanddleAI/HandleAiUi-new/front/pages/configSettingWidget.h @@ -13,11 +13,13 @@ #include #include #include +#include +#include +#include /**************格式****************/ //... //{ -// "className":"className",//大类名 // "showName":"Name", //仅显示 // "valueName":"Name2",//检索 // "value":"value" //值 @@ -25,35 +27,10 @@ // } // ... /***********************************/ -class simpleJsonSearch : public std::unordered_map < QString, std::unordered_map> -{ - //对于此界面来说,第一层QString为按钮名,如通用设置 - //第二层为其子项,QString为valuename,QString为值 -public: - void insertData(QString btnName, QString valueName,QVariant data) - { - if (this->find(btnName) == this->end()) - this->insert({ btnName,std::unordered_map() }); - - auto mapData = this->find(btnName); - mapData->second.insert(std::make_pair(valueName, data)); - } - //第一层QString为按钮名,第二层为valuename - QVariant searchData(QString btnName, QString valueName) - { - auto it1=this->find(btnName); - if (it1 != this->end()) - { - auto it2 = it1->second.find(valueName); - if (it2 != it1->second.end()) - { - return it2->second; - } - } - return "notFind"; - } -}; - +static bool isNumeric(const QString& str) { + QRegExp re("^-?\\d+(\\.\\d+)?([eE][-+]?\\d+)?$"); + return re.exactMatch(str); +} class configSettingWidget :public QWidget { Q_OBJECT @@ -69,7 +46,6 @@ public: }; struct aLineData { - QString className; QString showName; QString valueName; QVariant value; @@ -81,8 +57,7 @@ public: std::vectorbtns; QLabel* icon, * Title; QStackedWidget* stackedWidgets; - simpleJsonSearch configJsonDatas; - + int currentPageIndex = 0; configSettingWidget() { QPalette palette; @@ -129,6 +104,14 @@ public: { switch (_formatPolicy) { + case number: + if (!isNumeric(compareStr)) + { + textOut = u8"格式错误,非数字"; + colorOut = "red"; + return true; + } + break; case filePath: if (QFile(compareStr).exists() == false) { @@ -164,7 +147,7 @@ public: } void addConfigWidget(QString btnText,QString jsonPath) { - int currentPageIndex = privateJsondatas.size(); + int thistPageIndex = privateJsondatas.size(); QPalette palette; palette.setColor(QPalette::WindowText, Qt::white); QFont font("微软雅黑", 13, QFont::Bold); @@ -180,9 +163,9 @@ public: for (auto btnPtr : btns) btnPtr->toDefault(); btn->pressed(); - stackedWidgets->setCurrentIndex(currentPageIndex); + currentPageIndex = thistPageIndex; + stackedWidgets->setCurrentIndex(thistPageIndex); }); - privateWidgets.push_back(std::vector()); //页面widget QWidget* widget = new QWidget(); @@ -215,111 +198,81 @@ public: jsonLayouts.push_back(jsonLayout); //参数列表读取以及初始化 - std::unordered_map> jsonData=loadJson(jsonPath); - privateJsondatas.push_back(jsonData); - int index = 0; - for (auto& classData : jsonData) + std::vector widgets; + std::vector< aLineData> jsonData=loadJson(jsonPath); + for (auto& data : jsonData) { - QString className = classData.first; - std::vector< aLineData> classDatas = classData.second; + QWidget* tempWidget = new QWidget(); + QVBoxLayout* tempVLayout = new QVBoxLayout(tempWidget); + tempVLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop); + tempVLayout->setContentsMargins(0, 0, 0, 0); - QWidget* classWidget = new QWidget(); - classWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - QVBoxLayout* classVLayout = new QVBoxLayout(classWidget); - classVLayout->setSpacing(0); - classVLayout->setContentsMargins(0, 0, 0, 0); + QLabel* showLabel = new QLabel(data.showName); + showLabel->setFont(font); + showLabel->setPalette(palette); + showLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop); - QLabel* label = new QLabel(className); - label->setFont(font3); - label->setPalette(palette); - label->setFixedHeight(50); - classVLayout->addWidget(label); + QLabel* warningLabel = new QLabel(""); + warningLabel->setFixedHeight(30); + warningLabel->setFont(font2); - for (auto& data : classDatas) + if (data._formatPolicy == boolType) { - QWidget* tempWidget = new QWidget(); - QVBoxLayout* tempVLayout = new QVBoxLayout(tempWidget); - tempVLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop); - tempVLayout->setContentsMargins(0, 0, 0, 0); + QCheckBox* checkBox = new QCheckBox(); + checkBox->setFont(font); + checkBox->setPalette(palette); + checkBox->setFixedWidth(500); - QLabel* showLabel = new QLabel(data.showName); - showLabel->setFont(font); - showLabel->setPalette(palette); - showLabel->setAlignment(Qt::AlignLeft|Qt::AlignTop); + QHBoxLayout* tempLayout = new QHBoxLayout(); - QLabel* warningLabel = new QLabel(""); - warningLabel->setFixedHeight(30); - warningLabel->setFont(font2); + tempLayout->addWidget(showLabel); + tempLayout->addWidget(checkBox); + tempVLayout->addLayout(tempLayout); - if (data._formatPolicy == boolType) - { - QCheckBox* checkBox = new QCheckBox(); - checkBox->setFont(font); - checkBox->setPalette(palette); - checkBox->setFixedWidth(500); - - QHBoxLayout* tempLayout = new QHBoxLayout(); - - tempLayout->addWidget(showLabel); - tempLayout->addWidget(checkBox); - tempVLayout->addLayout(tempLayout); + tempVLayout->addWidget(warningLabel); + } + else + { + QLineEdit* lineEdit = new QLineEdit(data.value.toString()); + lineEdit->setFont(font); + lineEdit->setPalette(palette); + lineEdit->setFixedWidth(500); - tempVLayout->addWidget(warningLabel); - } - else - { - QLineEdit* lineEdit = new QLineEdit(data.value.toString()); - lineEdit->setFont(font); - lineEdit->setPalette(palette); - lineEdit->setFixedWidth(500); - - tempVLayout->addWidget(showLabel); - tempVLayout->addWidget(lineEdit); - tempVLayout->addWidget(warningLabel); - //修改时警告 - connect(lineEdit, &QLineEdit::textChanged, [=]() + tempVLayout->addWidget(showLabel); + tempVLayout->addWidget(lineEdit); + tempVLayout->addWidget(warningLabel); + //修改时警告 + connect(lineEdit, &QLineEdit::textChanged, [=]() + { + if (lineEdit->text().compare(data.value.toString()))//修改后的值不匹配 { - if (lineEdit->text().compare(data.value.toString()))//修改后的值不匹配 + QString text, color; + if (formatPolicyCompare(data._formatPolicy, lineEdit->text(), text, color)) { - QString text, color; - if (formatPolicyCompare(data._formatPolicy, lineEdit->text(), text, color)) - { - warningLabel->setText(text); - warningLabel->setStyleSheet(QString("color:%1;").arg(color)); - lineEdit->setStyleSheet(QString("border: 2px solid %1;").arg(color)); - } - else - { - warningLabel->setText("此项被修改!"); - warningLabel->setStyleSheet("color:yellow"); - lineEdit->setStyleSheet("border: 2px solid yellow;"); - } + warningLabel->setText(text); + warningLabel->setStyleSheet(QString("color:%1;").arg(color)); + lineEdit->setStyleSheet(QString("border: 2px solid %1;").arg(color)); } else { - warningLabel->setText(""); - lineEdit->setStyleSheet(""); - warningLabel->setText(""); + warningLabel->setText("此项被修改!"); + warningLabel->setStyleSheet("color:yellow"); + lineEdit->setStyleSheet("border: 2px solid yellow;"); } - }); - } - tempWidget->setFixedHeight(100); - classVLayout->addWidget(tempWidget); + } + else + { + warningLabel->setText(""); + lineEdit->setStyleSheet(""); + warningLabel->setText(""); + } + }); } - // json数据 - for (auto& classData : jsonData) - { - std::vector< aLineData> classDatas = classData.second; - for (auto& data : classDatas) - configJsonDatas.insertData(btnText,data.valueName,data.value); - } - setMinimumSizePolicy(classWidget); - classWidget->adjustSize(); - classWidget->setFixedSize(classWidget->size()); - privateWidgets[currentPageIndex].push_back(classWidget); - //jsonLayout->addWidget(classWidget,index,0); - index++; + tempWidget->setFixedHeight(100); + widgets.push_back(tempWidget); + jsonLayout->addWidget(tempWidget); } + privateWidgets.push_back(widgets); //保存按钮 fancyButtonText* saveBtn = new fancyButtonText(160, 50, u8"保存", u8"保存当前配置文件"); connect(saveBtn, &QPushButton::clicked, this, [=]() {saveJson(jsonPath); }); @@ -335,138 +288,118 @@ public: } } //读取json - std::unordered_map> loadJson(const QString& fileName) { - QFile file(fileName); - std::unordered_map> returnDatas; - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - //QMessageBox::warning(this, tr(u8"路径失效!!!"), tr(fileName.toStdString().c_str())); - return returnDatas; + std::vector< aLineData> loadJson(const QString& fileName) { + std::vector< aLineData> returnData; + nlohmann::json json = readJsonFromPath(fileName.toStdString()); + for (auto data : json) + { + aLineData lineData; + std::string policyStr = data["policy"]; + std::string showName = data["showName"]; + std::string value = data["value"]; + std::string valueName = data["valueName"]; + formatPolicy _formatPolicy = formatPolicy::none; + if (!policyStr.compare("filepath")) + _formatPolicy = filePath; + else if (!policyStr.compare("bhdpath")) + _formatPolicy = bhdPath; + else if (!policyStr.compare("ip")) + _formatPolicy = IP; + else if (!policyStr.compare("number")) + _formatPolicy = number; + else if (!policyStr.compare("bool")) + _formatPolicy = boolType; + + lineData.showName = QString::fromStdString(showName); + lineData._formatPolicy = _formatPolicy; + lineData.value = QString::fromStdString(value); + lineData.valueName = QString::fromStdString(valueName); + returnData.push_back(lineData); } - QByteArray jsonData = file.readAll(); - QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData); - QJsonArray jsonArray = jsonDoc.array(); - for (const QJsonValue& value : jsonArray) { - if (value.isObject()) { - QJsonObject obj = value.toObject(); - QString className = obj.value("className").toString(); - QString showName = obj.value("showName").toString(); - QString valueName = obj.value("valueName").toString(); - QString valueStr = obj.value("value").toString(); - QString policyStr = obj.value("policy").toString().toLower(); - formatPolicy _formatPolicy = formatPolicy::none; - if (policyStr.contains("filepath")) - _formatPolicy = filePath; - else if (policyStr.contains("bhdpath")) - _formatPolicy = bhdPath; - else if (policyStr.contains("ip")) - _formatPolicy = IP; - else if (policyStr.contains("number")) - _formatPolicy = number; - else if (policyStr.contains("bool")) - _formatPolicy = boolType; - - //无分类 - if (className == "") - className = "none"; - - if (returnDatas.find(className) == returnDatas.end()) - returnDatas.insert({ className ,std::vector< aLineData>() }); - - auto classVec = returnDatas.find(className); - classVec->second.push_back({ className, showName ,valueName ,valueStr ,policyStr ,_formatPolicy }); - } - } - file.close(); - return returnDatas; + return returnData; } void updateLayout() { - for (int widgetIndex = 0; widgetIndex < privateWidgets.size(); widgetIndex++) + QMainWindow* mainWindow = qobject_cast(this->window()); + QSize stackedWidgetSize = mainWindow->size(); + int xCount = stackedWidgetSize.width() / 600; + if (xCount == 0) + return; + int eachWidth = stackedWidgetSize.width() / xCount; + std::vectoreachHeightCount(xCount, 0); + std::vectoreachHeightIndexCount(xCount, 0); + if (xCount == 1) { - QMainWindow* mainWindow = qobject_cast(this->window()); - QSize stackedWidgetSize = mainWindow->size(); - //QSize stackedWidgetSize = stackedWidgets->size(); - std::vector widgets = privateWidgets[widgetIndex]; - int xCount = stackedWidgetSize.width() / 600; - if (xCount == 0) - continue; - int eachWidth = stackedWidgetSize.width() / xCount; - std::vectoreachHeightCount(xCount,0); - std::vectoreachHeightIndexCount(xCount, 0); - if (xCount == 1) - { - for (int i = 0; i < widgets.size(); i++) - jsonLayouts[widgetIndex]->addWidget(widgets[i], i, 0); - continue; - } - for (int i = 0; i < widgets.size(); i++) - { - int xIndex = 0; - for (xIndex = eachHeightCount.size() - 1; xIndex > 0; xIndex--) - if (eachHeightCount[xIndex - 1] > eachHeightCount[xIndex]) - { - break; - } - eachHeightCount[xIndex] += widgets[i]->size().height(); - jsonLayouts[widgetIndex]->addWidget(widgets[i], eachHeightIndexCount[xIndex], xIndex); - eachHeightIndexCount[xIndex]++; - } + for (int i = 0; i < privateWidgets[currentPageIndex].size(); i++) + jsonLayouts[currentPageIndex]->addWidget(privateWidgets[currentPageIndex][i], i, 0); + } + for (int i = 0; i < privateWidgets[currentPageIndex].size(); i++) + { + int xIndex = 0; + for (xIndex = eachHeightCount.size() - 1; xIndex > 0; xIndex--) + if (eachHeightCount[xIndex - 1] > eachHeightCount[xIndex]) + { + break; + } + eachHeightCount[xIndex] += privateWidgets[currentPageIndex][i]->size().height(); + jsonLayouts[currentPageIndex]->addWidget(privateWidgets[currentPageIndex][i], eachHeightIndexCount[xIndex], xIndex); + eachHeightIndexCount[xIndex]++; } //jsonLayout->addLayout(classVLayout, jsonDataIndex, 0); } void saveJson(QString path) { // 构建 JSON 对象 - QJsonArray jsonArray; - for (auto& classData : privateJsondatas) - { - for(auto& jsonData: classData) - for (auto& data : jsonData.second) - { - QJsonObject obj1; - obj1["className"] = data.className; - obj1["showName"] = data.showName; - obj1["valueName"] = data.valueName; + //QJsonArray jsonArray; + //for (auto& classData : privateJsondatas) + //{ + // for(auto& jsonData: classData) + // for (auto& data : jsonData.second) + // { + // QJsonObject obj1; + // obj1["className"] = data.className; + // obj1["showName"] = data.showName; + // obj1["valueName"] = data.valueName; - switch (data.value.type()) { - case QVariant::Bool: - obj1["value"] = data.value.toBool(); - break; - case QVariant::Int: - obj1["value"] = data.value.toInt(); - break; - case QVariant::Double: - obj1["value"] = data.value.toDouble(); - break; - case QVariant::String: - obj1["value"] = data.value.toString(); - break; - default: - obj1["value"] = "error"; - break; - } + // switch (data.value.type()) { + // case QVariant::Bool: + // obj1["value"] = data.value.toBool(); + // break; + // case QVariant::Int: + // obj1["value"] = data.value.toInt(); + // break; + // case QVariant::Double: + // obj1["value"] = data.value.toDouble(); + // break; + // case QVariant::String: + // obj1["value"] = data.value.toString(); + // break; + // default: + // obj1["value"] = "error"; + // break; + // } - obj1["policy"] = data.formatPolicyStr; - jsonArray.append(obj1); - } - } - std::string sss = path.toStdString(); + // obj1["policy"] = data.formatPolicyStr; + // jsonArray.append(obj1); + // } + //} + //std::string sss = path.toStdString(); - QJsonDocument jsonDocument(jsonArray); + //QJsonDocument jsonDocument(jsonArray); - // 保存 JSON 文档到文件 - QFile file(path); - if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { - QTextStream out(&file); - out.setCodec("UTF-8"); - out << jsonDocument.toJson(); - file.close(); - QMessageBox::information(this, "成功", ""); - qDebug() << "JSON 文件保存成功"; - } - else { - qDebug() << "无法保存 JSON 文件"; - } + //// 保存 JSON 文档到文件 + //QFile file(path); + //if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { + // QTextStream out(&file); + // out.setCodec("UTF-8"); + // out << jsonDocument.toJson(); + // file.close(); + // QMessageBox::information(this, "成功", ""); + // qDebug() << "JSON 文件保存成功"; + //} + //else { + // qDebug() << "无法保存 JSON 文件"; + //} } protected: void resizeEvent(QResizeEvent* event) override { @@ -475,7 +408,7 @@ protected: } private: - std::vector>> privateJsondatas;//路径与数据 + std::vector> privateJsondatas;//路径与数据 std::vector> privateWidgets;//路径与数据 std::vectorjsonLayouts; }; diff --git a/HanddleAI/HandleAiUi-new/globalStruct.h b/HanddleAI/HandleAiUi-new/globalStruct.h index 6cfa7508..bf917186 100644 --- a/HanddleAI/HandleAiUi-new/globalStruct.h +++ b/HanddleAI/HandleAiUi-new/globalStruct.h @@ -17,8 +17,8 @@ #define sColor_Black "22, 22, 22" #define sColor_BlackWithWhite "45, 45, 45" -#define enableHandleAiModel 1 -#define disableBackEndCheck 0 +#define enableHandleAiModel 0 +#define disableBackEndCheck 1 #define disableeAlgo 0 //绐楀彛璁剧疆 diff --git a/HanddleAI/HandleAiUi-new/uiModule/components/fancyWarnWindow.h b/HanddleAI/HandleAiUi-new/uiModule/components/fancyWarnWindow.h index 25ad2ad0..176f236f 100644 --- a/HanddleAI/HandleAiUi-new/uiModule/components/fancyWarnWindow.h +++ b/HanddleAI/HandleAiUi-new/uiModule/components/fancyWarnWindow.h @@ -13,7 +13,7 @@ public: { Warning, tip - }; + }; QPushButton* closeBtn = new QPushButton(this); fancyButtonText* continueBtn = new fancyButtonText(120,60,"继续","继续"); fancyWarnWindow(type typeIn,QString title,QString detail) diff --git a/lib/Hd_3DCameraLMI_module_PointLazer.exp b/lib/Hd_3DCameraLMI_module_PointLazer.exp index b70953a7..83d8b980 100644 Binary files a/lib/Hd_3DCameraLMI_module_PointLazer.exp and b/lib/Hd_3DCameraLMI_module_PointLazer.exp differ diff --git a/lib/Hd_3DCameraLMI_module_PointLazer.lib b/lib/Hd_3DCameraLMI_module_PointLazer.lib index b506c2ad..b04150d6 100644 Binary files a/lib/Hd_3DCameraLMI_module_PointLazer.lib and b/lib/Hd_3DCameraLMI_module_PointLazer.lib differ diff --git a/lib/Hd_DalsaCamera_module.exp b/lib/Hd_DalsaCamera_module.exp index 9c60276f..efae2b9e 100644 Binary files a/lib/Hd_DalsaCamera_module.exp and b/lib/Hd_DalsaCamera_module.exp differ diff --git a/lib/Hd_DalsaCamera_module.lib b/lib/Hd_DalsaCamera_module.lib index c271a24e..9c451b2e 100644 Binary files a/lib/Hd_DalsaCamera_module.lib and b/lib/Hd_DalsaCamera_module.lib differ diff --git a/lib/Hd_FinsTcp_module.exp b/lib/Hd_FinsTcp_module.exp index 2ba9e5fa..3de4f63b 100644 Binary files a/lib/Hd_FinsTcp_module.exp and b/lib/Hd_FinsTcp_module.exp differ diff --git a/lib/Hd_FinsTcp_module.lib b/lib/Hd_FinsTcp_module.lib index e7784b3e..f679fdae 100644 Binary files a/lib/Hd_FinsTcp_module.lib and b/lib/Hd_FinsTcp_module.lib differ diff --git a/lib/Hd_MvCamera_module_GENTL.exp b/lib/Hd_MvCamera_module_GENTL.exp index 5b9c4dde..d4933722 100644 Binary files a/lib/Hd_MvCamera_module_GENTL.exp and b/lib/Hd_MvCamera_module_GENTL.exp differ diff --git a/lib/Hd_MvCamera_module_GENTL.lib b/lib/Hd_MvCamera_module_GENTL.lib index 4010f0a3..578b535e 100644 Binary files a/lib/Hd_MvCamera_module_GENTL.lib and b/lib/Hd_MvCamera_module_GENTL.lib differ diff --git a/lib/Hd_MvCamera_module_GIGE.exp b/lib/Hd_MvCamera_module_GIGE.exp index f1841164..3dad3e86 100644 Binary files a/lib/Hd_MvCamera_module_GIGE.exp and b/lib/Hd_MvCamera_module_GIGE.exp differ diff --git a/lib/Hd_MvCamera_module_GIGE.lib b/lib/Hd_MvCamera_module_GIGE.lib index 110ae8d7..f5ba12df 100644 Binary files a/lib/Hd_MvCamera_module_GIGE.lib and b/lib/Hd_MvCamera_module_GIGE.lib differ diff --git a/lib/Hd_ResultsSummary_module.exp b/lib/Hd_ResultsSummary_module.exp index 4426c915..b54e9ed3 100644 Binary files a/lib/Hd_ResultsSummary_module.exp and b/lib/Hd_ResultsSummary_module.exp differ diff --git a/lib/Hd_ResultsSummary_module.lib b/lib/Hd_ResultsSummary_module.lib index 8baafc1c..ff33633f 100644 Binary files a/lib/Hd_ResultsSummary_module.lib and b/lib/Hd_ResultsSummary_module.lib differ diff --git a/lib/Hd_SocketModule_ModbusTcp.exp b/lib/Hd_SocketModule_ModbusTcp.exp index e9596cc0..b95b63b1 100644 Binary files a/lib/Hd_SocketModule_ModbusTcp.exp and b/lib/Hd_SocketModule_ModbusTcp.exp differ diff --git a/lib/Hd_SocketModule_ModbusTcp.lib b/lib/Hd_SocketModule_ModbusTcp.lib index b3ff8f19..7d987e79 100644 Binary files a/lib/Hd_SocketModule_ModbusTcp.lib and b/lib/Hd_SocketModule_ModbusTcp.lib differ