SpinSlider and ScrollSpinBox read-only support

PIVariantEdit - support for read-only for all types
PIValueTreeEdit - drop Parent grouping, default now Groups, full grouping control, global read-only support, fix new label error
This commit is contained in:
2023-04-28 19:51:22 +03:00
parent e7ef97dc6a
commit 46fd68a0fd
13 changed files with 102 additions and 27 deletions

View File

@@ -97,9 +97,7 @@ PIValueTree PIValueTreeEdit::value() const {
void PIValueTreeEdit::setGrouping(Grouping g) {
applyValues();
cur_grouping = real_grouping = g;
if (parent_tree && g == Parent) real_grouping = parent_tree->real_grouping;
if (real_grouping == Parent) real_grouping = Indent;
cur_grouping = g;
for (auto * a: widget_params->menu_grouping.actions()) {
if (a->data().toInt() == g) {
a->setChecked(true);
@@ -117,6 +115,13 @@ void PIValueTreeEdit::setFullEditMode(bool yes) {
}
void PIValueTreeEdit::setReadOnly(bool yes) {
applyValues();
m_read_only = yes;
build();
}
void PIValueTreeEdit::rollback() {
current = source;
build();
@@ -195,7 +200,7 @@ void PIValueTreeEdit::build() {
int index = 0;
for (const auto & i: current.children()) {
auto * ve = new PIVariantEdit();
ve->setAttributes(current.attributes());
ve->setAttributes(attributesWithRO(current.attributes()));
ve->setValue(i.value(), array_type);
grid->add(PIValueTree({PIString::fromNumber(index), PIVariant()}), PIString::fromNumber(index + 1), ve, i.comment());
++index;
@@ -467,10 +472,11 @@ PIValueTreeEdit * PIValueTreeEdit::addTreeEdit(const PIValueTree & vt) {
rp << vt.name();
ve->root_path = rp;
ve->parent_tree = this;
ve->setGrouping((Grouping)vt.attribute(Attribute::grouping, Parent).toEnum().selectedValue());
ve->m_read_only = m_read_only;
ve->setGrouping((Grouping)vt.attribute(Attribute::grouping, PIVariantEditorBase::createGrouping()).toEnum().selectedValue());
ve->setFullEditMode(is_full_edit);
ve->setValue(vt);
switch (real_grouping) {
switch (cur_grouping) {
case Indent: grid->add(vt, vt.name(), ve, vt.comment(), true); break;
case Groups: {
auto * gb = new GroupBox(ve);
@@ -523,7 +529,7 @@ void PIValueTreeEdit::applyArrayAttributes() {
uint array_type = PIVariant::typeIDFromName(current.attribute(Attribute::arrayType).toString());
for (int i = 0; i < array_edits.size_s(); ++i) {
auto * w = array_edits[i];
w->setAttributes(current.attributes());
w->setAttributes(attributesWithRO(current.attributes()));
w->setValue(i < current.children().size_s() ? current.children()[i].value() : PIVariant(), array_type);
}
}
@@ -540,7 +546,7 @@ QLabel * PIValueTreeEdit::newLabel(const PIValueTree & vt) {
void PIValueTreeEdit::applyVariantEdit(PIVariantEdit * ve, const PIValueTree & vt) {
ve->setAttributes(vt.attributes());
ve->setAttributes(attributesWithRO(vt.attributes()));
ve->setValue(vt.value());
ve->setFullEditMode(is_full_edit);
}
@@ -562,7 +568,7 @@ void PIValueTreeEdit::resizeArray() {
array_edits.resize(grid->rowCount());
for (int i = grid->rowCount(); i < value; ++i) {
auto * ve = new PIVariantEdit();
ve->setAttributes(current.attributes());
ve->setAttributes(attributesWithRO(current.attributes()));
ve->setValue(PIVariant::fromType(array_type), array_type);
grid->add(PIValueTree(), PIString::fromNumber(i + 1), ve, "");
array_edits << ve;
@@ -570,6 +576,13 @@ void PIValueTreeEdit::resizeArray() {
}
PIVariantMap PIValueTreeEdit::attributesWithRO(const PIVariantMap & attr) {
PIVariantMap ret = attr;
if (m_read_only) ret[PIValueTree::Attribute::readOnly] = true;
return ret;
}
void PIValueTreeEdit::newRequest(NewType type) {
PIString nn;
if (rootTreeEdit()->allowed_names && (type == NewType::Value)) {
@@ -605,7 +618,14 @@ void PIValueTreeEdit::newRequest(NewType type) {
}
current.addChild(vt);
switch (type) {
case NewType::Value: addValueEdit(vt); break;
case NewType::Value:
if (vt.attribute(Attribute::isLabel, false).toBool()) {
auto * l = newLabel(vt);
grid->add(vt, l);
} else {
addValueEdit(vt);
}
break;
case NewType::Group: addTreeEdit(vt); break;
case NewType::Array: addTreeEdit(vt)->resizeArray(); break;
}
@@ -626,7 +646,7 @@ PIValueTreeEdit::GridWidgets::GridWidgets(PIValueTreeEdit * p) {
auto common_actions =
{newSeparator(), wp->actionCut, wp->actionCopy, wp->actionPasteBefore, wp->actionPasteAfter, newSeparator(), wp->actionRemove};
menu_group.addActions({wp->actionRename, wp->actionReorder, wp->menu_grouping.menuAction()});
menu_conf.addActions({wp->actionRename, wp->actionChange, wp->actionReorder});
menu_conf.addActions({wp->actionRename, wp->actionChange, wp->actionReorder, wp->menu_grouping.menuAction()});
menu_group.addActions(common_actions);
menu_conf.addActions(common_actions);
menu_new.addActions({wp->actionValue, wp->actionGroup, wp->actionArray, newSeparator(), wp->actionPaste});