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; };