From bd54309be87315178701e9f6ee16d2373ee5146b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 17 Oct 2024 15:31:10 +0200 Subject: [PATCH] Remember the expanded state of custom class properties The expanded state is now remembered for each "path", meaning you can select different objects, and when they happen to have the same properties the expanded state applies to all of them. For now the state is lost when Tiled is closed. It might be nice to store the list of expanded property paths in the session. --- src/tiled/propertieswidget.cpp | 10 ++++++++++ src/tiled/varianteditor.cpp | 12 +++++++++++- src/tiled/varianteditor.h | 6 ++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/tiled/propertieswidget.cpp b/src/tiled/propertieswidget.cpp index a0b1b1d18d..6a231a6167 100644 --- a/src/tiled/propertieswidget.cpp +++ b/src/tiled/propertieswidget.cpp @@ -517,6 +517,7 @@ class VariantMapProperty : public GroupProperty QVariantMap mValue; QVariantMap mSuggestions; QHash mPropertyMap; + QSet mExpandedProperties; }; @@ -2576,6 +2577,15 @@ Property *VariantMapProperty::createProperty(const QStringList &path, createClassMembers(path, groupProperty, classType, std::move(get)); + groupProperty->setExpanded(mExpandedProperties.contains(path)); + + connect(groupProperty, &GroupProperty::expandedChanged, this, [=](bool expanded) { + if (expanded) + mExpandedProperties.insert(path); + else + mExpandedProperties.remove(path); + }); + property = groupProperty; break; } diff --git a/src/tiled/varianteditor.cpp b/src/tiled/varianteditor.cpp index be4862808b..6b401288bb 100644 --- a/src/tiled/varianteditor.cpp +++ b/src/tiled/varianteditor.cpp @@ -73,6 +73,14 @@ void Property::setActions(Actions actions) } } +void GroupProperty::setExpanded(bool expanded) +{ + if (m_expanded != expanded) { + m_expanded = expanded; + emit expandedChanged(expanded); + } +} + void StringProperty::setPlaceholderText(const QString &placeholderText) { if (m_placeholderText != placeholderText) { @@ -664,12 +672,14 @@ QLayout *VariantEditor::createPropertyLayout(Property *property) widgets.childrenLayout->addLayout(rowLayout); widgets.layout = widgets.childrenLayout; + connect(groupProperty, &GroupProperty::expandedChanged, widgets.label, &PropertyLabel::setExpanded); connect(widgets.label, &PropertyLabel::toggled, this, [=](bool expanded) { setPropertyChildrenExpanded(groupProperty, expanded); + groupProperty->setExpanded(expanded); }); widgets.label->setExpandable(true); - widgets.label->setExpanded(widgets.label->isHeader()); + widgets.label->setExpanded(groupProperty->isExpanded()); } updatePropertyEnabled(widgets, property->isEnabled()); diff --git a/src/tiled/varianteditor.h b/src/tiled/varianteditor.h index b21d2df0f3..8afc1dd1b5 100644 --- a/src/tiled/varianteditor.h +++ b/src/tiled/varianteditor.h @@ -128,6 +128,7 @@ class Separator final : public Property class GroupProperty : public Property { Q_OBJECT + Q_PROPERTY(bool expanded READ isExpanded WRITE setExpanded NOTIFY expandedChanged) public: GroupProperty(const QString &name, QObject *parent = nullptr) @@ -143,6 +144,9 @@ class GroupProperty : public Property void setHeader(bool header) { m_header = header; } + bool isExpanded() const { return m_expanded; } + void setExpanded(bool expanded); + void clear() { qDeleteAll(m_subProperties); @@ -176,10 +180,12 @@ class GroupProperty : public Property const QList &subProperties() const { return m_subProperties; } signals: + void expandedChanged(bool expanded); void propertyAdded(int index, Property *property); private: bool m_header = true; + bool m_expanded = true; QList m_subProperties; };