White-Oak / qml-rust

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

trait for QAbstractItemModel #37

Open vandenoever opened 7 years ago

vandenoever commented 7 years ago

QAbstractItemModel is the bread and butter of QML. It would be great if they could be created in Rust via a trait. A minimal trait would look like this:

trait QAbstractItemModel {
    fn column_count(&self, parent: QModelIndex) -> i32;
    fn data(&self, index: QModelIndex, role: i32) -> QVariant;
    fn index(&self, row: i32, column: i32, parent: QModelIndex) -> QModelIndex;
    fn parent(&self, index: QModelIndex) -> QModelIndex;
    fn row_count(&self, parent: QModelIndex) -> i32;
}

role could be an enum. Since QModelIndex is the same size as a reference, they're passes by value. (I guess QModelIndex can implement Copy trait).