Finis support for ENUM item types
This commit is contained in:
parent
e881472e7c
commit
3794e0031b
4 changed files with 96 additions and 1 deletions
|
|
@ -60,6 +60,13 @@ void ItemData::storeWithChanges(QJsonObject& json, const ItemFieldChanges& chang
|
|||
json["Value"] = static_cast<double>(value_);
|
||||
if(changes.groupName)
|
||||
json["GroupName"] = groupName_;
|
||||
if(changes.valueNames)
|
||||
{
|
||||
QJsonArray valueNamesArray;
|
||||
for(const QString& name : valueNames_)
|
||||
valueNamesArray.append(name);
|
||||
json["ValueNames"] = valueNamesArray;
|
||||
}
|
||||
}
|
||||
|
||||
void ItemData::load(const QJsonObject &json, const bool preserve)
|
||||
|
|
@ -87,6 +94,19 @@ ItemFieldChanges ItemData::loadWithChanges(const QJsonObject& json, const bool p
|
|||
groupName_ = json["GroupName"].toString();
|
||||
changes.groupName = true;
|
||||
}
|
||||
if(json.contains("ValueType"))
|
||||
{
|
||||
type_ = static_cast<item_value_type_t>(json["ValueType"].toInt());
|
||||
changes.type = true;
|
||||
}
|
||||
if(json.contains("ValueNames"))
|
||||
{
|
||||
valueNames_.clear();
|
||||
QJsonArray valueNamesArray = json["ValueNames"].toArray();
|
||||
for(int i = 0; i < valueNamesArray.size(); ++i)
|
||||
valueNames_.push_back(valueNamesArray[i].toString());
|
||||
changes.valueNames = true;
|
||||
}
|
||||
itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0));
|
||||
}
|
||||
return changes;
|
||||
|
|
@ -120,6 +140,8 @@ bool ItemData::hasChanged(const ItemData& other, const ItemFieldChanges& changes
|
|||
return true;
|
||||
if(changes.actors)
|
||||
return true;
|
||||
if(changes.valueNames && other.getValueNames() != getValueNames())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -148,6 +170,33 @@ void ItemData::setGroupName(QString groupName)
|
|||
groupName_ = groupName;
|
||||
}
|
||||
|
||||
std::vector<QString> ItemData::getValueNames() const
|
||||
{
|
||||
return valueNames_;
|
||||
}
|
||||
|
||||
void ItemData::setValueNames(std::vector<QString> valueNames)
|
||||
{
|
||||
valueNames_ = std::move(valueNames);
|
||||
}
|
||||
|
||||
int ItemData::valueNameToIndex(const QString& name) const
|
||||
{
|
||||
for(size_t i = 0; i < valueNames_.size(); ++i)
|
||||
{
|
||||
if(valueNames_[i] == name)
|
||||
return static_cast<int>(i);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
QString ItemData::indexToValueName(int index) const
|
||||
{
|
||||
if(index >= 0 && static_cast<size_t>(index) < valueNames_.size())
|
||||
return valueNames_[index];
|
||||
return QString();
|
||||
}
|
||||
|
||||
//item
|
||||
|
||||
Item::Item(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent): QObject(parent), ItemData (itemIdIn, name,
|
||||
|
|
@ -205,6 +254,7 @@ Item& Item::operator=(const ItemData& other)
|
|||
itemId_ = other.id();
|
||||
hidden_ = other.isHidden();
|
||||
groupName_ = other.getGroupName();
|
||||
valueNames_ = other.getValueNames();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -248,6 +298,8 @@ void Item::requestUpdate(ItemUpdateRequest update)
|
|||
for(std::shared_ptr<Actor>& actor : update.newActors)
|
||||
addActor(actor);
|
||||
}
|
||||
if(update.changes.valueNames)
|
||||
valueNames_ = update.payload.getValueNames();
|
||||
update.payload = *this;
|
||||
updated(update);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue