fix:1.当编辑除了key以外的属性,无法编辑,会提示有相同key。

2.点击x退出时触发的是yes按钮功能。
3.属性编辑了key之后,界面没有同步更新。
This commit is contained in:
taynpg 2024-05-16 14:42:19 +08:00
parent 106f51aad2
commit 0ca591c238
4 changed files with 44 additions and 14 deletions

View File

@ -11,7 +11,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
{ {
ui->setupUi(this); ui->setupUi(this);
setWindowTitle(u8"OneLevelXmlOpr v1.2.5"); setWindowTitle(u8"OneLevelXmlOpr v1.2.6");
setWindowIcon(QIcon("://resource/xml.ico")); setWindowIcon(QIcon("://resource/xml.ico"));
setMinimumWidth(900); setMinimumWidth(900);
@ -68,7 +68,7 @@ void MainWidget::copy_key()
} }
QClipboard* clip = QApplication::clipboard(); QClipboard* clip = QApplication::clipboard();
clip->setText(QString(target->Attribute(keys_[0].c_str()))); clip->setText(QString(target->Attribute(keys_[0].c_str())));
//CUtil::msg(this, u8"已复制"); // CUtil::msg(this, u8"已复制");
} }
void MainWidget::closeEvent(QCloseEvent* event) void MainWidget::closeEvent(QCloseEvent* event)
@ -301,7 +301,7 @@ void MainWidget::copy_select_line()
} }
Element_t* newer = xml_.copy_element(target); Element_t* newer = xml_.copy_element(target);
if (!edit_property(newer)) { if (!edit_property(newer, cur_item->row())) {
return; return;
} }
@ -322,7 +322,7 @@ void MainWidget::copy_select_line()
} }
// 返回 true 表示确认编辑了, false 表示取消编辑了。 // 返回 true 表示确认编辑了, false 表示取消编辑了。
bool MainWidget::edit_property(Element_t* target) bool MainWidget::edit_property(Element_t* target, int row)
{ {
if (target == nullptr) { if (target == nullptr) {
return false; return false;
@ -331,6 +331,8 @@ bool MainWidget::edit_property(Element_t* target)
Property_t property; Property_t property;
xml_.get_key_value(target, property); xml_.get_key_value(target, property);
// 检测key值是否变化
std::string value_pre = property[0].value;
attri_edit_->set_attribute(property); attri_edit_->set_attribute(property);
attri_edit_->exec(); attri_edit_->exec();
@ -339,18 +341,35 @@ bool MainWidget::edit_property(Element_t* target)
} }
attri_edit_->get_attribute(property); attri_edit_->get_attribute(property);
while (xml_.check_key_exists(property)) { if (property[0].value != value_pre) {
CUtil::msg(attri_edit_, u8"不能有相同的key,请检查。"); while (xml_.check_key_exists(property)) {
attri_edit_->exec(); CUtil::msg(attri_edit_, u8"不能有相同的key,请检查。");
attri_edit_->get_attribute(property); attri_edit_->exec();
if (!attri_edit_->is_ok_) { attri_edit_->get_attribute(property);
return false; if (!attri_edit_->is_ok_) {
return false;
}
} }
} }
xml_.key_value_to_element(target, property); xml_.key_value_to_element(target, property);
// 这里要同步到界面
ele_update_gui(target, row);
return true; 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() void MainWidget::init_menu()
{ {
context_menu_ = new QMenu(); context_menu_ = new QMenu();
@ -365,8 +384,16 @@ void MainWidget::init_menu()
context_menu_->addAction(ac_copy_key_); context_menu_->addAction(ac_copy_key_);
connect(ac_edit_property_, &QAction::triggered, this, [&]() { connect(ac_edit_property_, &QAction::triggered, this, [&]() {
Element_t* ele = get_current_select_key(); QTableWidgetItem* cur_item = get_current_select_item();
edit_property(ele); 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_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(); });

View File

@ -40,8 +40,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); bool edit_property(Element_t* target, int row);
void init_menu(); void init_menu();
void ele_update_gui(Element_t* target, int row);
protected: protected:
void closeEvent(QCloseEvent* event); void closeEvent(QCloseEvent* event);

View File

@ -57,6 +57,8 @@ void CAttributeEdit::show_before()
{ {
init_table(); init_table();
is_ok_ = false;
for(auto i = 0; i < property_.size(); ++i) { for(auto i = 0; i < property_.size(); ++i) {
int row = table_->rowCount(); int row = table_->rowCount();
table_->insertRow(row); table_->insertRow(row);

View File

@ -30,7 +30,7 @@ private:
void handle_ok(); void handle_ok();
public: public:
bool is_ok_{}; bool is_ok_{ false };
private: private:
Ui::CAttributeEdit* ui; Ui::CAttributeEdit* ui;