update:导入逻辑进度更新。
This commit is contained in:
parent
2bc368c781
commit
00b15c46b8
@ -29,6 +29,10 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
|||||||
ui->btnSave->setEnabled(false);
|
ui->btnSave->setEnabled(false);
|
||||||
ui->edAllPage->setEnabled(false);
|
ui->edAllPage->setEnabled(false);
|
||||||
ui->cbCaseSensitive->setChecked(false);
|
ui->cbCaseSensitive->setChecked(false);
|
||||||
|
ui->btnImport->setEnabled(false);
|
||||||
|
ui->btnExport->setEnabled(false);
|
||||||
|
ui->btnBackup->setEnabled(false);
|
||||||
|
ui->cbRepOnlySelect->setChecked(true);
|
||||||
ui->btnRead->setFixedWidth(100);
|
ui->btnRead->setFixedWidth(100);
|
||||||
ui->btnSave->setFixedWidth(100);
|
ui->btnSave->setFixedWidth(100);
|
||||||
ui->btnExit->setFixedWidth(100);
|
ui->btnExit->setFixedWidth(100);
|
||||||
@ -265,6 +269,9 @@ void MainWidget::read(const QString& 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->btnExport->setEnabled(true);
|
||||||
|
ui->btnBackup->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::search()
|
void MainWidget::search()
|
||||||
|
@ -51,18 +51,26 @@ void CDataEdit::import_data()
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> valid_data{};
|
std::vector<std::string> valid_data{};
|
||||||
QStringList list = data.trimmed().split("\n");
|
QStringList list = data.trimmed().split("\n");
|
||||||
for (int i = 0; i < list.size(); ++i) {
|
for (int i = 0; i < list.size(); ++i) {
|
||||||
const QString& item = list[i];
|
const QString& item = list[i];
|
||||||
if (item.trimmed().isEmpty()) {
|
if (item.trimmed().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (xml_opr_->check_same_struct (item.toStdString())) {
|
if (xml_opr_->check_same_struct(item.toStdString())) {
|
||||||
CUtil::msg(this, u8"不是合法的xml语句或者与现有结构不一致。");
|
CUtil::msg(this, u8"不是合法的xml语句或者与现有结构不一致。");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
valid_data.push_back(item.toStdString());
|
valid_data.push_back(item.toStdString());
|
||||||
}
|
}
|
||||||
|
auto task_count = valid_data.size();
|
||||||
|
std::size_t success_count{};
|
||||||
|
if (!xml_opr_->import_newer_data(valid_data, success_count)) {
|
||||||
|
CUtil::msg(this, u8"导入失败。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QString info = QString(u8"需要导入 %1 条数据,成功导入 %2 条。").arg(task_count).arg(success_count);
|
||||||
|
CUtil::msg(this, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDataEdit::showEvent(QShowEvent* event)
|
void CDataEdit::showEvent(QShowEvent* event)
|
||||||
|
@ -127,7 +127,7 @@ bool CXmlOpr::check_same_struct(const std::string& data)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto* attribute = own_ele->FirstAttribute();
|
const auto* attribute = own_ele->FirstAttribute();
|
||||||
int own_cnt = 0;
|
int own_cnt = 0;
|
||||||
while (attribute) {
|
while (attribute) {
|
||||||
++own_cnt;
|
++own_cnt;
|
||||||
if (import_ele->FindAttribute(attribute->Name()) == nullptr) {
|
if (import_ele->FindAttribute(attribute->Name()) == nullptr) {
|
||||||
@ -137,7 +137,7 @@ bool CXmlOpr::check_same_struct(const std::string& data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto* attr_import = import_ele->FirstAttribute();
|
const auto* attr_import = import_ele->FirstAttribute();
|
||||||
int import_cnt = 0;
|
int import_cnt = 0;
|
||||||
while (attr_import) {
|
while (attr_import) {
|
||||||
++import_cnt;
|
++import_cnt;
|
||||||
attr_import = attr_import->Next();
|
attr_import = attr_import->Next();
|
||||||
@ -150,10 +150,27 @@ bool CXmlOpr::check_same_struct(const std::string& data)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXmlOpr::import_newer_data(const std::vector<std::string>& vec)
|
// Warning: 不检查 xml 格式合法性,请自行调用 check_valid_xml_data
|
||||||
|
// 且导入前每条数据请自行使用 check_same_struct 检测。
|
||||||
|
bool CXmlOpr::import_newer_data(const std::vector<std::string>& vec, std::size_t success_count)
|
||||||
{
|
{
|
||||||
|
success_count = 0;
|
||||||
return false;
|
auto* last_item = parent_node_->LastChildElement(opr_base_.the_node.c_str());
|
||||||
|
if (last_item == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (const auto& data : vec) {
|
||||||
|
tinyxml2::XMLDocument doc;
|
||||||
|
doc.Parse(data.c_str());
|
||||||
|
auto* item = doc.FirstChildElement(opr_base_.the_node.c_str());
|
||||||
|
if (item == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
++success_count;
|
||||||
|
auto* nitem = copy_element(item);
|
||||||
|
insert_brother_node(last_item, nitem);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXmlOpr::del_element(Element_t* ele)
|
void CXmlOpr::del_element(Element_t* ele)
|
||||||
|
@ -37,7 +37,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);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void get_key_value(Element_t* ele, Property_t& vec);
|
void get_key_value(Element_t* ele, Property_t& vec);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user