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->edAllPage->setEnabled(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->btnSave->setFixedWidth(100);
|
||||
ui->btnExit->setFixedWidth(100);
|
||||
@ -265,6 +269,9 @@ void MainWidget::read(const QString& file_path)
|
||||
ui->btnRead->setEnabled(false);
|
||||
ui->btnSave->setEnabled(true);
|
||||
ui->btnSelectFile->setEnabled(false);
|
||||
ui->btnImport->setEnabled(true);
|
||||
ui->btnExport->setEnabled(true);
|
||||
ui->btnBackup->setEnabled(true);
|
||||
}
|
||||
|
||||
void MainWidget::search()
|
||||
|
@ -57,12 +57,20 @@ void CDataEdit::import_data()
|
||||
if (item.trimmed().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (xml_opr_->check_same_struct (item.toStdString())) {
|
||||
if (xml_opr_->check_same_struct(item.toStdString())) {
|
||||
CUtil::msg(this, u8"不是合法的xml语句或者与现有结构不一致。");
|
||||
return;
|
||||
}
|
||||
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)
|
||||
|
@ -150,10 +150,27 @@ bool CXmlOpr::check_same_struct(const std::string& data)
|
||||
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;
|
||||
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)
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
// 不检查 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);
|
||||
bool import_newer_data(const std::vector<std::string>& vec, std::size_t success_count);
|
||||
|
||||
public:
|
||||
void get_key_value(Element_t* ele, Property_t& vec);
|
||||
|
Loading…
x
Reference in New Issue
Block a user