func:导入功能初步完成(没有检查重复)
This commit is contained in:
parent
00b15c46b8
commit
6d13738078
@ -381,7 +381,7 @@ bool MainWidget::edit_property(Element_t* target, int row)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Property_t property;
|
Property_t property;
|
||||||
xml_.get_key_value(target, property);
|
xml_.get_attributes(target, property);
|
||||||
|
|
||||||
// 检测key值是否变化
|
// 检测key值是否变化
|
||||||
std::string value_pre = property[0].value;
|
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);
|
ele_update_gui(target, row);
|
||||||
|
@ -57,7 +57,7 @@ void CDataEdit::import_data()
|
|||||||
if (item.trimmed().isEmpty()) {
|
if (item.trimmed().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (xml_opr_->check_same_struct(item.toStdString())) {
|
if (!xml_opr_->check_same_struct(item.toStdString())) {
|
||||||
CUtil::msg(this, u8"不是合法的xml语句或者与现有结构不一致。");
|
CUtil::msg(this, u8"不是合法的xml语句或者与现有结构不一致。");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -71,6 +71,7 @@ void CDataEdit::import_data()
|
|||||||
}
|
}
|
||||||
QString info = QString(u8"需要导入 %1 条数据,成功导入 %2 条。").arg(task_count).arg(success_count);
|
QString info = QString(u8"需要导入 %1 条数据,成功导入 %2 条。").arg(task_count).arg(success_count);
|
||||||
CUtil::msg(this, info);
|
CUtil::msg(this, info);
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDataEdit::showEvent(QShowEvent* event)
|
void CDataEdit::showEvent(QShowEvent* event)
|
||||||
|
@ -131,7 +131,7 @@ bool CXmlOpr::check_same_struct(const std::string& data)
|
|||||||
while (attribute) {
|
while (attribute) {
|
||||||
++own_cnt;
|
++own_cnt;
|
||||||
if (import_ele->FindAttribute(attribute->Name()) == nullptr) {
|
if (import_ele->FindAttribute(attribute->Name()) == nullptr) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
attribute = attribute->Next();
|
attribute = attribute->Next();
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ bool CXmlOpr::check_same_struct(const std::string& data)
|
|||||||
|
|
||||||
// Warning: 不检查 xml 格式合法性,请自行调用 check_valid_xml_data
|
// Warning: 不检查 xml 格式合法性,请自行调用 check_valid_xml_data
|
||||||
// 且导入前每条数据请自行使用 check_same_struct 检测。
|
// 且导入前每条数据请自行使用 check_same_struct 检测。
|
||||||
bool CXmlOpr::import_newer_data(const std::vector<std::string>& vec, std::size_t success_count)
|
bool CXmlOpr::import_newer_data(const std::vector<std::string>& vec, std::size_t& success_count)
|
||||||
{
|
{
|
||||||
success_count = 0;
|
success_count = 0;
|
||||||
auto* last_item = parent_node_->LastChildElement(opr_base_.the_node.c_str());
|
auto* last_item = parent_node_->LastChildElement(opr_base_.the_node.c_str());
|
||||||
@ -203,7 +203,7 @@ bool CXmlOpr::save()
|
|||||||
return true;
|
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) {
|
if (ele == nullptr) {
|
||||||
return;
|
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) {
|
if (ele == nullptr) {
|
||||||
return;
|
return;
|
||||||
|
@ -37,11 +37,11 @@ public:
|
|||||||
// 不检查 xml 格式合法性,请自行调用 check_valid_xml_data
|
// 不检查 xml 格式合法性,请自行调用 check_valid_xml_data
|
||||||
bool check_same_struct(const std::string& data);
|
bool check_same_struct(const std::string& data);
|
||||||
// 不检查 xml 格式合法性,请自行调用 check_valid_xml_data
|
// 不检查 xml 格式合法性,请自行调用 check_valid_xml_data
|
||||||
bool import_newer_data(const std::vector<std::string>& vec, std::size_t success_count);
|
bool import_newer_data(const std::vector<std::string>& vec, std::size_t& success_count);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void get_key_value(Element_t* ele, Property_t& vec);
|
void get_attributes(Element_t* ele, Property_t& vec);
|
||||||
void key_value_to_element(Element_t* ele, const Property_t& vec);
|
void attributes_to_element(Element_t* ele, const Property_t& vec);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
tinyxml2::XMLDocument doc_{};
|
tinyxml2::XMLDocument doc_{};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user