Item: only save fields that are set in the item

This commit is contained in:
Carl Philipp Klemm 2026-04-25 23:40:35 +02:00
parent 221cb519a2
commit a96b27c741

View file

@ -58,9 +58,9 @@ void ItemData::storeWithChanges(QJsonObject& json, const ItemFieldChanges& chang
json["Name"] = name_; json["Name"] = name_;
if(changes.value) if(changes.value)
json["Value"] = static_cast<double>(value_); json["Value"] = static_cast<double>(value_);
if(changes.groupName) if(changes.groupName && !groupName_.isEmpty() && groupName_ != "All")
json["GroupName"] = groupName_; json["GroupName"] = groupName_;
if(changes.valueNames) if(changes.valueNames && !valueNames_.empty())
{ {
QJsonArray valueNamesArray; QJsonArray valueNamesArray;
for(const QString& name : valueNames_) for(const QString& name : valueNames_)
@ -218,6 +218,8 @@ void Item::store(QJsonObject &json)
{ {
ItemData::store(json); ItemData::store(json);
json["override"] = override_; json["override"] = override_;
if(!actors_.empty())
{
QJsonArray actorsArray; QJsonArray actorsArray;
for(size_t i = 0; i < actors_.size(); ++i) for(size_t i = 0; i < actors_.size(); ++i)
{ {
@ -230,11 +232,14 @@ void Item::store(QJsonObject &json)
} }
json["Actors"] = actorsArray; json["Actors"] = actorsArray;
} }
}
void Item::load(const QJsonObject &json, const bool preserve) void Item::load(const QJsonObject &json, const bool preserve)
{ {
ItemData::load(json, preserve); ItemData::load(json, preserve);
override_ = json["override"].toBool(false); override_ = json["override"].toBool(false);
if(json.contains("Actors"))
{
const QJsonArray actorsArray(json["Actors"].toArray(QJsonArray())); const QJsonArray actorsArray(json["Actors"].toArray(QJsonArray()));
for(int i = 0; i < actorsArray.size(); ++i) for(int i = 0; i < actorsArray.size(); ++i)
{ {
@ -246,6 +251,7 @@ void Item::load(const QJsonObject &json, const bool preserve)
} }
} }
} }
}
Item& Item::operator=(const ItemData& other) Item& Item::operator=(const ItemData& other)
{ {