diff --git a/.vscode/settings.json b/.vscode/settings.json index f074984..be26477 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -19,7 +19,7 @@ "visualizerFile": "${workspaceRoot}/.vscode/qt6.natvis" }, "cmake.environment": { - "PATH": "${env:PATH};C:/Qt/6.6.3/msvc2019_64/bin" + "PATH": "${env:PATH};C:/Qt/6.7.2/bin" }, "cmake.options.statusBarVisibility": "visible", "cmake.generator": "Ninja", diff --git a/CMakeLists.txt b/CMakeLists.txt index dd871aa..8321ea1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,8 @@ endif() message(STATUS "User home directory: ${USER_HOME}") set(CMAKE_PREFIX_PATH - "C:/Qt/6.6.3/msvc2019_64" + ${CMAKE_PREFIX_PATH} + "C:/Qt/6.7.2" "${USER_HOME}/Qt5.14.2/5.14.2/gcc_64/" ) diff --git a/MainWidget.cpp b/MainWidget.cpp index 7e0c5d7..2a8fbee 100644 --- a/MainWidget.cpp +++ b/MainWidget.cpp @@ -18,7 +18,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget { ui->setupUi(this); - setWindowTitle(u8"OneLevelXmlOpr v1.3.0"); + setWindowTitle(u8"OneLevelXmlOpr v1.3.1"); setWindowIcon(QIcon("://resource/xml.ico")); QScreen* primaryScreen = QGuiApplication::primaryScreen(); @@ -483,7 +483,7 @@ bool MainWidget::edit_property(Element_t* target, int row) } attri_edit_->get_attribute(property); - if (property[0].value != value_pre) { + if (property[0].value == value_pre) { while (xml_.check_key_exists(property)) { CUtil::msg(attri_edit_, u8"不能有相同的key,请检查。"); attri_edit_->exec(); diff --git a/README.md b/README.md index 6d1b694..f6806e2 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ # 编译环境 -在 `msvc Qt5.14.2` 和 `vs2017` 环境下通过。 \ No newline at end of file +`windows`下,`Qt6`可正常使用无乱码。 \ No newline at end of file diff --git a/resource/xml.ico b/resource/xml.ico index 8f1f467..1574bde 100644 Binary files a/resource/xml.ico and b/resource/xml.ico differ diff --git a/resource/xml.png b/resource/xml.png deleted file mode 100644 index bb8811e..0000000 Binary files a/resource/xml.png and /dev/null differ diff --git a/src/attribute_edit.cpp b/src/attribute_edit.cpp index 34bb1c5..3fcd516 100644 --- a/src/attribute_edit.cpp +++ b/src/attribute_edit.cpp @@ -1,4 +1,5 @@ #include "attribute_edit.h" + #include "ui_attribute_edit.h" CAttributeEdit::CAttributeEdit(QWidget* parent) : QDialog(parent), ui(new Ui::CAttributeEdit) @@ -22,13 +23,12 @@ void CAttributeEdit::handle_ok() for (int i = 0; i < row; ++i) { QString key = table_->item(i, 0)->text(); QString value = table_->item(i, 1)->text(); - property_.emplace_back(key.toLocal8Bit().constData(), value.toLocal8Bit().constData()); + property_.emplace_back(key.toStdString().c_str(), value.toStdString().c_str()); } is_ok_ = true; close(); } - CAttributeEdit::~CAttributeEdit() { delete ui; @@ -59,7 +59,7 @@ void CAttributeEdit::show_before() is_ok_ = false; - for(auto i = 0; i < property_.size(); ++i) { + for (auto i = 0; i < property_.size(); ++i) { int row = table_->rowCount(); table_->insertRow(row); diff --git a/src/config.cpp b/src/config.cpp index 4a44c1a..8d11e84 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -1,4 +1,5 @@ #include "config.h" + #include #include @@ -13,7 +14,7 @@ void CGroupIni::default_set() QDir dir; std::string path = dir.homePath().toStdString(); fs::path p(path); - p.append(".config"); + p.append(".config/OneLevelXmlOpr"); if (!fs::exists(p)) { fs::create_directories(p); @@ -41,7 +42,7 @@ void CGroupIni::get_all_node(StrVec_t& vec) { vec.clear(); - CSimpleIni::TNamesDepend secs; + CSimpleIniA::TNamesDepend secs; ini_.GetAllSections(secs); for (const auto& sec : secs) { vec.push_back(sec.pItem); @@ -93,7 +94,7 @@ bool CGroupIni::get_item(OneGroupIni& group) return true; } -bool CGroupIni::del_item(const std::string &key) +bool CGroupIni::del_item(const std::string& key) { ini_.Delete(key.c_str(), "MainNodes", true); ini_.Delete(key.c_str(), "RelativeNodes", true); diff --git a/src/config.h b/src/config.h index 2fd8129..51fec0e 100644 --- a/src/config.h +++ b/src/config.h @@ -3,7 +3,7 @@ #include #include - +#include /* [Basic] diff --git a/src/data_edit.cpp b/src/data_edit.cpp index 59e441e..081d12d 100644 --- a/src/data_edit.cpp +++ b/src/data_edit.cpp @@ -1,11 +1,14 @@ #include "data_edit.h" -#include "ui_data_edit.h" -#include -#include + #include -#include + +#include +#include #include +#include + #include "../public_def.h" +#include "ui_data_edit.h" CDataEdit::CDataEdit(QWidget* parent) : QDialog(parent), ui(new Ui::CDataEdit) { @@ -58,7 +61,7 @@ void CDataEdit::import_data() } std::vector valid_data{}; - QStringList list = data.trimmed().split("\n"); + QStringList list = data.trimmed().split("\n"); for (int i = 0; i < list.size(); ++i) { const QString& item = list[i]; if (item.trimmed().isEmpty()) { @@ -70,7 +73,7 @@ void CDataEdit::import_data() } valid_data.push_back(item.toStdString()); } - auto task_count = valid_data.size(); + auto task_count = valid_data.size(); std::size_t success_count{}; if (!xml_opr_->import_newer_data(valid_data, success_count)) { CUtil::msg(this, u8"导入失败。"); @@ -91,7 +94,7 @@ void CDataEdit::showEvent(QShowEvent* event) void CDataEdit::show_before() { QScreen* primaryScreen = QGuiApplication::primaryScreen(); - QRect screenGeometry = primaryScreen->geometry(); + QRect screenGeometry = primaryScreen->geometry(); setMinimumWidth(screenGeometry.width() * 0.8); if (is_import_) { ui->btnCopy->setVisible(false); diff --git a/src/history.cpp b/src/history.cpp index 515d914..c3bccc6 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -41,7 +41,7 @@ void CHistory::default_set() QDir dir; std::string path = dir.homePath().toStdString(); fs::path p(path); - p.append(".config"); + p.append(".config/OneLevelXmlOpr"); if (!fs::exists(p)) { fs::create_directories(p); diff --git a/src/xml_opr.cpp b/src/xml_opr.cpp index dd4e57d..cb0633f 100644 --- a/src/xml_opr.cpp +++ b/src/xml_opr.cpp @@ -1,7 +1,9 @@ #include "xml_opr.h" -#include "../public_def.h" + #include +#include "../public_def.h" + namespace fs = std::filesystem; CXmlOpr::CXmlOpr() = default; @@ -13,12 +15,13 @@ bool CXmlOpr::open(const std::string& xml_path) if (doc_.LoadFile(CUtil::utf8_to_gbk(xml_path).c_str()) != tinyxml2::XML_SUCCESS) { return false; } + xml_path_ = CUtil::utf8_to_gbk(xml_path); #else if (doc_.LoadFile(xml_path.c_str()) != tinyxml2::XML_SUCCESS) { return false; } -#endif xml_path_ = xml_path; +#endif return true; } @@ -44,21 +47,21 @@ bool CXmlOpr::get_all_elements(std::vector& vec, const std::string& { vec.clear(); - Element_t* temp = parent_node_; + parent_node2_ = parent_node_; if (!unit.empty()) { - temp = temp->FirstChildElement(unit.c_str()); + parent_node2_ = parent_node2_->FirstChildElement(unit.c_str()); } if (!opr_base_.relative_nodes.empty()) { auto v = CUtil::splitString(opr_base_.relative_nodes, ","); // 向下子项跳跃 for (const auto& it : v) { - temp = temp->FirstChildElement(it.c_str()); + parent_node2_ = parent_node2_->FirstChildElement(it.c_str()); } } - auto purpose_node = temp->FirstChildElement(opr_base_.item_key.c_str()); + auto purpose_node = parent_node2_->FirstChildElement(opr_base_.item_key.c_str()); while (purpose_node) { vec.push_back(purpose_node); purpose_node = purpose_node->NextSiblingElement(); @@ -81,7 +84,6 @@ bool CXmlOpr::parse_xml(std::vector& vec) auto nodes = CUtil::splitString(opr_base_.main_nodes, "/"); for (const auto& item : nodes) { - if (item.empty()) { continue; } @@ -93,6 +95,10 @@ bool CXmlOpr::parse_xml(std::vector& vec) } } + if (parent_node_ == nullptr) { + return false; + } + if (opr_base_.is_same) { units_.clear(); auto p = parent_node_->FirstChildElement(); @@ -110,7 +116,7 @@ bool CXmlOpr::parse_xml(std::vector& vec) return true; } -bool CXmlOpr::get_all_unit(std::vector &units) +bool CXmlOpr::get_all_unit(std::vector& units) { units = units_; return true; @@ -121,7 +127,7 @@ void CXmlOpr::copy_and_del(std::vector& vec, std::vector { out.clear(); // 先找到最后一个节点 - Element_t* last_node = parent_node_->LastChildElement(opr_base_.item_key.c_str()); + Element_t* last_node = parent_node2_->LastChildElement(opr_base_.item_key.c_str()); Element_t* last_node_bk = last_node; if (last_node == nullptr) { return; @@ -133,14 +139,14 @@ void CXmlOpr::copy_and_del(std::vector& vec, std::vector last_node = n; } // 删除原有的节点 - Element_t* fnode = parent_node_->FirstChildElement(opr_base_.item_key.c_str()); + Element_t* fnode = parent_node2_->FirstChildElement(opr_base_.item_key.c_str()); Element_t* fnext = fnode->NextSiblingElement(); while (fnode != last_node_bk) { - parent_node_->DeleteChild(fnode); + parent_node2_->DeleteChild(fnode); fnode = fnext; fnext = fnode->NextSiblingElement(); } - parent_node_->DeleteChild(last_node_bk); + parent_node2_->DeleteChild(last_node_bk); } void CXmlOpr::insert_brother_node(Element_t* brother, Element_t* newer) @@ -148,7 +154,7 @@ void CXmlOpr::insert_brother_node(Element_t* brother, Element_t* newer) if (!brother || !newer) { return; } - parent_node_->InsertAfterChild(brother, newer); + parent_node2_->InsertAfterChild(brother, newer); } Element_t* CXmlOpr::copy_element(Element_t* ele) @@ -177,7 +183,7 @@ bool CXmlOpr::check_valid_xml_data(const std::string& data) bool CXmlOpr::check_same_struct(const std::string& data) { - auto* own_ele = parent_node_->FirstChildElement(opr_base_.item_key.c_str()); + auto* own_ele = parent_node2_->FirstChildElement(opr_base_.item_key.c_str()); if (own_ele == nullptr) { return true; } @@ -219,7 +225,7 @@ bool CXmlOpr::check_same_struct(const std::string& data) 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_.item_key.c_str()); + auto* last_item = parent_node2_->LastChildElement(opr_base_.item_key.c_str()); if (last_item == nullptr) { return false; } @@ -244,7 +250,7 @@ bool CXmlOpr::import_newer_data(const std::vector& vec, std::size_t void CXmlOpr::del_element(Element_t* ele) { - parent_node_->DeleteChild(ele); + parent_node2_->DeleteChild(ele); } bool CXmlOpr::check_key_exists(const Property_t& property) @@ -252,7 +258,7 @@ bool CXmlOpr::check_key_exists(const Property_t& property) if (keys_.size() < 1 || property.size() < 1) { return false; } - return check_key_exists(property[0].key); + return check_key_exists(property[0].value); } bool CXmlOpr::check_key_exists(const std::string& key) @@ -260,7 +266,7 @@ bool CXmlOpr::check_key_exists(const std::string& key) if (keys_.size() < 1 || key.empty()) { return false; } - Element_t* purpose_node = parent_node_->FirstChildElement(opr_base_.item_key.c_str()); + Element_t* purpose_node = parent_node2_->FirstChildElement(opr_base_.item_key.c_str()); while (purpose_node) { const char* value = purpose_node->Attribute(keys_[0].c_str()); if (key == std::string(value)) { diff --git a/src/xml_opr.h b/src/xml_opr.h index 1f8e3b4..d9f92d8 100644 --- a/src/xml_opr.h +++ b/src/xml_opr.h @@ -52,6 +52,7 @@ private: OneGroupIni opr_base_{}; std::string xml_path_{}; Element_t* parent_node_{}; + Element_t* parent_node2_{}; std::vector keys_{}; std::vector units_{}; };