PIValueTreeEdit label switch support, label style

This commit is contained in:
2022-12-16 23:06:53 +03:00
parent 55e5e819f8
commit 5327e4f7b0
6 changed files with 145 additions and 13 deletions

View File

@@ -48,6 +48,7 @@ bool PIValueTreeEditParameters::showFor(PIValueTree & vt) {
}
comboType->blockSignals(true);
comboType->setEnabled(true);
if (vt.isArray()) {
uint array_type = PIVariant::typeIDFromName(vt.attribute(Attribute::arrayType).toString());
comboType->setCurrentIndex(comboType->findData(array_type));
@@ -58,13 +59,19 @@ bool PIValueTreeEditParameters::showFor(PIValueTree & vt) {
createAttributes(ve_array, layoutArray, vt.attributes(), true);
groupArray->show();
} else {
if (vt.attribute(Attribute::isLabel, false).toBool()) {
comboType->setEnabled(false);
checkAttribute(vt, Attribute::style, "");
}
comboType->setCurrentIndex(comboType->findData(vt.value().typeID()));
groupArray->hide();
}
comboType->blockSignals(false);
checkHidden->setChecked(vt.attribute(Attribute::hidden, false).toBool());
checkReadOnly->setChecked(vt.attribute(Attribute::readOnly, false).toBool());
checkLabel->blockSignals(true);
checkLabel->setChecked(vt.attribute(Attribute::isLabel, false).toBool());
checkLabel->blockSignals(false);
lineComment->setText(PI2QString(vt.comment()));
createAttributes(ve_attr, layoutAttributes, vt.attributes());
@@ -142,3 +149,31 @@ void PIValueTreeEditParameters::checkAttribute(PIValueTree & vt, PIString an, PI
void PIValueTreeEditParameters::on_comboType_currentIndexChanged(int) {
createAttributes(ve_attr, layoutAttributes);
}
void PIValueTreeEditParameters::on_checkLabel_toggled(bool on) {
if (!on) {
comboType->setEnabled(true);
for (int r = 0; r < layoutAttributes->rowCount(); ++r) {
auto * w = qobject_cast<PIVariantEdit *>(layoutAttributes->itemAt(r, QFormLayout::FieldRole)->widget());
if (!w) continue;
PIString an = Q2PIString(w->property(property_name).toString());
if (an == Attribute::style) {
ve_attr.removeOne(w);
layoutAttributes->removeRow(r);
break;
}
}
} else {
comboType->setEnabled(false);
comboType->setCurrentIndex(comboType->findData(PIVariant::typeID<PIString>()));
ve_attr.clear();
while (layoutAttributes->rowCount() > 0)
layoutAttributes->removeRow(0);
createAttributes(ve_attr,
layoutAttributes,
{
{Attribute::style, ""}
});
}
}