func:1.添加删除添加功能。

2.添加编辑属性界面
3.删除添加同步到界面未完成。
This commit is contained in:
2024-05-15 23:06:48 +08:00
parent 950949c130
commit 41713baede
12 changed files with 534 additions and 69 deletions

View File

@@ -3,7 +3,7 @@
CXmlOpr::CXmlOpr() = default;
CXmlOpr::~CXmlOpr() = default;
bool CXmlOpr::open(const std::string &xml_path)
bool CXmlOpr::open(const std::string& xml_path)
{
if (doc_.LoadFile(xml_path.c_str()) != tinyxml2::XML_SUCCESS) {
return false;
@@ -31,22 +31,20 @@ bool CXmlOpr::parse_xml(std::vector<tinyxml2::XMLElement*>& vec)
if (parent_node_ == nullptr) {
parent_node_ = doc_.FirstChildElement(item.c_str());
}
else {
} else {
parent_node_ = parent_node_->FirstChildElement(item.c_str());
}
}
vec.clear();
element* purpose_node = parent_node_->FirstChildElement(opr_base_.the_node.c_str());
while (purpose_node)
{
Element_t* purpose_node = parent_node_->FirstChildElement(opr_base_.the_node.c_str());
while (purpose_node) {
vec.push_back(purpose_node);
purpose_node = purpose_node->NextSiblingElement();
}
return true;
}
void CXmlOpr::insert_brother_node(element* brother, element* newer)
void CXmlOpr::insert_brother_node(Element_t* brother, Element_t* newer)
{
if (!brother || !newer) {
return;
@@ -54,12 +52,12 @@ void CXmlOpr::insert_brother_node(element* brother, element* newer)
parent_node_->InsertAfterChild(brother, newer);
}
element* CXmlOpr::copy_element(element* ele)
Element_t* CXmlOpr::copy_element(Element_t* ele)
{
if (!ele) {
return nullptr;
}
element* ret = doc_.NewElement(ele->Name());
Element_t* ret = doc_.NewElement(ele->Name());
const auto* attribute = ele->FirstAttribute();
while (attribute) {
ret->SetAttribute(attribute->Name(), attribute->Value());
@@ -68,6 +66,11 @@ element* CXmlOpr::copy_element(element* ele)
return ret;
}
void CXmlOpr::del_element(Element_t* ele)
{
parent_node_->DeleteChild(ele);
}
bool CXmlOpr::save()
{
auto ret = doc_.SaveFile(xml_path_.c_str());
@@ -76,3 +79,32 @@ bool CXmlOpr::save()
}
return true;
}
void CXmlOpr::get_key_value(Element_t* ele, Property_t& vec)
{
if (ele == nullptr) {
return;
}
vec.clear();
const auto* attribute = ele->FirstAttribute();
while (attribute) {
vec.emplace_back(attribute->Name(), attribute->Value());
attribute = attribute->Next();
}
}
void CXmlOpr::key_value_to_element(Element_t* ele, const Property_t& vec)
{
if (ele == nullptr) {
return;
}
for (const auto& data : vec) {
ele->SetAttribute(data.key.c_str(), data.value.c_str());
}
}
SKeyValue::SKeyValue(const char* pkey, const char* pvalue)
{
key = std::string(pkey);
value = std::string(pvalue);
}