diff --git a/MainWidget.cpp b/MainWidget.cpp index 2ade3d9..cccf083 100644 --- a/MainWidget.cpp +++ b/MainWidget.cpp @@ -381,7 +381,7 @@ bool MainWidget::edit_property(Element_t* target, int row) } Property_t property; - xml_.get_key_value(target, property); + xml_.get_attributes(target, property); // 检测key值是否变化 std::string value_pre = property[0].value; @@ -403,7 +403,7 @@ bool MainWidget::edit_property(Element_t* target, int row) } } } - xml_.key_value_to_element(target, property); + xml_.attributes_to_element(target, property); // 这里要同步到界面 ele_update_gui(target, row); diff --git a/src/data_edit.cpp b/src/data_edit.cpp index fc1bc16..38332f4 100644 --- a/src/data_edit.cpp +++ b/src/data_edit.cpp @@ -57,7 +57,7 @@ void CDataEdit::import_data() if (item.trimmed().isEmpty()) { continue; } - if (xml_opr_->check_same_struct(item.toStdString())) { + if (!xml_opr_->check_same_struct(item.toStdString())) { CUtil::msg(this, u8"不是合法的xml语句或者与现有结构不一致。"); return; } @@ -71,6 +71,7 @@ void CDataEdit::import_data() } QString info = QString(u8"需要导入 %1 条数据,成功导入 %2 条。").arg(task_count).arg(success_count); CUtil::msg(this, info); + close(); } void CDataEdit::showEvent(QShowEvent* event) diff --git a/src/xml_opr.cpp b/src/xml_opr.cpp index 411d90f..e98e763 100644 --- a/src/xml_opr.cpp +++ b/src/xml_opr.cpp @@ -131,7 +131,7 @@ bool CXmlOpr::check_same_struct(const std::string& data) while (attribute) { ++own_cnt; if (import_ele->FindAttribute(attribute->Name()) == nullptr) { - return true; + return false; } attribute = attribute->Next(); } @@ -152,7 +152,7 @@ bool CXmlOpr::check_same_struct(const std::string& data) // Warning: 不检查 xml 格式合法性,请自行调用 check_valid_xml_data // 且导入前每条数据请自行使用 check_same_struct 检测。 -bool CXmlOpr::import_newer_data(const std::vector& vec, std::size_t success_count) +bool CXmlOpr::import_newer_data(const std::vector& vec, std::size_t& success_count) { success_count = 0; auto* last_item = parent_node_->LastChildElement(opr_base_.the_node.c_str()); @@ -203,7 +203,7 @@ bool CXmlOpr::save() return true; } -void CXmlOpr::get_key_value(Element_t* ele, Property_t& vec) +void CXmlOpr::get_attributes(Element_t* ele, Property_t& vec) { if (ele == nullptr) { return; @@ -216,7 +216,7 @@ void CXmlOpr::get_key_value(Element_t* ele, Property_t& vec) } } -void CXmlOpr::key_value_to_element(Element_t* ele, const Property_t& vec) +void CXmlOpr::attributes_to_element(Element_t* ele, const Property_t& vec) { if (ele == nullptr) { return; diff --git a/src/xml_opr.h b/src/xml_opr.h index 915db9f..de09447 100644 --- a/src/xml_opr.h +++ b/src/xml_opr.h @@ -37,11 +37,11 @@ public: // 不检查 xml 格式合法性,请自行调用 check_valid_xml_data bool check_same_struct(const std::string& data); // 不检查 xml 格式合法性,请自行调用 check_valid_xml_data - bool import_newer_data(const std::vector& vec, std::size_t success_count); + bool import_newer_data(const std::vector& vec, std::size_t& success_count); public: - void get_key_value(Element_t* ele, Property_t& vec); - void key_value_to_element(Element_t* ele, const Property_t& vec); + void get_attributes(Element_t* ele, Property_t& vec); + void attributes_to_element(Element_t* ele, const Property_t& vec); private: tinyxml2::XMLDocument doc_{};