add:添加可以不用重启切换配置文件重新加载。
This commit is contained in:
parent
2451ae76be
commit
c2c3f6f2ca
@ -20,7 +20,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
setWindowTitle(u8"OneLevelXmlOpr v1.3.8");
|
setWindowTitle(u8"OneLevelXmlOpr v1.3.9");
|
||||||
setWindowIcon(QIcon("://resource/xml.ico"));
|
setWindowIcon(QIcon("://resource/xml.ico"));
|
||||||
|
|
||||||
QScreen* primaryScreen = QGuiApplication::primaryScreen();
|
QScreen* primaryScreen = QGuiApplication::primaryScreen();
|
||||||
@ -96,8 +96,9 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
|||||||
});
|
});
|
||||||
|
|
||||||
connect(ui->btnSet, &QPushButton::clicked, this, [&]() {
|
connect(ui->btnSet, &QPushButton::clicked, this, [&]() {
|
||||||
|
QString cur = ui->cbConfig->currentText();
|
||||||
group_set_->exec();
|
group_set_->exec();
|
||||||
base_init();
|
base_init(cur);
|
||||||
});
|
});
|
||||||
connect(ui->btnHis, &QPushButton::clicked, this, [&]() {
|
connect(ui->btnHis, &QPushButton::clicked, this, [&]() {
|
||||||
CUIHistory his(this, his_);
|
CUIHistory his(this, his_);
|
||||||
@ -139,7 +140,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
|||||||
restoreGeometry(settings.value("geometry").toByteArray());
|
restoreGeometry(settings.value("geometry").toByteArray());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
// QFile qss_file("://qss/lightblue.css");
|
//QFile qss_file("://qss/lightblue.css");
|
||||||
// QFile qss_file("://qss/flatgray.css");
|
// QFile qss_file("://qss/flatgray.css");
|
||||||
// if (qss_file.open(QFile::ReadOnly)) {
|
// if (qss_file.open(QFile::ReadOnly)) {
|
||||||
// qApp->setStyleSheet(qss_file.readAll());
|
// qApp->setStyleSheet(qss_file.readAll());
|
||||||
@ -147,7 +148,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
|||||||
|
|
||||||
init_menu();
|
init_menu();
|
||||||
// 基本处理
|
// 基本处理
|
||||||
base_init();
|
base_init("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::copy_key()
|
void MainWidget::copy_key()
|
||||||
@ -212,7 +213,10 @@ void MainWidget::show_custom_menu()
|
|||||||
|
|
||||||
void MainWidget::generate_table_widget()
|
void MainWidget::generate_table_widget()
|
||||||
{
|
{
|
||||||
tab_widget_ = new QTableWidget();
|
clear_tab_widget();
|
||||||
|
if (tab_widget_ == nullptr) {
|
||||||
|
tab_widget_ = new QTableWidget();
|
||||||
|
}
|
||||||
metrics_ = std::make_shared<QFontMetrics>(tab_widget_->font());
|
metrics_ = std::make_shared<QFontMetrics>(tab_widget_->font());
|
||||||
tab_widget_->setContextMenuPolicy(Qt::CustomContextMenu);
|
tab_widget_->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
|
||||||
@ -244,9 +248,11 @@ void MainWidget::generate_table_widget()
|
|||||||
tab_widget_->setColumnWidth(i, col_with_[i]);
|
tab_widget_->setColumnWidth(i, col_with_[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
QHBoxLayout* lay = new QHBoxLayout();
|
if (lay_ == nullptr) {
|
||||||
lay->addWidget(tab_widget_);
|
lay_ = new QHBoxLayout();
|
||||||
ui->widget->setLayout(lay);
|
}
|
||||||
|
lay_->addWidget(tab_widget_);
|
||||||
|
ui->widget->setLayout(lay_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::push_content(const std::vector<tinyxml2::XMLElement*>& eles, std::size_t page, bool auto_jump_pre)
|
void MainWidget::push_content(const std::vector<tinyxml2::XMLElement*>& eles, std::size_t page, bool auto_jump_pre)
|
||||||
@ -316,22 +322,44 @@ void MainWidget::judge_btn_page()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWidget::clear_data()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool MainWidget::read(const QString& file_path)
|
bool MainWidget::read(const QString& file_path)
|
||||||
{
|
{
|
||||||
|
unit_change_auto_ = true;
|
||||||
|
ui->cbUnit->clear();
|
||||||
|
unit_change_auto_ = false;
|
||||||
|
if (alreay_open_) {
|
||||||
|
if (!CUtil::affirm(this, u8"确认", u8"当前已有打开文件在使用,请确认已保存相关内容再继续。")) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
xml_.clear_data();
|
||||||
|
current_.clear();
|
||||||
|
vec_.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
// 获取配置
|
// 获取配置
|
||||||
cur_config_.name = ui->cbConfig->currentText().toStdString();
|
cur_config_.name = ui->cbConfig->currentText().toStdString();
|
||||||
if (!ini_oper_->get_item(cur_config_)) {
|
if (!ini_oper_->get_item(cur_config_)) {
|
||||||
CUtil::msg(this, u8"获取配置失败。");
|
CUtil::msg(this, u8"获取配置失败。");
|
||||||
|
clear_tab_widget();
|
||||||
|
alreay_open_ = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!xml_.open(file_path.toStdString())) {
|
if (!xml_.open(file_path.toStdString())) {
|
||||||
CUtil::msg(this, u8"打开xml失败。");
|
CUtil::msg(this, u8"打开xml失败。");
|
||||||
|
clear_tab_widget();
|
||||||
|
alreay_open_ = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
xml_.set_baseinfo(cur_config_);
|
xml_.set_baseinfo(cur_config_);
|
||||||
if (!xml_.parse_xml(vec_)) {
|
if (!xml_.parse_xml(vec_)) {
|
||||||
CUtil::msg(this, u8"解析xml失败。");
|
CUtil::msg(this, u8"解析xml失败。");
|
||||||
|
clear_tab_widget();
|
||||||
|
alreay_open_ = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,6 +382,7 @@ bool MainWidget::read(const QString& file_path)
|
|||||||
}
|
}
|
||||||
u_ = false;
|
u_ = false;
|
||||||
ui->btnResort->setEnabled(false);
|
ui->btnResort->setEnabled(false);
|
||||||
|
ui->cbUnit->setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
ui->cbUnit->setEnabled(false);
|
ui->cbUnit->setEnabled(false);
|
||||||
}
|
}
|
||||||
@ -369,21 +398,20 @@ bool MainWidget::read(const QString& file_path)
|
|||||||
current_ = vec_;
|
current_ = vec_;
|
||||||
|
|
||||||
ui->edStatus->setText(file_path);
|
ui->edStatus->setText(file_path);
|
||||||
ui->btnRead->setEnabled(false);
|
// ui->btnRead->setEnabled(false);
|
||||||
ui->btnSave->setEnabled(true);
|
ui->btnSave->setEnabled(true);
|
||||||
ui->btnSelectFile->setEnabled(false);
|
// ui->btnSelectFile->setEnabled(false);
|
||||||
ui->btnImport->setEnabled(true);
|
ui->btnImport->setEnabled(true);
|
||||||
ui->btnExport->setEnabled(true);
|
ui->btnExport->setEnabled(true);
|
||||||
ui->btnBackup->setEnabled(true);
|
ui->btnBackup->setEnabled(true);
|
||||||
ui->btnBackup->setEnabled(true);
|
|
||||||
ui->btnResort->setEnabled(true);
|
ui->btnResort->setEnabled(true);
|
||||||
|
|
||||||
ui->cbConfig->setEnabled(false);
|
// ui->cbConfig->setEnabled(false);
|
||||||
ui->btnSet->setEnabled(false);
|
// ui->btnSet->setEnabled(false);
|
||||||
ui->btnHis->setEnabled(false);
|
// ui->btnHis->setEnabled(false);
|
||||||
|
|
||||||
his_->push(ui->edStatus->text().toStdString());
|
his_->push(ui->edStatus->text().toStdString());
|
||||||
|
alreay_open_ = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -896,14 +924,18 @@ void MainWidget::backup_file()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::base_init()
|
void MainWidget::base_init(const QString& cur_config)
|
||||||
{
|
{
|
||||||
StrVec_t vec;
|
StrVec_t vec;
|
||||||
ini_oper_->get_all_node(vec);
|
ini_oper_->get_all_node(vec);
|
||||||
|
|
||||||
QStringList list;
|
QStringList list;
|
||||||
|
bool have = false;
|
||||||
for (const auto& data : vec) {
|
for (const auto& data : vec) {
|
||||||
list.append(QString::fromStdString(data));
|
list.append(QString::fromStdString(data));
|
||||||
|
if (QString::fromStdString(data) == cur_config) {
|
||||||
|
have = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ui->cbConfig->clear();
|
ui->cbConfig->clear();
|
||||||
|
|
||||||
@ -912,7 +944,11 @@ void MainWidget::base_init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ui->cbConfig->addItems(list);
|
ui->cbConfig->addItems(list);
|
||||||
ui->cbConfig->setCurrentIndex(0);
|
if (have) {
|
||||||
|
ui->cbConfig->setCurrentIndex(list.indexOf(cur_config));
|
||||||
|
} else {
|
||||||
|
ui->cbConfig->setCurrentIndex(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::unit_change()
|
void MainWidget::unit_change()
|
||||||
@ -920,6 +956,9 @@ void MainWidget::unit_change()
|
|||||||
if (u_) {
|
if (u_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (unit_change_auto_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
std::string unit = ui->cbUnit->currentText().toStdString();
|
std::string unit = ui->cbUnit->currentText().toStdString();
|
||||||
if (!xml_.get_all_elements(vec_, unit)) {
|
if (!xml_.get_all_elements(vec_, unit)) {
|
||||||
CUtil::msg(this, u8"获取单元信息失败:" + QString::fromStdString(unit));
|
CUtil::msg(this, u8"获取单元信息失败:" + QString::fromStdString(unit));
|
||||||
@ -955,6 +994,18 @@ bool MainWidget::format_xml()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWidget::clear_tab_widget()
|
||||||
|
{
|
||||||
|
if (tab_widget_) {
|
||||||
|
tab_widget_->setRowCount(0);
|
||||||
|
if (lay_) {
|
||||||
|
lay_->removeWidget(tab_widget_);
|
||||||
|
}
|
||||||
|
delete tab_widget_;
|
||||||
|
tab_widget_ = new QTableWidget();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string MainWidget::extract_prefix(const std::string& name)
|
std::string MainWidget::extract_prefix(const std::string& name)
|
||||||
{
|
{
|
||||||
auto pos = name.find('.');
|
auto pos = name.find('.');
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
|
||||||
#include "conf_setting.h"
|
#include "conf_setting.h"
|
||||||
#include "src/attribute_edit.h"
|
#include "src/attribute_edit.h"
|
||||||
@ -57,6 +58,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool read(const QString& file_path);
|
bool read(const QString& file_path);
|
||||||
|
void clear_data();
|
||||||
void search(const QString& key);
|
void search(const QString& key);
|
||||||
void item_changed_handle(QTableWidgetItem* item);
|
void item_changed_handle(QTableWidgetItem* item);
|
||||||
void save();
|
void save();
|
||||||
@ -74,9 +76,10 @@ private:
|
|||||||
void copy_multi_data();
|
void copy_multi_data();
|
||||||
void replace_content(bool is_common = true);
|
void replace_content(bool is_common = true);
|
||||||
void backup_file();
|
void backup_file();
|
||||||
void base_init();
|
void base_init(const QString& cur_config);
|
||||||
void unit_change();
|
void unit_change();
|
||||||
bool format_xml();
|
bool format_xml();
|
||||||
|
void clear_tab_widget();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string extract_prefix(const std::string& name);
|
std::string extract_prefix(const std::string& name);
|
||||||
@ -126,5 +129,8 @@ private:
|
|||||||
CHistory* his_{};
|
CHistory* his_{};
|
||||||
OneGroupIni cur_config_{};
|
OneGroupIni cur_config_{};
|
||||||
bool u_{false};
|
bool u_{false};
|
||||||
|
bool alreay_open_{false};
|
||||||
|
QHBoxLayout* lay_{};
|
||||||
|
bool unit_change_auto_{true};
|
||||||
};
|
};
|
||||||
#endif // MAINWIDGET_H
|
#endif // MAINWIDGET_H
|
||||||
|
@ -23,7 +23,7 @@ CGroupSetting::~CGroupSetting()
|
|||||||
|
|
||||||
void CGroupSetting::showEvent(QShowEvent* event)
|
void CGroupSetting::showEvent(QShowEvent* event)
|
||||||
{
|
{
|
||||||
update_ini();
|
update_ini("");
|
||||||
QDialog::showEvent(event);
|
QDialog::showEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ void CGroupSetting::add_item()
|
|||||||
CUtil::msg(this, u8"失败");
|
CUtil::msg(this, u8"失败");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
update_ini();
|
update_ini(QString::fromStdString(gp.name));
|
||||||
CUtil::msg(this, u8"成功");
|
CUtil::msg(this, u8"成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ void CGroupSetting::del_item()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 删除成功之后要更新 cb
|
// 删除成功之后要更新 cb
|
||||||
update_ini();
|
update_ini("");
|
||||||
|
|
||||||
CUtil::msg(this, u8"成功");
|
CUtil::msg(this, u8"成功");
|
||||||
}
|
}
|
||||||
@ -108,21 +108,29 @@ void CGroupSetting::change_ini()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGroupSetting::update_ini()
|
void CGroupSetting::update_ini(const QString& cur_key)
|
||||||
{
|
{
|
||||||
StrVec_t vec;
|
StrVec_t vec;
|
||||||
ini_opr_->get_all_node(vec);
|
ini_opr_->get_all_node(vec);
|
||||||
|
|
||||||
QStringList list;
|
QStringList list;
|
||||||
|
bool has_cur = false;
|
||||||
for (const auto& data : vec) {
|
for (const auto& data : vec) {
|
||||||
list.append(QString::fromStdString(data));
|
list.append(QString::fromStdString(data));
|
||||||
|
if (data == cur_key.toStdString()) {
|
||||||
|
has_cur = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto_add_ = true;
|
auto_add_ = true;
|
||||||
ui->cbConfig->clear();
|
ui->cbConfig->clear();
|
||||||
if (!list.empty()) {
|
if (!list.empty()) {
|
||||||
ui->cbConfig->addItems(list);
|
ui->cbConfig->addItems(list);
|
||||||
ui->cbConfig->setCurrentIndex(0);
|
if (has_cur) {
|
||||||
|
ui->cbConfig->setCurrentIndex(list.indexOf(cur_key));
|
||||||
|
} else {
|
||||||
|
ui->cbConfig->setCurrentIndex(0);
|
||||||
|
}
|
||||||
OneGroupIni gp;
|
OneGroupIni gp;
|
||||||
gp.name = ui->cbConfig->currentText().toStdString();
|
gp.name = ui->cbConfig->currentText().toStdString();
|
||||||
if (!ini_opr_->get_item(gp)) {
|
if (!ini_opr_->get_item(gp)) {
|
||||||
|
@ -25,7 +25,7 @@ private:
|
|||||||
void del_item();
|
void del_item();
|
||||||
void set_ui(const OneGroupIni& gp);
|
void set_ui(const OneGroupIni& gp);
|
||||||
void change_ini();
|
void change_ini();
|
||||||
void update_ini();
|
void update_ini(const QString& cur_key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool auto_add_{false};
|
bool auto_add_{false};
|
||||||
|
@ -15,8 +15,7 @@ CXmlOpr::~CXmlOpr() = default;
|
|||||||
bool CXmlOpr::open(const std::string& xml_path)
|
bool CXmlOpr::open(const std::string& xml_path)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (doc_.LoadFile(CUtil::utf8_to_gbk(xml_path).c_str()) !=
|
if (doc_.LoadFile(CUtil::utf8_to_gbk(xml_path).c_str()) != tinyxml2::XML_SUCCESS) {
|
||||||
tinyxml2::XML_SUCCESS) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
xml_path_ = CUtil::utf8_to_gbk(xml_path);
|
xml_path_ = CUtil::utf8_to_gbk(xml_path);
|
||||||
@ -29,8 +28,7 @@ bool CXmlOpr::open(const std::string& xml_path)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXmlOpr::backup_file(const std::string& desti_folder,
|
bool CXmlOpr::backup_file(const std::string& desti_folder, const std::string& time)
|
||||||
const std::string& time)
|
|
||||||
{
|
{
|
||||||
if (!fs::exists(xml_path_)) {
|
if (!fs::exists(xml_path_)) {
|
||||||
return false;
|
return false;
|
||||||
@ -39,8 +37,7 @@ bool CXmlOpr::backup_file(const std::string& desti_folder,
|
|||||||
fs::create_directories(desti_folder);
|
fs::create_directories(desti_folder);
|
||||||
}
|
}
|
||||||
fs::path file_path = fs::path(xml_path_);
|
fs::path file_path = fs::path(xml_path_);
|
||||||
fs::path des = fs::path(desti_folder)
|
fs::path des = fs::path(desti_folder).append(file_path.stem().string() + "_" + time + ".xml");
|
||||||
.append(file_path.stem().string() + "_" + time + ".xml");
|
|
||||||
return fs::copy_file(xml_path_, des);
|
return fs::copy_file(xml_path_, des);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,8 +46,7 @@ void CXmlOpr::set_baseinfo(const OneGroupIni& base)
|
|||||||
opr_base_ = base;
|
opr_base_ = base;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXmlOpr::get_all_elements(std::vector<Element_t*>& vec,
|
bool CXmlOpr::get_all_elements(std::vector<Element_t*>& vec, const std::string& unit)
|
||||||
const std::string& unit)
|
|
||||||
{
|
{
|
||||||
vec.clear();
|
vec.clear();
|
||||||
|
|
||||||
@ -68,8 +64,7 @@ bool CXmlOpr::get_all_elements(std::vector<Element_t*>& vec,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto purpose_node =
|
auto purpose_node = parent_node2_->FirstChildElement(opr_base_.item_key.c_str());
|
||||||
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();
|
||||||
@ -131,13 +126,11 @@ bool CXmlOpr::get_all_unit(std::vector<std::string>& units)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 排序后(仅指针排序)的节点进行复制(让实际内容有序),删除原始节点
|
// 排序后(仅指针排序)的节点进行复制(让实际内容有序),删除原始节点
|
||||||
void CXmlOpr::copy_and_del(std::vector<Element_t*>& vec,
|
void CXmlOpr::copy_and_del(std::vector<Element_t*>& vec, std::vector<Element_t*>& out)
|
||||||
std::vector<Element_t*>& out)
|
|
||||||
{
|
{
|
||||||
out.clear();
|
out.clear();
|
||||||
// 先找到最后一个节点
|
// 先找到最后一个节点
|
||||||
Element_t* last_node =
|
Element_t* last_node = parent_node2_->LastChildElement(opr_base_.item_key.c_str());
|
||||||
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;
|
||||||
@ -149,8 +142,7 @@ void CXmlOpr::copy_and_del(std::vector<Element_t*>& vec,
|
|||||||
last_node = n;
|
last_node = n;
|
||||||
}
|
}
|
||||||
// 删除原有的节点
|
// 删除原有的节点
|
||||||
Element_t* fnode =
|
Element_t* fnode = parent_node2_->FirstChildElement(opr_base_.item_key.c_str());
|
||||||
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_node2_->DeleteChild(fnode);
|
parent_node2_->DeleteChild(fnode);
|
||||||
@ -194,8 +186,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 =
|
auto* own_ele = parent_node2_->FirstChildElement(opr_base_.item_key.c_str());
|
||||||
parent_node2_->FirstChildElement(opr_base_.item_key.c_str());
|
|
||||||
if (own_ele == nullptr) {
|
if (own_ele == nullptr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -234,12 +225,10 @@ 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,
|
bool CXmlOpr::import_newer_data(const std::vector<std::string>& vec, std::size_t& success_count)
|
||||||
std::size_t& success_count)
|
|
||||||
{
|
{
|
||||||
success_count = 0;
|
success_count = 0;
|
||||||
auto* last_item =
|
auto* last_item = parent_node2_->LastChildElement(opr_base_.item_key.c_str());
|
||||||
parent_node2_->LastChildElement(opr_base_.item_key.c_str());
|
|
||||||
if (last_item == nullptr) {
|
if (last_item == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -262,8 +251,7 @@ bool CXmlOpr::import_newer_data(const std::vector<std::string>& vec,
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::string CXmlOpr::handle_space(const std::string& content,
|
std::string CXmlOpr::handle_space(const std::string& content, const std::vector<std::string>& keychars)
|
||||||
const std::vector<std::string>& keychars)
|
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
@ -276,10 +264,8 @@ std::string CXmlOpr::handle_space(const std::string& content,
|
|||||||
}
|
}
|
||||||
std::string op(keychars[i]);
|
std::string op(keychars[i]);
|
||||||
for (const char& c : op) {
|
for (const char& c : op) {
|
||||||
if (c == '|' || c == '\\' || c == '(' || c == ')' || c == '[' ||
|
if (c == '|' || c == '\\' || c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c == '}' || c == '^' ||
|
||||||
c == ']' || c == '{' || c == '}' || c == '^' || c == '$' ||
|
c == '$' || c == '.' || c == '*' || c == '+' || c == '?' || c == '|' || c == '\\') {
|
||||||
c == '.' || c == '*' || c == '+' || c == '?' || c == '|' ||
|
|
||||||
c == '\\') {
|
|
||||||
oss << '\\'; // 添加转义字符
|
oss << '\\'; // 添加转义字符
|
||||||
}
|
}
|
||||||
oss << c;
|
oss << c;
|
||||||
@ -308,10 +294,8 @@ std::string CXmlOpr::handle_space(const std::string& content,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract the quoted content
|
// Extract the quoted content
|
||||||
std::string quoted_content =
|
std::string quoted_content = content.substr(start_quote + 1, end_quote - start_quote - 1);
|
||||||
content.substr(start_quote + 1, end_quote - start_quote - 1);
|
std::string processed_content = std::regex_replace(quoted_content, operators_regex, " $& ");
|
||||||
std::string processed_content =
|
|
||||||
std::regex_replace(quoted_content, operators_regex, " $& ");
|
|
||||||
|
|
||||||
// Process quoted content to replace multiple spaces with a single space
|
// Process quoted content to replace multiple spaces with a single space
|
||||||
std::istringstream iss(processed_content);
|
std::istringstream iss(processed_content);
|
||||||
@ -335,8 +319,7 @@ std::string CXmlOpr::handle_space(const std::string& content,
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
bool CXmlOpr::handle_transfer(const std::string& path,
|
bool CXmlOpr::handle_transfer(const std::string& path, const std::vector<std::string>& keychars)
|
||||||
const std::vector<std::string>& keychars)
|
|
||||||
{
|
{
|
||||||
std::ifstream file(path);
|
std::ifstream file(path);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
@ -414,8 +397,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 =
|
Element_t* purpose_node = parent_node2_->FirstChildElement(opr_base_.item_key.c_str());
|
||||||
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)) {
|
||||||
@ -435,8 +417,17 @@ bool CXmlOpr::save()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXmlOpr::handle_save(const std::string& path,
|
void CXmlOpr::clear_data()
|
||||||
const std::vector<std::string>& keychars)
|
{
|
||||||
|
xml_path_.clear();
|
||||||
|
parent_node_ = nullptr;
|
||||||
|
parent_node2_ = nullptr;
|
||||||
|
keys_.clear();
|
||||||
|
units_.clear();
|
||||||
|
doc_.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CXmlOpr::handle_save(const std::string& path, const std::vector<std::string>& keychars)
|
||||||
{
|
{
|
||||||
if (!open(path)) {
|
if (!open(path)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -28,15 +28,14 @@ public:
|
|||||||
void set_baseinfo(const OneGroupIni& base);
|
void set_baseinfo(const OneGroupIni& base);
|
||||||
bool parse_xml(std::vector<Element_t*>& vec);
|
bool parse_xml(std::vector<Element_t*>& vec);
|
||||||
bool get_all_unit(std::vector<std::string>& units);
|
bool get_all_unit(std::vector<std::string>& units);
|
||||||
bool get_all_elements(std::vector<Element_t*>& vec,
|
bool get_all_elements(std::vector<Element_t*>& vec, const std::string& unit = "");
|
||||||
const std::string& unit = "");
|
void copy_and_del(std::vector<Element_t*>& vec, std::vector<Element_t*>& out);
|
||||||
void copy_and_del(std::vector<Element_t*>& vec,
|
|
||||||
std::vector<Element_t*>& out);
|
|
||||||
void insert_brother_node(Element_t* brother, Element_t* newer);
|
void insert_brother_node(Element_t* brother, Element_t* newer);
|
||||||
void del_element(Element_t* ele);
|
void del_element(Element_t* ele);
|
||||||
bool check_key_exists(const Property_t& property);
|
bool check_key_exists(const Property_t& property);
|
||||||
bool check_key_exists(const std::string& key);
|
bool check_key_exists(const std::string& key);
|
||||||
bool save();
|
bool save();
|
||||||
|
void clear_data();
|
||||||
bool handle_save(const std::string& path, const std::vector<std::string>& keychars);
|
bool handle_save(const std::string& path, const std::vector<std::string>& keychars);
|
||||||
std::string handle_space(const std::string& content, const std::vector<std::string>& keychars);
|
std::string handle_space(const std::string& content, const std::vector<std::string>& keychars);
|
||||||
|
|
||||||
@ -47,8 +46,7 @@ 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,
|
bool import_newer_data(const std::vector<std::string>& vec, std::size_t& success_count);
|
||||||
std::size_t& success_count);
|
|
||||||
// 处理转义
|
// 处理转义
|
||||||
bool handle_transfer(const std::string& path, const std::vector<std::string>& keychars);
|
bool handle_transfer(const std::string& path, const std::vector<std::string>& keychars);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user