diff --git a/demo/rust/src/testinterface.rs b/demo/rust/src/testinterface.rs index 162ca05..2b880f2 100644 --- a/demo/rust/src/testinterface.rs +++ b/demo/rust/src/testinterface.rs @@ -203,6 +203,8 @@ pub trait DirectoryTrait { fn get_path(&self) -> String; fn set_path(&mut self, value: String); fn row_count(&self) -> c_int; + fn can_fetch_more(&self) -> bool { false } + fn fetch_more(&self) {} fn file_icon(&self, row: c_int) -> Variant; fn file_path(&self, row: c_int) -> Variant; fn file_name(&self, row: c_int) -> Variant; @@ -258,6 +260,14 @@ pub unsafe extern "C" fn directory_path_set(ptr: *mut Directory, v: QStringIn) { pub unsafe extern "C" fn directory_row_count(ptr: *const Directory) -> c_int { (&*ptr).row_count() } +#[no_mangle] +pub unsafe extern "C" fn directory_can_fetch_more(ptr: *const Directory) -> bool { + (&*ptr).can_fetch_more() +} +#[no_mangle] +pub unsafe extern "C" fn directory_fetch_more(ptr: *mut Directory) { + (&mut *ptr).fetch_more() +} #[no_mangle] pub unsafe extern "C" fn directory_data_file_icon(ptr: *const Directory, diff --git a/demo/src/tmp.cpp b/demo/src/tmp.cpp index 34d5fb7..2a692ec 100644 --- a/demo/src/tmp.cpp +++ b/demo/src/tmp.cpp @@ -223,7 +223,9 @@ extern "C" { void directory_data_file_name(DirectoryInterface*, int, QVariant*, qvariant_set); void directory_data_file_permissions(DirectoryInterface*, int, QVariant*, qvariant_set); - int directory_row_count(DirectoryInterface*, qmodelindex_t parent); + int directory_row_count(DirectoryInterface*); + bool directory_can_fetch_more(DirectoryInterface*); + void directory_fetch_more(DirectoryInterface*); } int Directory::columnCount(const QModelIndex &parent) const { @@ -232,7 +234,7 @@ int Directory::columnCount(const QModelIndex &parent) const int Directory::rowCount(const QModelIndex &parent) const { - return (parent.isValid()) ? 0 : directory_row_count(d, parent); + return (parent.isValid()) ? 0 : directory_row_count(d); } QModelIndex Directory::index(int row, int column, const QModelIndex &parent) const @@ -248,6 +250,18 @@ QModelIndex Directory::parent(const QModelIndex &) const return QModelIndex(); } +bool Directory::canFetchMore(const QModelIndex &parent) const +{ + return (parent.isValid()) ? 0 : directory_can_fetch_more(d); +} + +void Directory::fetchMore(const QModelIndex &parent) +{ + if (!parent.isValid()) { + directory_fetch_more(d); + } +} + QVariant Directory::data(const QModelIndex &index, int role) const { QVariant v; diff --git a/demo/src/tmp.h b/demo/src/tmp.h index c81b52d..37b2f75 100644 --- a/demo/src/tmp.h +++ b/demo/src/tmp.h @@ -59,6 +59,8 @@ public: QModelIndex index(int row, int column, const QModelIndex &parent) const; QModelIndex parent(const QModelIndex &index) const; int rowCount(const QModelIndex &parent) const; + bool canFetchMore(const QModelIndex &parent) const; + void fetchMore(const QModelIndex &parent); QHash roleNames() const; signals: void newDataReady(); diff --git a/rust_qt_binding_generator/rust_qt_binding_generator.cpp b/rust_qt_binding_generator/rust_qt_binding_generator.cpp index 2367d47..8948905 100644 --- a/rust_qt_binding_generator/rust_qt_binding_generator.cpp +++ b/rust_qt_binding_generator/rust_qt_binding_generator.cpp @@ -227,6 +227,8 @@ void writeHeaderItemModel(QTextStream& h, const Object&) { QModelIndex index(int row, int column, const QModelIndex &parent) const; QModelIndex parent(const QModelIndex &index) const; int rowCount(const QModelIndex &parent) const; + bool canFetchMore(const QModelIndex &parent) const; + void fetchMore(const QModelIndex &parent); QHash roleNames() const; signals: void newDataReady(); @@ -248,7 +250,9 @@ void writeCppListModel(QTextStream& cpp, const Object& o) { .arg(o.name, lcname, snakeCase(role.name)); } cpp << QString(R"( - int %2_row_count(%1Interface*, qmodelindex_t parent); + int %2_row_count(%1Interface*); + bool %2_can_fetch_more(%1Interface*); + void %2_fetch_more(%1Interface*); } int %1::columnCount(const QModelIndex &parent) const { @@ -257,7 +261,7 @@ int %1::columnCount(const QModelIndex &parent) const int %1::rowCount(const QModelIndex &parent) const { - return (parent.isValid()) ? 0 : %2_row_count(d, parent); + return (parent.isValid()) ? 0 : %2_row_count(d); } QModelIndex %1::index(int row, int column, const QModelIndex &parent) const @@ -273,6 +277,18 @@ QModelIndex %1::parent(const QModelIndex &) const return QModelIndex(); } +bool %1::canFetchMore(const QModelIndex &parent) const +{ + return (parent.isValid()) ? 0 : %2_can_fetch_more(d); +} + +void %1::fetchMore(const QModelIndex &parent) +{ + if (!parent.isValid()) { + %2_fetch_more(d); + } +} + QVariant %1::data(const QModelIndex &index, int role) const { QVariant v; @@ -681,6 +697,8 @@ pub trait %1Trait { } if (o.type == ObjectTypeList) { r << " fn row_count(&self) -> c_int;\n"; + r << " fn can_fetch_more(&self) -> bool { false }\n"; + r << " fn fetch_more(&self) {}\n"; for (auto role: o.roles) { r << QString(" fn %1(&self, row: c_int) -> Variant;\n") .arg(snakeCase(role.name)); @@ -781,6 +799,14 @@ pub unsafe extern "C" fn %2_set(ptr: *mut %1, v: %4) { pub unsafe extern "C" fn %2_row_count(ptr: *const %1) -> c_int { (&*ptr).row_count() } +#[no_mangle] +pub unsafe extern "C" fn %2_can_fetch_more(ptr: *const %1) -> bool { + (&*ptr).can_fetch_more() +} +#[no_mangle] +pub unsafe extern "C" fn %2_fetch_more(ptr: *mut %1) { + (&mut *ptr).fetch_more() +} )").arg(o.name, lcname); for (auto role: o.roles) { r << QString(R"(