From 34d26537448cec1e8a53dabe3abdcd5d4d5c8e04 Mon Sep 17 00:00:00 2001 From: peri4 Date: Thu, 26 Jan 2023 12:32:28 +0300 Subject: [PATCH] PIValueTreeEdit sort attributes according to PIValueTree::standardAttributes --- .../pivaluetree_edit_parameters.cpp | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/libs/piqt_widgets/pivaluetree_edit_parameters.cpp b/libs/piqt_widgets/pivaluetree_edit_parameters.cpp index 95f7baf..34987cb 100644 --- a/libs/piqt_widgets/pivaluetree_edit_parameters.cpp +++ b/libs/piqt_widgets/pivaluetree_edit_parameters.cpp @@ -124,14 +124,23 @@ void PIValueTreeEditParameters::createAttributes(QList & list, if (!cf && inv_filter) continue; dal[vit.key()] = vit.value(); } + auto addEdit = [&list, &lay](const QString & name, const PIVariant & value) { + auto * ve = new PIVariantEdit(); + ve->setAttributes(PIVariantEditorBase::editorDefaultAttributes(value.typeID())); + ve->setValue(value); + ve->setProperty(property_name, name); + list << ve; + lay->addRow(name + ":", ve); + }; + const auto & sal(PIValueTree::standardAttributes()); + for (const auto & sn: sal) { + if (!dal.contains(sn)) continue; + addEdit(PI2QString(sn), dal.value(sn)); + dal.remove(sn); + } auto dit = dal.makeIterator(); while (dit.next()) { - auto * ve = new PIVariantEdit(); - ve->setAttributes(PIVariantEditorBase::editorDefaultAttributes(dit.value().typeID())); - ve->setValue(dit.value()); - ve->setProperty(property_name, PI2QString(dit.key())); - list << ve; - lay->addRow(PI2QString(dit.key() + ":"), ve); + addEdit(PI2QString(dit.key()), dit.value()); } } @@ -186,10 +195,8 @@ void PIValueTreeEditParameters::on_checkLabel_toggled(bool on) { ve_attr.clear(); while (layoutAttributes->rowCount() > 0) layoutAttributes->removeRow(0); - createAttributes(ve_attr, - layoutAttributes, - { - {Attribute::style, ""} - }); + // clang-format off + createAttributes(ve_attr, layoutAttributes, {{Attribute::style, ""}}); + // clang-format on } }