Support item tabs based on item group string
This commit is contained in:
parent
0e09b6f46c
commit
a17cd23a4e
29 changed files with 527 additions and 181 deletions
|
|
@ -46,21 +46,49 @@ uint32_t ItemData::id() const
|
|||
|
||||
void ItemData::store(QJsonObject &json)
|
||||
{
|
||||
json["Name"] = name_;
|
||||
storeWithChanges(json, ItemFieldChanges(true));
|
||||
}
|
||||
|
||||
void ItemData::storeWithChanges(QJsonObject& json, const ItemFieldChanges& changes)
|
||||
{
|
||||
json["ItemId"] = static_cast<double>(itemId_);
|
||||
json["Value"] = static_cast<double>(value_);
|
||||
json["GroupName"] = groupName_;
|
||||
json["ValueType"] = type_;
|
||||
if(changes.name)
|
||||
json["Name"] = name_;
|
||||
if(changes.value)
|
||||
json["Value"] = static_cast<double>(value_);
|
||||
if(changes.groupName)
|
||||
json["GroupName"] = groupName_;
|
||||
}
|
||||
|
||||
void ItemData::load(const QJsonObject &json, const bool preserve)
|
||||
{
|
||||
loadWithChanges(json, preserve);
|
||||
}
|
||||
|
||||
ItemFieldChanges ItemData::loadWithChanges(const QJsonObject& json, const bool preserve)
|
||||
{
|
||||
ItemFieldChanges changes;
|
||||
if(!preserve)
|
||||
{
|
||||
name_ = json["Name"].toString(name_);
|
||||
if(json.contains("Name"))
|
||||
{
|
||||
name_ = json["Name"].toString();
|
||||
changes.name = true;
|
||||
}
|
||||
if(json.contains("Value"))
|
||||
{
|
||||
value_ = json["Value"].toInt();
|
||||
changes.value = true;
|
||||
}
|
||||
if(json.contains("GroupName"))
|
||||
{
|
||||
groupName_ = json["GroupName"].toString();
|
||||
changes.groupName = true;
|
||||
}
|
||||
itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0));
|
||||
value_ = json["Value"].toInt();
|
||||
groupName_ = json["GroupName"].toString("All");
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
|
||||
bool ItemData::getLoaded() const
|
||||
|
|
@ -73,15 +101,23 @@ void ItemData::setLoaded(bool loaded)
|
|||
loaded_ = loaded;
|
||||
}
|
||||
|
||||
bool ItemData::hasChanged(const ItemData& other)
|
||||
bool ItemData::hasChanged(const ItemData& other) const
|
||||
{
|
||||
if(other != *this)
|
||||
return false;
|
||||
if(other.getName() != getName())
|
||||
ItemFieldChanges changes(true);
|
||||
return hasChanged(other, changes);
|
||||
}
|
||||
|
||||
bool ItemData::hasChanged(const ItemData& other, const ItemFieldChanges& changes) const
|
||||
{
|
||||
if(changes.name && other.getName() != getName())
|
||||
return true;
|
||||
if(other.getValue() != getValue())
|
||||
if(changes.value && other.getValue() != getValue())
|
||||
return true;
|
||||
if(other.getLoaded() != getLoaded())
|
||||
if(changes.hidden && other.isHidden() != isHidden())
|
||||
return true;
|
||||
if(changes.groupName && other.getGroupName() != getGroupName())
|
||||
return true;
|
||||
if(changes.actors)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -143,7 +179,6 @@ void Item::store(QJsonObject &json)
|
|||
}
|
||||
}
|
||||
json["Actors"] = actorsArray;
|
||||
json["ValueType"] = type_;
|
||||
}
|
||||
|
||||
void Item::load(const QJsonObject &json, const bool preserve)
|
||||
|
|
@ -175,7 +210,14 @@ Item& Item::operator=(const ItemData& other)
|
|||
void Item::requestUpdate(ItemUpdateRequest update)
|
||||
{
|
||||
assert(update.type != ITEM_UPDATE_INVALID);
|
||||
if(update.type != ITEM_UPDATE_LOADED && value_ == update.payload.getValue())
|
||||
assert(!update.changes.isNone());
|
||||
|
||||
if(update.type == ITEM_UPDATE_LOADED)
|
||||
{
|
||||
qDebug()<<__func__<<update.changes.actors<<update.newActors.size();
|
||||
}
|
||||
|
||||
if(!hasChanged(update.payload, update.changes))
|
||||
return;
|
||||
|
||||
if(update.type == ITEM_UPDATE_ACTOR && override_)
|
||||
|
|
@ -183,20 +225,24 @@ void Item::requestUpdate(ItemUpdateRequest update)
|
|||
|
||||
qDebug()<<"Item Update Request for"<<getName()<<" type "<<update.type<<" value "<<update.payload.getValue();
|
||||
|
||||
if(update.type != ITEM_UPDATE_LOADED &&
|
||||
update.type != ITEM_UPDATE_BACKEND &&
|
||||
(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY))
|
||||
if(update.type != ITEM_UPDATE_LOADED && update.type != ITEM_UPDATE_BACKEND &&
|
||||
(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY) &&
|
||||
update.changes.value)
|
||||
enactValue(update.payload.getValue());
|
||||
|
||||
if(update.type != ITEM_UPDATE_LOADED)
|
||||
{
|
||||
|
||||
if(update.changes.value)
|
||||
value_ = update.payload.getValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(update.changes.name)
|
||||
name_ = update.payload.getName();
|
||||
//itemId_ = update.payload.id();
|
||||
if(update.changes.hidden)
|
||||
hidden_ = update.payload.isHidden();
|
||||
if(update.changes.groupName)
|
||||
groupName_ = update.payload.getGroupName();
|
||||
if(update.changes.type)
|
||||
type_ = update.payload.getValueType();
|
||||
if(update.changes.actors)
|
||||
{
|
||||
actors_.clear();
|
||||
for(std::shared_ptr<Actor>& actor : update.newActors)
|
||||
addActor(actor);
|
||||
|
|
@ -302,14 +348,12 @@ std::shared_ptr<Item> Item::loadItem(const QJsonObject& json)
|
|||
return newItem;
|
||||
}
|
||||
|
||||
ItemUpdateRequest Item::createValueUpdateRequest(uint8_t value,
|
||||
item_update_type_t type,
|
||||
ItemUpdateRequest Item::createValueUpdateRequest(item_update_type_t type,
|
||||
bool withActors)
|
||||
{
|
||||
ItemUpdateRequest update;
|
||||
update.type = type;
|
||||
update.payload = *this;
|
||||
update.payload.setValueData(value);
|
||||
if(withActors)
|
||||
update.newActors = actors_;
|
||||
return update;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue