White-Oak / qml-rust

QML (Qt Quick) bindings for Rust language
MIT License
205 stars 18 forks source link

enahnce Q_LISTMODEL to support struct insert #18

Closed fneddy closed 7 years ago

fneddy commented 7 years ago

I don’t know if it is a desired feature but I think it is much more handy to insert structs then to insert structs fields to a QListModel.

I wrote a macro that wraps the old behaviour: https://github.com/berlineddy/qml-rust/commit/462004f84a0f870e3f30fbfe6aeeaa7eef145898

proposed syntax:

Q_LISTMODEL_ITEM!{
    pub TestModel<TestModelItem> {
        name: String,
        number: i32,
    }
}

// ...

let mut qqae = QmlEngine::new();
let mut qalm = QTestModel::new();
let item1 = TestModelItem {
    name: "foo".into(),
    number: 42
};
let item2 = TestModelItem {
    name: "bar".into(),
    number: 23
};
qalm.insert_item(item1);
qalm.insert_item(item2);
// `&QTestModel` implements `Into<QVariant>`
qqae.set_and_store_property("listModel", &qalm);
qqae.exec();

If this feature is wanted I'll do a push request otherwise this issue can be closed.

White-Oak commented 7 years ago

It looks awesome! Does it work with single items? Or is it just like #16? I'm experiencing strange issues with that one.

Also, do you notice your commits are authored by not-github user? You can add your email in Github options, or you can set your local commit email via git config user.email.

fneddy commented 7 years ago

yes, this works also with with single items.

16 happens here. I was thinking of replacing the set_data(tuple) with a set_data(struct). But for this this the Q_LISTMODEL! macro needs to know about the nested struct.

White-Oak commented 7 years ago

16 is fixed, but this enhancement is still welcomed.