fix:修正界面更新逻辑问题。
This commit is contained in:
parent
f9796c7090
commit
49c4a40dc9
@ -19,7 +19,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
setWindowTitle(u8"OneLevelXmlOpr v1.3.2");
|
setWindowTitle(u8"OneLevelXmlOpr v1.3.3");
|
||||||
setWindowIcon(QIcon("://resource/xml.ico"));
|
setWindowIcon(QIcon("://resource/xml.ico"));
|
||||||
|
|
||||||
QScreen* primaryScreen = QGuiApplication::primaryScreen();
|
QScreen* primaryScreen = QGuiApplication::primaryScreen();
|
||||||
@ -244,7 +244,7 @@ void MainWidget::generate_table_widget()
|
|||||||
ui->widget->setLayout(lay);
|
ui->widget->setLayout(lay);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::push_content(const std::vector<tinyxml2::XMLElement*>& eles, std::size_t page)
|
void MainWidget::push_content(const std::vector<tinyxml2::XMLElement*>& eles, std::size_t page, bool auto_jump_pre)
|
||||||
{
|
{
|
||||||
if (tab_widget_ == nullptr || page == 0) {
|
if (tab_widget_ == nullptr || page == 0) {
|
||||||
return;
|
return;
|
||||||
@ -258,6 +258,10 @@ void MainWidget::push_content(const std::vector<tinyxml2::XMLElement*>& eles, st
|
|||||||
++all_page_;
|
++all_page_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (auto_jump_pre && page > all_page_ && page > 1) {
|
||||||
|
page -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (page < 1 || page > all_page_) {
|
if (page < 1 || page > all_page_) {
|
||||||
if (eles.size() > 0) {
|
if (eles.size() > 0) {
|
||||||
CUtil::msg(this, u8"页码不在范围内");
|
CUtil::msg(this, u8"页码不在范围内");
|
||||||
@ -376,7 +380,7 @@ void MainWidget::search(const QString& key)
|
|||||||
QString bkey = key;
|
QString bkey = key;
|
||||||
if (bkey.isEmpty()) {
|
if (bkey.isEmpty()) {
|
||||||
current_ = vec_;
|
current_ = vec_;
|
||||||
push_content(current_);
|
push_content(current_, ui->edCurPage->text().toUInt(), true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (tab_widget_ == nullptr) {
|
if (tab_widget_ == nullptr) {
|
||||||
@ -402,7 +406,7 @@ void MainWidget::search(const QString& key)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
push_content(current_);
|
push_content(current_, ui->edCurPage->text().toUInt(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::item_changed_handle(QTableWidgetItem* item)
|
void MainWidget::item_changed_handle(QTableWidgetItem* item)
|
||||||
@ -450,7 +454,7 @@ void MainWidget::copy_select_line()
|
|||||||
}
|
}
|
||||||
Element_t* newer = xml_.copy_element(target);
|
Element_t* newer = xml_.copy_element(target);
|
||||||
|
|
||||||
if (!edit_property(newer, cur_item->row())) {
|
if (!edit_property(newer, cur_item->row(), true)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,7 +475,7 @@ void MainWidget::copy_select_line()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 返回 true 表示确认编辑了, false 表示取消编辑了。
|
// 返回 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) {
|
if (target == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
@ -490,7 +494,8 @@ bool MainWidget::edit_property(Element_t* target, int row)
|
|||||||
}
|
}
|
||||||
|
|
||||||
attri_edit_->get_attribute(property);
|
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)) {
|
while (xml_.check_key_exists(property)) {
|
||||||
CUtil::msg(attri_edit_, u8"不能有相同的key,请检查。");
|
CUtil::msg(attri_edit_, u8"不能有相同的key,请检查。");
|
||||||
attri_edit_->exec();
|
attri_edit_->exec();
|
||||||
@ -503,23 +508,31 @@ bool MainWidget::edit_property(Element_t* target, int row)
|
|||||||
xml_.attributes_to_element(target, property);
|
xml_.attributes_to_element(target, property);
|
||||||
|
|
||||||
// 这里要同步到界面
|
// 这里要同步到界面
|
||||||
ele_update_gui(target, row);
|
ele_update_gui(target, QString::fromStdString(value_pre));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ele_update_gui 的 row 参数暂时废弃,无意义。
|
// 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) {
|
if (tab_widget_ == nullptr) {
|
||||||
return;
|
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 target_row = -1;
|
||||||
// 获取当前显示的内容,查找更改。
|
// 获取当前显示的内容,查找更改。
|
||||||
int cur_show_cnt = tab_widget_->rowCount();
|
int cur_show_cnt = tab_widget_->rowCount();
|
||||||
for (int i = 0; i < cur_show_cnt; ++i) {
|
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;
|
target_row = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -562,7 +575,7 @@ void MainWidget::init_menu()
|
|||||||
if (target == nullptr) {
|
if (target == nullptr) {
|
||||||
return;
|
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_copy_curline_, &QAction::triggered, this, [&]() { copy_select_line(); });
|
||||||
connect(ac_del_curline_, &QAction::triggered, this, [&]() { del_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);
|
replace_str(item->element_, key, after);
|
||||||
}
|
}
|
||||||
if (!is_search) {
|
if (!is_search) {
|
||||||
ele_update_gui(item->element_, item->row_);
|
ele_update_gui(item->element_);
|
||||||
}
|
}
|
||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
@ -798,7 +811,7 @@ void MainWidget::replace_str(const QString& pre, const QString& after, Element_t
|
|||||||
if (ele == nullptr) {
|
if (ele == nullptr) {
|
||||||
return;
|
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());
|
auto* value = ele->Attribute(keys_[i].c_str());
|
||||||
QString content(value);
|
QString content(value);
|
||||||
if (content.contains(pre)) {
|
if (content.contains(pre)) {
|
||||||
|
@ -51,7 +51,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
void set_work_exe(char* path);
|
void set_work_exe(char* path);
|
||||||
void generate_table_widget();
|
void generate_table_widget();
|
||||||
void push_content(const std::vector<Element_t*>& eles, std::size_t page = 1);
|
void push_content(const std::vector<Element_t*>& eles, std::size_t page = 1, bool auto_jump_pre = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool read(const QString& file_path);
|
bool read(const QString& file_path);
|
||||||
@ -64,9 +64,9 @@ private:
|
|||||||
void reset();
|
void reset();
|
||||||
void judge_btn_page();
|
void judge_btn_page();
|
||||||
void copy_key();
|
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 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 show_custom_menu();
|
||||||
void sort_by_repeat(std::vector<Element_t*>& vec);
|
void sort_by_repeat(std::vector<Element_t*>& vec);
|
||||||
void copy_multi_data();
|
void copy_multi_data();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
|
|
||||||
#include "xml_opr.h"
|
#include "xml_opr.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@ -30,13 +31,13 @@ private:
|
|||||||
void handle_ok();
|
void handle_ok();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool is_ok_{ false };
|
bool is_ok_{false};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::CAttributeEdit* ui;
|
Ui::CAttributeEdit* ui;
|
||||||
Property_t property_{};
|
Property_t property_{};
|
||||||
QTableWidget* table_{};
|
QTableWidget* table_{};
|
||||||
bool is_key_edit_{true};
|
bool is_key_edit_{true};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ATTRIBUTE_EDIT_H
|
#endif // ATTRIBUTE_EDIT_H
|
||||||
|
@ -19,6 +19,13 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnDel">
|
||||||
|
<property name="text">
|
||||||
|
<string>删除</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
@ -32,13 +39,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="btnDel">
|
|
||||||
<property name="text">
|
|
||||||
<string>删除</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnOk">
|
<widget class="QPushButton" name="btnOk">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -52,6 +52,19 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnExit">
|
<widget class="QPushButton" name="btnExit">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user