Key change is in database/ObjectStore.cpp, where unwrapAndMapAsNeeded and wrapAndUnmapAsNeeded handle converting between how we store things in the database and how we store them in memory. In particular, they now:
force the QVariant to be of the "right" type, which should address the issue discussed in the ticket about how QVariant can present an enum as either a string or an integer depending on how you ask it;
check that the Qt property type matches what we've said the database type is (so we should spot problems sooner where, eg, something that's supposed be an int is declared as a double for its Qt property interface;
handles conversion to and from NULL for optional fields (of which there aren't any yet but lots will soon be arriving when we do BeerJSON).
The other, currently mostly unused, thing added is the static typeLookup function on all the model classes. The fiddly stuff to make this work is in utils/TypeLookup.h and utils/TypeLookup.cpp. Basically the idea is that, for any given Qt property on the model classes, we want to be able to know whether it's a strongly-typed enum and whether it's a type wrapped in std::optional. This is needed to avoid additional complexity in all the serialisation code (including to BeerJSON and BeerXML). Eg, we don't want to have to add new types or flags to all the mappings to say whether something is optional if we can figure it out almost completely automatically.
Also, there were some bugs in the Water assignment operator. I've tried to make sure all the member variables are accessed in the same order in all the constructors etc.
Sorry to make it a bigger change that it needed to be. I was merging stuff back from Brewken and I didn't want to unpick all the std::optional handling that's already coded there.
Fix for https://github.com/Brewtarget/brewtarget/issues/736, plus a bit more currently unused code that will allow us to have optional fields (for BeerJSON).
Key change is in database/ObjectStore.cpp, where
unwrapAndMapAsNeeded
andwrapAndUnmapAsNeeded
handle converting between how we store things in the database and how we store them in memory. In particular, they now:QVariant
to be of the "right" type, which should address the issue discussed in the ticket about howQVariant
can present anenum
as either a string or an integer depending on how you ask it;int
is declared as adouble
for its Qt property interface;NULL
for optional fields (of which there aren't any yet but lots will soon be arriving when we do BeerJSON).The other, currently mostly unused, thing added is the static
typeLookup
function on all the model classes. The fiddly stuff to make this work is inutils/TypeLookup.h
andutils/TypeLookup.cpp
. Basically the idea is that, for any given Qt property on the model classes, we want to be able to know whether it's a strongly-typedenum
and whether it's a type wrapped instd::optional
. This is needed to avoid additional complexity in all the serialisation code (including to BeerJSON and BeerXML). Eg, we don't want to have to add new types or flags to all the mappings to say whether something is optional if we can figure it out almost completely automatically.Also, there were some bugs in the
Water
assignment operator. I've tried to make sure all the member variables are accessed in the same order in all the constructors etc.Sorry to make it a bigger change that it needed to be. I was merging stuff back from Brewken and I didn't want to unpick all the
std::optional
handling that's already coded there.