PIValueTreeEdit arrays fix, support for array comment (only from source now)
This commit is contained in:
@@ -180,22 +180,11 @@ void PIValueTreeEdit::build() {
|
||||
auto * ve = new PIVariantEdit();
|
||||
ve->setAttributes(current.attributes());
|
||||
ve->setValue(i.value(), array_type);
|
||||
grid->add(PIValueTree(), PIString::fromNumber(++index), ve, i.comment());
|
||||
grid->add(PIValueTree({PIString::fromNumber(index), PIVariant()}), PIString::fromNumber(index + 1), ve, i.comment());
|
||||
++index;
|
||||
array_edits << ve;
|
||||
}
|
||||
connect(ui_array->spinCount, QOverload<int>::of(&QSpinBox::valueChanged), widget_array, [this, array_type](int value) {
|
||||
value = piMaxi(value, 0);
|
||||
for (int i = grid->rowCount() - 1; i >= value; --i)
|
||||
grid->removeRow(i);
|
||||
array_edits.resize(grid->rowCount());
|
||||
for (int i = grid->rowCount(); i < value; ++i) {
|
||||
auto * ve = new PIVariantEdit();
|
||||
ve->setAttributes(current.attributes());
|
||||
ve->setValue(PIVariant::fromType(array_type), array_type);
|
||||
grid->add(PIValueTree(), PIString::fromNumber(i + 1), ve, "");
|
||||
array_edits << ve;
|
||||
}
|
||||
});
|
||||
connect(ui_array->spinCount, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int) { PIValueTreeEdit::resizeArray(); });
|
||||
layout()->addWidget(widget_array);
|
||||
} else {
|
||||
grid->create_edit_buttons = is_full_edit;
|
||||
@@ -223,8 +212,12 @@ void PIValueTreeEdit::applyValues() const {
|
||||
if (current.isArray()) {
|
||||
if (array_edits.isNotEmpty()) current.mergeAttributes(array_edits[0]->attributes());
|
||||
current.clearChildren();
|
||||
for (int i = 0; i < array_edits.size_s(); ++i)
|
||||
current.addChild({PIString::fromNumber(i), array_edits[i]->value()});
|
||||
for (int i = 0; i < array_edits.size_s(); ++i) {
|
||||
PIValueTree vt(PIString::fromNumber(i), array_edits[i]->value());
|
||||
auto comm_lbl = comm_labels.value(vt.name());
|
||||
if (comm_lbl) vt.setComment(Q2PIString(comm_lbl->text()));
|
||||
current.addChild(vt);
|
||||
}
|
||||
} else {
|
||||
auto vit = value_edits.makeIterator();
|
||||
while (vit.next()) {
|
||||
@@ -322,6 +315,7 @@ void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & vn,
|
||||
vt = ve->value();
|
||||
if (!widget_params->showFor(vt)) return;
|
||||
ve->setValue(vt);
|
||||
ve->resizeArray();
|
||||
// ve->applyArrayAttributes();
|
||||
} else {
|
||||
bool was_label = vt.attribute(Attribute::isLabel, false).toBool();
|
||||
@@ -465,6 +459,23 @@ void PIValueTreeEdit::createTabWidget() {
|
||||
}
|
||||
|
||||
|
||||
void PIValueTreeEdit::resizeArray() {
|
||||
if (!ui_array) return;
|
||||
uint array_type = PIVariant::typeIDFromName(current.attribute(Attribute::arrayType).toString());
|
||||
int value = piMaxi(ui_array->spinCount->value(), 0);
|
||||
for (int i = grid->rowCount() - 1; i >= value; --i)
|
||||
grid->removeRow(i);
|
||||
array_edits.resize(grid->rowCount());
|
||||
for (int i = grid->rowCount(); i < value; ++i) {
|
||||
auto * ve = new PIVariantEdit();
|
||||
ve->setAttributes(current.attributes());
|
||||
ve->setValue(PIVariant::fromType(array_type), array_type);
|
||||
grid->add(PIValueTree(), PIString::fromNumber(i + 1), ve, "");
|
||||
array_edits << ve;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PIValueTreeEdit::newRequest(NewType type) {
|
||||
PIString nn;
|
||||
if (rootTreeEdit()->allowed_names && (type == NewType::Value)) {
|
||||
@@ -502,7 +513,7 @@ void PIValueTreeEdit::newRequest(NewType type) {
|
||||
switch (type) {
|
||||
case NewType::Value: addValueEdit(vt); break;
|
||||
case NewType::Group: addTreeEdit(vt); break;
|
||||
case NewType::Array: addTreeEdit(vt); break;
|
||||
case NewType::Array: addTreeEdit(vt)->resizeArray(); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user