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
|
Layout * create(Layout::PersistentData * persistentData) const override
|
||||||
{
|
{
|
||||||
initPersistentData(persistentData);
|
initPersistentData(persistentData, true);
|
||||||
Layout * layout = new T(this, persistentData);
|
Layout * layout = new T(this, persistentData);
|
||||||
if (layout) {
|
if (layout) {
|
||||||
layout->create();
|
layout->create();
|
||||||
@@ -144,6 +144,7 @@ class BaseLayoutFactory: public LayoutFactory
|
|||||||
|
|
||||||
Layout * load(Layout::PersistentData * persistentData) const override
|
Layout * load(Layout::PersistentData * persistentData) const override
|
||||||
{
|
{
|
||||||
|
initPersistentData(persistentData, false);
|
||||||
Layout * layout = new T(this, persistentData);
|
Layout * layout = new T(this, persistentData);
|
||||||
if (layout) {
|
if (layout) {
|
||||||
layout->load();
|
layout->load();
|
||||||
@@ -151,16 +152,24 @@ class BaseLayoutFactory: public LayoutFactory
|
|||||||
return layout;
|
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) {
|
if (options) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const ZoneOption * option = options; option->name; option++, i++) {
|
for (const ZoneOption* option = options; option->name; option++, i++) {
|
||||||
TRACE("LayoutFactory::initPersistentData() setting option '%s'", option->name);
|
TRACE("LayoutFactory::initPersistentData() setting option '%s'",
|
||||||
// TODO compiler bug? The CPU freezes ... persistentData->options[i++] = option->deflt;
|
option->name);
|
||||||
memcpy(&persistentData->options[i].value, &option->deflt, sizeof(ZoneOptionValue));
|
// TODO compiler bug? The CPU freezes ... persistentData->options[i++]
|
||||||
persistentData->options[i].type = zoneValueEnumFromType(option->type);
|
// = 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;
|
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) {
|
if (options) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const ZoneOption * option = options; option->name; option++, i++) {
|
for (const ZoneOption * option = options; option->name; option++, i++) {
|
||||||
TRACE("WidgetFactory::initPersistentData() setting option '%s'", option->name);
|
TRACE("WidgetFactory::initPersistentData() setting option '%s'", option->name);
|
||||||
// TODO compiler bug? The CPU freezes ... persistentData->options[i++] = option->deflt;
|
// TODO compiler bug? The CPU freezes ... persistentData->options[i++] = option->deflt;
|
||||||
memcpy(&persistentData->options[i].value, &option->deflt, sizeof(ZoneOptionValue));
|
auto optVal = &persistentData->options[i];
|
||||||
persistentData->options[i].type = zoneValueEnumFromType(option->type);
|
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
|
Widget * create(FormGroup * parent, const rect_t & rect, Widget::PersistentData * persistentData, bool init = true) const override
|
||||||
{
|
{
|
||||||
if (init) {
|
initPersistentData(persistentData, init);
|
||||||
initPersistentData(persistentData);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new T(this, parent, rect, persistentData);
|
return new T(this, parent, rect, persistentData);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user