diff --git a/crates/cxx-qt-gen/test_inputs/inheritance.rs b/crates/cxx-qt-gen/test_inputs/inheritance.rs index b076f261a..54fbb9299 100644 --- a/crates/cxx-qt-gen/test_inputs/inheritance.rs +++ b/crates/cxx-qt-gen/test_inputs/inheritance.rs @@ -26,15 +26,11 @@ mod inheritance { unsafe fn fetch_more(self: Pin<&mut qobject::MyObject>, index: &QModelIndex); } - impl qobject::MyObject { + unsafe extern "RustQt" { #[qinvokable(cxx_override)] - pub fn data(&self, _index: &QModelIndex, _role: i32) -> QVariant { - QVariant::default() - } + fn data(self: &qobject::MyObject, _index: &QModelIndex, _role: i32) -> QVariant; #[qinvokable(cxx_override)] - pub fn has_children(&self, _parent: &QModelIndex) -> bool { - false - } + fn has_children(self: &qobject::MyObject, _parent: &QModelIndex) -> bool; } } diff --git a/crates/cxx-qt-gen/test_inputs/invokables.rs b/crates/cxx-qt-gen/test_inputs/invokables.rs index 017ed3a65..92a053c9a 100644 --- a/crates/cxx-qt-gen/test_inputs/invokables.rs +++ b/crates/cxx-qt-gen/test_inputs/invokables.rs @@ -43,62 +43,5 @@ mod ffi { fn invokable_virtual(self: &qobject::MyObject); } - impl qobject::MyObject { - pub fn invokable(&self) { - println!("invokable"); - } - - pub fn invokable_mutable(self: Pin<&mut Self>) { - println!("This method is mutable!"); - } - - pub fn invokable_parameters(&self, opaque: &QColor, trivial: &QPoint, primitive: i32) { - println!( - "Red: {}, Point X: {}, Number: {}", - opaque.red(), - trivial.x(), - primitive, - ); - } - - pub fn invokable_return_opaque(self: Pin<&mut Self>) -> UniquePtr { - Opaque::new() - } - - pub fn invokable_return_trivial(self: Pin<&mut Self>) -> QPoint { - QPoint::new(1, 2) - } - - pub fn invokable_final(&self) { - println!("Final"); - } - - pub fn invokable_override(&self) { - println!("Override"); - } - - pub fn invokable_virtual(&self) { - println!("Virtual"); - } - - pub fn cpp_context_method(&self) { - println!("C++ context method"); - } - - pub fn cpp_context_method_mutable(self: Pin<&mut Self>) { - println!("mutable method"); - } - - pub fn cpp_context_method_return_opaque(&self) -> UniquePtr { - Opaque::new() - } - } - - impl MyObject { - pub fn rust_only_method(&self) { - println!("QML or C++ can't call this :)"); - } - } - impl cxx_qt::Threading for qobject::MyObject {} } diff --git a/crates/cxx-qt-gen/test_inputs/passthrough_and_naming.rs b/crates/cxx-qt-gen/test_inputs/passthrough_and_naming.rs index 4929b9b87..74d46088c 100644 --- a/crates/cxx-qt-gen/test_inputs/passthrough_and_naming.rs +++ b/crates/cxx-qt-gen/test_inputs/passthrough_and_naming.rs @@ -85,39 +85,12 @@ pub mod ffi { property_name: i32, } - impl Default for MyObject { - fn default() -> Self { - Self { property_name: 32 } - } - } - unsafe extern "RustQt" { #[qsignal] fn ready(self: Pin<&mut qobject::MyObject>); - } - - impl qobject::MyObject { - pub const MY_CONSTANT: i32 = 42; // the answer to everything ;) - - type MyType = i32; - - my_macro!(); #[qinvokable] - pub fn invokable_name(self: Pin<&mut Self>) { - println!("Bye from Rust!"); - self.as_mut().set_property_name(5); - } - } - - impl MyObject { - fn test_angled(&self, optional: Option) -> Option { - optional - } - - fn test_unknown(&self, unknown: MyType) -> MyType { - unknown - } + fn invokable_name(self: Pin<&mut qobject::MyObject>); } impl MyTrait for MyObject { @@ -134,23 +107,12 @@ pub mod ffi { unsafe impl !cxx_qt::Locking for qobject::SecondObject {} - impl Default for SecondObject { - fn default() -> Self { - Self { property_name: 32 } - } - } - unsafe extern "RustQt" { #[my_attribute] #[qsignal] fn ready(self: Pin<&mut qobject::SecondObject>); - } - impl qobject::SecondObject { #[qinvokable] - pub fn invokable_name(self: Pin<&mut Self>) { - println!("Bye from second Rust!"); - self.as_mut().set_property_name(5); - } + fn invokable_name(self: Pin<&mut qobject::SecondObject>); } -} +} \ No newline at end of file diff --git a/crates/cxx-qt-gen/test_inputs/signals.rs b/crates/cxx-qt-gen/test_inputs/signals.rs index 94d86a084..a8f5ae709 100644 --- a/crates/cxx-qt-gen/test_inputs/signals.rs +++ b/crates/cxx-qt-gen/test_inputs/signals.rs @@ -29,23 +29,12 @@ mod ffi { third: QPoint, fourth: &'a QPoint, ); + + #[qinvokable] + fn invokable(self: Pin<&mut qobject::MyObject>); } #[cxx_qt::qobject] #[derive(Default)] pub struct MyObject; - - impl qobject::MyObject { - #[qinvokable] - pub fn invokable(self: Pin<&mut Self>) { - self.as_mut().on_data_changed( - |_sender, _first, _second, _third, _fourth| { - println!("DataChanged"); - }, - cxx_qt_lib::ConnectionType::AutoConnection, - ); - self.as_mut() - .data_changed(1, Opaque::new(), QPoint::new(1, 2), &QPoint::new(1, 2)); - } - } } diff --git a/crates/cxx-qt-gen/test_outputs/inheritance.cpp b/crates/cxx-qt-gen/test_outputs/inheritance.cpp index bfbc06474..4b31ed53c 100644 --- a/crates/cxx-qt-gen/test_outputs/inheritance.cpp +++ b/crates/cxx-qt-gen/test_outputs/inheritance.cpp @@ -20,3 +20,17 @@ MyObject::unsafeRustMut() { return *m_rustObj; } + +QVariant +MyObject::data(QModelIndex const& _index, ::std::int32_t _role) const +{ + const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); + return m_rustObj->dataWrapper(*this, _index, _role); +} + +bool +MyObject::hasChildren(QModelIndex const& _parent) const +{ + const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); + return m_rustObj->hasChildrenWrapper(*this, _parent); +} diff --git a/crates/cxx-qt-gen/test_outputs/inheritance.h b/crates/cxx-qt-gen/test_outputs/inheritance.h index 66e7a6193..614e69cc4 100644 --- a/crates/cxx-qt-gen/test_outputs/inheritance.h +++ b/crates/cxx-qt-gen/test_outputs/inheritance.h @@ -23,6 +23,9 @@ class MyObject : public QAbstractItemModel MyObjectRust& unsafeRustMut(); public: + Q_INVOKABLE QVariant data(QModelIndex const& _index, + ::std::int32_t _role) const override; + Q_INVOKABLE bool hasChildren(QModelIndex const& _parent) const override; template bool hasChildrenCxxQtInherit(Args... args) const { diff --git a/crates/cxx-qt-gen/test_outputs/inheritance.rs b/crates/cxx-qt-gen/test_outputs/inheritance.rs index 69e49a8bd..4ab92247e 100644 --- a/crates/cxx-qt-gen/test_outputs/inheritance.rs +++ b/crates/cxx-qt-gen/test_outputs/inheritance.rs @@ -6,16 +6,6 @@ mod inheritance { include!("cxx-qt-lib/qvariant.h"); type QVariant = cxx_qt_lib::QVariant; } - impl qobject::MyObject { - #[qinvokable(cxx_override)] - pub fn data(&self, _index: &QModelIndex, _role: i32) -> QVariant { - QVariant::default() - } - #[qinvokable(cxx_override)] - pub fn has_children(&self, _parent: &QModelIndex) -> bool { - false - } - } unsafe extern "C++" { include ! (< QtCore / QObject >); include!("cxx-qt-lib/qt.h"); @@ -46,6 +36,19 @@ mod inheritance { #[cxx_name = "MyObjectRust"] type MyObject; } + extern "Rust" { + #[cxx_name = "dataWrapper"] + fn data_wrapper( + self: &MyObject, + cpp: &MyObjectQt, + _index: &QModelIndex, + _role: i32, + ) -> QVariant; + } + extern "Rust" { + #[cxx_name = "hasChildrenWrapper"] + fn has_children_wrapper(self: &MyObject, cpp: &MyObjectQt, _parent: &QModelIndex) -> bool; + } unsafe extern "C++" { #[doc = " Inherited hasChildren from the base class"] #[cxx_name = "hasChildrenCxxQtInherit"] @@ -84,6 +87,27 @@ pub mod cxx_qt_inheritance { pub struct MyObject { data: Vec, } + impl MyObject { + #[doc(hidden)] + pub fn data_wrapper( + self: &MyObject, + cpp: &MyObjectQt, + _index: &QModelIndex, + _role: i32, + ) -> QVariant { + return cpp.data(_index, _role); + } + } + impl MyObject { + #[doc(hidden)] + pub fn has_children_wrapper( + self: &MyObject, + cpp: &MyObjectQt, + _parent: &QModelIndex, + ) -> bool { + return cpp.has_children(_parent); + } + } impl cxx_qt::Locking for MyObjectQt {} impl cxx_qt::CxxQtType for MyObjectQt { type Rust = MyObject; diff --git a/crates/cxx-qt-gen/test_outputs/invokables.rs b/crates/cxx-qt-gen/test_outputs/invokables.rs index dcae35fea..dc716d7cf 100644 --- a/crates/cxx-qt-gen/test_outputs/invokables.rs +++ b/crates/cxx-qt-gen/test_outputs/invokables.rs @@ -7,46 +7,6 @@ mod ffi { include!("cxx-qt-lib/qpoint.h"); type QPoint = cxx_qt_lib::QPoint; } - impl qobject::MyObject { - pub fn invokable(&self) { - println!("invokable"); - } - pub fn invokable_mutable(self: Pin<&mut Self>) { - println!("This method is mutable!"); - } - pub fn invokable_parameters(&self, opaque: &QColor, trivial: &QPoint, primitive: i32) { - println!( - "Red: {}, Point X: {}, Number: {}", - opaque.red(), - trivial.x(), - primitive, - ); - } - pub fn invokable_return_opaque(self: Pin<&mut Self>) -> UniquePtr { - Opaque::new() - } - pub fn invokable_return_trivial(self: Pin<&mut Self>) -> QPoint { - QPoint::new(1, 2) - } - pub fn invokable_final(&self) { - println!("Final"); - } - pub fn invokable_override(&self) { - println!("Override"); - } - pub fn invokable_virtual(&self) { - println!("Virtual"); - } - pub fn cpp_context_method(&self) { - println!("C++ context method"); - } - pub fn cpp_context_method_mutable(self: Pin<&mut Self>) { - println!("mutable method"); - } - pub fn cpp_context_method_return_opaque(&self) -> UniquePtr { - Opaque::new() - } - } unsafe extern "C++" { include ! (< QtCore / QObject >); include!("cxx-qt-lib/qt.h"); @@ -175,11 +135,6 @@ pub mod cxx_qt_ffi { use std::pin::Pin; #[doc(hidden)] type UniquePtr = cxx::UniquePtr; - impl MyObject { - pub fn rust_only_method(&self) { - println!("QML or C++ can't call this :)"); - } - } #[derive(Default)] pub struct MyObject; impl MyObject { diff --git a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.cpp b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.cpp index 1ef1697ea..de6fd1519 100644 --- a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.cpp +++ b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.cpp @@ -52,6 +52,13 @@ MyObject::propertyNameChangedConnect(::rust::Fn func, type); } +void +MyObject::invokableName() +{ + const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); + m_rustObj->invokableNameWrapper(*this); +} + ::QMetaObject::Connection MyObject::readyConnect(::rust::Fn func, ::Qt::ConnectionType type) @@ -117,6 +124,13 @@ SecondObject::propertyNameChangedConnect(::rust::Fn func, type); } +void +SecondObject::invokableName() +{ + + m_rustObj->invokableNameWrapper(*this); +} + ::QMetaObject::Connection SecondObject::readyConnect(::rust::Fn func, ::Qt::ConnectionType type) diff --git a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h index f67fb6cd3..1b1fdeb2b 100644 --- a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h +++ b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h @@ -40,6 +40,7 @@ class MyObject : public QStringListModel ::QMetaObject::Connection propertyNameChangedConnect( ::rust::Fn func, ::Qt::ConnectionType type); + Q_INVOKABLE void invokableName(); Q_SIGNAL void ready(); ::QMetaObject::Connection readyConnect(::rust::Fn func, ::Qt::ConnectionType type); @@ -75,6 +76,7 @@ class SecondObject : public QObject ::QMetaObject::Connection propertyNameChangedConnect( ::rust::Fn func, ::Qt::ConnectionType type); + Q_INVOKABLE void invokableName(); Q_SIGNAL void ready(); ::QMetaObject::Connection readyConnect(::rust::Fn func, ::Qt::ConnectionType type); diff --git a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs index f31b65c9b..696eafc98 100644 --- a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs +++ b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs @@ -44,23 +44,6 @@ pub mod ffi { unsafe extern "C++" { include ! (< QtCore / QStringListModel >); } - impl qobject::MyObject { - pub const MY_CONSTANT: i32 = 42; - type MyType = i32; - my_macro!(); - #[qinvokable] - pub fn invokable_name(self: Pin<&mut Self>) { - println!("Bye from Rust!"); - self.as_mut().set_property_name(5); - } - } - impl qobject::SecondObject { - #[qinvokable] - pub fn invokable_name(self: Pin<&mut Self>) { - println!("Bye from second Rust!"); - self.as_mut().set_property_name(5); - } - } unsafe extern "C++" { include ! (< QtCore / QObject >); include!("cxx-qt-lib/qt.h"); @@ -116,6 +99,10 @@ pub mod ffi { conn_type: CxxQtConnectionType, ) -> CxxQtQMetaObjectConnection; } + extern "Rust" { + #[cxx_name = "invokableNameWrapper"] + fn invokable_name_wrapper(self: &mut MyObject, cpp: Pin<&mut MyObjectQt>); + } unsafe extern "C++" { #[rust_name = "ready"] fn ready(self: Pin<&mut MyObjectQt>); @@ -186,6 +173,10 @@ pub mod ffi { conn_type: CxxQtConnectionType, ) -> CxxQtQMetaObjectConnection; } + extern "Rust" { + #[cxx_name = "invokableNameWrapper"] + fn invokable_name_wrapper(self: &mut SecondObject, cpp: Pin<&mut SecondObjectQt>); + } unsafe extern "C++" { #[my_attribute] #[rust_name = "ready"] @@ -228,19 +219,6 @@ pub mod cxx_qt_ffi { #[doc(hidden)] type UniquePtr = cxx::UniquePtr; use super::MyTrait; - impl Default for MyObject { - fn default() -> Self { - Self { property_name: 32 } - } - } - impl MyObject { - fn test_angled(&self, optional: Option) -> Option { - optional - } - fn test_unknown(&self, unknown: MyType) -> MyType { - unknown - } - } impl MyTrait for MyObject { fn my_func() -> String { "Hello".to_owned() @@ -293,6 +271,12 @@ pub mod cxx_qt_ffi { self.connect_property_name_changed(func, CxxQtConnectionType::AutoConnection) } } + impl MyObject { + #[doc(hidden)] + pub fn invokable_name_wrapper(self: &mut MyObject, cpp: Pin<&mut MyObjectQt>) { + cpp.invokable_name(); + } + } impl MyObjectQt { #[doc = "Connect the given function pointer to the signal "] #[doc = "ready"] @@ -321,11 +305,6 @@ pub mod cxx_qt_ffi { pub fn create_rs_my_object() -> std::boxed::Box { std::default::Default::default() } - impl Default for SecondObject { - fn default() -> Self { - Self { property_name: 32 } - } - } pub struct SecondObject { property_name: i32, } @@ -373,6 +352,12 @@ pub mod cxx_qt_ffi { self.connect_property_name_changed(func, CxxQtConnectionType::AutoConnection) } } + impl SecondObject { + #[doc(hidden)] + pub fn invokable_name_wrapper(self: &mut SecondObject, cpp: Pin<&mut SecondObjectQt>) { + cpp.invokable_name(); + } + } impl SecondObjectQt { #[doc = "Connect the given function pointer to the signal "] #[doc = "ready"] diff --git a/crates/cxx-qt-gen/test_outputs/signals.cpp b/crates/cxx-qt-gen/test_outputs/signals.cpp index ab80d0f02..2d58f6eee 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.cpp +++ b/crates/cxx-qt-gen/test_outputs/signals.cpp @@ -23,6 +23,13 @@ MyObject::unsafeRustMut() return *m_rustObj; } +void +MyObject::invokable() +{ + const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex); + m_rustObj->invokableWrapper(*this); +} + ::QMetaObject::Connection MyObject::readyConnect(::rust::Fn func, ::Qt::ConnectionType type) diff --git a/crates/cxx-qt-gen/test_outputs/signals.h b/crates/cxx-qt-gen/test_outputs/signals.h index 7c2901f87..e7bd6a6d7 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.h +++ b/crates/cxx-qt-gen/test_outputs/signals.h @@ -27,6 +27,7 @@ class MyObject : public QObject MyObjectRust& unsafeRustMut(); public: + Q_INVOKABLE void invokable(); Q_SIGNAL void ready(); ::QMetaObject::Connection readyConnect(::rust::Fn func, ::Qt::ConnectionType type); diff --git a/crates/cxx-qt-gen/test_outputs/signals.rs b/crates/cxx-qt-gen/test_outputs/signals.rs index 8e2c7a3dd..5043c203e 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.rs +++ b/crates/cxx-qt-gen/test_outputs/signals.rs @@ -5,19 +5,6 @@ mod ffi { include!("cxx-qt-lib/qpoint.h"); type QPoint = cxx_qt_lib::QPoint; } - impl qobject::MyObject { - #[qinvokable] - pub fn invokable(self: Pin<&mut Self>) { - self.as_mut().on_data_changed( - |_sender, _first, _second, _third, _fourth| { - println!("DataChanged"); - }, - cxx_qt_lib::ConnectionType::AutoConnection, - ); - self.as_mut() - .data_changed(1, Opaque::new(), QPoint::new(1, 2), &QPoint::new(1, 2)); - } - } unsafe extern "C++" { include ! (< QtCore / QObject >); include!("cxx-qt-lib/qt.h"); @@ -48,6 +35,10 @@ mod ffi { #[cxx_name = "MyObjectRust"] type MyObject; } + extern "Rust" { + #[cxx_name = "invokableWrapper"] + fn invokable_wrapper(self: &mut MyObject, cpp: Pin<&mut MyObjectQt>); + } unsafe extern "C++" { #[rust_name = "ready"] fn ready(self: Pin<&mut MyObjectQt>); @@ -146,6 +137,12 @@ pub mod cxx_qt_ffi { type UniquePtr = cxx::UniquePtr; #[derive(Default)] pub struct MyObject; + impl MyObject { + #[doc(hidden)] + pub fn invokable_wrapper(self: &mut MyObject, cpp: Pin<&mut MyObjectQt>) { + cpp.invokable(); + } + } impl MyObjectQt { #[doc = "Connect the given function pointer to the signal "] #[doc = "ready"]