[Development] RFC: unified data model API in QtCore => thin wrapper proposal
Tor Arne Vestbø
Tor.arne.Vestbo at qt.io
Fri Jun 15 15:46:43 CEST 2018
> On 15 Jun 2018, at 13:31, Arnaud Clère <arnaud.clere at minmaxmedical.com> wrote:
>
[snip]
> Most user-defined bind methods would be very simple and the type system would
> guarantee that data is well-formed (no sequence or record left open...):
>
> struct Person {
> QString m_firstName, m_lastName;
> int m_age;
>
> template<TResult>
> TResult bind(Val<TResult> value) { return value
> .record()
> .sequence("name")
> .bind(m_firstName)
> .bind(m_lastName)
> .out()
> .bind("age" , m_age); // automagically closes opened record
> }
> };
Not commenting on this API, but I’d like to note that the API I brought up as “missing” from my use-case was a more “light weight” in-place edit API, where the user does not have to define bindings to data structures like above. Similar to e.g. python:
>>> data = json.loads('{ "foo": [1, 2, 3] }')
>>> data
{u'foo': [1, 2, 3]}
>>> data["foo"][0] = 42
>>> data
{u'foo': [42, 2, 3]}
With our existing APIs I’d expect:
QJsonDocument doc;
doc[“foo”][0] = 42;
Tor Arne
More information about the Development
mailing list