func:添加属性编辑功能。

This commit is contained in:
taynpg 2024-05-16 00:09:26 +08:00
parent a640f149f5
commit 6783e6e4f8
5 changed files with 41 additions and 8 deletions

View File

@ -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_;

View File

@ -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();

View File

@ -168,6 +168,13 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnEditProperty">
<property name="text">
<string>编辑</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCopyKey">
<property name="text">

View File

@ -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);
}
}
}

View File

@ -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