func:添加属性编辑功能。
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user