修复配置设置
This commit is contained in:
@@ -10,6 +10,10 @@
|
||||
#include <qscrollarea.h>
|
||||
#include <qcheckbox.h>
|
||||
#include <unordered_map>
|
||||
#include <qobject.h>
|
||||
#include <qmainwindow.h>
|
||||
#include <qmessagebox.h>
|
||||
|
||||
/**************格式****************/
|
||||
//...
|
||||
//{
|
||||
@@ -48,6 +52,7 @@ public:
|
||||
|
||||
class configSettingWidget :public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum formatPolicy
|
||||
{
|
||||
@@ -71,7 +76,7 @@ public:
|
||||
QHBoxLayout* btnLayout;
|
||||
std::vector<gradientButton*>btns;
|
||||
QLabel* icon, * Title;
|
||||
QStackedWidget* widgets;
|
||||
QStackedWidget* stackedWidgets;
|
||||
simpleJsonSearch jsonDatas;
|
||||
|
||||
|
||||
@@ -81,9 +86,9 @@ public:
|
||||
palette.setColor(QPalette::WindowText, Qt::white);
|
||||
QFont font("微软雅黑", 24, QFont::Bold);
|
||||
|
||||
widgets = new QStackedWidget();
|
||||
widgets->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
widgets->setMaximumSize(9999, 9999);
|
||||
stackedWidgets = new QStackedWidget();
|
||||
stackedWidgets->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
stackedWidgets->setMaximumSize(9999, 9999);
|
||||
|
||||
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
this->setMaximumSize(9999, 9999);
|
||||
@@ -114,7 +119,7 @@ public:
|
||||
addConfigWidget(u8"模型设置","");
|
||||
btns[0]->pressed();
|
||||
|
||||
Layout->addWidget(widgets);
|
||||
Layout->addWidget(stackedWidgets);
|
||||
}
|
||||
//格式检查
|
||||
bool formatPolicyCompare(formatPolicy _formatPolicy,QString compareStr,QString& textOut,QString &colorOut)
|
||||
@@ -154,7 +159,6 @@ public:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void addConfigWidget(QString btnText,QString jsonPath)
|
||||
{
|
||||
int currentPageIndex = privateJsondatas.size();
|
||||
@@ -173,12 +177,13 @@ public:
|
||||
for (auto btnPtr : btns)
|
||||
btnPtr->toDefault();
|
||||
btn->pressed();
|
||||
widgets->setCurrentIndex(currentPageIndex);
|
||||
stackedWidgets->setCurrentIndex(currentPageIndex);
|
||||
});
|
||||
privateWidgets.push_back(std::vector<QWidget*>());
|
||||
|
||||
//页面widget
|
||||
QWidget* widget = new QWidget();
|
||||
widgets->addWidget(widget);
|
||||
stackedWidgets->addWidget(widget);
|
||||
widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
QVBoxLayout* widgetLayout = new QVBoxLayout(widget);
|
||||
@@ -200,135 +205,129 @@ public:
|
||||
"border-radius: 0px;}");
|
||||
jsonWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
jsonWidget->setMaximumSize(9999 , 9999);
|
||||
QHBoxLayout* jsonLayout = new QHBoxLayout(jsonWidget);
|
||||
QGridLayout* jsonLayout = new QGridLayout(jsonWidget);
|
||||
jsonLayout->setAlignment(Qt::AlignTop);
|
||||
jsonLayout->setContentsMargins(0, 0, 0, 0);
|
||||
scrollArea->setWidget(jsonWidget);
|
||||
|
||||
//左边用来显示小项
|
||||
QVBoxLayout* jsonLayoutLeft = new QVBoxLayout();
|
||||
jsonLayoutLeft->setContentsMargins(0, 0, 0, 0);
|
||||
jsonLayoutLeft->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
jsonLayout->addLayout(jsonLayoutLeft);
|
||||
//右边显示包含类的
|
||||
QVBoxLayout* jsonLayoutRight = new QVBoxLayout();
|
||||
jsonLayoutRight->setContentsMargins(0, 0, 0, 0);
|
||||
jsonLayoutRight->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
jsonLayout->addLayout(jsonLayoutRight);
|
||||
jsonLayouts.push_back(jsonLayout);
|
||||
|
||||
//参数列表读取以及初始化
|
||||
std::vector< aLineData> jsonData=loadJson(jsonPath);
|
||||
std::unordered_map<QString, std::vector< aLineData>> jsonData=loadJson(jsonPath);
|
||||
privateJsondatas.push_back(jsonData);
|
||||
std::vector<QString>classLabelsText;//防止重复
|
||||
for (auto data : jsonData)
|
||||
int index = 0;
|
||||
for (auto& classData : jsonData)
|
||||
{
|
||||
QVBoxLayout* tempVLayout = new QVBoxLayout();
|
||||
tempVLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
tempVLayout->setContentsMargins(0, 0, 0, 0);
|
||||
QString className = classData.first;
|
||||
std::vector< aLineData> classDatas = classData.second;
|
||||
|
||||
bool left = true;
|
||||
//类标题添加
|
||||
if (data.className != "")
|
||||
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* label = new QLabel(className);
|
||||
label->setFont(font3);
|
||||
label->setPalette(palette);
|
||||
label->setFixedHeight(50);
|
||||
classVLayout->addWidget(label);
|
||||
|
||||
for (auto& data : classDatas)
|
||||
{
|
||||
bool notCompared = false;
|
||||
left = false;
|
||||
for (auto str : classLabelsText)
|
||||
QWidget* tempWidget = new QWidget();
|
||||
QVBoxLayout* tempVLayout = new QVBoxLayout(tempWidget);
|
||||
tempVLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
tempVLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
QLabel* showLabel = new QLabel(data.showName);
|
||||
showLabel->setFont(font);
|
||||
showLabel->setPalette(palette);
|
||||
showLabel->setAlignment(Qt::AlignLeft|Qt::AlignTop);
|
||||
|
||||
QLabel* warningLabel = new QLabel("");
|
||||
warningLabel->setFixedHeight(30);
|
||||
warningLabel->setFont(font2);
|
||||
|
||||
if (data._formatPolicy == boolType)
|
||||
{
|
||||
if (!data.className.compare(str))
|
||||
{
|
||||
notCompared = true;
|
||||
break;
|
||||
}
|
||||
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);
|
||||
}
|
||||
if (notCompared == false)
|
||||
else
|
||||
{
|
||||
QLabel* label = new QLabel(data.className);
|
||||
label->setFont(font3);
|
||||
label->setPalette(palette);
|
||||
tempVLayout->addWidget(label);
|
||||
classLabelsText.push_back(data.className);
|
||||
}
|
||||
}
|
||||
QLineEdit* lineEdit = new QLineEdit(data.value.toString());
|
||||
lineEdit->setFont(font);
|
||||
lineEdit->setPalette(palette);
|
||||
lineEdit->setFixedWidth(500);
|
||||
|
||||
QLabel* showLabel = new QLabel(data.showName);
|
||||
showLabel->setFont(font);
|
||||
showLabel->setPalette(palette);
|
||||
showLabel->setAlignment(Qt::AlignLeft|Qt::AlignTop);
|
||||
|
||||
QLabel* warningLabel = new QLabel("");
|
||||
warningLabel->setFixedHeight(30);
|
||||
warningLabel->setFont(font2);
|
||||
|
||||
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(showLabel);
|
||||
tempVLayout->addWidget(lineEdit);
|
||||
tempVLayout->addWidget(warningLabel);
|
||||
//修改时警告
|
||||
connect(lineEdit, &QLineEdit::textChanged, [=]()
|
||||
{
|
||||
if (lineEdit->text().compare(data.value.toString()))//修改后的值不匹配
|
||||
tempVLayout->addWidget(showLabel);
|
||||
tempVLayout->addWidget(lineEdit);
|
||||
tempVLayout->addWidget(warningLabel);
|
||||
//修改时警告
|
||||
connect(lineEdit, &QLineEdit::textChanged, [=]()
|
||||
{
|
||||
QString text, color;
|
||||
if (formatPolicyCompare(data._formatPolicy, lineEdit->text(), text, color))
|
||||
if (lineEdit->text().compare(data.value.toString()))//修改后的值不匹配
|
||||
{
|
||||
warningLabel->setText(text);
|
||||
warningLabel->setStyleSheet(QString("color:%1;").arg(color));
|
||||
lineEdit->setStyleSheet(QString("border: 2px solid %1;").arg(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;");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
warningLabel->setText("此项被修改!");
|
||||
warningLabel->setStyleSheet("color:yellow");
|
||||
lineEdit->setStyleSheet("border: 2px solid yellow;");
|
||||
warningLabel->setText("");
|
||||
lineEdit->setStyleSheet("");
|
||||
warningLabel->setText("");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
warningLabel->setText("");
|
||||
lineEdit->setStyleSheet("");
|
||||
warningLabel->setText("");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
tempWidget->setFixedHeight(100);
|
||||
classVLayout->addWidget(tempWidget);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(left==true)
|
||||
jsonLayoutLeft->addLayout(tempVLayout);
|
||||
else
|
||||
jsonLayoutRight->addLayout(tempVLayout);
|
||||
|
||||
setMinimumSizePolicy(classWidget);
|
||||
classWidget->adjustSize();
|
||||
classWidget->setFixedSize(classWidget->size());
|
||||
privateWidgets[currentPageIndex].push_back(classWidget);
|
||||
//jsonLayout->addWidget(classWidget,index,0);
|
||||
index++;
|
||||
}
|
||||
|
||||
//保存按钮
|
||||
fancyButtonText* saveBtn = new fancyButtonText(160, 50, u8"保存", u8"保存当前配置文件");
|
||||
connect(saveBtn, &QPushButton::clicked, this, [=]() {saveJson(jsonPath); });
|
||||
widgetLayout->addWidget(saveBtn);
|
||||
}
|
||||
|
||||
void setMinimumSizePolicy(QWidget* widget) {
|
||||
widget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
for (QObject* child : widget->children()) {
|
||||
QWidget* childWidget = qobject_cast<QWidget*>(child);
|
||||
if (childWidget) {
|
||||
setMinimumSizePolicy(childWidget);
|
||||
}
|
||||
}
|
||||
}
|
||||
//读取json
|
||||
std::vector< aLineData> loadJson(const QString& fileName) {
|
||||
std::unordered_map<QString, std::vector< aLineData>> loadJson(const QString& fileName) {
|
||||
QFile file(fileName);
|
||||
std::vector < aLineData> returnDatas;
|
||||
std::unordered_map<QString, std::vector < aLineData>> returnDatas;
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
//QMessageBox::warning(this, tr(u8"路径失效!!!"), tr(fileName.toStdString().c_str()));
|
||||
return returnDatas;
|
||||
@@ -355,45 +354,91 @@ public:
|
||||
_formatPolicy = number;
|
||||
else if (policyStr.contains("bool"))
|
||||
_formatPolicy = boolType;
|
||||
returnDatas.push_back({ className, showName ,valueName ,valueStr ,policyStr ,_formatPolicy });
|
||||
|
||||
//无分类
|
||||
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;
|
||||
}
|
||||
|
||||
void updateLayout()
|
||||
{
|
||||
for (int widgetIndex = 0; widgetIndex < privateWidgets.size(); widgetIndex++)
|
||||
{
|
||||
QMainWindow* mainWindow = qobject_cast<QMainWindow*>(this->window());
|
||||
QSize stackedWidgetSize = mainWindow->size();
|
||||
//QSize stackedWidgetSize = stackedWidgets->size();
|
||||
std::vector<QWidget*> widgets = privateWidgets[widgetIndex];
|
||||
int xCount = stackedWidgetSize.width() / 600;
|
||||
if (xCount == 0)
|
||||
continue;
|
||||
int eachWidth = stackedWidgetSize.width() / xCount;
|
||||
std::vector<int>eachHeightCount(xCount,0);
|
||||
std::vector<int>eachHeightIndexCount(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]++;
|
||||
}
|
||||
}
|
||||
//jsonLayout->addLayout(classVLayout, jsonDataIndex, 0);
|
||||
}
|
||||
void saveJson(QString path)
|
||||
{
|
||||
// 构建 JSON 对象
|
||||
QJsonArray jsonArray;
|
||||
|
||||
for (auto data : privateJsondatas[0])
|
||||
for (auto& classData : privateJsondatas)
|
||||
{
|
||||
QJsonObject obj1;
|
||||
obj1["className"] = data.className;
|
||||
obj1["showName"] = data.showName;
|
||||
obj1["valueName"] = data.valueName;
|
||||
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;
|
||||
}
|
||||
|
||||
obj1["policy"] = data.formatPolicyStr;
|
||||
jsonArray.append(obj1);
|
||||
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();
|
||||
|
||||
@@ -413,7 +458,15 @@ public:
|
||||
qDebug() << "无法保存 JSON 文件";
|
||||
}
|
||||
}
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent* event) override {
|
||||
Q_UNUSED(event);
|
||||
QTimer::singleShot(0, this, &configSettingWidget::updateLayout);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector< std::vector< aLineData>> privateJsondatas;//路径与数据
|
||||
std::vector<std::unordered_map<QString, std::vector< aLineData>>> privateJsondatas;//路径与数据
|
||||
std::vector<std::vector<QWidget*>> privateWidgets;//路径与数据
|
||||
std::vector<QGridLayout*>jsonLayouts;
|
||||
};
|
||||
#pragma once
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user