Skip to content

Commit

Permalink
server: DecoderFunctions update on Decoder id change
Browse files Browse the repository at this point in the history
- This allows updatating `ItemsEditWidget` list which
  contains ids prefixed with decoder id

TODO: find a more generic way. Also for nested SubObjects

Also BlockInputMap and others should benefit from this
  • Loading branch information
gfgit committed Aug 17, 2024
1 parent 34a64a8 commit 29af12b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions server/src/core/objectvectorproperty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ class ObjectVectorProperty : public AbstractObjectVectorProperty
changed();
}

void parentIdChanged()
{
changed();
}

void load(std::vector<std::shared_ptr<T>> values)
{
m_values = std::move(values);
Expand Down
11 changes: 9 additions & 2 deletions server/src/hardware/decoder/decoderfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include "../../core/objectvectorproperty.tpp"
#include "../../utils/displayname.hpp"

DecoderFunctions::DecoderFunctions(Object& _parent, std::string_view parentPropertyName)
: SubObject(_parent, parentPropertyName)
DecoderFunctions::DecoderFunctions(Decoder &decoder_, std::string_view parentPropertyName)
: SubObject(decoder_, parentPropertyName)
, items{*this, "items", {}, PropertyFlags::ReadOnly | PropertyFlags::Store | PropertyFlags::SubObject}
, create{*this, "create",
[this]() -> void
Expand Down Expand Up @@ -88,6 +88,13 @@ DecoderFunctions::DecoderFunctions(Object& _parent, std::string_view parentPrope
Attributes::addDisplayName(moveDown, DisplayName::List::moveDown);
Attributes::addEnabled(moveDown, editable);
m_interfaceItems.add(moveDown);

decoder_.propertyChanged.connect(
[this](BaseProperty& property)
{
if(property.name() == "id")
items.parentIdChanged();
});
}

void DecoderFunctions::load(WorldLoader& loader, const nlohmann::json& data)
Expand Down
4 changes: 3 additions & 1 deletion server/src/hardware/decoder/decoderfunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "../../core/method.hpp"
#include "decoderfunction.hpp"

class Decoder;

class DecoderFunctions : public SubObject
{
protected:
Expand All @@ -45,7 +47,7 @@ class DecoderFunctions : public SubObject

using const_iterator = ObjectVectorProperty<DecoderFunction>::const_iterator;

DecoderFunctions(Object& _parent, std::string_view parentPropertyName);
DecoderFunctions(Decoder& _parent, std::string_view parentPropertyName);

inline const_iterator begin() const { return items.begin(); }
inline const_iterator end() const { return items.end(); }
Expand Down

0 comments on commit 29af12b

Please sign in to comment.