Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed crash when changing file member of custom class #3795

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Scripting: Added API for editing tile layers using terrain sets (with a-morphous, #3758)
* Scripting: Support erasing tiles in Tool.preview and TileMap.merge
* Scripting: Added WangSet.effectiveTypeForColor
* Fixed crash when changing file property of custom class (#3783)
* Fixed object preview position with parallax factor on group layer (#3669)
* Fixed hover highlight rendering with active parallax factor (#3669)
* Fixed updating of object selection outlines when changing parallax factor (#3669)
Expand Down
9 changes: 9 additions & 0 deletions src/libtiled/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class TILEDSHARED_EXPORT PropertyValue

const PropertyType *type() const;
QString typeName() const;

bool operator==(const PropertyValue &o) const
{ return typeId == o.typeId && value == o.value; }
};

class TILEDSHARED_EXPORT FilePath
Expand All @@ -70,6 +73,9 @@ class TILEDSHARED_EXPORT FilePath
public:
QUrl url;

bool operator==(const FilePath &o) const
{ return url == o.url; }

static QString toString(const FilePath &path);
static FilePath fromString(const QString &string);
};
Expand All @@ -82,6 +88,9 @@ class TILEDSHARED_EXPORT ObjectRef
public:
int id;

bool operator==(const ObjectRef &o) const
{ return id == o.id; }

static int toInt(const ObjectRef &ref) { return ref.id; }
static ObjectRef fromInt(int id) { return ObjectRef { id }; }
};
Expand Down
13 changes: 9 additions & 4 deletions src/tiled/propertytypeseditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,13 +1133,18 @@ void PropertyTypesEditor::memberValueChanged(const QStringList &path, const QVar
if (!classType)
return;

auto &topLevelName = path.first();

if (!setPropertyMemberValue(classType->members, path, value))
return;

if (auto property = mPropertiesHelper->property(topLevelName))
property->setValue(mPropertiesHelper->toDisplayValue(classType->members.value(topLevelName)));
// When a nested property was changed, we need to update the value of the
// top-level property to match.
if (path.size() > 1) {
auto &topLevelName = path.first();
if (auto property = mPropertiesHelper->property(topLevelName)) {
QScopedValueRollback<bool> updatingDetails(mUpdatingDetails, true);
property->setValue(mPropertiesHelper->toDisplayValue(classType->members.value(topLevelName)));
}
}

applyPropertyTypes();
}
Expand Down
Loading