fix:v1.3.1修复BUG。

This commit is contained in:
taynpg 2024-08-27 20:15:41 +08:00
parent b05783191f
commit f2b1525b92
13 changed files with 50 additions and 38 deletions

View File

@ -19,7 +19,7 @@
"visualizerFile": "${workspaceRoot}/.vscode/qt6.natvis" "visualizerFile": "${workspaceRoot}/.vscode/qt6.natvis"
}, },
"cmake.environment": { "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.options.statusBarVisibility": "visible",
"cmake.generator": "Ninja", "cmake.generator": "Ninja",

View File

@ -13,7 +13,8 @@ endif()
message(STATUS "User home directory: ${USER_HOME}") message(STATUS "User home directory: ${USER_HOME}")
set(CMAKE_PREFIX_PATH 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/" "${USER_HOME}/Qt5.14.2/5.14.2/gcc_64/"
) )

View File

@ -18,7 +18,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
{ {
ui->setupUi(this); ui->setupUi(this);
setWindowTitle(u8"OneLevelXmlOpr v1.3.0"); setWindowTitle(u8"OneLevelXmlOpr v1.3.1");
setWindowIcon(QIcon("://resource/xml.ico")); setWindowIcon(QIcon("://resource/xml.ico"));
QScreen* primaryScreen = QGuiApplication::primaryScreen(); QScreen* primaryScreen = QGuiApplication::primaryScreen();
@ -483,7 +483,7 @@ bool MainWidget::edit_property(Element_t* target, int row)
} }
attri_edit_->get_attribute(property); attri_edit_->get_attribute(property);
if (property[0].value != value_pre) { if (property[0].value == value_pre) {
while (xml_.check_key_exists(property)) { while (xml_.check_key_exists(property)) {
CUtil::msg(attri_edit_, u8"不能有相同的key,请检查。"); CUtil::msg(attri_edit_, u8"不能有相同的key,请检查。");
attri_edit_->exec(); attri_edit_->exec();

View File

@ -4,4 +4,4 @@
# 编译环境 # 编译环境
`msvc Qt5.14.2``vs2017` 环境下通过 `windows`下,`Qt6`可正常使用无乱码

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

View File

@ -1,4 +1,5 @@
#include "attribute_edit.h" #include "attribute_edit.h"
#include "ui_attribute_edit.h" #include "ui_attribute_edit.h"
CAttributeEdit::CAttributeEdit(QWidget* parent) : QDialog(parent), ui(new Ui::CAttributeEdit) 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) { for (int i = 0; i < row; ++i) {
QString key = table_->item(i, 0)->text(); QString key = table_->item(i, 0)->text();
QString value = table_->item(i, 1)->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; is_ok_ = true;
close(); close();
} }
CAttributeEdit::~CAttributeEdit() CAttributeEdit::~CAttributeEdit()
{ {
delete ui; delete ui;
@ -59,7 +59,7 @@ void CAttributeEdit::show_before()
is_ok_ = false; 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

@ -1,4 +1,5 @@
#include "config.h" #include "config.h"
#include <QDir> #include <QDir>
#include <filesystem> #include <filesystem>
@ -13,7 +14,7 @@ void CGroupIni::default_set()
QDir dir; QDir dir;
std::string path = dir.homePath().toStdString(); std::string path = dir.homePath().toStdString();
fs::path p(path); fs::path p(path);
p.append(".config"); p.append(".config/OneLevelXmlOpr");
if (!fs::exists(p)) { if (!fs::exists(p)) {
fs::create_directories(p); fs::create_directories(p);
@ -41,7 +42,7 @@ void CGroupIni::get_all_node(StrVec_t& vec)
{ {
vec.clear(); vec.clear();
CSimpleIni::TNamesDepend secs; CSimpleIniA::TNamesDepend secs;
ini_.GetAllSections(secs); ini_.GetAllSections(secs);
for (const auto& sec : secs) { for (const auto& sec : secs) {
vec.push_back(sec.pItem); vec.push_back(sec.pItem);
@ -93,7 +94,7 @@ bool CGroupIni::get_item(OneGroupIni& group)
return true; 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(), "MainNodes", true);
ini_.Delete(key.c_str(), "RelativeNodes", true); ini_.Delete(key.c_str(), "RelativeNodes", true);

View File

@ -3,7 +3,7 @@
#include <string> #include <string>
#include <SimpleIni.h> #include <SimpleIni.h>
#include <vector>
/* /*
[Basic] [Basic]

View File

@ -1,11 +1,14 @@
#include "data_edit.h" #include "data_edit.h"
#include "ui_data_edit.h"
#include <QScreen>
#include <QClipboard>
#include <tinyxml2.h> #include <tinyxml2.h>
#include <vector>
#include <QClipboard>
#include <QScreen>
#include <string> #include <string>
#include <vector>
#include "../public_def.h" #include "../public_def.h"
#include "ui_data_edit.h"
CDataEdit::CDataEdit(QWidget* parent) : QDialog(parent), ui(new Ui::CDataEdit) CDataEdit::CDataEdit(QWidget* parent) : QDialog(parent), ui(new Ui::CDataEdit)
{ {

View File

@ -41,7 +41,7 @@ void CHistory::default_set()
QDir dir; QDir dir;
std::string path = dir.homePath().toStdString(); std::string path = dir.homePath().toStdString();
fs::path p(path); fs::path p(path);
p.append(".config"); p.append(".config/OneLevelXmlOpr");
if (!fs::exists(p)) { if (!fs::exists(p)) {
fs::create_directories(p); fs::create_directories(p);

View File

@ -1,7 +1,9 @@
#include "xml_opr.h" #include "xml_opr.h"
#include "../public_def.h"
#include <filesystem> #include <filesystem>
#include "../public_def.h"
namespace fs = std::filesystem; namespace fs = std::filesystem;
CXmlOpr::CXmlOpr() = default; 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) { if (doc_.LoadFile(CUtil::utf8_to_gbk(xml_path).c_str()) != tinyxml2::XML_SUCCESS) {
return false; return false;
} }
xml_path_ = CUtil::utf8_to_gbk(xml_path);
#else #else
if (doc_.LoadFile(xml_path.c_str()) != tinyxml2::XML_SUCCESS) { if (doc_.LoadFile(xml_path.c_str()) != tinyxml2::XML_SUCCESS) {
return false; return false;
} }
#endif
xml_path_ = xml_path; xml_path_ = xml_path;
#endif
return true; return true;
} }
@ -44,21 +47,21 @@ bool CXmlOpr::get_all_elements(std::vector<Element_t*>& vec, const std::string&
{ {
vec.clear(); vec.clear();
Element_t* temp = parent_node_; parent_node2_ = parent_node_;
if (!unit.empty()) { if (!unit.empty()) {
temp = temp->FirstChildElement(unit.c_str()); parent_node2_ = parent_node2_->FirstChildElement(unit.c_str());
} }
if (!opr_base_.relative_nodes.empty()) { if (!opr_base_.relative_nodes.empty()) {
auto v = CUtil::splitString(opr_base_.relative_nodes, ","); auto v = CUtil::splitString(opr_base_.relative_nodes, ",");
// 向下子项跳跃 // 向下子项跳跃
for (const auto& it : v) { 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) { while (purpose_node) {
vec.push_back(purpose_node); vec.push_back(purpose_node);
purpose_node = purpose_node->NextSiblingElement(); purpose_node = purpose_node->NextSiblingElement();
@ -81,7 +84,6 @@ bool CXmlOpr::parse_xml(std::vector<tinyxml2::XMLElement*>& vec)
auto nodes = CUtil::splitString(opr_base_.main_nodes, "/"); auto nodes = CUtil::splitString(opr_base_.main_nodes, "/");
for (const auto& item : nodes) { for (const auto& item : nodes) {
if (item.empty()) { if (item.empty()) {
continue; continue;
} }
@ -93,6 +95,10 @@ bool CXmlOpr::parse_xml(std::vector<tinyxml2::XMLElement*>& vec)
} }
} }
if (parent_node_ == nullptr) {
return false;
}
if (opr_base_.is_same) { if (opr_base_.is_same) {
units_.clear(); units_.clear();
auto p = parent_node_->FirstChildElement(); auto p = parent_node_->FirstChildElement();
@ -110,7 +116,7 @@ bool CXmlOpr::parse_xml(std::vector<tinyxml2::XMLElement*>& vec)
return true; return true;
} }
bool CXmlOpr::get_all_unit(std::vector<std::string> &units) bool CXmlOpr::get_all_unit(std::vector<std::string>& units)
{ {
units = units_; units = units_;
return true; return true;
@ -121,7 +127,7 @@ void CXmlOpr::copy_and_del(std::vector<Element_t*>& vec, std::vector<Element_t*>
{ {
out.clear(); 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; Element_t* last_node_bk = last_node;
if (last_node == nullptr) { if (last_node == nullptr) {
return; return;
@ -133,14 +139,14 @@ void CXmlOpr::copy_and_del(std::vector<Element_t*>& vec, std::vector<Element_t*>
last_node = n; 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(); Element_t* fnext = fnode->NextSiblingElement();
while (fnode != last_node_bk) { while (fnode != last_node_bk) {
parent_node_->DeleteChild(fnode); parent_node2_->DeleteChild(fnode);
fnode = fnext; fnode = fnext;
fnext = fnode->NextSiblingElement(); 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) 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) { if (!brother || !newer) {
return; return;
} }
parent_node_->InsertAfterChild(brother, newer); parent_node2_->InsertAfterChild(brother, newer);
} }
Element_t* CXmlOpr::copy_element(Element_t* ele) 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) 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) { if (own_ele == nullptr) {
return true; return true;
} }
@ -219,7 +225,7 @@ bool CXmlOpr::check_same_struct(const std::string& data)
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_.item_key.c_str()); auto* last_item = parent_node2_->LastChildElement(opr_base_.item_key.c_str());
if (last_item == nullptr) { if (last_item == nullptr) {
return false; return false;
} }
@ -244,7 +250,7 @@ bool CXmlOpr::import_newer_data(const std::vector<std::string>& vec, std::size_t
void CXmlOpr::del_element(Element_t* ele) void CXmlOpr::del_element(Element_t* ele)
{ {
parent_node_->DeleteChild(ele); parent_node2_->DeleteChild(ele);
} }
bool CXmlOpr::check_key_exists(const Property_t& property) 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) { if (keys_.size() < 1 || property.size() < 1) {
return false; 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) 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()) { if (keys_.size() < 1 || key.empty()) {
return false; 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) { while (purpose_node) {
const char* value = purpose_node->Attribute(keys_[0].c_str()); const char* value = purpose_node->Attribute(keys_[0].c_str());
if (key == std::string(value)) { if (key == std::string(value)) {

View File

@ -52,6 +52,7 @@ private:
OneGroupIni opr_base_{}; OneGroupIni opr_base_{};
std::string xml_path_{}; std::string xml_path_{};
Element_t* parent_node_{}; Element_t* parent_node_{};
Element_t* parent_node2_{};
std::vector<std::string> keys_{}; std::vector<std::string> keys_{};
std::vector<std::string> units_{}; std::vector<std::string> units_{};
}; };