Init value types properly from factory option defs
This is needed to dump the options with the proper type into yaml file.
This commit is contained in:
@@ -134,7 +134,7 @@ class BaseLayoutFactory: public LayoutFactory
|
||||
|
||||
Layout * create(Layout::PersistentData * persistentData) const override
|
||||
{
|
||||
initPersistentData(persistentData);
|
||||
initPersistentData(persistentData, true);
|
||||
Layout * layout = new T(this, persistentData);
|
||||
if (layout) {
|
||||
layout->create();
|
||||
@@ -144,6 +144,7 @@ class BaseLayoutFactory: public LayoutFactory
|
||||
|
||||
Layout * load(Layout::PersistentData * persistentData) const override
|
||||
{
|
||||
initPersistentData(persistentData, false);
|
||||
Layout * layout = new T(this, persistentData);
|
||||
if (layout) {
|
||||
layout->load();
|
||||
@@ -151,16 +152,24 @@ class BaseLayoutFactory: public LayoutFactory
|
||||
return layout;
|
||||
}
|
||||
|
||||
void initPersistentData(Layout::PersistentData * persistentData) const override
|
||||
void initPersistentData(Layout::PersistentData* persistentData,
|
||||
bool setDefault) const override
|
||||
{
|
||||
memset(persistentData, 0, sizeof(Layout::PersistentData));
|
||||
if (setDefault) {
|
||||
memset(persistentData, 0, sizeof(Layout::PersistentData));
|
||||
}
|
||||
if (options) {
|
||||
int i = 0;
|
||||
for (const ZoneOption * option = options; option->name; option++, i++) {
|
||||
TRACE("LayoutFactory::initPersistentData() setting option '%s'", option->name);
|
||||
// TODO compiler bug? The CPU freezes ... persistentData->options[i++] = option->deflt;
|
||||
memcpy(&persistentData->options[i].value, &option->deflt, sizeof(ZoneOptionValue));
|
||||
persistentData->options[i].type = zoneValueEnumFromType(option->type);
|
||||
for (const ZoneOption* option = options; option->name; option++, i++) {
|
||||
TRACE("LayoutFactory::initPersistentData() setting option '%s'",
|
||||
option->name);
|
||||
// TODO compiler bug? The CPU freezes ... persistentData->options[i++]
|
||||
// = option->deflt;
|
||||
auto optVal = &persistentData->options[i];
|
||||
if (setDefault) {
|
||||
memcpy(&optVal->value, &option->deflt, sizeof(ZoneOptionValue));
|
||||
}
|
||||
optVal->type = zoneValueEnumFromType(option->type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,16 +148,22 @@ class WidgetFactory
|
||||
return name;
|
||||
}
|
||||
|
||||
void initPersistentData(Widget::PersistentData * persistentData) const
|
||||
void initPersistentData(Widget::PersistentData * persistentData, bool setDefault) const
|
||||
{
|
||||
memset(persistentData, 0, sizeof(Widget::PersistentData));
|
||||
if (setDefault) {
|
||||
memset(persistentData, 0, sizeof(Widget::PersistentData));
|
||||
}
|
||||
if (options) {
|
||||
int i = 0;
|
||||
for (const ZoneOption * option = options; option->name; option++, i++) {
|
||||
TRACE("WidgetFactory::initPersistentData() setting option '%s'", option->name);
|
||||
// TODO compiler bug? The CPU freezes ... persistentData->options[i++] = option->deflt;
|
||||
memcpy(&persistentData->options[i].value, &option->deflt, sizeof(ZoneOptionValue));
|
||||
persistentData->options[i].type = zoneValueEnumFromType(option->type);
|
||||
auto optVal = &persistentData->options[i];
|
||||
if (setDefault) {
|
||||
// reset to default value
|
||||
memcpy(&optVal->value, &option->deflt, sizeof(ZoneOptionValue));
|
||||
}
|
||||
optVal->type = zoneValueEnumFromType(option->type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,10 +167,7 @@ class BaseWidgetFactory: public WidgetFactory
|
||||
|
||||
Widget * create(FormGroup * parent, const rect_t & rect, Widget::PersistentData * persistentData, bool init = true) const override
|
||||
{
|
||||
if (init) {
|
||||
initPersistentData(persistentData);
|
||||
}
|
||||
|
||||
initPersistentData(persistentData, init);
|
||||
return new T(this, parent, rect, persistentData);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user