func:1.添加删除添加功能。
2.添加编辑属性界面 3.删除添加同步到界面未完成。
This commit is contained in:
parent
950949c130
commit
41713baede
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -19,7 +19,7 @@
|
|||||||
"visualizerFile": "${workspaceRoot}/.vscode/qt5.natvis"
|
"visualizerFile": "${workspaceRoot}/.vscode/qt5.natvis"
|
||||||
},
|
},
|
||||||
"cmake.environment": {
|
"cmake.environment": {
|
||||||
"PATH": "${env:PATH};C:/Qt/Qt5.14.2/5.14.2/msvc2017_64/bin;",
|
"PATH": "${env:PATH};C:/Qt/Qt5.14.2/5.14.2/msvc2017_64/bin",
|
||||||
"LD_LIBRARY_PATH": "$LD_LIBRARY_PATH:/home/xxx"
|
"LD_LIBRARY_PATH": "$LD_LIBRARY_PATH:/home/xxx"
|
||||||
},
|
},
|
||||||
"cmake.options.statusBarVisibility": "visible",
|
"cmake.options.statusBarVisibility": "visible",
|
||||||
|
@ -20,7 +20,8 @@ set(PROJECT_SOURCES
|
|||||||
MainWidget.ui 3rd/tinyxml2.cpp
|
MainWidget.ui 3rd/tinyxml2.cpp
|
||||||
src/xml_opr.h src/xml_opr.cpp
|
src/xml_opr.h src/xml_opr.cpp
|
||||||
src/config.h src/config.cpp public_def.cpp resource.qrc
|
src/config.h src/config.cpp public_def.cpp resource.qrc
|
||||||
resource/ico.rc
|
resource/ico.rc src/attribute_edit.ui src/attribute_edit.h
|
||||||
|
src/attribute_edit.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
|
126
MainWidget.cpp
126
MainWidget.cpp
@ -1,32 +1,67 @@
|
|||||||
#include "MainWidget.h"
|
#include "MainWidget.h"
|
||||||
|
#include <QClipboard>
|
||||||
#include "./ui_MainWidget.h"
|
#include "./ui_MainWidget.h"
|
||||||
|
|
||||||
|
constexpr std::size_t g_OnePage = 100;
|
||||||
|
|
||||||
MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget)
|
MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
setWindowTitle(u8"OneLevelXmlOpr v1.0.0");
|
setWindowTitle(u8"OneLevelXmlOpr v1.1");
|
||||||
setWindowIcon(QIcon("://resource/xml.ico"));
|
setWindowIcon(QIcon("://resource/xml.ico"));
|
||||||
|
|
||||||
|
setMinimumWidth(900);
|
||||||
|
setMinimumHeight(800);
|
||||||
|
|
||||||
width_.push_back(280);
|
width_.push_back(280);
|
||||||
for (int i = 0; i < 30; ++i) {
|
for (int i = 0; i < 30; ++i) {
|
||||||
width_.push_back(160);
|
width_.push_back(160);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
attri_edit_ = new CAttributeEdit();
|
||||||
|
|
||||||
ui->edStatus->setEnabled(false);
|
ui->edStatus->setEnabled(false);
|
||||||
ui->btnSave->setEnabled(false);
|
ui->btnSave->setEnabled(false);
|
||||||
ui->btnCopySelectLine->setEnabled(false);
|
ui->btnCopySelectLine->setEnabled(false);
|
||||||
ui->btnDelSelectLine->setEnabled(false);
|
ui->btnDelSelectLine->setEnabled(false);
|
||||||
|
ui->edAllPage->setEnabled(false);
|
||||||
|
|
||||||
connect(ui->btnRead, &QPushButton::clicked, this, [&]() { read(); });
|
connect(ui->btnRead, &QPushButton::clicked, this, [&]() { read(); });
|
||||||
connect(ui->btnSearch, &QPushButton::clicked, this, [&]() { search(); });
|
connect(ui->btnSearch, &QPushButton::clicked, this, [&]() { search(); });
|
||||||
connect(ui->btnSave, &QPushButton::clicked, this, [&]() { save(); });
|
connect(ui->btnSave, &QPushButton::clicked, this, [&]() { save(); });
|
||||||
connect(ui->btnCopySelectLine, &QPushButton::clicked, this, [&]() { copy_select_line(); });
|
connect(ui->btnCopySelectLine, &QPushButton::clicked, this, [&]() { copy_select_line(); });
|
||||||
connect(ui->btnDelSelectLine, &QPushButton::clicked, this, [&]() { del_select_line(); });
|
connect(ui->btnDelSelectLine, &QPushButton::clicked, this, [&]() { del_select_line(); });
|
||||||
|
connect(ui->btnReset, &QPushButton::clicked, this, &MainWidget::reset);
|
||||||
|
connect(ui->btnPagePre, &QPushButton::clicked, this, [&]() {
|
||||||
|
unsigned int cur = ui->edCurPage->text().toUInt();
|
||||||
|
push_content(current_, cur - 1);
|
||||||
|
});
|
||||||
|
connect(ui->btnPageNext, &QPushButton::clicked, this, [&]() {
|
||||||
|
unsigned int cur = ui->edCurPage->text().toUInt();
|
||||||
|
push_content(current_, cur + 1);
|
||||||
|
});
|
||||||
|
connect(ui->btnJump, &QPushButton::clicked, this, [&]() {
|
||||||
|
unsigned int cur = ui->edCurPage->text().toUInt();
|
||||||
|
push_content(current_, cur);
|
||||||
|
});
|
||||||
|
connect(ui->btnCopyKey, &QPushButton::clicked, this, &MainWidget::copy_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWidget::copy_key()
|
||||||
|
{
|
||||||
|
Element_t* target = get_current_select_key();
|
||||||
|
if (target == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QClipboard* clip = QApplication::clipboard();
|
||||||
|
clip->setText(QString(target->Attribute(keys_[0].c_str())));
|
||||||
|
CUtil::msg(this, u8"已复制");
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWidget::~MainWidget()
|
MainWidget::~MainWidget()
|
||||||
{
|
{
|
||||||
|
delete attri_edit_;
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,15 +102,34 @@ void MainWidget::generate_table_widget()
|
|||||||
ui->widget->setLayout(lay);
|
ui->widget->setLayout(lay);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::push_content(const std::vector<tinyxml2::XMLElement*>& eles)
|
void MainWidget::push_content(const std::vector<tinyxml2::XMLElement*>& eles, std::size_t page)
|
||||||
{
|
{
|
||||||
|
if (tab_widget_ == nullptr || page == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t all_size = eles.size();
|
||||||
|
std::size_t max_show = g_OnePage * page;
|
||||||
|
all_page_ = all_size / 100;
|
||||||
|
|
||||||
|
if (all_size % 100 != 0) {
|
||||||
|
++all_page_;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (page < 1 || page > all_page_) {
|
||||||
|
CUtil::msg(this, u8"不在范围内");
|
||||||
|
ui->edCurPage->setText(QString::number(cur_page_));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
tab_widget_->clearContents();
|
tab_widget_->clearContents();
|
||||||
tab_widget_->setRowCount(0);
|
tab_widget_->setRowCount(0);
|
||||||
for (const auto& ele : eles) {
|
|
||||||
|
for (auto p = (page - 1) * g_OnePage; p < all_size && p < max_show; ++p) {
|
||||||
int row_cnt = tab_widget_->rowCount();
|
int row_cnt = tab_widget_->rowCount();
|
||||||
tab_widget_->insertRow(row_cnt);
|
tab_widget_->insertRow(row_cnt);
|
||||||
for (auto i = 0; i < keys_.size(); ++i) {
|
for (auto i = 0; i < keys_.size(); ++i) {
|
||||||
const char* data = ele->Attribute(keys_[i].c_str());
|
const char* data = eles[p]->Attribute(keys_[i].c_str());
|
||||||
QTableWidgetItem* wgItem = new QTableWidgetItem();
|
QTableWidgetItem* wgItem = new QTableWidgetItem();
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
@ -86,6 +140,26 @@ void MainWidget::push_content(const std::vector<tinyxml2::XMLElement*>& eles)
|
|||||||
tab_widget_->setItem(row_cnt, i, wgItem);
|
tab_widget_->setItem(row_cnt, i, wgItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ui->edCurPage->setText(QString::number(page));
|
||||||
|
cur_page_ = page;
|
||||||
|
ui->edAllPage->setText(QString::number(all_page_));
|
||||||
|
judge_btn_page();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWidget::judge_btn_page()
|
||||||
|
{
|
||||||
|
int cur = ui->edCurPage->text().trimmed().toUInt();
|
||||||
|
if (cur <= 1) {
|
||||||
|
ui->btnPagePre->setEnabled(false);
|
||||||
|
} else {
|
||||||
|
ui->btnPagePre->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cur >= all_page_) {
|
||||||
|
ui->btnPageNext->setEnabled(false);
|
||||||
|
} else {
|
||||||
|
ui->btnPageNext->setEnabled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::read()
|
void MainWidget::read()
|
||||||
@ -155,7 +229,7 @@ void MainWidget::item_changed_handle(QTableWidgetItem* item)
|
|||||||
int col = item->column();
|
int col = item->column();
|
||||||
|
|
||||||
QString xml_key = tab_widget_->item(row, 0)->text();
|
QString xml_key = tab_widget_->item(row, 0)->text();
|
||||||
element* result = get_element_bykey(xml_key);
|
Element_t* result = get_element_bykey(xml_key);
|
||||||
if (result == nullptr) {
|
if (result == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -173,28 +247,49 @@ void MainWidget::save()
|
|||||||
|
|
||||||
void MainWidget::copy_select_line()
|
void MainWidget::copy_select_line()
|
||||||
{
|
{
|
||||||
element* target = get_current_select_key();
|
if (!CUtil::affirm(this, u8"确认", u8"确认复制吗?")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Element_t* target = get_current_select_key();
|
||||||
if (target == nullptr) {
|
if (target == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
element* newer = xml_.copy_element(target);
|
Element_t* newer = xml_.copy_element(target);
|
||||||
|
|
||||||
|
Property_t property;
|
||||||
|
xml_.get_key_value(newer, property);
|
||||||
|
|
||||||
|
attri_edit_->set_attribute(property);
|
||||||
|
attri_edit_->exec();
|
||||||
|
|
||||||
|
if (!attri_edit_->is_ok_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
attri_edit_->get_attribute(property);
|
||||||
|
xml_.key_value_to_element(newer, property);
|
||||||
xml_.insert_brother_node(target, newer);
|
xml_.insert_brother_node(target, newer);
|
||||||
|
|
||||||
// TODO: 添加到界面
|
// TODO: 添加到界面
|
||||||
CUtil::msg(this, u8"已复制");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::del_select_line()
|
void MainWidget::del_select_line()
|
||||||
{
|
{
|
||||||
element* target = get_current_select_key();
|
if (!CUtil::affirm(this, u8"确认", u8"确认删除吗?")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Element_t* target = get_current_select_key();
|
||||||
if (target == nullptr) {
|
if (target == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
xml_.del_element(target);
|
||||||
|
|
||||||
|
// TODO: 添加到界面
|
||||||
}
|
}
|
||||||
|
|
||||||
element* MainWidget::get_current_select_key()
|
Element_t* MainWidget::get_current_select_key()
|
||||||
{
|
{
|
||||||
element* ret = nullptr;
|
Element_t* ret = nullptr;
|
||||||
if (tab_widget_ == nullptr) {
|
if (tab_widget_ == nullptr) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -209,9 +304,16 @@ element* MainWidget::get_current_select_key()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWidget::reset()
|
||||||
|
{
|
||||||
|
current_.clear();
|
||||||
|
current_ = vec_;
|
||||||
|
push_content(current_);
|
||||||
|
}
|
||||||
|
|
||||||
tinyxml2::XMLElement* MainWidget::get_element_bykey(const QString& key)
|
tinyxml2::XMLElement* MainWidget::get_element_bykey(const QString& key)
|
||||||
{
|
{
|
||||||
element* ret = nullptr;
|
Element_t* ret = nullptr;
|
||||||
for (const auto& ele : current_) {
|
for (const auto& ele : current_) {
|
||||||
const char* data = ele->Attribute(keys_[0].c_str());
|
const char* data = ele->Attribute(keys_[0].c_str());
|
||||||
QString qdata(data);
|
QString qdata(data);
|
||||||
|
17
MainWidget.h
17
MainWidget.h
@ -6,6 +6,7 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include "src/xml_opr.h"
|
#include "src/xml_opr.h"
|
||||||
#include "src/config.h"
|
#include "src/config.h"
|
||||||
|
#include "src/attribute_edit.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@ -24,7 +25,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
void set_work_exe(char* path);
|
void set_work_exe(char* path);
|
||||||
void generate_table_widget();
|
void generate_table_widget();
|
||||||
void push_content(const std::vector<element*>& eles);
|
void push_content(const std::vector<Element_t*>& eles, std::size_t page = 1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void read();
|
void read();
|
||||||
@ -33,10 +34,13 @@ private:
|
|||||||
void save();
|
void save();
|
||||||
void copy_select_line();
|
void copy_select_line();
|
||||||
void del_select_line();
|
void del_select_line();
|
||||||
element* get_current_select_key();
|
Element_t* get_current_select_key();
|
||||||
|
void reset();
|
||||||
|
void judge_btn_page();
|
||||||
|
void copy_key();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
element* get_element_bykey(const QString& key);
|
Element_t* get_element_bykey(const QString& key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWidget* ui;
|
Ui::MainWidget* ui;
|
||||||
@ -44,10 +48,13 @@ private:
|
|||||||
CXmlOpr xml_{};
|
CXmlOpr xml_{};
|
||||||
std::string exe_path_{};
|
std::string exe_path_{};
|
||||||
QTableWidget* tab_widget_{};
|
QTableWidget* tab_widget_{};
|
||||||
std::vector<element*> vec_{};
|
std::vector<Element_t*> vec_{};
|
||||||
std::vector<element*> current_{};
|
std::vector<Element_t*> current_{};
|
||||||
std::vector<std::string> keys_{};
|
std::vector<std::string> keys_{};
|
||||||
std::vector<int> width_{};
|
std::vector<int> width_{};
|
||||||
bool auto_add_{false};
|
bool auto_add_{false};
|
||||||
|
std::size_t cur_page_{1};
|
||||||
|
std::size_t all_page_{1};
|
||||||
|
CAttributeEdit* attri_edit_{};
|
||||||
};
|
};
|
||||||
#endif // MAINWIDGET_H
|
#endif // MAINWIDGET_H
|
||||||
|
136
MainWidget.ui
136
MainWidget.ui
@ -6,16 +6,29 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1181</width>
|
<width>573</width>
|
||||||
<height>980</height>
|
<height>602</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>MainWidget</string>
|
<string>MainWidget</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="widget" native="true">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="edStatus"/>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnRead">
|
<widget class="QPushButton" name="btnRead">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -23,13 +36,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QLineEdit" name="edStatus"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="edSearchKey">
|
<widget class="QLineEdit" name="edSearchKey">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -48,12 +54,16 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnSave">
|
<widget class="QPushButton" name="btnReset">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>保存</string>
|
<string>重置</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
@ -67,6 +77,97 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="edCurPage">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>50</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>/</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="edAllPage">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>50</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>页</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnJump">
|
||||||
|
<property name="text">
|
||||||
|
<string>跳转</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnPagePre">
|
||||||
|
<property name="text">
|
||||||
|
<string>上一页</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnPageNext">
|
||||||
|
<property name="text">
|
||||||
|
<string>下一页</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnCopyKey">
|
||||||
|
<property name="text">
|
||||||
|
<string>复制Key</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnCopySelectLine">
|
<widget class="QPushButton" name="btnCopySelectLine">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -81,19 +182,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QWidget" name="widget" native="true">
|
<widget class="QPushButton" name="btnSave">
|
||||||
<property name="sizePolicy">
|
<property name="text">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
<string>保存</string>
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#include "public_def.h"
|
#include "public_def.h"
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
std::vector<std::string> splitString(const std::string& input, const std::string& delimiter) {
|
std::vector<std::string> splitString(const std::string& input, const std::string& delimiter)
|
||||||
|
{
|
||||||
std::vector<std::string> tokens;
|
std::vector<std::string> tokens;
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
std::string backup = input;
|
std::string backup = input;
|
||||||
@ -22,3 +23,18 @@ void CUtil::msg(QWidget* parent, const QString& content)
|
|||||||
{
|
{
|
||||||
QMessageBox::information(parent, u8"提示", content);
|
QMessageBox::information(parent, u8"提示", content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CUtil::affirm(QWidget* parent, const QString& titile, const QString& content)
|
||||||
|
{
|
||||||
|
QMessageBox questionBox(parent);
|
||||||
|
questionBox.setText(content);
|
||||||
|
questionBox.setWindowTitle(titile);
|
||||||
|
questionBox.setIcon(QMessageBox::Question);
|
||||||
|
questionBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||||
|
int result = questionBox.exec();
|
||||||
|
if (result != QMessageBox::Yes) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,7 @@ public:
|
|||||||
~CUtil() = default;
|
~CUtil() = default;
|
||||||
public:
|
public:
|
||||||
static void msg(QWidget* parent, const QString& content);
|
static void msg(QWidget* parent, const QString& content);
|
||||||
|
static bool affirm(QWidget* parent, const QString& titile, const QString& content);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
93
src/attribute_edit.cpp
Normal file
93
src/attribute_edit.cpp
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
#include "attribute_edit.h"
|
||||||
|
#include "ui_attribute_edit.h"
|
||||||
|
|
||||||
|
CAttributeEdit::CAttributeEdit(QWidget* parent) : QDialog(parent), ui(new Ui::CAttributeEdit)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
setWindowTitle(u8"属性编辑");
|
||||||
|
setMinimumSize(400, 600);
|
||||||
|
|
||||||
|
connect(ui->btnOk, &QPushButton::clicked, this, &CAttributeEdit::handle_ok);
|
||||||
|
connect(ui->btnCancel, &QPushButton::clicked, this, [&]() {
|
||||||
|
is_ok_ = false;
|
||||||
|
close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAttributeEdit::handle_ok()
|
||||||
|
{
|
||||||
|
property_.clear();
|
||||||
|
int row = table_->rowCount();
|
||||||
|
for (int i = 0; i < row; ++i) {
|
||||||
|
QString key = table_->item(i, 0)->text();
|
||||||
|
QString value = table_->item(i, 1)->text();
|
||||||
|
property_.emplace_back(key.toLocal8Bit().constData(), value.toLocal8Bit().constData());
|
||||||
|
}
|
||||||
|
is_ok_ = true;
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CAttributeEdit::~CAttributeEdit()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAttributeEdit::showEvent(QShowEvent* event)
|
||||||
|
{
|
||||||
|
show_before();
|
||||||
|
QDialog::showEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAttributeEdit::set_attribute(const Property_t& property)
|
||||||
|
{
|
||||||
|
property_.clear();
|
||||||
|
property_ = property;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAttributeEdit::get_attribute(Property_t& property)
|
||||||
|
{
|
||||||
|
property.clear();
|
||||||
|
property = property_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAttributeEdit::show_before()
|
||||||
|
{
|
||||||
|
init_table();
|
||||||
|
|
||||||
|
for (const auto& item : property_) {
|
||||||
|
int row = table_->rowCount();
|
||||||
|
table_->insertRow(row);
|
||||||
|
|
||||||
|
QTableWidgetItem* pkey = new QTableWidgetItem();
|
||||||
|
pkey->setText(item.key.c_str());
|
||||||
|
pkey->setFlags(pkey->flags() & ~Qt::ItemIsEditable);
|
||||||
|
table_->setItem(row, 0, pkey);
|
||||||
|
|
||||||
|
QTableWidgetItem* pvalue = new QTableWidgetItem();
|
||||||
|
pvalue->setText(item.value.c_str());
|
||||||
|
table_->setItem(row, 1, pvalue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAttributeEdit::init_table()
|
||||||
|
{
|
||||||
|
if (table_ == nullptr) {
|
||||||
|
QStringList list;
|
||||||
|
list << u8"属性" << u8"值";
|
||||||
|
table_ = new QTableWidget();
|
||||||
|
table_->setColumnCount(list.size());
|
||||||
|
table_->setHorizontalHeaderLabels(list);
|
||||||
|
table_->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
|
table_->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
|
||||||
|
table_->setColumnWidth(0, 80);
|
||||||
|
table_->setColumnWidth(1, 200);
|
||||||
|
QHBoxLayout* ly = new QHBoxLayout();
|
||||||
|
ly->addWidget(table_);
|
||||||
|
ui->widget->setLayout(ly);
|
||||||
|
} else {
|
||||||
|
table_->clearContents();
|
||||||
|
table_->setRowCount(0);
|
||||||
|
}
|
||||||
|
}
|
40
src/attribute_edit.h
Normal file
40
src/attribute_edit.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#ifndef ATTRIBUTE_EDIT_H
|
||||||
|
#define ATTRIBUTE_EDIT_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QTableWidget>
|
||||||
|
#include "xml_opr.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class CAttributeEdit;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CAttributeEdit : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit CAttributeEdit(QWidget* parent = nullptr);
|
||||||
|
~CAttributeEdit();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void showEvent(QShowEvent* event) override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void set_attribute(const Property_t& property);
|
||||||
|
void get_attribute(Property_t& property);
|
||||||
|
private:
|
||||||
|
void show_before();
|
||||||
|
void init_table();
|
||||||
|
void handle_ok();
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool is_ok_{};
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::CAttributeEdit* ui;
|
||||||
|
Property_t property_{};
|
||||||
|
QTableWidget* table_{};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ATTRIBUTE_EDIT_H
|
62
src/attribute_edit.ui
Normal file
62
src/attribute_edit.ui
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>CAttributeEdit</class>
|
||||||
|
<widget class="QDialog" name="CAttributeEdit">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>318</width>
|
||||||
|
<height>618</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="widget" native="true">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnOk">
|
||||||
|
<property name="text">
|
||||||
|
<string>确认</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnCancel">
|
||||||
|
<property name="text">
|
||||||
|
<string>取消</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
@ -31,22 +31,20 @@ bool CXmlOpr::parse_xml(std::vector<tinyxml2::XMLElement*>& vec)
|
|||||||
|
|
||||||
if (parent_node_ == nullptr) {
|
if (parent_node_ == nullptr) {
|
||||||
parent_node_ = doc_.FirstChildElement(item.c_str());
|
parent_node_ = doc_.FirstChildElement(item.c_str());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
parent_node_ = parent_node_->FirstChildElement(item.c_str());
|
parent_node_ = parent_node_->FirstChildElement(item.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vec.clear();
|
vec.clear();
|
||||||
element* purpose_node = parent_node_->FirstChildElement(opr_base_.the_node.c_str());
|
Element_t* purpose_node = parent_node_->FirstChildElement(opr_base_.the_node.c_str());
|
||||||
while (purpose_node)
|
while (purpose_node) {
|
||||||
{
|
|
||||||
vec.push_back(purpose_node);
|
vec.push_back(purpose_node);
|
||||||
purpose_node = purpose_node->NextSiblingElement();
|
purpose_node = purpose_node->NextSiblingElement();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXmlOpr::insert_brother_node(element* brother, element* newer)
|
void CXmlOpr::insert_brother_node(Element_t* brother, Element_t* newer)
|
||||||
{
|
{
|
||||||
if (!brother || !newer) {
|
if (!brother || !newer) {
|
||||||
return;
|
return;
|
||||||
@ -54,12 +52,12 @@ void CXmlOpr::insert_brother_node(element* brother, element* newer)
|
|||||||
parent_node_->InsertAfterChild(brother, newer);
|
parent_node_->InsertAfterChild(brother, newer);
|
||||||
}
|
}
|
||||||
|
|
||||||
element* CXmlOpr::copy_element(element* ele)
|
Element_t* CXmlOpr::copy_element(Element_t* ele)
|
||||||
{
|
{
|
||||||
if (!ele) {
|
if (!ele) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
element* ret = doc_.NewElement(ele->Name());
|
Element_t* ret = doc_.NewElement(ele->Name());
|
||||||
const auto* attribute = ele->FirstAttribute();
|
const auto* attribute = ele->FirstAttribute();
|
||||||
while (attribute) {
|
while (attribute) {
|
||||||
ret->SetAttribute(attribute->Name(), attribute->Value());
|
ret->SetAttribute(attribute->Name(), attribute->Value());
|
||||||
@ -68,6 +66,11 @@ element* CXmlOpr::copy_element(element* ele)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CXmlOpr::del_element(Element_t* ele)
|
||||||
|
{
|
||||||
|
parent_node_->DeleteChild(ele);
|
||||||
|
}
|
||||||
|
|
||||||
bool CXmlOpr::save()
|
bool CXmlOpr::save()
|
||||||
{
|
{
|
||||||
auto ret = doc_.SaveFile(xml_path_.c_str());
|
auto ret = doc_.SaveFile(xml_path_.c_str());
|
||||||
@ -76,3 +79,32 @@ bool CXmlOpr::save()
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CXmlOpr::get_key_value(Element_t* ele, Property_t& vec)
|
||||||
|
{
|
||||||
|
if (ele == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
vec.clear();
|
||||||
|
const auto* attribute = ele->FirstAttribute();
|
||||||
|
while (attribute) {
|
||||||
|
vec.emplace_back(attribute->Name(), attribute->Value());
|
||||||
|
attribute = attribute->Next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CXmlOpr::key_value_to_element(Element_t* ele, const Property_t& vec)
|
||||||
|
{
|
||||||
|
if (ele == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const auto& data : vec) {
|
||||||
|
ele->SetAttribute(data.key.c_str(), data.value.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SKeyValue::SKeyValue(const char* pkey, const char* pvalue)
|
||||||
|
{
|
||||||
|
key = std::string(pkey);
|
||||||
|
value = std::string(pvalue);
|
||||||
|
}
|
||||||
|
@ -4,9 +4,17 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <tinyxml2.h>
|
#include <tinyxml2.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
#include "../public_def.h"
|
#include "../public_def.h"
|
||||||
|
|
||||||
typedef tinyxml2::XMLElement element;
|
struct SKeyValue {
|
||||||
|
SKeyValue(const char* pkey, const char* pvalue);
|
||||||
|
std::string key;
|
||||||
|
std::string value;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef tinyxml2::XMLElement Element_t;
|
||||||
|
typedef std::vector<SKeyValue> Property_t;
|
||||||
class CXmlOpr
|
class CXmlOpr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -16,16 +24,21 @@ public:
|
|||||||
public:
|
public:
|
||||||
bool open(const std::string& xml_path);
|
bool open(const std::string& xml_path);
|
||||||
void set_baseinfo(const OprBase& base);
|
void set_baseinfo(const OprBase& base);
|
||||||
bool parse_xml(std::vector<element*>& vec);
|
bool parse_xml(std::vector<Element_t*>& vec);
|
||||||
void insert_brother_node(element* brother, element* newer);
|
void insert_brother_node(Element_t* brother, Element_t* newer);
|
||||||
element* copy_element(element* ele);
|
Element_t* copy_element(Element_t* ele);
|
||||||
|
void del_element(Element_t* ele);
|
||||||
bool save();
|
bool save();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void get_key_value(Element_t* ele, Property_t& vec);
|
||||||
|
void key_value_to_element(Element_t* ele, const Property_t& vec);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
tinyxml2::XMLDocument doc_{};
|
tinyxml2::XMLDocument doc_{};
|
||||||
OprBase opr_base_{};
|
OprBase opr_base_{};
|
||||||
std::string xml_path_{};
|
std::string xml_path_{};
|
||||||
element* parent_node_{};
|
Element_t* parent_node_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user