big-change:添加两种类型结构读写支持
This commit is contained in:
186
MainWidget.cpp
186
MainWidget.cpp
@@ -1,5 +1,8 @@
|
||||
#include "MainWidget.h"
|
||||
|
||||
#include "./ui_MainWidget.h"
|
||||
#include "src/data_edit.h"
|
||||
#include "public_def.h"
|
||||
#include <QClipboard>
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
@@ -8,10 +11,6 @@
|
||||
#include <QScreen>
|
||||
#include <QSettings>
|
||||
#include <filesystem>
|
||||
#include <regex>
|
||||
|
||||
#include "./ui_MainWidget.h"
|
||||
#include "src/data_edit.h"
|
||||
|
||||
constexpr std::size_t g_OnePage = 100;
|
||||
namespace fs = std::filesystem;
|
||||
@@ -19,7 +18,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
setWindowTitle(u8"OneLevelXmlOpr v1.2.18");
|
||||
setWindowTitle(u8"OneLevelXmlOpr v1.3.0");
|
||||
setWindowIcon(QIcon("://resource/xml.ico"));
|
||||
|
||||
QScreen* primaryScreen = QGuiApplication::primaryScreen();
|
||||
@@ -30,7 +29,11 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
||||
// setMinimumWidth(900);
|
||||
// setMinimumHeight(800);
|
||||
|
||||
his_ = new CHistory();
|
||||
attri_edit_ = new CAttributeEdit();
|
||||
ini_oper_ = new CGroupIni();
|
||||
ini_oper_->load_ini();
|
||||
group_set_ = new CGroupSetting(this, ini_oper_);
|
||||
|
||||
ui->edStatus->setReadOnly(true);
|
||||
ui->btnSave->setEnabled(false);
|
||||
@@ -50,8 +53,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
||||
if (file.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
read(file);
|
||||
// ui->edStatus->setText(file);
|
||||
ui->edStatus->setText(file);
|
||||
});
|
||||
connect(ui->btnSearch, &QPushButton::clicked, this, [&]() { search(ui->edSearchKey->text()); });
|
||||
connect(ui->btnBackup, &QPushButton::clicked, this, [&]() { backup_file(); });
|
||||
@@ -61,6 +63,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
||||
connect(ui->btnReset, &QPushButton::clicked, this, &MainWidget::reset);
|
||||
connect(ui->btnReplace, &QPushButton::clicked, this, [&]() { replace_content(true); });
|
||||
connect(ui->btnRxReplace, &QPushButton::clicked, this, [&]() { 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, [&]() {
|
||||
unsigned int cur = ui->edCurPage->text().toUInt();
|
||||
@@ -80,6 +83,20 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
||||
current_ = vec_;
|
||||
push_content(current_);
|
||||
});
|
||||
|
||||
connect(ui->btnSet, &QPushButton::clicked, this, [&]() {
|
||||
group_set_->exec();
|
||||
base_init();
|
||||
});
|
||||
connect(ui->btnHis, &QPushButton::clicked, this, [&]() {
|
||||
CUIHistory his(this, his_);
|
||||
his.exec();
|
||||
|
||||
if (his.cur_ != "") {
|
||||
ui->edStatus->setText(his.cur_);
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->btnPageNext, &QPushButton::clicked, this, [&]() {
|
||||
unsigned int cur = ui->edCurPage->text().toUInt();
|
||||
push_content(current_, cur + 1);
|
||||
@@ -114,14 +131,11 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
||||
|
||||
init_menu();
|
||||
|
||||
ini_.set_work_exe(exe_path_);
|
||||
base_ = ini_.get_config();
|
||||
|
||||
if (base_.blank_width > 20) {
|
||||
blank_with_ = base_.blank_width;
|
||||
if (cur_config_.max_blank_add > 20) {
|
||||
blank_with_ = cur_config_.max_blank_add;
|
||||
}
|
||||
|
||||
ui->edStatus->setText(QString::fromStdString(base_.xml_path));
|
||||
// 基本处理
|
||||
base_init();
|
||||
}
|
||||
|
||||
void MainWidget::copy_key()
|
||||
@@ -147,19 +161,21 @@ void MainWidget::closeEvent(QCloseEvent* event)
|
||||
void MainWidget::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Return:
|
||||
search(ui->edSearchKey->text());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case Qt::Key_Return:
|
||||
search(ui->edSearchKey->text());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
QWidget::keyPressEvent(event);
|
||||
}
|
||||
|
||||
MainWidget::~MainWidget()
|
||||
{
|
||||
delete attri_edit_;
|
||||
delete ui;
|
||||
delete attri_edit_;
|
||||
delete ini_oper_;
|
||||
delete his_;
|
||||
}
|
||||
|
||||
void MainWidget::set_work_exe(char* path)
|
||||
@@ -190,8 +206,7 @@ void MainWidget::generate_table_widget()
|
||||
|
||||
connect(tab_widget_, &QTableWidget::itemChanged, this, [&](QTableWidgetItem* item) { item_changed_handle(item); });
|
||||
connect(tab_widget_, &QTableWidget::customContextMenuRequested, this, &MainWidget::show_custom_menu);
|
||||
auto config = ini_.get_config();
|
||||
auto keys = CUtil::splitString(config.purpose, ",");
|
||||
auto keys = CUtil::splitString(cur_config_.propertis, ",");
|
||||
keys_.clear();
|
||||
|
||||
QStringList list;
|
||||
@@ -285,29 +300,48 @@ void MainWidget::judge_btn_page()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::read(const QString& file_path)
|
||||
bool MainWidget::read(const QString& file_path)
|
||||
{
|
||||
base_.xml_path = file_path.toStdString();
|
||||
if (!ini_.set_xml_path(base_.xml_path)) {
|
||||
CUtil::msg(this, u8"没有ini配置文件或者保存ini失败。");
|
||||
return;
|
||||
// 获取配置
|
||||
cur_config_.name = ui->cbConfig->currentText().toStdString();
|
||||
if (!ini_oper_->get_item(cur_config_)) {
|
||||
CUtil::msg(this, u8"获取配置失败。");
|
||||
return false;
|
||||
}
|
||||
ui->edStatus->setText(file_path);
|
||||
|
||||
if (!xml_.open(base_.xml_path)) {
|
||||
if (!xml_.open(file_path.toStdString())) {
|
||||
CUtil::msg(this, u8"打开xml失败。");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
xml_.set_baseinfo(base_);
|
||||
xml_.set_baseinfo(cur_config_);
|
||||
if (!xml_.parse_xml(vec_)) {
|
||||
CUtil::msg(this, u8"解析xml失败。");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (base_.allow_max_width < 0 || base_.allow_max_width > 1000) {
|
||||
if (cur_config_.is_same) {
|
||||
std::vector<std::string> units;
|
||||
xml_.get_all_unit(units);
|
||||
QStringList list;
|
||||
for (const auto& unit : units) {
|
||||
list.append(QString::fromStdString(unit));
|
||||
}
|
||||
u_ = true;
|
||||
ui->cbUnit->clear();
|
||||
if (!list.isEmpty()) {
|
||||
ui->cbUnit->addItems(list);
|
||||
ui->cbUnit->setCurrentIndex(0);
|
||||
}
|
||||
u_ = false;
|
||||
}
|
||||
else {
|
||||
ui->cbUnit->setEnabled(false);
|
||||
}
|
||||
|
||||
if (cur_config_.max_col_len < 0 || cur_config_.max_col_len > 1000) {
|
||||
allow_max_with_ = 100;
|
||||
} else {
|
||||
allow_max_with_ = base_.allow_max_width;
|
||||
allow_max_with_ = cur_config_.max_col_len;
|
||||
}
|
||||
|
||||
generate_table_widget();
|
||||
@@ -321,6 +355,13 @@ void MainWidget::read(const QString& file_path)
|
||||
ui->btnImport->setEnabled(true);
|
||||
ui->btnExport->setEnabled(true);
|
||||
ui->btnBackup->setEnabled(true);
|
||||
|
||||
ui->cbConfig->setEnabled(false);
|
||||
ui->btnSet->setEnabled(false);
|
||||
|
||||
his_->push(ui->edStatus->text().toStdString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWidget::search(const QString& key)
|
||||
@@ -782,30 +823,30 @@ void MainWidget::get_related_elements(std::vector<OperElement*>& out, ReplaceAre
|
||||
assert(tab_widget_);
|
||||
out.clear();
|
||||
switch (area) {
|
||||
case AREA_ALL_PAGE: {
|
||||
out.resize(current_.size());
|
||||
std::transform(current_.begin(), current_.end(), out.begin(), [](Element_t* ele) { return new OperElement(ele, 0); });
|
||||
break;
|
||||
case AREA_ALL_PAGE: {
|
||||
out.resize(current_.size());
|
||||
std::transform(current_.begin(), current_.end(), out.begin(), [](Element_t* ele) { return new OperElement(ele, 0); });
|
||||
break;
|
||||
}
|
||||
case AREA_CUR_PAGE: {
|
||||
int rows = tab_widget_->rowCount();
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
out.emplace_back(new OperElement(get_element_by_row(i), i));
|
||||
}
|
||||
case AREA_CUR_PAGE: {
|
||||
int rows = tab_widget_->rowCount();
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
out.emplace_back(new OperElement(get_element_by_row(i), i));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AREA_ALL: {
|
||||
out.resize(vec_.size());
|
||||
std::transform(vec_.begin(), vec_.end(), out.begin(), [](Element_t* ele) { return new OperElement(ele, 0); });
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
QModelIndexList indexList = tab_widget_->selectionModel()->selectedRows();
|
||||
for (int i = 0; i < indexList.size(); ++i) {
|
||||
out.emplace_back(new OperElement(get_element_by_row(indexList[i].row()), indexList[i].row()));
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
case AREA_ALL: {
|
||||
out.resize(vec_.size());
|
||||
std::transform(vec_.begin(), vec_.end(), out.begin(), [](Element_t* ele) { return new OperElement(ele, 0); });
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
QModelIndexList indexList = tab_widget_->selectionModel()->selectedRows();
|
||||
for (int i = 0; i < indexList.size(); ++i) {
|
||||
out.emplace_back(new OperElement(get_element_by_row(indexList[i].row()), indexList[i].row()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -823,6 +864,39 @@ void MainWidget::backup_file()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::base_init()
|
||||
{
|
||||
StrVec_t vec;
|
||||
ini_oper_->get_all_node(vec);
|
||||
|
||||
QStringList list;
|
||||
for (const auto& data : vec) {
|
||||
list.append(QString::fromStdString(data));
|
||||
}
|
||||
ui->cbConfig->clear();
|
||||
|
||||
if (list.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ui->cbConfig->addItems(list);
|
||||
ui->cbConfig->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
void MainWidget::unit_change()
|
||||
{
|
||||
if (u_) {
|
||||
return;
|
||||
}
|
||||
std::string unit = ui->cbUnit->currentText().toStdString();
|
||||
if (!xml_.get_all_elements(vec_, unit)) {
|
||||
CUtil::msg(this, u8"获取单元信息失败:" + QString::fromStdString(unit));
|
||||
return;
|
||||
}
|
||||
push_content(vec_);
|
||||
current_ = vec_;
|
||||
}
|
||||
|
||||
std::string MainWidget::extract_prefix(const std::string& name)
|
||||
{
|
||||
auto pos = name.find('.');
|
||||
|
||||
Reference in New Issue
Block a user