Compare commits
No commits in common. "c2c3f6f2caa48620c76048febd8f4a3e5ea204f2" and "4db3a6b202de2dd3965c2d692ddbd1aedd6ba468" have entirely different histories.
c2c3f6f2ca
...
4db3a6b202
@ -11,7 +11,7 @@ ReflowComments: true
|
|||||||
SpacesBeforeTrailingComments: 3
|
SpacesBeforeTrailingComments: 3
|
||||||
TabWidth: 4
|
TabWidth: 4
|
||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||||
ColumnLimit: 130
|
ColumnLimit: 80
|
||||||
AllowShortBlocksOnASingleLine: Never
|
AllowShortBlocksOnASingleLine: Never
|
||||||
AllowShortFunctionsOnASingleLine: None
|
AllowShortFunctionsOnASingleLine: None
|
||||||
AllowShortEnumsOnASingleLine: false
|
AllowShortEnumsOnASingleLine: false
|
||||||
|
@ -52,7 +52,7 @@ if (MSVC)
|
|||||||
# if(${QT_VERSION_MAJOR} LESS 6)
|
# if(${QT_VERSION_MAJOR} LESS 6)
|
||||||
# add_compile_options(/source-charset:utf-8)
|
# add_compile_options(/source-charset:utf-8)
|
||||||
# endif()
|
# endif()
|
||||||
add_compile_options(/utf-8)
|
#add_compile_options(/source-charset:utf-8)
|
||||||
add_compile_options(/EHsc)
|
add_compile_options(/EHsc)
|
||||||
add_compile_options(/wd4267)
|
add_compile_options(/wd4267)
|
||||||
add_compile_options(-D_CRT_SECURE_NO_WARNINGS)
|
add_compile_options(-D_CRT_SECURE_NO_WARNINGS)
|
||||||
|
187
MainWidget.cpp
187
MainWidget.cpp
@ -16,11 +16,12 @@
|
|||||||
|
|
||||||
constexpr std::size_t g_OnePage = 100;
|
constexpr std::size_t g_OnePage = 100;
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget)
|
MainWidget::MainWidget(QWidget* parent)
|
||||||
|
: QWidget(parent), ui(new Ui::MainWidget)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
setWindowTitle(u8"OneLevelXmlOpr v1.3.9");
|
setWindowTitle(u8"OneLevelXmlOpr v1.3.8");
|
||||||
setWindowIcon(QIcon("://resource/xml.ico"));
|
setWindowIcon(QIcon("://resource/xml.ico"));
|
||||||
|
|
||||||
QScreen* primaryScreen = QGuiApplication::primaryScreen();
|
QScreen* primaryScreen = QGuiApplication::primaryScreen();
|
||||||
@ -53,23 +54,33 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
|||||||
ui->btnResort->setEnabled(false);
|
ui->btnResort->setEnabled(false);
|
||||||
|
|
||||||
connect(ui->btnSelectFile, &QPushButton::clicked, this, [&]() {
|
connect(ui->btnSelectFile, &QPushButton::clicked, this, [&]() {
|
||||||
QString file = CUtil::select_file(this, u8"请选择xml文件", u8"XML(*.xml);;所有文件 (*)");
|
QString file = CUtil::select_file(this, u8"请选择xml文件",
|
||||||
|
u8"XML(*.xml);;所有文件 (*)");
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ui->edStatus->setText(file);
|
ui->edStatus->setText(file);
|
||||||
});
|
});
|
||||||
connect(ui->btnSearch, &QPushButton::clicked, this, [&]() { search(ui->edSearchKey->text()); });
|
connect(ui->btnSearch, &QPushButton::clicked, this,
|
||||||
connect(ui->btnBackup, &QPushButton::clicked, this, [&]() { backup_file(); });
|
[&]() { search(ui->edSearchKey->text()); });
|
||||||
connect(ui->btnFormat, &QPushButton::clicked, this, [&]() { format_xml(); });
|
connect(ui->btnBackup, &QPushButton::clicked, this,
|
||||||
connect(ui->btnRead, &QPushButton::clicked, this, [&]() { read(ui->edStatus->text().trimmed()); });
|
[&]() { backup_file(); });
|
||||||
|
connect(ui->btnFormat, &QPushButton::clicked, this,
|
||||||
|
[&]() { format_xml(); });
|
||||||
|
connect(ui->btnRead, &QPushButton::clicked, this,
|
||||||
|
[&]() { read(ui->edStatus->text().trimmed()); });
|
||||||
connect(ui->btnSave, &QPushButton::clicked, this, [&]() { save(); });
|
connect(ui->btnSave, &QPushButton::clicked, this, [&]() { save(); });
|
||||||
connect(ui->btnExit, &QPushButton::clicked, this, [&]() { QApplication::exit(0); });
|
connect(ui->btnExit, &QPushButton::clicked, this,
|
||||||
|
[&]() { QApplication::exit(0); });
|
||||||
connect(ui->btnReset, &QPushButton::clicked, this, &MainWidget::reset);
|
connect(ui->btnReset, &QPushButton::clicked, this, &MainWidget::reset);
|
||||||
connect(ui->btnReplace, &QPushButton::clicked, this, [&]() { replace_content(true); });
|
connect(ui->btnReplace, &QPushButton::clicked, this,
|
||||||
connect(ui->btnRxReplace, &QPushButton::clicked, this, [&]() { replace_content(false); });
|
[&]() { replace_content(true); });
|
||||||
connect(ui->cbUnit, &QComboBox::currentTextChanged, this, [&](const QString& content) { unit_change(); });
|
connect(ui->btnRxReplace, &QPushButton::clicked, this,
|
||||||
connect(ui->btnExport, &QPushButton::clicked, this, &MainWidget::copy_multi_data);
|
[&]() { replace_content(false); });
|
||||||
|
connect(ui->cbUnit, &QComboBox::currentTextChanged, this,
|
||||||
|
[&](const QString& content) { unit_change(); });
|
||||||
|
connect(ui->btnExport, &QPushButton::clicked, this,
|
||||||
|
&MainWidget::copy_multi_data);
|
||||||
connect(ui->btnPagePre, &QPushButton::clicked, this, [&]() {
|
connect(ui->btnPagePre, &QPushButton::clicked, this, [&]() {
|
||||||
unsigned int cur = ui->edCurPage->text().toUInt();
|
unsigned int cur = ui->edCurPage->text().toUInt();
|
||||||
push_content(current_, cur - 1);
|
push_content(current_, cur - 1);
|
||||||
@ -85,7 +96,8 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cur_config_.is_same) {
|
if (cur_config_.is_same) {
|
||||||
xml_.get_all_elements(vec_, ui->cbUnit->currentText().toStdString());
|
xml_.get_all_elements(vec_,
|
||||||
|
ui->cbUnit->currentText().toStdString());
|
||||||
} else {
|
} else {
|
||||||
xml_.get_all_elements(vec_);
|
xml_.get_all_elements(vec_);
|
||||||
}
|
}
|
||||||
@ -96,9 +108,8 @@ 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(cur);
|
base_init();
|
||||||
});
|
});
|
||||||
connect(ui->btnHis, &QPushButton::clicked, this, [&]() {
|
connect(ui->btnHis, &QPushButton::clicked, this, [&]() {
|
||||||
CUIHistory his(this, his_);
|
CUIHistory his(this, his_);
|
||||||
@ -140,7 +151,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());
|
||||||
@ -148,7 +159,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()
|
||||||
@ -213,15 +224,14 @@ void MainWidget::show_custom_menu()
|
|||||||
|
|
||||||
void MainWidget::generate_table_widget()
|
void MainWidget::generate_table_widget()
|
||||||
{
|
{
|
||||||
clear_tab_widget();
|
tab_widget_ = new QTableWidget();
|
||||||
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);
|
||||||
|
|
||||||
connect(tab_widget_, &QTableWidget::itemChanged, this, [&](QTableWidgetItem* item) { item_changed_handle(item); });
|
connect(tab_widget_, &QTableWidget::itemChanged, this,
|
||||||
connect(tab_widget_, &QTableWidget::customContextMenuRequested, this, &MainWidget::show_custom_menu);
|
[&](QTableWidgetItem* item) { item_changed_handle(item); });
|
||||||
|
connect(tab_widget_, &QTableWidget::customContextMenuRequested, this,
|
||||||
|
&MainWidget::show_custom_menu);
|
||||||
auto keys = CUtil::splitString(cur_config_.propertis, ",");
|
auto keys = CUtil::splitString(cur_config_.propertis, ",");
|
||||||
keys_.clear();
|
keys_.clear();
|
||||||
|
|
||||||
@ -248,14 +258,13 @@ void MainWidget::generate_table_widget()
|
|||||||
tab_widget_->setColumnWidth(i, col_with_[i]);
|
tab_widget_->setColumnWidth(i, col_with_[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lay_ == nullptr) {
|
QHBoxLayout* lay = new QHBoxLayout();
|
||||||
lay_ = new QHBoxLayout();
|
lay->addWidget(tab_widget_);
|
||||||
}
|
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)
|
||||||
{
|
{
|
||||||
if (tab_widget_ == nullptr || page == 0) {
|
if (tab_widget_ == nullptr || page == 0) {
|
||||||
return;
|
return;
|
||||||
@ -322,44 +331,22 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,7 +369,6 @@ 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);
|
||||||
}
|
}
|
||||||
@ -398,20 +384,21 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,7 +452,8 @@ void MainWidget::item_changed_handle(QTableWidgetItem* item)
|
|||||||
if (result == nullptr) {
|
if (result == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
result->SetAttribute(keys_[col].c_str(), item->text().toStdString().c_str());
|
result->SetAttribute(keys_[col].c_str(),
|
||||||
|
item->text().toStdString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::save()
|
void MainWidget::save()
|
||||||
@ -562,7 +550,8 @@ void MainWidget::ele_update_gui(Element_t* target, const QString& pre_value)
|
|||||||
QString search_key;
|
QString search_key;
|
||||||
|
|
||||||
if (pre_value.isEmpty()) {
|
if (pre_value.isEmpty()) {
|
||||||
search_key = QString::fromLocal8Bit(target->Attribute(keys_[0].c_str()));
|
search_key =
|
||||||
|
QString::fromLocal8Bit(target->Attribute(keys_[0].c_str()));
|
||||||
} else {
|
} else {
|
||||||
search_key = pre_value;
|
search_key = pre_value;
|
||||||
}
|
}
|
||||||
@ -616,8 +605,10 @@ void MainWidget::init_menu()
|
|||||||
}
|
}
|
||||||
edit_property(target, cur_item->row(), false);
|
edit_property(target, cur_item->row(), false);
|
||||||
});
|
});
|
||||||
connect(ac_copy_curline_, &QAction::triggered, this, [&]() { copy_select_line(); });
|
connect(ac_copy_curline_, &QAction::triggered, this,
|
||||||
connect(ac_del_curline_, &QAction::triggered, this, [&]() { del_select_line(); });
|
[&]() { copy_select_line(); });
|
||||||
|
connect(ac_del_curline_, &QAction::triggered, this,
|
||||||
|
[&]() { del_select_line(); });
|
||||||
connect(ac_copy_key_, &QAction::triggered, this, [&]() { copy_key(); });
|
connect(ac_copy_key_, &QAction::triggered, this, [&]() { copy_key(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -637,8 +628,10 @@ void MainWidget::insert_one_line(Element_t* ele, int row)
|
|||||||
}
|
}
|
||||||
QString sda(data);
|
QString sda(data);
|
||||||
int dwidth = metrics_->horizontalAdvance(sda) + blank_with_;
|
int dwidth = metrics_->horizontalAdvance(sda) + blank_with_;
|
||||||
int need_set_width = dwidth > allow_max_with_ ? allow_max_with_ : dwidth;
|
int need_set_width =
|
||||||
col_with_[i] = col_with_[i] < need_set_width ? need_set_width : col_with_[i];
|
dwidth > allow_max_with_ ? allow_max_with_ : dwidth;
|
||||||
|
col_with_[i] =
|
||||||
|
col_with_[i] < need_set_width ? need_set_width : col_with_[i];
|
||||||
wgItem->setText(sda);
|
wgItem->setText(sda);
|
||||||
tab_widget_->setItem(row, i, wgItem);
|
tab_widget_->setItem(row, i, wgItem);
|
||||||
}
|
}
|
||||||
@ -744,7 +737,9 @@ void MainWidget::sort_by_repeat(std::vector<Element_t*>& vec)
|
|||||||
turn_vec.emplace_back(item, d);
|
turn_vec.emplace_back(item, d);
|
||||||
}
|
}
|
||||||
std::sort(turn_vec.begin(), turn_vec.end(),
|
std::sort(turn_vec.begin(), turn_vec.end(),
|
||||||
[&](const SElement_t& se1, const SElement_t& se2) { return compare_by_prefix(se1, se2); });
|
[&](const SElement_t& se1, const SElement_t& se2) {
|
||||||
|
return compare_by_prefix(se1, se2);
|
||||||
|
});
|
||||||
vec.clear();
|
vec.clear();
|
||||||
for (const auto& item : turn_vec) {
|
for (const auto& item : turn_vec) {
|
||||||
vec.push_back(item.ele);
|
vec.push_back(item.ele);
|
||||||
@ -816,7 +811,8 @@ void MainWidget::replace_content(bool is_common)
|
|||||||
|
|
||||||
std::vector<OperElement*> vec;
|
std::vector<OperElement*> vec;
|
||||||
if (ui->rbReplaceSelect->isChecked()) {
|
if (ui->rbReplaceSelect->isChecked()) {
|
||||||
QModelIndexList indexList = tab_widget_->selectionModel()->selectedRows();
|
QModelIndexList indexList =
|
||||||
|
tab_widget_->selectionModel()->selectedRows();
|
||||||
if (indexList.size() < 1) {
|
if (indexList.size() < 1) {
|
||||||
CUtil::msg(this, u8"无选择数据");
|
CUtil::msg(this, u8"无选择数据");
|
||||||
return;
|
return;
|
||||||
@ -846,7 +842,8 @@ void MainWidget::replace_content(bool is_common)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::replace_str(const QString& pre, const QString& after, Element_t* ele)
|
void MainWidget::replace_str(const QString& pre, const QString& after,
|
||||||
|
Element_t* ele)
|
||||||
{
|
{
|
||||||
if (ele == nullptr) {
|
if (ele == nullptr) {
|
||||||
return;
|
return;
|
||||||
@ -861,7 +858,8 @@ void MainWidget::replace_str(const QString& pre, const QString& after, Element_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::replace_str(Element_t* ele, const QString& rg, const QString& after)
|
void MainWidget::replace_str(Element_t* ele, const QString& rg,
|
||||||
|
const QString& after)
|
||||||
{
|
{
|
||||||
QRegularExpression rx(rg);
|
QRegularExpression rx(rg);
|
||||||
if (ele == nullptr) {
|
if (ele == nullptr) {
|
||||||
@ -878,14 +876,17 @@ void MainWidget::replace_str(Element_t* ele, const QString& rg, const QString& a
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::get_related_elements(std::vector<OperElement*>& out, ReplaceArea area)
|
void MainWidget::get_related_elements(std::vector<OperElement*>& out,
|
||||||
|
ReplaceArea area)
|
||||||
{
|
{
|
||||||
assert(tab_widget_);
|
assert(tab_widget_);
|
||||||
out.clear();
|
out.clear();
|
||||||
switch (area) {
|
switch (area) {
|
||||||
case AREA_ALL_PAGE: {
|
case AREA_ALL_PAGE: {
|
||||||
out.resize(current_.size());
|
out.resize(current_.size());
|
||||||
std::transform(current_.begin(), current_.end(), out.begin(), [](Element_t* ele) { return new OperElement(ele, 0); });
|
std::transform(
|
||||||
|
current_.begin(), current_.end(), out.begin(),
|
||||||
|
[](Element_t* ele) { return new OperElement(ele, 0); });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AREA_CUR_PAGE: {
|
case AREA_CUR_PAGE: {
|
||||||
@ -897,13 +898,18 @@ void MainWidget::get_related_elements(std::vector<OperElement*>& out, ReplaceAre
|
|||||||
}
|
}
|
||||||
case AREA_ALL: {
|
case AREA_ALL: {
|
||||||
out.resize(vec_.size());
|
out.resize(vec_.size());
|
||||||
std::transform(vec_.begin(), vec_.end(), out.begin(), [](Element_t* ele) { return new OperElement(ele, 0); });
|
std::transform(
|
||||||
|
vec_.begin(), vec_.end(), out.begin(),
|
||||||
|
[](Element_t* ele) { return new OperElement(ele, 0); });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
QModelIndexList indexList = tab_widget_->selectionModel()->selectedRows();
|
QModelIndexList indexList =
|
||||||
|
tab_widget_->selectionModel()->selectedRows();
|
||||||
for (int i = 0; i < indexList.size(); ++i) {
|
for (int i = 0; i < indexList.size(); ++i) {
|
||||||
out.emplace_back(new OperElement(get_element_by_row(indexList[i].row()), indexList[i].row()));
|
out.emplace_back(
|
||||||
|
new OperElement(get_element_by_row(indexList[i].row()),
|
||||||
|
indexList[i].row()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -917,25 +923,23 @@ void MainWidget::backup_file()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString time = QDateTime::currentDateTime().toString("yyyy-MMdd-hhmmss");
|
QString time = QDateTime::currentDateTime().toString("yyyy-MMdd-hhmmss");
|
||||||
if (!xml_.backup_file(fs::path(exe_path_).parent_path().append("backup").string(), time.toStdString())) {
|
if (!xml_.backup_file(
|
||||||
|
fs::path(exe_path_).parent_path().append("backup").string(),
|
||||||
|
time.toStdString())) {
|
||||||
CUtil::msg(this, u8"备份失败。");
|
CUtil::msg(this, u8"备份失败。");
|
||||||
} else {
|
} else {
|
||||||
CUtil::msg(this, u8"备份完成。");
|
CUtil::msg(this, u8"备份完成。");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::base_init(const QString& cur_config)
|
void MainWidget::base_init()
|
||||||
{
|
{
|
||||||
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();
|
||||||
|
|
||||||
@ -944,11 +948,7 @@ void MainWidget::base_init(const QString& cur_config)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ui->cbConfig->addItems(list);
|
ui->cbConfig->addItems(list);
|
||||||
if (have) {
|
ui->cbConfig->setCurrentIndex(0);
|
||||||
ui->cbConfig->setCurrentIndex(list.indexOf(cur_config));
|
|
||||||
} else {
|
|
||||||
ui->cbConfig->setCurrentIndex(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::unit_change()
|
void MainWidget::unit_change()
|
||||||
@ -956,9 +956,6 @@ 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));
|
||||||
@ -982,7 +979,9 @@ bool MainWidget::format_xml()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CUtil::affirm(this, u8"确认", u8"重排版内容将会覆盖源文件,请确认是否需要备份,继续?")) {
|
if (!CUtil::affirm(
|
||||||
|
this, u8"确认",
|
||||||
|
u8"重排版内容将会覆盖源文件,请确认是否需要备份,继续?")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -994,18 +993,6 @@ 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,7 +7,6 @@
|
|||||||
#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"
|
||||||
@ -58,7 +57,6 @@ 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();
|
||||||
@ -76,10 +74,9 @@ 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(const QString& cur_config);
|
void base_init();
|
||||||
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);
|
||||||
@ -129,8 +126,5 @@ 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
|
||||||
|
@ -3,17 +3,21 @@
|
|||||||
#include "public_def.h"
|
#include "public_def.h"
|
||||||
#include "ui_conf_setting.h"
|
#include "ui_conf_setting.h"
|
||||||
|
|
||||||
CGroupSetting::CGroupSetting(QWidget* parent, CGroupIni* oper) : QDialog(parent), ui(new Ui::CGroupSetting)
|
CGroupSetting::CGroupSetting(QWidget* parent, CGroupIni* oper)
|
||||||
|
: QDialog(parent), ui(new Ui::CGroupSetting)
|
||||||
{
|
{
|
||||||
ini_opr_ = oper;
|
ini_opr_ = oper;
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
setWindowTitle(u8"配置编辑");
|
setWindowTitle(u8"配置编辑");
|
||||||
|
|
||||||
connect(ui->btnAddConfig, &QPushButton::clicked, this, [&]() { add_item(); });
|
connect(ui->btnAddConfig, &QPushButton::clicked, this,
|
||||||
connect(ui->btnDelConfig, &QPushButton::clicked, this, [&]() { del_item(); });
|
[&]() { add_item(); });
|
||||||
|
connect(ui->btnDelConfig, &QPushButton::clicked, this,
|
||||||
|
[&]() { del_item(); });
|
||||||
connect(ui->btnExit, &QPushButton::clicked, this, [&]() { close(); });
|
connect(ui->btnExit, &QPushButton::clicked, this, [&]() { close(); });
|
||||||
connect(ui->cbConfig, &QComboBox::currentTextChanged, this, [&](const QString& content) { change_ini(); });
|
connect(ui->cbConfig, &QComboBox::currentTextChanged, this,
|
||||||
|
[&](const QString& content) { change_ini(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
CGroupSetting::~CGroupSetting()
|
CGroupSetting::~CGroupSetting()
|
||||||
@ -23,21 +27,19 @@ CGroupSetting::~CGroupSetting()
|
|||||||
|
|
||||||
void CGroupSetting::showEvent(QShowEvent* event)
|
void CGroupSetting::showEvent(QShowEvent* event)
|
||||||
{
|
{
|
||||||
update_ini("");
|
update_ini();
|
||||||
QDialog::showEvent(event);
|
QDialog::showEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGroupSetting::add_item()
|
void CGroupSetting::add_item()
|
||||||
{
|
{
|
||||||
if (!CUtil::affirm(this, u8"确认", u8"确认添加/更新吗?")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QString config_name = ui->edConfigName->text();
|
QString config_name = ui->edConfigName->text();
|
||||||
config_name = config_name.trimmed();
|
config_name = config_name.trimmed();
|
||||||
if (config_name.isEmpty()) {
|
if (config_name.isEmpty()) {
|
||||||
CUtil::msg(this, u8"配置名为空");
|
CUtil::msg(this, u8"配置名为空");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证重名
|
// 验证重名
|
||||||
|
|
||||||
// 添加
|
// 添加
|
||||||
@ -55,15 +57,12 @@ void CGroupSetting::add_item()
|
|||||||
CUtil::msg(this, u8"失败");
|
CUtil::msg(this, u8"失败");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
update_ini(QString::fromStdString(gp.name));
|
update_ini();
|
||||||
CUtil::msg(this, u8"成功");
|
CUtil::msg(this, u8"成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGroupSetting::del_item()
|
void CGroupSetting::del_item()
|
||||||
{
|
{
|
||||||
if (!CUtil::affirm(this, u8"确认", u8"确认删除吗?")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::string key = ui->cbConfig->currentText().toStdString();
|
std::string key = ui->cbConfig->currentText().toStdString();
|
||||||
if (!ini_opr_->del_item(key)) {
|
if (!ini_opr_->del_item(key)) {
|
||||||
CUtil::msg(this, u8"失败");
|
CUtil::msg(this, u8"失败");
|
||||||
@ -71,7 +70,7 @@ void CGroupSetting::del_item()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 删除成功之后要更新 cb
|
// 删除成功之后要更新 cb
|
||||||
update_ini("");
|
update_ini();
|
||||||
|
|
||||||
CUtil::msg(this, u8"成功");
|
CUtil::msg(this, u8"成功");
|
||||||
}
|
}
|
||||||
@ -108,29 +107,21 @@ void CGroupSetting::change_ini()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGroupSetting::update_ini(const QString& cur_key)
|
void CGroupSetting::update_ini()
|
||||||
{
|
{
|
||||||
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);
|
||||||
if (has_cur) {
|
ui->cbConfig->setCurrentIndex(0);
|
||||||
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(const QString& cur_key);
|
void update_ini();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool auto_add_{false};
|
bool auto_add_{false};
|
||||||
|
@ -52,7 +52,8 @@ void CGroupIni::get_all_node(StrVec_t& vec)
|
|||||||
bool CGroupIni::add_item(const OneGroupIni& group)
|
bool CGroupIni::add_item(const OneGroupIni& group)
|
||||||
{
|
{
|
||||||
ini_.SetValue(group.name.c_str(), "MainNodes", group.main_nodes.c_str());
|
ini_.SetValue(group.name.c_str(), "MainNodes", group.main_nodes.c_str());
|
||||||
ini_.SetValue(group.name.c_str(), "RelativeNodes", group.relative_nodes.c_str());
|
ini_.SetValue(group.name.c_str(), "RelativeNodes",
|
||||||
|
group.relative_nodes.c_str());
|
||||||
ini_.SetValue(group.name.c_str(), "ItemKey", group.item_key.c_str());
|
ini_.SetValue(group.name.c_str(), "ItemKey", group.item_key.c_str());
|
||||||
ini_.SetValue(group.name.c_str(), "Properties", group.propertis.c_str());
|
ini_.SetValue(group.name.c_str(), "Properties", group.propertis.c_str());
|
||||||
ini_.SetLongValue(group.name.c_str(), "MaxColLen", group.max_col_len);
|
ini_.SetLongValue(group.name.c_str(), "MaxColLen", group.max_col_len);
|
||||||
@ -96,7 +97,12 @@ bool CGroupIni::get_item(OneGroupIni& group)
|
|||||||
|
|
||||||
bool CGroupIni::del_item(const std::string& key)
|
bool CGroupIni::del_item(const std::string& key)
|
||||||
{
|
{
|
||||||
ini_.Delete(key.c_str(), nullptr);
|
ini_.Delete(key.c_str(), "MainNodes", true);
|
||||||
|
ini_.Delete(key.c_str(), "RelativeNodes", true);
|
||||||
|
ini_.Delete(key.c_str(), "ItemKey", true);
|
||||||
|
ini_.Delete(key.c_str(), "Properties", true);
|
||||||
|
ini_.Delete(key.c_str(), "MaxColLen", true);
|
||||||
|
ini_.Delete(key.c_str(), "MaxBlankAdd", true);
|
||||||
if (ini_.SaveFile(work_file_.c_str()) != SI_OK) {
|
if (ini_.SaveFile(work_file_.c_str()) != SI_OK) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,8 @@ 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()) != 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);
|
xml_path_ = CUtil::utf8_to_gbk(xml_path);
|
||||||
@ -28,7 +29,8 @@ bool CXmlOpr::open(const std::string& xml_path)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXmlOpr::backup_file(const std::string& desti_folder, const std::string& time)
|
bool CXmlOpr::backup_file(const std::string& desti_folder,
|
||||||
|
const std::string& time)
|
||||||
{
|
{
|
||||||
if (!fs::exists(xml_path_)) {
|
if (!fs::exists(xml_path_)) {
|
||||||
return false;
|
return false;
|
||||||
@ -37,7 +39,8 @@ bool CXmlOpr::backup_file(const std::string& desti_folder, const std::string& ti
|
|||||||
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).append(file_path.stem().string() + "_" + time + ".xml");
|
fs::path des = fs::path(desti_folder)
|
||||||
|
.append(file_path.stem().string() + "_" + time + ".xml");
|
||||||
return fs::copy_file(xml_path_, des);
|
return fs::copy_file(xml_path_, des);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +49,8 @@ void CXmlOpr::set_baseinfo(const OneGroupIni& base)
|
|||||||
opr_base_ = base;
|
opr_base_ = base;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXmlOpr::get_all_elements(std::vector<Element_t*>& vec, const std::string& unit)
|
bool CXmlOpr::get_all_elements(std::vector<Element_t*>& vec,
|
||||||
|
const std::string& unit)
|
||||||
{
|
{
|
||||||
vec.clear();
|
vec.clear();
|
||||||
|
|
||||||
@ -64,7 +68,8 @@ bool CXmlOpr::get_all_elements(std::vector<Element_t*>& vec, const std::string&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto purpose_node = parent_node2_->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();
|
||||||
@ -126,11 +131,13 @@ bool CXmlOpr::get_all_unit(std::vector<std::string>& units)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 排序后(仅指针排序)的节点进行复制(让实际内容有序),删除原始节点
|
// 排序后(仅指针排序)的节点进行复制(让实际内容有序),删除原始节点
|
||||||
void CXmlOpr::copy_and_del(std::vector<Element_t*>& vec, std::vector<Element_t*>& out)
|
void CXmlOpr::copy_and_del(std::vector<Element_t*>& vec,
|
||||||
|
std::vector<Element_t*>& out)
|
||||||
{
|
{
|
||||||
out.clear();
|
out.clear();
|
||||||
// 先找到最后一个节点
|
// 先找到最后一个节点
|
||||||
Element_t* last_node = parent_node2_->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;
|
||||||
@ -142,7 +149,8 @@ void CXmlOpr::copy_and_del(std::vector<Element_t*>& vec, std::vector<Element_t*>
|
|||||||
last_node = n;
|
last_node = n;
|
||||||
}
|
}
|
||||||
// 删除原有的节点
|
// 删除原有的节点
|
||||||
Element_t* fnode = parent_node2_->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_node2_->DeleteChild(fnode);
|
parent_node2_->DeleteChild(fnode);
|
||||||
@ -186,7 +194,8 @@ 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_node2_->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;
|
||||||
}
|
}
|
||||||
@ -225,10 +234,12 @@ 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_node2_->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;
|
||||||
}
|
}
|
||||||
@ -251,7 +262,8 @@ bool CXmlOpr::import_newer_data(const std::vector<std::string>& vec, std::size_t
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::string CXmlOpr::handle_space(const std::string& content, const std::vector<std::string>& keychars)
|
std::string CXmlOpr::handle_space(const std::string& content,
|
||||||
|
const std::vector<std::string>& keychars)
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
@ -264,8 +276,10 @@ std::string CXmlOpr::handle_space(const std::string& content, const std::vector<
|
|||||||
}
|
}
|
||||||
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 == '[' || 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 == '\\') {
|
||||||
oss << '\\'; // 添加转义字符
|
oss << '\\'; // 添加转义字符
|
||||||
}
|
}
|
||||||
oss << c;
|
oss << c;
|
||||||
@ -294,8 +308,10 @@ std::string CXmlOpr::handle_space(const std::string& content, const std::vector<
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract the quoted content
|
// Extract the quoted content
|
||||||
std::string quoted_content = content.substr(start_quote + 1, end_quote - start_quote - 1);
|
std::string quoted_content =
|
||||||
std::string processed_content = std::regex_replace(quoted_content, operators_regex, " $& ");
|
content.substr(start_quote + 1, end_quote - start_quote - 1);
|
||||||
|
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);
|
||||||
@ -319,7 +335,8 @@ std::string CXmlOpr::handle_space(const std::string& content, const std::vector<
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
bool CXmlOpr::handle_transfer(const std::string& path, const std::vector<std::string>& keychars)
|
bool CXmlOpr::handle_transfer(const std::string& path,
|
||||||
|
const std::vector<std::string>& keychars)
|
||||||
{
|
{
|
||||||
std::ifstream file(path);
|
std::ifstream file(path);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
@ -397,7 +414,8 @@ 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_node2_->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)) {
|
||||||
@ -417,17 +435,8 @@ bool CXmlOpr::save()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXmlOpr::clear_data()
|
bool CXmlOpr::handle_save(const std::string& path,
|
||||||
{
|
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,14 +28,15 @@ 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, const std::string& unit = "");
|
bool get_all_elements(std::vector<Element_t*>& vec,
|
||||||
void copy_and_del(std::vector<Element_t*>& vec, std::vector<Element_t*>& out);
|
const std::string& unit = "");
|
||||||
|
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);
|
||||||
|
|
||||||
@ -46,7 +47,8 @@ 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);
|
||||||
// 处理转义
|
// 处理转义
|
||||||
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