Continue refactor

This commit is contained in:
Carl Philipp Klemm 2026-03-30 18:25:25 +02:00
parent 18cf2b01bd
commit 219fbfb4c7
14 changed files with 104 additions and 125 deletions

View file

@ -34,6 +34,11 @@ uint8_t ItemData::getValue() const
return value_;
}
void ItemData::setValueData(uint8_t value)
{
value_ = value;
}
uint32_t ItemData::id() const
{
return itemId_;
@ -156,41 +161,27 @@ Item& Item::operator=(const ItemData& other)
void Item::requestUpdate(ItemUpdateRequest update)
{
if(!hasChanged(update.data))
if(!hasChanged(update.payload))
return;
if(update.type == ITEM_UPDATE_USER || (update.type == ITEM_UPDATE_ACTOR && !override_) || update.type == ITEM_UPDATE_REMOTE)
if(update.type == ITEM_UPDATE_ACTOR && override_)
return;
if(update.type != ITEM_UPDATE_LOADED
&& (programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY))
enactValue(update.payload.getValue());
*this = update.payload;
update.payload = *this;
if(update.type == ITEM_UPDATE_LOADED)
{
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
enactValue(update.data.getValue());
*this = update.data;
update.data = *this;
updated(update);
actors_.clear();
for(std::shared_ptr<Actor>& actor : update.newActors)
addActor(actor);
}
}
void Item::actorSetValue(uint8_t value)
{
if(!override_ && (programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY))
setValue(value);
}
void Item::setValue(uint8_t value)
{
qDebug()<<__func__;
informValue(value);
updated(*this);
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
enactValue(value);
}
void Item::informValue(uint8_t value)
{
if(value_ != value)
{
value_ = value;
valueChanged(value_);
}
updated(update);
}
void Item::enactValue(uint8_t value)
@ -203,8 +194,8 @@ void Item::addActor(std::shared_ptr<Actor> actor)
actor->setParent(this);
actors_.push_back(actor);
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
connect(actor.get(), &Actor::sigValue, this, &Item::actorSetValue);
connect(this, &Item::valueChanged, actor.get(), &Actor::onValueChanged);
connect(actor.get(), &Actor::sigItemUpdate, this, &Item::requestUpdate);
connect(this, &Item::updated, actor.get(), &Actor::onItemUpdated);
std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
if(sensorActor)
@ -263,14 +254,6 @@ void Item::setActorsActive(bool in)
in ? actors_[i]->makeActive() : actors_[i]->makeInactive();
}
void Item::mergeLoaded(Item& item)
{
name_ = item.name_;
actors_.clear();
for(std::shared_ptr<Actor> actor : item.actors_)
addActor(actor);
}
std::shared_ptr<Item> Item::loadItem(const QJsonObject& json)
{
std::shared_ptr<Item> newItem = nullptr;
@ -298,3 +281,14 @@ std::shared_ptr<Item> Item::loadItem(const QJsonObject& json)
return newItem;
}
ItemUpdateRequest Item::createValueUpdateRequest(uint8_t value,
item_update_type_t type,
bool withActors)
{
ItemUpdateRequest update;
update.payload = *this;
update.payload.setValueData(value);
if(withActors)
update.newActors = actors_;
return update;
}