void VPropertyFormWidget::commitData(int row) { if (row < 0 || row >= d_ptr->EditorWidgets.count() || row >= d_ptr->Properties.count()) { return; } VPropertyFormWidgetPrivate::SEditorWidget& tmpEditorWidget = d_ptr->EditorWidgets[row]; VProperty* tmpProperty = d_ptr->Properties[row]; if (tmpEditorWidget.FormWidget) { tmpEditorWidget.FormWidget->commitData(); } else if (tmpEditorWidget.Editor && tmpProperty) { QVariant newValue = tmpProperty->getEditorData(tmpEditorWidget.Editor); QVariant oldValue = tmpProperty->data(VProperty::DPC_Data, Qt::EditRole); if (oldValue != newValue) { VProperty *parent = tmpProperty->getParent(); if (parent == nullptr) { tmpProperty->setValue(newValue); emit propertyDataSubmitted(tmpProperty); } else if (parent->propertyType() == Property::Complex) { tmpProperty->UpdateParent(newValue); emit propertyDataSubmitted(parent); } else { tmpProperty->setValue(newValue); emit propertyDataSubmitted(tmpProperty); } } } }
void VPropertyFormWidget::build() { // Clear the old content, delete old widgets d_ptr->EditorWidgets.clear(); if (layout()) { QLayoutItem *child; while (layout()->count() > 0 && (child = layout()->takeAt(0)) != 0) { if (child->widget()) { delete child->widget(); } delete child; } delete layout(); } // Create new content if (d_ptr->Properties.isEmpty()) { return; //... only if there are properties } QFormLayout* tmpFormLayout = new QFormLayout(this); setLayout(tmpFormLayout); for (int i = 0; i < d_ptr->Properties.count(); ++i) { // Get the current property VProperty* tmpProperty = d_ptr->Properties.value(i, nullptr); if (!tmpProperty) { continue; } if (tmpProperty->getRowCount() > 0) { if (tmpProperty->propertyType() == Property::Complex) { buildEditor(tmpProperty, tmpFormLayout, Property::Complex); QWidget *group = new QWidget(this); tmpFormLayout->addRow(group); QFormLayout* subFormLayout = new QFormLayout(group); QMargins margins = subFormLayout->contentsMargins(); margins.setTop(0); margins.setLeft(14); subFormLayout->setContentsMargins(margins); group->setLayout(subFormLayout); QList<VProperty*> children = tmpProperty->getChildren(); for (int j = 0; j < children.size(); ++j) { buildEditor(children[j], subFormLayout); connect(children[j], &VProperty::childChanged, tmpProperty, &VProperty::ValueChildChanged, Qt::UniqueConnection); ++i; d_ptr->Properties.insert(i, children[j]); } } else { // Child properties, the property itself is not being added VPropertyFormWidget* tmpNewFormWidget = new VPropertyFormWidget(tmpProperty, this); tmpFormLayout->addRow(tmpNewFormWidget); d_ptr->EditorWidgets.append(VPropertyFormWidgetPrivate::SEditorWidget(tmpNewFormWidget)); tmpNewFormWidget->setCommitBehaviour(d_ptr->UpdateEditors); } } else if (tmpProperty->type() == "widget") { VWidgetProperty* tmpWidgetProperty = static_cast<VWidgetProperty*>(tmpProperty); tmpFormLayout->addRow(tmpWidgetProperty->getWidget()); d_ptr->EditorWidgets.append(VPropertyFormWidgetPrivate::SEditorWidget(tmpWidgetProperty->getWidget())); } else { buildEditor(tmpProperty, tmpFormLayout); } } }