func:添加key字段重复检测。

This commit is contained in:
2024-05-16 12:18:20 +08:00
parent 32aa6dd101
commit 726c42f537
5 changed files with 71 additions and 39 deletions

View File

@@ -11,7 +11,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
{
ui->setupUi(this);
setWindowTitle(u8"OneLevelXmlOpr v1.2.2");
setWindowTitle(u8"OneLevelXmlOpr v1.2.3");
setWindowIcon(QIcon("://resource/xml.ico"));
setMinimumWidth(900);
@@ -38,7 +38,10 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
connect(ui->btnDelSelectLine, &QPushButton::clicked, this, [&]() { del_select_line(); });
connect(ui->btnExit, &QPushButton::clicked, this, [&]() { QApplication::exit(0); });
connect(ui->btnReset, &QPushButton::clicked, this, &MainWidget::reset);
connect(ui->btnEditProperty, &QPushButton::clicked, this, &MainWidget::edit_property);
connect(ui->btnEditProperty, &QPushButton::clicked, this, [&]() {
Element_t* ele = get_current_select_key();
edit_property(ele);
});
connect(ui->btnPagePre, &QPushButton::clicked, this, [&]() {
unsigned int cur = ui->edCurPage->text().toUInt();
push_content(current_, cur - 1);
@@ -75,24 +78,6 @@ void MainWidget::copy_key()
CUtil::msg(this, u8"已复制");
}
void MainWidget::edit_property()
{
Element_t* target = get_current_select_key();
if (target == nullptr) {
return;
}
Property_t property;
xml_.get_key_value(target, property);
attri_edit_->set_attribute(property, false);
attri_edit_->exec();
if (!attri_edit_->is_ok_) {
return;
}
attri_edit_->get_attribute(property);
xml_.key_value_to_element(target, property);
}
void MainWidget::closeEvent(QCloseEvent* event)
{
QSettings settings;
@@ -104,8 +89,7 @@ void MainWidget::closeEvent(QCloseEvent* event)
void MainWidget::keyPressEvent(QKeyEvent* event)
{
switch (event->key())
{
switch (event->key()) {
case Qt::Key_Return:
search();
break;
@@ -325,18 +309,10 @@ void MainWidget::copy_select_line()
}
Element_t* newer = xml_.copy_element(target);
Property_t property;
xml_.get_key_value(newer, property);
attri_edit_->set_attribute(property);
attri_edit_->exec();
if (!attri_edit_->is_ok_) {
if (!edit_property(newer)) {
return;
}
attri_edit_->get_attribute(property);
xml_.key_value_to_element(newer, property);
xml_.insert_brother_node(target, newer);
tab_widget_->insertRow(cur_item->row() + 1);
@@ -353,6 +329,36 @@ void MainWidget::copy_select_line()
search();
}
// 返回 true 表示确认编辑了, false 表示取消编辑了。
bool MainWidget::edit_property(Element_t* target)
{
if (target == nullptr) {
return false;
}
Property_t property;
xml_.get_key_value(target, property);
attri_edit_->set_attribute(property);
attri_edit_->exec();
if (!attri_edit_->is_ok_) {
return false;
}
attri_edit_->get_attribute(property);
while (xml_.check_key_exists(property)) {
CUtil::msg(attri_edit_, u8"不能有相同的key,请检查。");
attri_edit_->exec();
attri_edit_->get_attribute(property);
if (!attri_edit_->is_ok_) {
return false;
}
}
xml_.key_value_to_element(target, property);
return true;
}
void MainWidget::insert_one_line(Element_t* ele, int row)
{
if (ele == nullptr) {