From 6783e6e4f88b3595f3fcd8b7c5f0affb1cd723f5 Mon Sep 17 00:00:00 2001 From: taynpg Date: Thu, 16 May 2024 00:09:26 +0800 Subject: [PATCH] =?UTF-8?q?func=EF=BC=9A=E6=B7=BB=E5=8A=A0=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E7=BC=96=E8=BE=91=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MainWidget.cpp | 21 ++++++++++++++++++++- MainWidget.h | 2 +- MainWidget.ui | 7 +++++++ src/attribute_edit.cpp | 15 ++++++++++----- src/attribute_edit.h | 4 +++- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/MainWidget.cpp b/MainWidget.cpp index 7ad88ce..24b91a6 100644 --- a/MainWidget.cpp +++ b/MainWidget.cpp @@ -8,7 +8,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget { ui->setupUi(this); - setWindowTitle(u8"OneLevelXmlOpr v1.1"); + setWindowTitle(u8"OneLevelXmlOpr v1.2"); setWindowIcon(QIcon("://resource/xml.ico")); setMinimumWidth(900); @@ -34,6 +34,7 @@ MainWidget::MainWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MainWidget connect(ui->btnDelSelectLine, &QPushButton::clicked, this, [&]() { del_select_line(); }); connect(ui->btnExit, &QPushButton::clicked, this, [&]() { QApplication::exit(0); }); connect(ui->btnReset, &QPushButton::clicked, this, &MainWidget::reset); + connect(ui->btnEditProperty, &QPushButton::clicked, this, &MainWidget::edit_property); connect(ui->btnPagePre, &QPushButton::clicked, this, [&]() { unsigned int cur = ui->edCurPage->text().toUInt(); push_content(current_, cur - 1); @@ -60,6 +61,24 @@ void MainWidget::copy_key() CUtil::msg(this, u8"已复制"); } +void MainWidget::edit_property() +{ + Element_t* target = get_current_select_key(); + if (target == nullptr) { + return; + } + Property_t property; + xml_.get_key_value(target, property); + attri_edit_->set_attribute(property, false); + attri_edit_->exec(); + + if (!attri_edit_->is_ok_) { + return; + } + attri_edit_->get_attribute(property); + xml_.key_value_to_element(target, property); +} + MainWidget::~MainWidget() { delete attri_edit_; diff --git a/MainWidget.h b/MainWidget.h index b263417..6f22c5b 100644 --- a/MainWidget.h +++ b/MainWidget.h @@ -38,7 +38,7 @@ private: void reset(); void judge_btn_page(); void copy_key(); - + void edit_property(); private: Element_t* get_element_bykey(const QString& key); Element_t* get_current_select_key(); diff --git a/MainWidget.ui b/MainWidget.ui index 61554f4..d877832 100644 --- a/MainWidget.ui +++ b/MainWidget.ui @@ -168,6 +168,13 @@ + + + + 编辑 + + + diff --git a/src/attribute_edit.cpp b/src/attribute_edit.cpp index 1ef164f..43cb103 100644 --- a/src/attribute_edit.cpp +++ b/src/attribute_edit.cpp @@ -22,7 +22,7 @@ void CAttributeEdit::handle_ok() 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()); + property_.emplace_back(key.toStdString().c_str(), value.toStdString().c_str()); } is_ok_ = true; close(); @@ -40,10 +40,11 @@ void CAttributeEdit::showEvent(QShowEvent* event) QDialog::showEvent(event); } -void CAttributeEdit::set_attribute(const Property_t& property) +void CAttributeEdit::set_attribute(const Property_t& property, bool is_key_edit) { property_.clear(); property_ = property; + is_key_edit_ = is_key_edit; } void CAttributeEdit::get_attribute(Property_t& property) @@ -56,18 +57,22 @@ void CAttributeEdit::show_before() { init_table(); - for (const auto& item : property_) { + for(auto i = 0; i < property_.size(); ++i) { int row = table_->rowCount(); table_->insertRow(row); QTableWidgetItem* pkey = new QTableWidgetItem(); - pkey->setText(item.key.c_str()); + pkey->setText(property_[i].key.c_str()); pkey->setFlags(pkey->flags() & ~Qt::ItemIsEditable); table_->setItem(row, 0, pkey); QTableWidgetItem* pvalue = new QTableWidgetItem(); - pvalue->setText(item.value.c_str()); + pvalue->setText(property_[i].value.c_str()); table_->setItem(row, 1, pvalue); + + if (!is_key_edit_ && i == 0) { + pvalue->setFlags(pvalue->flags() & ~Qt::ItemIsEditable); + } } } diff --git a/src/attribute_edit.h b/src/attribute_edit.h index 0c1650b..3b34f6a 100644 --- a/src/attribute_edit.h +++ b/src/attribute_edit.h @@ -21,8 +21,9 @@ protected: void showEvent(QShowEvent* event) override; public: - void set_attribute(const Property_t& property); + void set_attribute(const Property_t& property, bool is_key_edit = true); void get_attribute(Property_t& property); + private: void show_before(); void init_table(); @@ -35,6 +36,7 @@ private: Ui::CAttributeEdit* ui; Property_t property_{}; QTableWidget* table_{}; + bool is_key_edit_{true}; }; #endif // ATTRIBUTE_EDIT_H