update:导入数据功能进度更新(未完成)。
This commit is contained in:
parent
a89ef1e677
commit
2bc368c781
@ -31,7 +31,7 @@ TabWidth: 4
|
||||
# 构造函数的初始化列表要么都在同一行,要么都各自一行
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
# 每行字符的限制,0表示没有限制
|
||||
ColumnLimit: 100
|
||||
ColumnLimit: 110
|
||||
# 允许短的块放在同一行
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
# 是否允许短函数在一行
|
||||
|
@ -54,12 +54,8 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
||||
connect(ui->btnImport, &QPushButton::clicked, this, [&]() {
|
||||
CDataEdit edit;
|
||||
edit.is_import_ = true;
|
||||
edit.set_xml_opr(&xml_);
|
||||
edit.exec();
|
||||
if (edit.is_import_sucess_) {
|
||||
CUtil::msg(this, u8"导入成功");
|
||||
} else {
|
||||
CUtil::msg(this, u8"导入失败");
|
||||
}
|
||||
});
|
||||
connect(ui->btnPageNext, &QPushButton::clicked, this, [&]() {
|
||||
unsigned int cur = ui->edCurPage->text().toUInt();
|
||||
|
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>985</width>
|
||||
<width>1211</width>
|
||||
<height>805</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -37,13 +37,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnBackup">
|
||||
<property name="text">
|
||||
<string>备份快照</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSave">
|
||||
<property name="text">
|
||||
@ -74,6 +67,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnBackup">
|
||||
<property name="text">
|
||||
<string>备份快照</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include <QScreen>
|
||||
#include <QClipboard>
|
||||
#include <tinyxml2.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "../public_def.h"
|
||||
|
||||
CDataEdit::CDataEdit(QWidget* parent) : QDialog(parent), ui(new Ui::CDataEdit)
|
||||
@ -10,7 +12,7 @@ CDataEdit::CDataEdit(QWidget* parent) : QDialog(parent), ui(new Ui::CDataEdit)
|
||||
ui->setupUi(this);
|
||||
|
||||
// setMinimumWidth(600);
|
||||
setWindowTitle(u8"源属性编辑");
|
||||
setWindowTitle(u8"源编辑");
|
||||
|
||||
connect(ui->btnExit, &QPushButton::clicked, this, [&]() { close(); });
|
||||
connect(ui->btnAdd, &QPushButton::clicked, this, [&]() { import_data(); });
|
||||
@ -30,6 +32,11 @@ void CDataEdit::set_data(const QString& data)
|
||||
data_ = data;
|
||||
}
|
||||
|
||||
void CDataEdit::set_xml_opr(CXmlOpr* xml_opr)
|
||||
{
|
||||
xml_opr_ = xml_opr;
|
||||
}
|
||||
|
||||
void CDataEdit::import_data()
|
||||
{
|
||||
QString data = ui->plainTextEdit->toPlainText();
|
||||
@ -37,18 +44,24 @@ void CDataEdit::import_data()
|
||||
CUtil::msg(this, u8"内容为空");
|
||||
return;
|
||||
}
|
||||
|
||||
if (xml_opr_ == nullptr) {
|
||||
CUtil::msg(this, u8"xml_opr无实例。");
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> valid_data{};
|
||||
QStringList list = data.trimmed().split("\n");
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
const QString& item = list[i];
|
||||
if (item.trimmed().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(item.toStdString().c_str());
|
||||
if (doc.Error()) {
|
||||
CUtil::msg(this, u8"不是合法的xml语句。");
|
||||
if (xml_opr_->check_same_struct (item.toStdString())) {
|
||||
CUtil::msg(this, u8"不是合法的xml语句或者与现有结构不一致。");
|
||||
return;
|
||||
}
|
||||
valid_data.push_back(item.toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "xml_opr.h"
|
||||
|
||||
namespace Ui {
|
||||
class CDataEdit;
|
||||
}
|
||||
@ -18,6 +20,7 @@ public:
|
||||
public:
|
||||
void set_data(const QString& data);
|
||||
void import_data();
|
||||
void set_xml_opr(CXmlOpr* xml_opr);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
@ -30,6 +33,7 @@ public:
|
||||
private:
|
||||
Ui::CDataEdit* ui;
|
||||
QString data_{};
|
||||
CXmlOpr* xml_opr_{};
|
||||
};
|
||||
|
||||
#endif // DATA_EDIT_H
|
||||
|
@ -101,6 +101,61 @@ Element_t* CXmlOpr::copy_element(Element_t* ele)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool CXmlOpr::check_valid_xml_data(const std::string& data)
|
||||
{
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(data.c_str());
|
||||
if (doc.Error()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CXmlOpr::check_same_struct(const std::string& data)
|
||||
{
|
||||
auto* own_ele = parent_node_->FirstChildElement(opr_base_.the_node.c_str());
|
||||
if (own_ele == nullptr) {
|
||||
return true;
|
||||
}
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(data.c_str());
|
||||
if (doc.Error()) {
|
||||
return false;
|
||||
}
|
||||
const auto* import_ele = doc.FirstChildElement(opr_base_.the_node.c_str());
|
||||
if (import_ele == nullptr) {
|
||||
return false;
|
||||
}
|
||||
const auto* attribute = own_ele->FirstAttribute();
|
||||
int own_cnt = 0;
|
||||
while (attribute) {
|
||||
++own_cnt;
|
||||
if (import_ele->FindAttribute(attribute->Name()) == nullptr) {
|
||||
return true;
|
||||
}
|
||||
attribute = attribute->Next();
|
||||
}
|
||||
|
||||
const auto* attr_import = import_ele->FirstAttribute();
|
||||
int import_cnt = 0;
|
||||
while (attr_import) {
|
||||
++import_cnt;
|
||||
attr_import = attr_import->Next();
|
||||
}
|
||||
|
||||
if (import_cnt != own_cnt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CXmlOpr::import_newer_data(const std::vector<std::string>& vec)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CXmlOpr::del_element(Element_t* ele)
|
||||
{
|
||||
parent_node_->DeleteChild(ele);
|
||||
|
@ -21,15 +21,23 @@ public:
|
||||
~CXmlOpr();
|
||||
|
||||
public:
|
||||
bool open(const std::string& xml_path);
|
||||
void set_baseinfo(const OprBase& base);
|
||||
bool parse_xml(std::vector<Element_t*>& vec);
|
||||
void copy_and_del(std::vector<Element_t*>& vec, std::vector<Element_t*>& out);
|
||||
void insert_brother_node(Element_t* brother, Element_t* newer);
|
||||
bool open(const std::string& xml_path);
|
||||
void set_baseinfo(const OprBase& base);
|
||||
bool parse_xml(std::vector<Element_t*>& vec);
|
||||
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 del_element(Element_t* ele);
|
||||
bool check_key_exists(const Property_t& property);
|
||||
bool save();
|
||||
|
||||
public:
|
||||
Element_t* copy_element(Element_t* ele);
|
||||
void del_element(Element_t* ele);
|
||||
bool check_key_exists(const Property_t& property);
|
||||
bool save();
|
||||
// 检查 xml 格式合法性
|
||||
bool check_valid_xml_data(const std::string& data);
|
||||
// 不检查 xml 格式合法性,请自行调用 check_valid_xml_data
|
||||
bool check_same_struct(const std::string& data);
|
||||
// 不检查 xml 格式合法性,请自行调用 check_valid_xml_data
|
||||
bool import_newer_data(const std::vector<std::string>& vec);
|
||||
|
||||
public:
|
||||
void get_key_value(Element_t* ele, Property_t& vec);
|
||||
|
Loading…
x
Reference in New Issue
Block a user