Bug 397107 - PATCH WIP: Add moveable objects
Summary: PATCH WIP: Add moveable objects
Status: CONFIRMED
Alias: None
Product: rust-qt-binding-generator
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: Jos van den Oever
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-02 20:33 UTC by kdebuac.rhn
Modified: 2018-08-05 18:08 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
The WIP patch (46.32 KB, patch)
2018-08-02 20:33 UTC, kdebuac.rhn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description kdebuac.rhn 2018-08-02 20:33:16 UTC
Created attachment 114276 [details]
The WIP patch

Hello,

I want to have a bit more freedom dealing with QML objects, especially moving them around, so here's an implementation allowing objects to be nested from the perspective of QML (and also moved around).

The JSON declaration recycles "write" for the purpose of indicating that the object can be replaced. It implicitly means that the object is optional - when an object is declared in QML as a property, it will call always "set" of the parent object. Optionality here allows us not to care about the initial "empty" value. As such, they are treated differently than any other kind of a property.

One drawback I'd like to solve is the Clone trait on any inner object. In my project, it only contained one reference to a C structure, so it was not important to me. If the Rust structure needs to carry actual data, this will probably have to be reworked with some Arcs.

The best test case for this is QML:

    SomeObject { myObject: MyType {} }

However, I don't know how to test that within the existing framework.

This feature is already in use in my very incomplete email reader: https://github.com/rhn/notquick/

I hope we can swiftly beat this idea into shape, and then I can propose the more ambitious support for creating objects on the fly ;)
Comment 1 Jos van den Oever 2018-08-04 20:39:27 UTC
Making the object optional is one option. The other option is to require that the object implements the Default trait.

Implying that the object is optional is bad in my opinion. If the the first of the two alternatives is chosen, it should require that the binding JSON explicitly contains '"optional": true'.

Can you say a bit more about 'creating objects on the fly'?
Comment 2 kdebuac.rhn 2018-08-05 00:11:25 UTC
I chose to make optional implicit because I was concerned with the QML use case, where the object can be almost arbitrary, but is immediately replaced.

I think making optional explicit is not a bad choice. While this patch covers only the case of optional==True, it's self-contained and can be a starting point for optional==False support implemented as a separate change.

By "creating objects on the fly", I meant creating QML objects (e.g. list items) in Rust. I have prototyped it a bit and have an idea of how to proceed. It's unrelated to this change, but I could start a separate bug to elaborate.
Comment 3 Jos van den Oever 2018-08-05 16:55:07 UTC
Please upload the patch to code review so we can discuss it in detail.

https://phabricator.kde.org/differential/diff/create/
Comment 4 kdebuac.rhn 2018-08-05 18:08:29 UTC
Here it is: https://phabricator.kde.org/D14634