From 0ca591c238faadceeb7762ad99118904b8403178 Mon Sep 17 00:00:00 2001 From: taynpg Date: Thu, 16 May 2024 14:42:19 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A1.=E5=BD=93=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E9=99=A4=E4=BA=86key=E4=BB=A5=E5=A4=96=E7=9A=84=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=EF=BC=8C=E6=97=A0=E6=B3=95=E7=BC=96=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E4=BC=9A=E6=8F=90=E7=A4=BA=E6=9C=89=E7=9B=B8=E5=90=8Ckey?= =?UTF-8?q?=E3=80=82=202.=E7=82=B9=E5=87=BBx=E9=80=80=E5=87=BA=E6=97=B6?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E7=9A=84=E6=98=AFyes=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E3=80=82=203.=E5=B1=9E=E6=80=A7=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E4=BA=86key=E4=B9=8B=E5=90=8E=EF=BC=8C=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E6=B2=A1=E6=9C=89=E5=90=8C=E6=AD=A5=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MainWidget.cpp | 51 ++++++++++++++++++++++++++++++++---------- MainWidget.h | 3 ++- src/attribute_edit.cpp | 2 ++ src/attribute_edit.h | 2 +- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/MainWidget.cpp b/MainWidget.cpp index b7a4d4e..69bac61 100644 --- a/MainWidget.cpp +++ b/MainWidget.cpp @@ -11,7 +11,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget { ui->setupUi(this); - setWindowTitle(u8"OneLevelXmlOpr v1.2.5"); + setWindowTitle(u8"OneLevelXmlOpr v1.2.6"); setWindowIcon(QIcon("://resource/xml.ico")); setMinimumWidth(900); @@ -68,7 +68,7 @@ void MainWidget::copy_key() } QClipboard* clip = QApplication::clipboard(); clip->setText(QString(target->Attribute(keys_[0].c_str()))); - //CUtil::msg(this, u8"已复制"); + // CUtil::msg(this, u8"已复制"); } void MainWidget::closeEvent(QCloseEvent* event) @@ -301,7 +301,7 @@ void MainWidget::copy_select_line() } Element_t* newer = xml_.copy_element(target); - if (!edit_property(newer)) { + if (!edit_property(newer, cur_item->row())) { return; } @@ -322,7 +322,7 @@ void MainWidget::copy_select_line() } // 返回 true 表示确认编辑了, false 表示取消编辑了。 -bool MainWidget::edit_property(Element_t* target) +bool MainWidget::edit_property(Element_t* target, int row) { if (target == nullptr) { return false; @@ -331,6 +331,8 @@ bool MainWidget::edit_property(Element_t* target) Property_t property; xml_.get_key_value(target, property); + // 检测key值是否变化 + std::string value_pre = property[0].value; attri_edit_->set_attribute(property); attri_edit_->exec(); @@ -339,18 +341,35 @@ bool MainWidget::edit_property(Element_t* target) } 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; + if (property[0].value != value_pre) { + 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); + + // 这里要同步到界面 + ele_update_gui(target, row); return true; } +void MainWidget::ele_update_gui(Element_t* target, int row) +{ + if (tab_widget_ == nullptr) { + return; + } + for (auto i = 0; i < keys_.size(); ++i) { + const char* v = target->Attribute(keys_[i].c_str()); + auto* qitem = tab_widget_->item(row, i); + qitem->setText(QString(v)); + } +} + void MainWidget::init_menu() { context_menu_ = new QMenu(); @@ -365,8 +384,16 @@ void MainWidget::init_menu() context_menu_->addAction(ac_copy_key_); connect(ac_edit_property_, &QAction::triggered, this, [&]() { - Element_t* ele = get_current_select_key(); - edit_property(ele); + QTableWidgetItem* cur_item = get_current_select_item(); + if (cur_item == nullptr) { + return; + } + + Element_t* target = get_element_bykey(cur_item->text()); + if (target == nullptr) { + return; + } + edit_property(target, cur_item->row()); }); connect(ac_copy_curline_, &QAction::triggered, this, [&]() { copy_select_line(); }); connect(ac_del_curline_, &QAction::triggered, this, [&]() { del_select_line(); }); diff --git a/MainWidget.h b/MainWidget.h index fd9a2a7..cd1f357 100644 --- a/MainWidget.h +++ b/MainWidget.h @@ -40,8 +40,9 @@ private: void reset(); void judge_btn_page(); void copy_key(); - bool edit_property(Element_t* target); + bool edit_property(Element_t* target, int row); void init_menu(); + void ele_update_gui(Element_t* target, int row); protected: void closeEvent(QCloseEvent* event); diff --git a/src/attribute_edit.cpp b/src/attribute_edit.cpp index 682f1ae..8716ede 100644 --- a/src/attribute_edit.cpp +++ b/src/attribute_edit.cpp @@ -57,6 +57,8 @@ void CAttributeEdit::show_before() { init_table(); + is_ok_ = false; + for(auto i = 0; i < property_.size(); ++i) { int row = table_->rowCount(); table_->insertRow(row); diff --git a/src/attribute_edit.h b/src/attribute_edit.h index 3b34f6a..abbe6e6 100644 --- a/src/attribute_edit.h +++ b/src/attribute_edit.h @@ -30,7 +30,7 @@ private: void handle_ok(); public: - bool is_ok_{}; + bool is_ok_{ false }; private: Ui::CAttributeEdit* ui;