fix:修正替换后的界面显示和替换选项优化。
This commit is contained in:
parent
df1dd36d3b
commit
43c2d8680d
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -99,6 +99,7 @@
|
||||
"qtablewidget": "cpp",
|
||||
"qmenu": "cpp",
|
||||
"qmessagebox": "cpp",
|
||||
"qaction": "cpp"
|
||||
"qaction": "cpp",
|
||||
"codecvt": "cpp"
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget
|
||||
ui->btnImport->setEnabled(false);
|
||||
ui->btnExport->setEnabled(false);
|
||||
ui->btnBackup->setEnabled(false);
|
||||
ui->cbRepOnlySelect->setChecked(true);
|
||||
ui->rbReplaceSelect->setChecked(true);
|
||||
ui->btnRead->setFixedWidth(100);
|
||||
ui->btnSave->setFixedWidth(100);
|
||||
ui->btnExit->setFixedWidth(100);
|
||||
@ -642,7 +642,7 @@ void MainWidget::replace_content()
|
||||
CUtil::msg(this, u8"替换前数据为空。");
|
||||
return;
|
||||
}
|
||||
if (ui->cbRepOnlySelect->isChecked()) {
|
||||
if (ui->rbReplaceSelect->isChecked()) {
|
||||
QModelIndexList indexList = tab_widget_->selectionModel()->selectedRows();
|
||||
if (indexList.size() < 1) {
|
||||
CUtil::msg(this, u8"无选择数据");
|
||||
@ -654,15 +654,18 @@ void MainWidget::replace_content()
|
||||
if (e == nullptr) {
|
||||
continue;
|
||||
}
|
||||
auto* element = e->FirstAttribute();
|
||||
while (element) {
|
||||
QString content(element->Value());
|
||||
if (content.contains(key)) {
|
||||
content.replace(key, after);
|
||||
e->SetAttribute(element->Name(), content.toStdString().c_str());
|
||||
replace_str(key, after, e);
|
||||
ele_update_gui(e, indexList[i].row());
|
||||
}
|
||||
element = element->Next();
|
||||
} else if (ui->rbRepCurPage->isChecked()) {
|
||||
int row_count = tab_widget_->rowCount();
|
||||
for (int i = 0; i < row_count; ++i) {
|
||||
Element_t* e = get_element_by_row(i);
|
||||
if (e == nullptr) {
|
||||
continue;
|
||||
}
|
||||
replace_str(key, after, e);
|
||||
ele_update_gui(e, i);
|
||||
}
|
||||
} else {
|
||||
if (!CUtil::affirm(this, u8"确认", u8"确认进行全局替换吗?")) {
|
||||
@ -678,12 +681,28 @@ void MainWidget::replace_content()
|
||||
element = element->Next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xml_.get_all_elements(vec_);
|
||||
current_.clear();
|
||||
current_ = vec_;
|
||||
push_content(current_);
|
||||
search();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::replace_str(const QString& pre, const QString& after, Element_t* ele)
|
||||
{
|
||||
if (ele == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto* element = ele->FirstAttribute();
|
||||
while (element) {
|
||||
QString content(element->Value());
|
||||
if (content.contains(pre)) {
|
||||
content.replace(pre, after);
|
||||
ele->SetAttribute(element->Name(), content.toStdString().c_str());
|
||||
}
|
||||
element = element->Next();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::backup_file()
|
||||
@ -695,8 +714,7 @@ void MainWidget::backup_file()
|
||||
QString time = QDateTime::currentDateTime().toString("yyyy-MMdd-hhmmss");
|
||||
if (!xml_.backup_file(fs::path(exe_path_).parent_path().append("backup").string(), time.toStdString())) {
|
||||
CUtil::msg(this, u8"备份失败。");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
CUtil::msg(this, u8"备份完成。");
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ private:
|
||||
protected:
|
||||
void closeEvent(QCloseEvent* event);
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
|
||||
void replace_str(const QString& pre, const QString& after, Element_t* ele);
|
||||
private:
|
||||
Element_t* get_element_by_key(const QString& key);
|
||||
Element_t* get_element_by_row(int row);
|
||||
|
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1211</width>
|
||||
<width>1220</width>
|
||||
<height>805</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -82,9 +82,23 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="cbRepOnlySelect">
|
||||
<widget class="QRadioButton" name="rbReplaceSelect">
|
||||
<property name="text">
|
||||
<string>仅替换所选</string>
|
||||
<string>所选</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rbRepCurPage">
|
||||
<property name="text">
|
||||
<string>当前页</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rbRepAll">
|
||||
<property name="text">
|
||||
<string>全局</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -269,7 +283,6 @@
|
||||
<tabstop>btnExport</tabstop>
|
||||
<tabstop>btnImport</tabstop>
|
||||
<tabstop>btnBackup</tabstop>
|
||||
<tabstop>cbRepOnlySelect</tabstop>
|
||||
<tabstop>edRepPre</tabstop>
|
||||
<tabstop>edRepAfter</tabstop>
|
||||
<tabstop>btnReplace</tabstop>
|
||||
|
Loading…
x
Reference in New Issue
Block a user