2024-08-27 17:30:48 +08:00
|
|
|
#include "conf_setting.h"
|
2024-09-14 00:02:48 +08:00
|
|
|
|
2024-08-27 17:30:48 +08:00
|
|
|
#include "public_def.h"
|
|
|
|
#include "ui_conf_setting.h"
|
|
|
|
|
2025-04-03 13:39:36 +08:00
|
|
|
CGroupSetting::CGroupSetting(QWidget* parent, CGroupIni* oper) : QDialog(parent), ui(new Ui::CGroupSetting)
|
2024-08-27 17:30:48 +08:00
|
|
|
{
|
|
|
|
ini_opr_ = oper;
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
setWindowTitle(u8"配置编辑");
|
|
|
|
|
2025-04-03 13:39:36 +08:00
|
|
|
connect(ui->btnAddConfig, &QPushButton::clicked, this, [&]() { add_item(); });
|
|
|
|
connect(ui->btnDelConfig, &QPushButton::clicked, this, [&]() { del_item(); });
|
2024-08-27 17:30:48 +08:00
|
|
|
connect(ui->btnExit, &QPushButton::clicked, this, [&]() { close(); });
|
2025-04-03 13:39:36 +08:00
|
|
|
connect(ui->cbConfig, &QComboBox::currentTextChanged, this, [&](const QString& content) { change_ini(); });
|
2024-08-27 17:30:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CGroupSetting::~CGroupSetting()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGroupSetting::showEvent(QShowEvent* event)
|
|
|
|
{
|
2025-04-03 14:51:18 +08:00
|
|
|
update_ini("");
|
2024-08-27 17:30:48 +08:00
|
|
|
QDialog::showEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGroupSetting::add_item()
|
|
|
|
{
|
2025-04-03 13:39:36 +08:00
|
|
|
if (!CUtil::affirm(this, u8"确认", u8"确认添加/更新吗?")) {
|
|
|
|
return;
|
|
|
|
}
|
2024-08-27 17:30:48 +08:00
|
|
|
QString config_name = ui->edConfigName->text();
|
|
|
|
config_name = config_name.trimmed();
|
|
|
|
if (config_name.isEmpty()) {
|
|
|
|
CUtil::msg(this, u8"配置名为空");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// 验证重名
|
|
|
|
|
|
|
|
// 添加
|
|
|
|
OneGroupIni gp;
|
|
|
|
gp.name = config_name.toStdString();
|
|
|
|
gp.item_key = ui->edItemKey->text().toStdString();
|
|
|
|
gp.main_nodes = ui->edMainPath->text().toStdString();
|
|
|
|
gp.relative_nodes = ui->edRelativePath->text().toStdString();
|
|
|
|
gp.max_col_len = ui->edMaxColLen->text().toLong();
|
|
|
|
gp.max_blank_add = ui->edMaxFillLen->text().toLong();
|
|
|
|
gp.propertis = ui->edProperties->text().toStdString();
|
|
|
|
gp.is_same = ui->chbIsSame->isChecked();
|
|
|
|
|
|
|
|
if (!ini_opr_->add_item(gp)) {
|
|
|
|
CUtil::msg(this, u8"失败");
|
|
|
|
return;
|
|
|
|
}
|
2025-04-03 14:51:18 +08:00
|
|
|
update_ini(QString::fromStdString(gp.name));
|
2024-08-27 17:30:48 +08:00
|
|
|
CUtil::msg(this, u8"成功");
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGroupSetting::del_item()
|
|
|
|
{
|
2025-04-03 13:39:36 +08:00
|
|
|
if (!CUtil::affirm(this, u8"确认", u8"确认删除吗?")) {
|
|
|
|
return;
|
|
|
|
}
|
2024-08-27 17:30:48 +08:00
|
|
|
std::string key = ui->cbConfig->currentText().toStdString();
|
|
|
|
if (!ini_opr_->del_item(key)) {
|
|
|
|
CUtil::msg(this, u8"失败");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 删除成功之后要更新 cb
|
2025-04-03 14:51:18 +08:00
|
|
|
update_ini("");
|
2024-08-27 17:30:48 +08:00
|
|
|
|
|
|
|
CUtil::msg(this, u8"成功");
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGroupSetting::set_ui(const OneGroupIni& gp)
|
|
|
|
{
|
|
|
|
ui->edConfigName->setText(QString::fromStdString(gp.name));
|
|
|
|
ui->edItemKey->setText(QString::fromStdString(gp.item_key));
|
|
|
|
ui->edMainPath->setText(QString::fromStdString(gp.main_nodes));
|
|
|
|
ui->edRelativePath->setText(QString::fromStdString(gp.relative_nodes));
|
|
|
|
ui->edMaxColLen->setText(QString::number(gp.max_col_len));
|
|
|
|
ui->edMaxFillLen->setText(QString::number(gp.max_blank_add));
|
|
|
|
ui->edProperties->setText(QString::fromStdString(gp.propertis));
|
|
|
|
|
|
|
|
if (gp.is_same) {
|
|
|
|
ui->chbIsSame->setChecked(true);
|
2024-09-14 00:02:48 +08:00
|
|
|
} else {
|
2024-08-27 17:30:48 +08:00
|
|
|
ui->chbIsSame->setChecked(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGroupSetting::change_ini()
|
|
|
|
{
|
|
|
|
if (auto_add_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QString name_key = ui->cbConfig->currentText();
|
|
|
|
OneGroupIni gp;
|
|
|
|
gp.name = name_key.toStdString();
|
|
|
|
if (!ini_opr_->get_item(gp)) {
|
|
|
|
CUtil::msg(this, u8"加载" + ui->cbConfig->currentText() + "失败");
|
|
|
|
} else {
|
|
|
|
set_ui(gp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-03 14:51:18 +08:00
|
|
|
void CGroupSetting::update_ini(const QString& cur_key)
|
2024-08-27 17:30:48 +08:00
|
|
|
{
|
|
|
|
StrVec_t vec;
|
|
|
|
ini_opr_->get_all_node(vec);
|
|
|
|
|
|
|
|
QStringList list;
|
2025-04-03 14:51:18 +08:00
|
|
|
bool has_cur = false;
|
2024-08-27 17:30:48 +08:00
|
|
|
for (const auto& data : vec) {
|
|
|
|
list.append(QString::fromStdString(data));
|
2025-04-03 14:51:18 +08:00
|
|
|
if (data == cur_key.toStdString()) {
|
|
|
|
has_cur = true;
|
|
|
|
}
|
2024-08-27 17:30:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
auto_add_ = true;
|
|
|
|
ui->cbConfig->clear();
|
|
|
|
if (!list.empty()) {
|
|
|
|
ui->cbConfig->addItems(list);
|
2025-04-03 14:51:18 +08:00
|
|
|
if (has_cur) {
|
|
|
|
ui->cbConfig->setCurrentIndex(list.indexOf(cur_key));
|
|
|
|
} else {
|
|
|
|
ui->cbConfig->setCurrentIndex(0);
|
|
|
|
}
|
2024-08-27 17:30:48 +08:00
|
|
|
OneGroupIni gp;
|
|
|
|
gp.name = ui->cbConfig->currentText().toStdString();
|
|
|
|
if (!ini_opr_->get_item(gp)) {
|
|
|
|
CUtil::msg(this, u8"加载" + ui->cbConfig->currentText() + "失败");
|
|
|
|
} else {
|
|
|
|
set_ui(gp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto_add_ = false;
|
|
|
|
}
|