Skip to content

Commit

Permalink
Remember the expanded state of custom class properties
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bjorn committed Oct 24, 2024
1 parent 58d7a35 commit bd54309
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/tiled/propertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ class VariantMapProperty : public GroupProperty
QVariantMap mValue;
QVariantMap mSuggestions;
QHash<QString, Property*> mPropertyMap;
QSet<QStringList> mExpandedProperties;
};


Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 11 additions & 1 deletion src/tiled/varianteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down
6 changes: 6 additions & 0 deletions src/tiled/varianteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -176,10 +180,12 @@ class GroupProperty : public Property
const QList<Property*> &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<Property*> m_subProperties;
};

Expand Down

0 comments on commit bd54309

Please sign in to comment.