Brewtarget / brewtarget

Main brewtarget source code repository.
GNU General Public License v3.0
313 stars 134 forks source link

Water chemistry fixes (mostly) #739

Closed matty0ung closed 1 year ago

matty0ung commented 1 year ago

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 and wrapAndUnmapAsNeeded handle converting between how we store things in the database and how we store them in memory. In particular, they now:

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.