From 49c4a40dc9ef643ccf831c67f0bab65bf924dfea Mon Sep 17 00:00:00 2001 From: taynpg Date: Wed, 28 Aug 2024 09:35:45 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=AD=A3=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MainWidget.cpp | 41 +++++++++++++++++++++++++++-------------- MainWidget.h | 6 +++--- src/attribute_edit.h | 9 +++++---- src/uhistory.ui | 27 ++++++++++++++++++++------- 4 files changed, 55 insertions(+), 28 deletions(-) diff --git a/MainWidget.cpp b/MainWidget.cpp index 866abbb..3675d4a 100644 --- a/MainWidget.cpp +++ b/MainWidget.cpp @@ -19,7 +19,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget { ui->setupUi(this); - setWindowTitle(u8"OneLevelXmlOpr v1.3.2"); + setWindowTitle(u8"OneLevelXmlOpr v1.3.3"); setWindowIcon(QIcon("://resource/xml.ico")); QScreen* primaryScreen = QGuiApplication::primaryScreen(); @@ -244,7 +244,7 @@ void MainWidget::generate_table_widget() ui->widget->setLayout(lay); } -void MainWidget::push_content(const std::vector& eles, std::size_t page) +void MainWidget::push_content(const std::vector& eles, std::size_t page, bool auto_jump_pre) { if (tab_widget_ == nullptr || page == 0) { return; @@ -258,6 +258,10 @@ void MainWidget::push_content(const std::vector& eles, st ++all_page_; } + if (auto_jump_pre && page > all_page_ && page > 1) { + page -= 1; + } + if (page < 1 || page > all_page_) { if (eles.size() > 0) { CUtil::msg(this, u8"页码不在范围内"); @@ -376,7 +380,7 @@ void MainWidget::search(const QString& key) QString bkey = key; if (bkey.isEmpty()) { current_ = vec_; - push_content(current_); + push_content(current_, ui->edCurPage->text().toUInt(), true); return; } if (tab_widget_ == nullptr) { @@ -402,7 +406,7 @@ void MainWidget::search(const QString& key) break; } } - push_content(current_); + push_content(current_, ui->edCurPage->text().toUInt(), true); } void MainWidget::item_changed_handle(QTableWidgetItem* item) @@ -450,7 +454,7 @@ void MainWidget::copy_select_line() } Element_t* newer = xml_.copy_element(target); - if (!edit_property(newer, cur_item->row())) { + if (!edit_property(newer, cur_item->row(), true)) { return; } @@ -471,7 +475,7 @@ void MainWidget::copy_select_line() } // 返回 true 表示确认编辑了, false 表示取消编辑了。 -bool MainWidget::edit_property(Element_t* target, int row) +bool MainWidget::edit_property(Element_t* target, int row, bool is_copy) { if (target == nullptr) { return false; @@ -490,7 +494,8 @@ bool MainWidget::edit_property(Element_t* target, int row) } attri_edit_->get_attribute(property); - if (property[0].value == value_pre) { + // 如果是复制,或者编辑时更改了key值,检查重复性。 + if (property[0].value != value_pre || is_copy) { while (xml_.check_key_exists(property)) { CUtil::msg(attri_edit_, u8"不能有相同的key,请检查。"); attri_edit_->exec(); @@ -503,23 +508,31 @@ bool MainWidget::edit_property(Element_t* target, int row) xml_.attributes_to_element(target, property); // 这里要同步到界面 - ele_update_gui(target, row); + ele_update_gui(target, QString::fromStdString(value_pre)); return true; } // ele_update_gui 的 row 参数暂时废弃,无意义。 -void MainWidget::ele_update_gui(Element_t* target, int row) +void MainWidget::ele_update_gui(Element_t* target, const QString& pre_value) { if (tab_widget_ == nullptr) { return; } - QString tkey = QString::fromLocal8Bit(target->Attribute(keys_[0].c_str())); + QString search_key; + + if (pre_value.isEmpty()) { + search_key = QString::fromLocal8Bit(target->Attribute(keys_[0].c_str())); + } + else { + search_key = pre_value; + } + int target_row = -1; // 获取当前显示的内容,查找更改。 int cur_show_cnt = tab_widget_->rowCount(); for (int i = 0; i < cur_show_cnt; ++i) { - if (tab_widget_->item(i, 0)->text() == tkey) { + if (tab_widget_->item(i, 0)->text() == search_key) { target_row = i; break; } @@ -562,7 +575,7 @@ void MainWidget::init_menu() if (target == nullptr) { return; } - edit_property(target, cur_item->row()); + edit_property(target, cur_item->row(), false); }); connect(ac_copy_curline_, &QAction::triggered, this, [&]() { copy_select_line(); }); connect(ac_del_curline_, &QAction::triggered, this, [&]() { del_select_line(); }); @@ -755,7 +768,7 @@ void MainWidget::replace_content(bool is_common) replace_str(item->element_, key, after); } if (!is_search) { - ele_update_gui(item->element_, item->row_); + ele_update_gui(item->element_); } delete item; } @@ -798,7 +811,7 @@ void MainWidget::replace_str(const QString& pre, const QString& after, Element_t if (ele == nullptr) { return; } - for (auto i = 0; i < keys_.size(); ++i) { + for (auto i = 1; i < keys_.size(); ++i) { auto* value = ele->Attribute(keys_[i].c_str()); QString content(value); if (content.contains(pre)) { diff --git a/MainWidget.h b/MainWidget.h index f0a2b16..c59925c 100644 --- a/MainWidget.h +++ b/MainWidget.h @@ -51,7 +51,7 @@ public: public: void set_work_exe(char* path); void generate_table_widget(); - void push_content(const std::vector& eles, std::size_t page = 1); + void push_content(const std::vector& eles, std::size_t page = 1, bool auto_jump_pre = false); private: bool read(const QString& file_path); @@ -64,9 +64,9 @@ private: void reset(); void judge_btn_page(); void copy_key(); - bool edit_property(Element_t* target, int row); + bool edit_property(Element_t* target, int row, bool is_copy); void init_menu(); - void ele_update_gui(Element_t* target, int row); + void ele_update_gui(Element_t* target, const QString& pre_value = ""); void show_custom_menu(); void sort_by_repeat(std::vector& vec); void copy_multi_data(); diff --git a/src/attribute_edit.h b/src/attribute_edit.h index abbe6e6..ff92f0b 100644 --- a/src/attribute_edit.h +++ b/src/attribute_edit.h @@ -3,6 +3,7 @@ #include #include + #include "xml_opr.h" namespace Ui { @@ -30,13 +31,13 @@ private: void handle_ok(); public: - bool is_ok_{ false }; + bool is_ok_{false}; private: Ui::CAttributeEdit* ui; - Property_t property_{}; - QTableWidget* table_{}; - bool is_key_edit_{true}; + Property_t property_{}; + QTableWidget* table_{}; + bool is_key_edit_{true}; }; #endif // ATTRIBUTE_EDIT_H diff --git a/src/uhistory.ui b/src/uhistory.ui index 2aaea0c..b06e45d 100644 --- a/src/uhistory.ui +++ b/src/uhistory.ui @@ -19,6 +19,13 @@ + + + + 删除 + + + @@ -32,13 +39,6 @@ - - - - 删除 - - - @@ -52,6 +52,19 @@ + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + +