diff --git a/CHANGELOG.md b/CHANGELOG.md index 442d6c589..fe0c3dbfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - `VCPKG` is now set to off by default and packages are only built in release mode in the cache +- Connection now return a `QMetaObjectConnectionGuard` and `QMetaObjectConnection` is a separate type +- Internal `cxx-qt` headers have moved to the namespace `cxxqt1` and the folder `cxx-qt` +- `cxx-qt-gen` now does not generate code requiring `cxx-qt-lib`, this allows for `cxx-qt-lib` to be optional ### Fixed diff --git a/book/src/bridge/extern_rustqt.md b/book/src/bridge/extern_rustqt.md index 21b50789a..a3bbe2ae8 100644 --- a/book/src/bridge/extern_rustqt.md +++ b/book/src/bridge/extern_rustqt.md @@ -225,13 +225,14 @@ using the signal name `Changed` with no parameters. {{#include ../../../examples/qml_features/rust/src/signals.rs:book_signals_connect}} ``` -Each connection returns a [`QMetaObject::Connection`](https://doc.qt.io/qt-6/qmetaobject-connection.html) which is used to manage the connection. +Each connection returns a `QMetaObjectConnectionGuard` which is used to manage the [`QMetaObject::Connection`](https://doc.qt.io/qt-6/qmetaobject-connection.html) connection. Note that the `QMetaObjectConnection` returned by CXX-Qt behaves a bit different from the Qt C++ implementation. -When the `QMetaObjectConnection` is dropped, it automatically disconnects the connection, similar to how a C++ `std::unique_ptr` or Rusts `Box` behaves. -If you don't want to store the `QMetaObjectConnection`, call `release`, which will drop the object without disconnecting. -In this case, it is no longer possible to disconnect later. +When the `QMetaObjectConnectionGuard` is dropped, it automatically disconnects the connection, similar to how a C++ `std::unique_ptr` or Rusts `Box` behaves. +If you don't want to store the `QMetaObjectConnectionGuard`, call `release`, which will drop the object without disconnecting and return the internal `QMetaObjecConnection`. + +> Note that the `QMetaObjectConnection` has a `disconnect` which can be called manually later ```rust,ignore,noplayground {{#include ../../../examples/qml_features/rust/src/signals.rs:book_signals_disconnect}} diff --git a/crates/cxx-qt-build/Cargo.toml b/crates/cxx-qt-build/Cargo.toml index 9cacdd22e..c321f06ec 100644 --- a/crates/cxx-qt-build/Cargo.toml +++ b/crates/cxx-qt-build/Cargo.toml @@ -16,6 +16,7 @@ repository.workspace = true cc.workspace = true convert_case.workspace = true cxx-gen.workspace = true +cxx-qt.workspace = true cxx-qt-lib-headers.workspace = true cxx-qt-gen.workspace = true proc-macro2.workspace = true diff --git a/crates/cxx-qt-build/src/lib.rs b/crates/cxx-qt-build/src/lib.rs index da30105fa..c6b4137f7 100644 --- a/crates/cxx-qt-build/src/lib.rs +++ b/crates/cxx-qt-build/src/lib.rs @@ -445,7 +445,7 @@ impl CxxQtBuilder { qtbuild.cargo_link_libraries(&mut self.cc_builder); // Write cxx-qt-gen, cxx-qt-lib and cxx headers - cxx_qt_gen::write_headers(format!("{header_root}/cxx-qt-common")); + cxx_qt::write_headers(format!("{header_root}/cxx-qt")); cxx_qt_lib_headers::write_headers(format!("{header_root}/cxx-qt-lib")); std::fs::create_dir_all(format!("{header_root}/rust")) .expect("Could not create cxx header directory"); @@ -488,7 +488,7 @@ impl CxxQtBuilder { } for builder in [&mut self.cc_builder, &mut cc_builder_whole_archive] { - // Note, ensure our settings stay in sync across cxx-qt-build and cxx-qt-lib + // Note, ensure our settings stay in sync across cxx-qt, cxx-qt-build, and cxx-qt-lib builder.cpp(true); // MSVC builder.flag_if_supported("/std:c++17"); diff --git a/crates/cxx-qt-gen/src/generator/cpp/constructor.rs b/crates/cxx-qt-gen/src/generator/cpp/constructor.rs index e6380d0bb..2157dcd00 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/constructor.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/constructor.rs @@ -27,7 +27,7 @@ fn default_constructor( r#" {class_name}::{class_name}(QObject* parent) : {base_class}(parent) - , ::rust::cxxqtlib1::CxxQtType<{rust_obj}>(::{namespace_internals}::createRs()){initializers} + , ::rust::cxxqt1::CxxQtType<{rust_obj}>(::{namespace_internals}::createRs()){initializers} {{ }} "#, class_name = qobject.ident, @@ -118,7 +118,7 @@ pub fn generate( r#" {class_name}::{class_name}(::{namespace_internals}::CxxQtConstructorArguments{index}&& args) : {base_class}({base_args}) - , ::rust::cxxqtlib1::CxxQtType<{rust_obj}>(::{namespace_internals}::newRs{index}(::std::move(args.new_))){initializers} + , ::rust::cxxqt1::CxxQtType<{rust_obj}>(::{namespace_internals}::newRs{index}(::std::move(args.new_))){initializers} {{ ::{namespace_internals}::initialize{index}(*this, ::std::move(args.initialize)); }} @@ -184,7 +184,7 @@ mod tests { " MyObject::MyObject(QObject* parent) : BaseClass(parent) - , ::rust::cxxqtlib1::CxxQtType(::rust::createRs()) + , ::rust::cxxqt1::CxxQtType(::rust::createRs()) , member1(1) , member2{{ 2 }} {{ }} @@ -214,7 +214,7 @@ mod tests { " MyObject::MyObject(QObject* parent) : BaseClass(parent) - , ::rust::cxxqtlib1::CxxQtType(::rust::createRs()) + , ::rust::cxxqt1::CxxQtType(::rust::createRs()) {{ }} " ), @@ -245,7 +245,7 @@ mod tests { " MyObject::MyObject(::rust::CxxQtConstructorArguments0&& args) : BaseClass() - , ::rust::cxxqtlib1::CxxQtType(::rust::newRs0(::std::move(args.new_))) + , ::rust::cxxqt1::CxxQtType(::rust::newRs0(::std::move(args.new_))) {{ ::rust::initialize0(*this, ::std::move(args.initialize)); }} @@ -308,7 +308,7 @@ mod tests { " MyObject::MyObject(::rust::CxxQtConstructorArguments0&& args) : BaseClass(::std::move(args.base.arg0), ::std::move(args.base.arg1)) - , ::rust::cxxqtlib1::CxxQtType(::rust::newRs0(::std::move(args.new_))) + , ::rust::cxxqt1::CxxQtType(::rust::newRs0(::std::move(args.new_))) , initializer {{ ::rust::initialize0(*this, ::std::move(args.initialize)); @@ -378,7 +378,7 @@ mod tests { " MyObject::MyObject(::rust::CxxQtConstructorArguments0&& args) : BaseClass() - , ::rust::cxxqtlib1::CxxQtType(::rust::newRs0(::std::move(args.new_))) + , ::rust::cxxqt1::CxxQtType(::rust::newRs0(::std::move(args.new_))) , initializer {{ ::rust::initialize0(*this, ::std::move(args.initialize)); @@ -393,7 +393,7 @@ mod tests { " MyObject::MyObject(::rust::CxxQtConstructorArguments1&& args) : BaseClass(::std::move(args.base.arg0)) - , ::rust::cxxqtlib1::CxxQtType(::rust::newRs1(::std::move(args.new_))) + , ::rust::cxxqt1::CxxQtType(::rust::newRs1(::std::move(args.new_))) , initializer {{ ::rust::initialize1(*this, ::std::move(args.initialize)); diff --git a/crates/cxx-qt-gen/src/generator/cpp/cxxqttype.rs b/crates/cxx-qt-gen/src/generator/cpp/cxxqttype.rs index 62c6bb338..edd3b1e03 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/cxxqttype.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/cxxqttype.rs @@ -13,11 +13,11 @@ pub fn generate(qobject_idents: &QObjectName) -> Result".to_owned()); + .insert("#include ".to_owned()); result .base_classes - .push(format!("::rust::cxxqtlib1::CxxQtType<{rust_ident}>")); + .push(format!("::rust::cxxqt1::CxxQtType<{rust_ident}>")); Ok(result) } @@ -38,13 +38,13 @@ mod tests { assert_eq!(generated.includes.len(), 1); assert!(generated .includes - .contains("#include ")); + .contains("#include ")); // base class assert_eq!(generated.base_classes.len(), 1); assert_eq!( generated.base_classes[0], - "::rust::cxxqtlib1::CxxQtType" + "::rust::cxxqt1::CxxQtType" ); } } diff --git a/crates/cxx-qt-gen/src/generator/cpp/externcxxqt.rs b/crates/cxx-qt-gen/src/generator/cpp/externcxxqt.rs index 360fd071b..d8f7f6768 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/externcxxqt.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/externcxxqt.rs @@ -34,7 +34,7 @@ pub fn generate( // Ensure that we include MaybeLockGuard that is used in multiple places block .includes - .insert("#include ".to_owned()); + .insert("#include ".to_owned()); block.forward_declares = data.forward_declares; block.fragments = data.fragments; debug_assert!(data.methods.is_empty()); diff --git a/crates/cxx-qt-gen/src/generator/cpp/locking.rs b/crates/cxx-qt-gen/src/generator/cpp/locking.rs index d35c975a9..35e9b210e 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/locking.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/locking.rs @@ -11,13 +11,13 @@ pub fn generate() -> Result<(String, GeneratedCppQObjectBlocks)> { result .includes - .insert("#include ".to_owned()); + .insert("#include ".to_owned()); result .base_classes - .push("::rust::cxxqtlib1::CxxQtLocking".to_owned()); + .push("::rust::cxxqt1::CxxQtLocking".to_owned()); - let class_initializer = "::rust::cxxqtlib1::CxxQtLocking()".to_owned(); + let class_initializer = "::rust::cxxqt1::CxxQtLocking()".to_owned(); Ok((class_initializer, result)) } @@ -31,16 +31,16 @@ mod tests { let (initializer, generated) = generate().unwrap(); // initializer - assert_eq!(initializer, "::rust::cxxqtlib1::CxxQtLocking()"); + assert_eq!(initializer, "::rust::cxxqt1::CxxQtLocking()"); // includes assert_eq!(generated.includes.len(), 1); assert!(generated .includes - .contains("#include ")); + .contains("#include ")); // base class assert_eq!(generated.base_classes.len(), 1); - assert_eq!(generated.base_classes[0], "::rust::cxxqtlib1::CxxQtLocking"); + assert_eq!(generated.base_classes[0], "::rust::cxxqt1::CxxQtLocking"); } } diff --git a/crates/cxx-qt-gen/src/generator/cpp/method.rs b/crates/cxx-qt-gen/src/generator/cpp/method.rs index a11b4be05..b869d703e 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/method.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/method.rs @@ -113,7 +113,7 @@ pub fn generate_cpp_methods( {return_cxx_ty} {qobject_ident}::{ident}({parameter_types}){is_const} {{ - const ::rust::cxxqtlib1::MaybeLockGuard<{qobject_ident}> guard(*this); + const ::rust::cxxqt1::MaybeLockGuard<{qobject_ident}> guard(*this); {body}; }} "#, @@ -246,7 +246,7 @@ mod tests { void MyObject::voidInvokable() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); voidInvokableWrapper(); } "#} @@ -267,7 +267,7 @@ mod tests { ::std::int32_t MyObject::trivialInvokable(::std::int32_t param) const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return trivialInvokableWrapper(param); } "#} @@ -288,7 +288,7 @@ mod tests { ::std::unique_ptr MyObject::opaqueInvokable(QColor const& param) { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return opaqueInvokableWrapper(param); } "#} @@ -309,7 +309,7 @@ mod tests { ::std::int32_t MyObject::specifiersInvokable(::std::int32_t param) const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return specifiersInvokableWrapper(param); } "#} @@ -327,7 +327,7 @@ mod tests { void MyObject::cppMethod() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); cppMethodWrapper(); } "#} @@ -418,7 +418,7 @@ mod tests { B2 MyObject::trivialInvokable(A1 param) const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return trivialInvokableWrapper(param); } "#} diff --git a/crates/cxx-qt-gen/src/generator/cpp/property/getter.rs b/crates/cxx-qt-gen/src/generator/cpp/property/getter.rs index 737911841..f3f51d904 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/property/getter.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/property/getter.rs @@ -17,7 +17,7 @@ pub fn generate(idents: &QPropertyName, qobject_ident: &str, return_cxx_ty: &str {return_cxx_ty} const& {qobject_ident}::{ident_getter}() const {{ - const ::rust::cxxqtlib1::MaybeLockGuard<{qobject_ident}> guard(*this); + const ::rust::cxxqt1::MaybeLockGuard<{qobject_ident}> guard(*this); return {ident_getter_wrapper}(); }} "#, diff --git a/crates/cxx-qt-gen/src/generator/cpp/property/mod.rs b/crates/cxx-qt-gen/src/generator/cpp/property/mod.rs index ba8cec10f..62c53d5ac 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/property/mod.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/property/mod.rs @@ -103,7 +103,7 @@ mod tests { ::std::int32_t const& MyObject::getTrivialProperty() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return getTrivialPropertyWrapper(); } "#} @@ -124,7 +124,7 @@ mod tests { void MyObject::setTrivialProperty(::std::int32_t const& value) { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); setTrivialPropertyWrapper(value); } "#} @@ -145,7 +145,7 @@ mod tests { ::std::unique_ptr const& MyObject::getOpaqueProperty() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return getOpaquePropertyWrapper(); } "#} @@ -166,7 +166,7 @@ mod tests { void MyObject::setOpaqueProperty(::std::unique_ptr const& value) { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); setOpaquePropertyWrapper(value); } "#} @@ -207,7 +207,7 @@ mod tests { indoc! {r#" // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 - namespace rust::cxxqtlib1 { + namespace rust::cxxqt1 { template <> SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamstrivialPropertyChanged *>::~SignalHandler() noexcept { @@ -228,7 +228,7 @@ mod tests { static_assert(alignof(SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamstrivialPropertyChanged *>) <= alignof(::std::size_t), "unexpected aligment"); static_assert(sizeof(SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamstrivialPropertyChanged *>) == sizeof(::std::size_t[2]), "unexpected size"); - } // namespace rust::cxxqtlib1 + } // namespace rust::cxxqt1 namespace rust::cxxqtgen1 { ::QMetaObject::Connection @@ -239,7 +239,7 @@ mod tests { &MyObject::trivialPropertyChanged, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard guard(self); + const ::rust::cxxqt1::MaybeLockGuard guard(self); closure.template operator()(self); }, type); @@ -268,7 +268,7 @@ mod tests { indoc! {r#" // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 - namespace rust::cxxqtlib1 { + namespace rust::cxxqt1 { template <> SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamsopaquePropertyChanged *>::~SignalHandler() noexcept { @@ -289,7 +289,7 @@ mod tests { static_assert(alignof(SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamsopaquePropertyChanged *>) <= alignof(::std::size_t), "unexpected aligment"); static_assert(sizeof(SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamsopaquePropertyChanged *>) == sizeof(::std::size_t[2]), "unexpected size"); - } // namespace rust::cxxqtlib1 + } // namespace rust::cxxqt1 namespace rust::cxxqtgen1 { ::QMetaObject::Connection @@ -300,7 +300,7 @@ mod tests { &MyObject::opaquePropertyChanged, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard guard(self); + const ::rust::cxxqt1::MaybeLockGuard guard(self); closure.template operator()(self); }, type); @@ -383,7 +383,7 @@ mod tests { A1 const& MyObject::getMappedProperty() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return getMappedPropertyWrapper(); } "#} @@ -401,7 +401,7 @@ mod tests { void MyObject::setMappedProperty(A1 const& value) { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); setMappedPropertyWrapper(value); } "#} @@ -434,7 +434,7 @@ mod tests { indoc! {r#" // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 - namespace rust::cxxqtlib1 { + namespace rust::cxxqt1 { template <> SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamsmappedPropertyChanged *>::~SignalHandler() noexcept { @@ -455,7 +455,7 @@ mod tests { static_assert(alignof(SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamsmappedPropertyChanged *>) <= alignof(::std::size_t), "unexpected aligment"); static_assert(sizeof(SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamsmappedPropertyChanged *>) == sizeof(::std::size_t[2]), "unexpected size"); - } // namespace rust::cxxqtlib1 + } // namespace rust::cxxqt1 namespace rust::cxxqtgen1 { ::QMetaObject::Connection @@ -466,7 +466,7 @@ mod tests { &MyObject::mappedPropertyChanged, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard guard(self); + const ::rust::cxxqt1::MaybeLockGuard guard(self); closure.template operator()(self); }, type); diff --git a/crates/cxx-qt-gen/src/generator/cpp/property/setter.rs b/crates/cxx-qt-gen/src/generator/cpp/property/setter.rs index 39604afa9..d2e21aa4f 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/property/setter.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/property/setter.rs @@ -17,7 +17,7 @@ pub fn generate(idents: &QPropertyName, qobject_ident: &str, cxx_ty: &str) -> Cp void {qobject_ident}::{ident_setter}({cxx_ty} const& value) {{ - const ::rust::cxxqtlib1::MaybeLockGuard<{qobject_ident}> guard(*this); + const ::rust::cxxqt1::MaybeLockGuard<{qobject_ident}> guard(*this); {ident_setter_wrapper}(value); }} "#, diff --git a/crates/cxx-qt-gen/src/generator/cpp/qobject.rs b/crates/cxx-qt-gen/src/generator/cpp/qobject.rs index 3af13549d..e6f944dff 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/qobject.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/qobject.rs @@ -112,7 +112,7 @@ impl GeneratedCppQObject { generated .blocks .includes - .insert("#include ".to_owned()); + .insert("#include ".to_owned()); // Build the base class let base_class = qobject @@ -215,12 +215,9 @@ mod tests { assert_eq!(cpp.blocks.base_classes[0], "QObject"); assert_eq!( cpp.blocks.base_classes[1], - "::rust::cxxqtlib1::CxxQtType" - ); - assert_eq!( - cpp.blocks.base_classes[2], - "::rust::cxxqtlib1::CxxQtLocking" + "::rust::cxxqt1::CxxQtType" ); + assert_eq!(cpp.blocks.base_classes[2], "::rust::cxxqt1::CxxQtLocking"); assert_eq!(cpp.blocks.metaobjects.len(), 0); } @@ -248,12 +245,9 @@ mod tests { assert_eq!(cpp.blocks.base_classes[0], "QStringListModel"); assert_eq!( cpp.blocks.base_classes[1], - "::rust::cxxqtlib1::CxxQtType" - ); - assert_eq!( - cpp.blocks.base_classes[2], - "::rust::cxxqtlib1::CxxQtLocking" + "::rust::cxxqt1::CxxQtType" ); + assert_eq!(cpp.blocks.base_classes[2], "::rust::cxxqt1::CxxQtLocking"); assert_eq!(cpp.blocks.metaobjects.len(), 0); } diff --git a/crates/cxx-qt-gen/src/generator/cpp/signal.rs b/crates/cxx-qt-gen/src/generator/cpp/signal.rs index 9162bcbf2..de6ef1cb7 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/signal.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/signal.rs @@ -89,7 +89,7 @@ pub fn generate_cpp_signal( // Add the include we need generated .includes - .insert("#include ".to_owned()); + .insert("#include ".to_owned()); // Build a namespace that includes any namespace for the T let qobject_ident_str = qobject_ident.to_string(); @@ -122,7 +122,7 @@ pub fn generate_cpp_signal( generated.forward_declares.push(formatdoc! { r#" namespace {namespace} {{ - using {signal_handler_alias} = ::rust::cxxqtlib1::SignalHandler; + using {signal_handler_alias} = ::rust::cxxqt1::SignalHandler; }} // namespace {namespace} "# }); @@ -147,7 +147,7 @@ pub fn generate_cpp_signal( r#" // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 - namespace rust::cxxqtlib1 {{ + namespace rust::cxxqt1 {{ template <> {signal_handler_type}::~SignalHandler() noexcept {{ @@ -168,7 +168,7 @@ pub fn generate_cpp_signal( static_assert(alignof({signal_handler_type}) <= alignof(::std::size_t), "unexpected aligment"); static_assert(sizeof({signal_handler_type}) == sizeof(::std::size_t[2]), "unexpected size"); - }} // namespace rust::cxxqtlib1 + }} // namespace rust::cxxqt1 namespace {namespace} {{ ::QMetaObject::Connection @@ -179,7 +179,7 @@ pub fn generate_cpp_signal( &{qobject_ident_namespaced}::{signal_ident}, &self, [&, closure = ::std::move(closure)]({parameters_named_types}) mutable {{ - const ::rust::cxxqtlib1::MaybeLockGuard<{qobject_ident_namespaced}> guard(self); + const ::rust::cxxqt1::MaybeLockGuard<{qobject_ident_namespaced}> guard(self); closure.template operator()<{parameter_types_with_self}>({parameter_values_with_self}); }}, type); @@ -287,7 +287,7 @@ mod tests { indoc! {r#" // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 - namespace rust::cxxqtlib1 { + namespace rust::cxxqt1 { template <> SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamsdataChanged *>::~SignalHandler() noexcept { @@ -308,7 +308,7 @@ mod tests { static_assert(alignof(SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamsdataChanged *>) <= alignof(::std::size_t), "unexpected aligment"); static_assert(sizeof(SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamsdataChanged *>) == sizeof(::std::size_t[2]), "unexpected size"); - } // namespace rust::cxxqtlib1 + } // namespace rust::cxxqt1 namespace rust::cxxqtgen1 { ::QMetaObject::Connection @@ -319,7 +319,7 @@ mod tests { &MyObject::dataChanged, &self, [&, closure = ::std::move(closure)](::std::int32_t trivial, ::std::unique_ptr opaque) mutable { - const ::rust::cxxqtlib1::MaybeLockGuard guard(self); + const ::rust::cxxqt1::MaybeLockGuard guard(self); closure.template operator()>(self, ::std::move(trivial), ::std::move(opaque)); }, type); @@ -385,7 +385,7 @@ mod tests { indoc! {r#" // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 - namespace rust::cxxqtlib1 { + namespace rust::cxxqt1 { template <> SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamsdataChanged *>::~SignalHandler() noexcept { @@ -406,7 +406,7 @@ mod tests { static_assert(alignof(SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamsdataChanged *>) <= alignof(::std::size_t), "unexpected aligment"); static_assert(sizeof(SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamsdataChanged *>) == sizeof(::std::size_t[2]), "unexpected size"); - } // namespace rust::cxxqtlib1 + } // namespace rust::cxxqt1 namespace rust::cxxqtgen1 { ::QMetaObject::Connection @@ -417,7 +417,7 @@ mod tests { &MyObject::dataChanged, &self, [&, closure = ::std::move(closure)](A1 mapped) mutable { - const ::rust::cxxqtlib1::MaybeLockGuard guard(self); + const ::rust::cxxqt1::MaybeLockGuard guard(self); closure.template operator()(self, ::std::move(mapped)); }, type); @@ -473,7 +473,7 @@ mod tests { indoc! {r#" // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 - namespace rust::cxxqtlib1 { + namespace rust::cxxqt1 { template <> SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamsbaseName *>::~SignalHandler() noexcept { @@ -494,7 +494,7 @@ mod tests { static_assert(alignof(SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamsbaseName *>) <= alignof(::std::size_t), "unexpected aligment"); static_assert(sizeof(SignalHandler<::rust::cxxqtgen1::MyObjectCxxQtSignalParamsbaseName *>) == sizeof(::std::size_t[2]), "unexpected size"); - } // namespace rust::cxxqtlib1 + } // namespace rust::cxxqt1 namespace rust::cxxqtgen1 { ::QMetaObject::Connection @@ -505,7 +505,7 @@ mod tests { &MyObject::baseName, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard guard(self); + const ::rust::cxxqt1::MaybeLockGuard guard(self); closure.template operator()(self); }, type); @@ -561,7 +561,7 @@ mod tests { indoc! {r#" // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 - namespace rust::cxxqtlib1 { + namespace rust::cxxqt1 { template <> SignalHandler<::rust::cxxqtgen1::ObjRustCxxQtSignalParamssignalRustName *>::~SignalHandler() noexcept { @@ -582,7 +582,7 @@ mod tests { static_assert(alignof(SignalHandler<::rust::cxxqtgen1::ObjRustCxxQtSignalParamssignalRustName *>) <= alignof(::std::size_t), "unexpected aligment"); static_assert(sizeof(SignalHandler<::rust::cxxqtgen1::ObjRustCxxQtSignalParamssignalRustName *>) == sizeof(::std::size_t[2]), "unexpected size"); - } // namespace rust::cxxqtlib1 + } // namespace rust::cxxqt1 namespace rust::cxxqtgen1 { ::QMetaObject::Connection @@ -593,7 +593,7 @@ mod tests { &ObjRust::signalRustName, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard guard(self); + const ::rust::cxxqt1::MaybeLockGuard guard(self); closure.template operator()(self); }, type); @@ -652,7 +652,7 @@ mod tests { indoc! {r#" // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 - namespace rust::cxxqtlib1 { + namespace rust::cxxqt1 { template <> SignalHandler<::rust::cxxqtgen1::mynamespace::ObjRustCxxQtSignalParamssignalCxxName *>::~SignalHandler() noexcept { @@ -673,7 +673,7 @@ mod tests { static_assert(alignof(SignalHandler<::rust::cxxqtgen1::mynamespace::ObjRustCxxQtSignalParamssignalCxxName *>) <= alignof(::std::size_t), "unexpected aligment"); static_assert(sizeof(SignalHandler<::rust::cxxqtgen1::mynamespace::ObjRustCxxQtSignalParamssignalCxxName *>) == sizeof(::std::size_t[2]), "unexpected size"); - } // namespace rust::cxxqtlib1 + } // namespace rust::cxxqt1 namespace rust::cxxqtgen1::mynamespace { ::QMetaObject::Connection @@ -684,7 +684,7 @@ mod tests { &::mynamespace::ObjCpp::signalCxxName, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard<::mynamespace::ObjCpp> guard(self); + const ::rust::cxxqt1::MaybeLockGuard<::mynamespace::ObjCpp> guard(self); closure.template operator()<::mynamespace::ObjCpp&>(self); }, type); diff --git a/crates/cxx-qt-gen/src/generator/cpp/threading.rs b/crates/cxx-qt-gen/src/generator/cpp/threading.rs index 64c65aa9b..871617ca3 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/threading.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/threading.rs @@ -17,7 +17,7 @@ pub fn generate(qobject_idents: &QObjectName) -> Result<(String, GeneratedCppQOb let cxx_qt_thread_ident = &qobject_idents.cxx_qt_thread_class; result.forward_declares.push(format!( - "using {cxx_qt_thread_ident} = ::rust::cxxqtlib1::CxxQtThread<{cpp_class}>;" + "using {cxx_qt_thread_ident} = ::rust::cxxqt1::CxxQtThread<{cpp_class}>;" )); // Ensure that the CxxQtThread is of the correct size and alignment // which should be two std::shared_ptr which are two size_t each @@ -30,13 +30,13 @@ pub fn generate(qobject_idents: &QObjectName) -> Result<(String, GeneratedCppQOb result .includes - .insert("#include ".to_owned()); + .insert("#include ".to_owned()); result .base_classes - .push(format!("::rust::cxxqtlib1::CxxQtThreading<{cpp_class}>")); + .push(format!("::rust::cxxqt1::CxxQtThreading<{cpp_class}>")); - let class_initializer = format!("::rust::cxxqtlib1::CxxQtThreading<{cpp_class}>(this)"); + let class_initializer = format!("::rust::cxxqt1::CxxQtThreading<{cpp_class}>(this)"); Ok((class_initializer, result)) } @@ -60,13 +60,13 @@ mod tests { assert_str_eq!( generated.forward_declares[0], - "using MyObjectCxxQtThread = ::rust::cxxqtlib1::CxxQtThread;" + "using MyObjectCxxQtThread = ::rust::cxxqt1::CxxQtThread;" ); // initialiser assert_str_eq!( initializer, - "::rust::cxxqtlib1::CxxQtThreading(this)" + "::rust::cxxqt1::CxxQtThreading(this)" ); // methods @@ -89,13 +89,13 @@ mod tests { assert_eq!(generated.includes.len(), 1); assert!(generated .includes - .contains("#include ")); + .contains("#include ")); // base class assert_eq!(generated.base_classes.len(), 1); assert_eq!( generated.base_classes[0], - "::rust::cxxqtlib1::CxxQtThreading" + "::rust::cxxqt1::CxxQtThreading" ); } } diff --git a/crates/cxx-qt-gen/src/generator/rust/property/mod.rs b/crates/cxx-qt-gen/src/generator/rust/property/mod.rs index 129de0a9d..88c14315b 100644 --- a/crates/cxx-qt-gen/src/generator/rust/property/mod.rs +++ b/crates/cxx-qt-gen/src/generator/rust/property/mod.rs @@ -311,14 +311,13 @@ mod tests { #[doc = "Connect the given function pointer to the signal "] #[doc = "trivialPropertyChanged"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] - pub fn connect_trivial_property_changed, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt_lib::ConnectionType) -> cxx_qt_lib::QMetaObjectConnection + pub fn connect_trivial_property_changed, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_trivial_property_changed( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_trivial_property_changed( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), conn_type, - ) + )) } } }, @@ -332,14 +331,13 @@ mod tests { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] - pub fn on_trivial_property_changed, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt_lib::QMetaObjectConnection + pub fn on_trivial_property_changed, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_trivial_property_changed( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_trivial_property_changed( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } }, @@ -439,14 +437,13 @@ mod tests { #[doc = "Connect the given function pointer to the signal "] #[doc = "opaquePropertyChanged"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] - pub fn connect_opaque_property_changed, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt_lib::ConnectionType) -> cxx_qt_lib::QMetaObjectConnection + pub fn connect_opaque_property_changed, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_opaque_property_changed( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_opaque_property_changed( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), conn_type, - ) + )) } } }, @@ -460,14 +457,13 @@ mod tests { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] - pub fn on_opaque_property_changed, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt_lib::QMetaObjectConnection + pub fn on_opaque_property_changed, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_opaque_property_changed( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_opaque_property_changed( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } }, @@ -567,14 +563,13 @@ mod tests { #[doc = "Connect the given function pointer to the signal "] #[doc = "unsafePropertyChanged"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] - pub fn connect_unsafe_property_changed, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt_lib::ConnectionType) -> cxx_qt_lib::QMetaObjectConnection + pub fn connect_unsafe_property_changed, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_unsafe_property_changed( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_unsafe_property_changed( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), conn_type, - ) + )) } } }, @@ -588,14 +583,13 @@ mod tests { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] - pub fn on_unsafe_property_changed, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt_lib::QMetaObjectConnection + pub fn on_unsafe_property_changed, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_unsafe_property_changed( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_unsafe_property_changed( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } }, diff --git a/crates/cxx-qt-gen/src/generator/rust/signals.rs b/crates/cxx-qt-gen/src/generator/rust/signals.rs index 8eb889b78..a389e2fed 100644 --- a/crates/cxx-qt-gen/src/generator/rust/signals.rs +++ b/crates/cxx-qt-gen/src/generator/rust/signals.rs @@ -136,14 +136,13 @@ pub fn generate_rust_signal( #[doc = "Connect the given function pointer to the signal "] #[doc = #signal_name_cpp_str] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] - pub fn #connect_ident_rust(self: #self_type_qualified, mut closure: F, conn_type: cxx_qt_lib::ConnectionType) -> cxx_qt_lib::QMetaObjectConnection + pub fn #connect_ident_rust(self: #self_type_qualified, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard { - #module_ident::#free_connect_ident_rust( + cxx_qt::QMetaObjectConnectionGuard::from(#module_ident::#free_connect_ident_rust( self, cxx_qt::signalhandler::CxxQtSignalHandler::<#closure_struct>::new(Box::new(closure)), conn_type, - ) + )) } } }, @@ -154,14 +153,13 @@ pub fn generate_rust_signal( #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] - pub fn #on_ident_rust(self: #self_type_qualified, mut closure: F) -> cxx_qt_lib::QMetaObjectConnection + pub fn #on_ident_rust(self: #self_type_qualified, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard { - #module_ident::#free_connect_ident_rust( + cxx_qt::QMetaObjectConnectionGuard::from(#module_ident::#free_connect_ident_rust( self, cxx_qt::signalhandler::CxxQtSignalHandler::<#closure_struct>::new(Box::new(closure)), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } }, @@ -333,14 +331,13 @@ mod tests { #[doc = "Connect the given function pointer to the signal "] #[doc = "ready"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] - pub fn connect_ready, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt_lib::ConnectionType) -> cxx_qt_lib::QMetaObjectConnection + pub fn connect_ready, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_ready( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), conn_type, - ) + )) } } }, @@ -354,14 +351,13 @@ mod tests { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] - pub fn on_ready, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt_lib::QMetaObjectConnection + pub fn on_ready, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_ready( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } }, @@ -500,14 +496,13 @@ mod tests { #[doc = "Connect the given function pointer to the signal "] #[doc = "dataChanged"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] - pub fn connect_data_changed, i32, cxx::UniquePtr) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt_lib::ConnectionType) -> cxx_qt_lib::QMetaObjectConnection + pub fn connect_data_changed, i32, cxx::UniquePtr) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_data_changed( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_data_changed( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), conn_type, - ) + )) } } }, @@ -521,14 +516,13 @@ mod tests { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] - pub fn on_data_changed, i32, cxx::UniquePtr) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt_lib::QMetaObjectConnection + pub fn on_data_changed, i32, cxx::UniquePtr) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_data_changed( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_data_changed( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } }, @@ -661,14 +655,13 @@ mod tests { #[doc = "Connect the given function pointer to the signal "] #[doc = "unsafeSignal"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] - pub fn connect_unsafe_signal, *mut T) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt_lib::ConnectionType) -> cxx_qt_lib::QMetaObjectConnection + pub fn connect_unsafe_signal, *mut T) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_unsafe_signal( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_unsafe_signal( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), conn_type, - ) + )) } } }, @@ -682,14 +675,13 @@ mod tests { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] - pub fn on_unsafe_signal, *mut T) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt_lib::QMetaObjectConnection + pub fn on_unsafe_signal, *mut T) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_unsafe_signal( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_unsafe_signal( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } }, @@ -820,14 +812,13 @@ mod tests { #[doc = "Connect the given function pointer to the signal "] #[doc = "baseName"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] - pub fn connect_existing_signal, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt_lib::ConnectionType) -> cxx_qt_lib::QMetaObjectConnection + pub fn connect_existing_signal, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_existing_signal( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_existing_signal( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), conn_type, - ) + )) } } }, @@ -841,14 +832,13 @@ mod tests { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] - pub fn on_existing_signal, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt_lib::QMetaObjectConnection + pub fn on_existing_signal, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_existing_signal( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_existing_signal( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } }, @@ -974,14 +964,13 @@ mod tests { #[doc = "Connect the given function pointer to the signal "] #[doc = "ready"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] - pub fn connect_ready, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt_lib::ConnectionType) -> cxx_qt_lib::QMetaObjectConnection + pub fn connect_ready, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_ready( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), conn_type, - ) + )) } } }, @@ -995,14 +984,13 @@ mod tests { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] - pub fn on_ready, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt_lib::QMetaObjectConnection + pub fn on_ready, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_ready( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } }, @@ -1120,14 +1108,13 @@ mod tests { #[doc = "Connect the given function pointer to the signal "] #[doc = "ready"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] - pub fn connect_ready, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt_lib::ConnectionType) -> cxx_qt_lib::QMetaObjectConnection + pub fn connect_ready, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F, conn_type: cxx_qt::ConnectionType) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_ready( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), conn_type, - ) + )) } } }, @@ -1141,14 +1128,13 @@ mod tests { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] - pub fn on_ready, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt_lib::QMetaObjectConnection + pub fn on_ready, ) + 'static>(self: core::pin::Pin<&mut MyObject>, mut closure: F) -> cxx_qt::QMetaObjectConnectionGuard { - ffi::MyObject_connect_ready( + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new(Box::new(closure)), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } }, diff --git a/crates/cxx-qt-gen/src/generator/rust/threading.rs b/crates/cxx-qt-gen/src/generator/rust/threading.rs index 74e06fab3..172673702 100644 --- a/crates/cxx-qt-gen/src/generator/rust/threading.rs +++ b/crates/cxx-qt-gen/src/generator/rust/threading.rs @@ -49,7 +49,7 @@ pub fn generate( // #[doc(hidden)] type #cxx_qt_thread_ident = cxx_qt::CxxQtThread<#cpp_struct_ident>; - include!("cxx-qt-common/cxxqt_thread.h"); + include!("cxx-qt/cxxqt_thread.h"); #[doc(hidden)] #[cxx_name = "qtThread"] @@ -59,7 +59,7 @@ pub fn generate( // - Send + 'static: argument closure can be transferred to QObject thread. // - FnOnce: QMetaObject::invokeMethod() should call the function at most once. #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[cxx_name = "cxxQtThreadQueue"] fn #cxx_qt_thread_queue_fn( cxx_qt_thread: &#cxx_qt_thread_ident, @@ -68,12 +68,12 @@ pub fn generate( ) -> Result<()>; #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[cxx_name = "cxxQtThreadClone"] fn #cxx_qt_thread_clone(cxx_qt_thread: &#cxx_qt_thread_ident) -> #cxx_qt_thread_ident; #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[cxx_name = "cxxQtThreadDrop"] fn #cxx_qt_thread_drop(cxx_qt_thread: &mut #cxx_qt_thread_ident); } @@ -187,7 +187,7 @@ mod tests { unsafe extern "C++" { #[doc(hidden)] type MyObjectCxxQtThread = cxx_qt::CxxQtThread; - include!("cxx-qt-common/cxxqt_thread.h"); + include!("cxx-qt/cxxqt_thread.h"); #[doc(hidden)] #[cxx_name = "qtThread"] @@ -197,7 +197,7 @@ mod tests { // - Send + 'static: argument closure can be transferred to QObject thread. // - FnOnce: QMetaObject::invokeMethod() should call the function at most once. #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[cxx_name = "cxxQtThreadQueue"] fn cxx_qt_ffi_my_object_queue_boxed_fn( cxx_qt_thread: &MyObjectCxxQtThread, @@ -206,12 +206,12 @@ mod tests { ) -> Result<()>; #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[cxx_name = "cxxQtThreadClone"] fn cxx_qt_ffi_my_object_threading_clone(cxx_qt_thread: &MyObjectCxxQtThread) -> MyObjectCxxQtThread; #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[cxx_name = "cxxQtThreadDrop"] fn cxx_qt_ffi_my_object_threading_drop(cxx_qt_thread: &mut MyObjectCxxQtThread); } diff --git a/crates/cxx-qt-gen/src/lib.rs b/crates/cxx-qt-gen/src/lib.rs index f6a209f03..b2861f045 100644 --- a/crates/cxx-qt-gen/src/lib.rs +++ b/crates/cxx-qt-gen/src/lib.rs @@ -17,42 +17,8 @@ pub use parser::{qobject::QmlElementMetadata, Parser}; pub use syntax::{parse_qt_file, CxxQtItem}; pub use writer::{cpp::write_cpp, rust::write_rust}; -use std::{fs::File, io::Write, path::Path}; pub use syn::{Error, Result}; -/// Write the cxx-qt-gen headers to the specified directory. -pub fn write_headers(directory: impl AsRef) { - let directory = directory.as_ref(); - std::fs::create_dir_all(directory).expect("Could not create cxx-qt-gen header directory"); - for (file_contents, file_name) in [ - ( - include_str!("../include/cxxqt_locking.h"), - "cxxqt_locking.h", - ), - ( - include_str!("../include/cxxqt_maybelockguard.h"), - "cxxqt_maybelockguard.h", - ), - ( - include_str!("../include/cxxqt_signalhandler.h"), - "cxxqt_signalhandler.h", - ), - (include_str!("../include/cxxqt_thread.h"), "cxxqt_thread.h"), - ( - include_str!("../include/cxxqt_threading.h"), - "cxxqt_threading.h", - ), - (include_str!("../include/cxxqt_type.h"), "cxxqt_type.h"), - ] { - // Note that we do not need rerun-if-changed for these files - // as include_str causes a rerun when the header changes - // and the files are always written to the target. - let h_path = format!("{}/{file_name}", directory.display()); - let mut header = File::create(h_path).expect("Could not create cxx-qt-gen header"); - write!(header, "{file_contents}").expect("Could not write cxx-qt-gen header"); - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/crates/cxx-qt-gen/src/writer/rust/mod.rs b/crates/cxx-qt-gen/src/writer/rust/mod.rs index ce74bf068..e1f4758e4 100644 --- a/crates/cxx-qt-gen/src/writer/rust/mod.rs +++ b/crates/cxx-qt-gen/src/writer/rust/mod.rs @@ -22,19 +22,20 @@ pub fn write_rust(generated: &GeneratedRustBlocks) -> TokenStream { unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt-lib/qt.h"); + include!("cxx-qt/cxxqt_connection.h"); #[doc(hidden)] #[namespace = "Qt"] + // Rename to CxxQtConnectionType so the developer can define it + // in their bridges without an invisible conflict #[rust_name = "CxxQtConnectionType"] - type ConnectionType = cxx_qt_lib::ConnectionType; + type ConnectionType = cxx_qt::ConnectionType; - include!("cxx-qt-lib/qmetaobjectconnection.h"); #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] // Rename to CxxQtQMetaObjectConnection so the developer can define it // in their bridges without an invisible conflict #[rust_name = "CxxQtQMetaObjectConnection"] - type QMetaObjectConnection = cxx_qt_lib::QMetaObjectConnection; + type QMetaObjectConnection = cxx_qt::QMetaObjectConnection; } }) .expect("Could not build CXX common block"), @@ -191,17 +192,16 @@ mod tests { unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt-lib/qt.h"); + include!("cxx-qt/cxxqt_connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] - type ConnectionType = cxx_qt_lib::ConnectionType; + type ConnectionType = cxx_qt::ConnectionType; - include!("cxx-qt-lib/qmetaobjectconnection.h"); #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[rust_name = "CxxQtQMetaObjectConnection"] - type QMetaObjectConnection = cxx_qt_lib::QMetaObjectConnection; + type QMetaObjectConnection = cxx_qt::QMetaObjectConnection; } unsafe extern "C++" { @@ -238,17 +238,16 @@ mod tests { unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt-lib/qt.h"); + include!("cxx-qt/cxxqt_connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] - type ConnectionType = cxx_qt_lib::ConnectionType; + type ConnectionType = cxx_qt::ConnectionType; - include!("cxx-qt-lib/qmetaobjectconnection.h"); #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[rust_name = "CxxQtQMetaObjectConnection"] - type QMetaObjectConnection = cxx_qt_lib::QMetaObjectConnection; + type QMetaObjectConnection = cxx_qt::QMetaObjectConnection; } unsafe extern "C++" { diff --git a/crates/cxx-qt-gen/test_outputs/inheritance.cpp b/crates/cxx-qt-gen/test_outputs/inheritance.cpp index 68dcbe814..f015da4fc 100644 --- a/crates/cxx-qt-gen/test_outputs/inheritance.cpp +++ b/crates/cxx-qt-gen/test_outputs/inheritance.cpp @@ -3,20 +3,20 @@ QVariant MyObject::data(QModelIndex const& _index, ::std::int32_t _role) const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return dataWrapper(_index, _role); } bool MyObject::hasChildren(QModelIndex const& _parent) const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return hasChildrenWrapper(_parent); } MyObject::MyObject(QObject* parent) : QAbstractItemModel(parent) - , ::rust::cxxqtlib1::CxxQtType(::cxx_qt_my_object::createRs()) - , ::rust::cxxqtlib1::CxxQtLocking() + , ::rust::cxxqt1::CxxQtType(::cxx_qt_my_object::createRs()) + , ::rust::cxxqt1::CxxQtLocking() { } diff --git a/crates/cxx-qt-gen/test_outputs/inheritance.h b/crates/cxx-qt-gen/test_outputs/inheritance.h index 966fc3674..40440e804 100644 --- a/crates/cxx-qt-gen/test_outputs/inheritance.h +++ b/crates/cxx-qt-gen/test_outputs/inheritance.h @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include +#include +#include +#include class MyObject; @@ -10,8 +10,8 @@ class MyObject; class MyObject : public QAbstractItemModel - , public ::rust::cxxqtlib1::CxxQtType - , public ::rust::cxxqtlib1::CxxQtLocking + , public ::rust::cxxqt1::CxxQtType + , public ::rust::cxxqt1::CxxQtLocking { Q_OBJECT public: diff --git a/crates/cxx-qt-gen/test_outputs/inheritance.rs b/crates/cxx-qt-gen/test_outputs/inheritance.rs index fa5e5a156..7d7bd1b56 100644 --- a/crates/cxx-qt-gen/test_outputs/inheritance.rs +++ b/crates/cxx-qt-gen/test_outputs/inheritance.rs @@ -8,16 +8,15 @@ mod inheritance { } unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt-lib/qt.h"); + include!("cxx-qt/cxxqt_connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] - type ConnectionType = cxx_qt_lib::ConnectionType; - include!("cxx-qt-lib/qmetaobjectconnection.h"); + type ConnectionType = cxx_qt::ConnectionType; #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[rust_name = "CxxQtQMetaObjectConnection"] - type QMetaObjectConnection = cxx_qt_lib::QMetaObjectConnection; + type QMetaObjectConnection = cxx_qt::QMetaObjectConnection; } unsafe extern "C++" { include!("cxx-qt-gen/inheritance.cxxqt.h"); diff --git a/crates/cxx-qt-gen/test_outputs/invokables.cpp b/crates/cxx-qt-gen/test_outputs/invokables.cpp index ec3ad9bea..c3f79859e 100644 --- a/crates/cxx-qt-gen/test_outputs/invokables.cpp +++ b/crates/cxx-qt-gen/test_outputs/invokables.cpp @@ -4,21 +4,21 @@ namespace cxx_qt::my_object { void MyObject::cppMethod() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); cppMethodWrapper(); } void MyObject::invokable() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); invokableWrapper(); } void MyObject::invokableMutable() { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); invokableMutableWrapper(); } @@ -27,56 +27,56 @@ MyObject::invokableParameters(QColor const& opaque, QPoint const& trivial, ::std::int32_t primitive) const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); invokableParametersWrapper(opaque, trivial, primitive); } ::std::unique_ptr MyObject::invokableReturnOpaque() { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return invokableReturnOpaqueWrapper(); } QPoint MyObject::invokableReturnTrivial() { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return invokableReturnTrivialWrapper(); } void MyObject::invokableFinal() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); invokableFinalWrapper(); } void MyObject::invokableOverride() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); invokableOverrideWrapper(); } void MyObject::invokableVirtual() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); invokableVirtualWrapper(); } void MyObject::invokableResultTuple() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); invokableResultTupleWrapper(); } ::rust::String MyObject::invokableResultType() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return invokableResultTypeWrapper(); } @@ -100,9 +100,9 @@ MyObject::MyObject() MyObject::MyObject( ::cxx_qt::my_object::cxx_qt_my_object::CxxQtConstructorArguments0&& args) : QObject(::std::move(args.base.arg0)) - , ::rust::cxxqtlib1::CxxQtType( + , ::rust::cxxqt1::CxxQtType( ::cxx_qt::my_object::cxx_qt_my_object::newRs0(::std::move(args.new_))) - , ::rust::cxxqtlib1::CxxQtThreading(this) + , ::rust::cxxqt1::CxxQtThreading(this) { ::cxx_qt::my_object::cxx_qt_my_object::initialize0( *this, ::std::move(args.initialize)); @@ -111,9 +111,9 @@ MyObject::MyObject( MyObject::MyObject( ::cxx_qt::my_object::cxx_qt_my_object::CxxQtConstructorArguments1&& args) : QObject() - , ::rust::cxxqtlib1::CxxQtType( + , ::rust::cxxqt1::CxxQtType( ::cxx_qt::my_object::cxx_qt_my_object::newRs1(::std::move(args.new_))) - , ::rust::cxxqtlib1::CxxQtThreading(this) + , ::rust::cxxqt1::CxxQtThreading(this) { ::cxx_qt::my_object::cxx_qt_my_object::initialize1( *this, ::std::move(args.initialize)); diff --git a/crates/cxx-qt-gen/test_outputs/invokables.h b/crates/cxx-qt-gen/test_outputs/invokables.h index 4aa36c8b1..1b3a5fb22 100644 --- a/crates/cxx-qt-gen/test_outputs/invokables.h +++ b/crates/cxx-qt-gen/test_outputs/invokables.h @@ -1,12 +1,12 @@ #pragma once -#include -#include -#include +#include +#include +#include namespace cxx_qt::my_object { class MyObject; -using MyObjectCxxQtThread = ::rust::cxxqtlib1::CxxQtThread; +using MyObjectCxxQtThread = ::rust::cxxqt1::CxxQtThread; } // namespace cxx_qt::my_object @@ -15,8 +15,8 @@ using MyObjectCxxQtThread = ::rust::cxxqtlib1::CxxQtThread; namespace cxx_qt::my_object { class MyObject : public QObject - , public ::rust::cxxqtlib1::CxxQtType - , public ::rust::cxxqtlib1::CxxQtThreading + , public ::rust::cxxqt1::CxxQtType + , public ::rust::cxxqt1::CxxQtThreading { Q_OBJECT public: diff --git a/crates/cxx-qt-gen/test_outputs/invokables.rs b/crates/cxx-qt-gen/test_outputs/invokables.rs index 88a329482..2166624cc 100644 --- a/crates/cxx-qt-gen/test_outputs/invokables.rs +++ b/crates/cxx-qt-gen/test_outputs/invokables.rs @@ -11,16 +11,15 @@ mod ffi { } unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt-lib/qt.h"); + include!("cxx-qt/cxxqt_connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] - type ConnectionType = cxx_qt_lib::ConnectionType; - include!("cxx-qt-lib/qmetaobjectconnection.h"); + type ConnectionType = cxx_qt::ConnectionType; #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[rust_name = "CxxQtQMetaObjectConnection"] - type QMetaObjectConnection = cxx_qt_lib::QMetaObjectConnection; + type QMetaObjectConnection = cxx_qt::QMetaObjectConnection; } unsafe extern "C++" { include!("cxx-qt-gen/ffi.cxxqt.h"); @@ -96,12 +95,12 @@ mod ffi { unsafe extern "C++" { #[doc(hidden)] type MyObjectCxxQtThread = cxx_qt::CxxQtThread; - include!("cxx-qt-common/cxxqt_thread.h"); + include!("cxx-qt/cxxqt_thread.h"); #[doc(hidden)] #[cxx_name = "qtThread"] fn cxx_qt_ffi_qt_thread(self: &MyObject) -> MyObjectCxxQtThread; #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[cxx_name = "cxxQtThreadQueue"] fn cxx_qt_ffi_my_object_queue_boxed_fn( cxx_qt_thread: &MyObjectCxxQtThread, @@ -109,13 +108,13 @@ mod ffi { arg: Box, ) -> Result<()>; #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[cxx_name = "cxxQtThreadClone"] fn cxx_qt_ffi_my_object_threading_clone( cxx_qt_thread: &MyObjectCxxQtThread, ) -> MyObjectCxxQtThread; #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[cxx_name = "cxxQtThreadDrop"] fn cxx_qt_ffi_my_object_threading_drop(cxx_qt_thread: &mut MyObjectCxxQtThread); } 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 c9d857485..4ac846855 100644 --- a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.cpp +++ b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.cpp @@ -2,7 +2,7 @@ // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { template<> SignalHandler<::rust::cxxqtgen1::QPushButtonCxxQtSignalParamsclicked*>:: ~SignalHandler() noexcept @@ -33,7 +33,7 @@ static_assert( SignalHandler<::rust::cxxqtgen1::QPushButtonCxxQtSignalParamsclicked*>) == sizeof(::std::size_t[2]), "unexpected size"); -} // namespace rust::cxxqtlib1 +} // namespace rust::cxxqt1 namespace rust::cxxqtgen1 { ::QMetaObject::Connection @@ -47,7 +47,7 @@ QPushButton_clickedConnect( &QPushButton::clicked, &self, [&, closure = ::std::move(closure)](bool checked) mutable { - const ::rust::cxxqtlib1::MaybeLockGuard guard(self); + const ::rust::cxxqt1::MaybeLockGuard guard(self); closure.template operator()(self, ::std::move(checked)); }, @@ -57,7 +57,7 @@ QPushButton_clickedConnect( // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { template<> SignalHandler< ::rust::cxxqtgen1::mynamespace::ExternObjectCxxQtSignalParamsdataReady*>:: @@ -91,7 +91,7 @@ static_assert( ExternObjectCxxQtSignalParamsdataReady*>) == sizeof(::std::size_t[2]), "unexpected size"); -} // namespace rust::cxxqtlib1 +} // namespace rust::cxxqt1 namespace rust::cxxqtgen1::mynamespace { ::QMetaObject::Connection @@ -106,7 +106,7 @@ ExternObject_dataReadyConnect( &::mynamespace::ExternObjectCpp::dataReady, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard<::mynamespace::ExternObjectCpp> + const ::rust::cxxqt1::MaybeLockGuard<::mynamespace::ExternObjectCpp> guard(self); closure.template operator()<::mynamespace::ExternObjectCpp&>(self); }, @@ -116,7 +116,7 @@ ExternObject_dataReadyConnect( // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { template<> SignalHandler< ::rust::cxxqtgen1::mynamespace::ExternObjectCxxQtSignalParamserrorOccurred*>:: @@ -150,7 +150,7 @@ static_assert( ExternObjectCxxQtSignalParamserrorOccurred*>) == sizeof(::std::size_t[2]), "unexpected size"); -} // namespace rust::cxxqtlib1 +} // namespace rust::cxxqt1 namespace rust::cxxqtgen1::mynamespace { ::QMetaObject::Connection @@ -165,7 +165,7 @@ ExternObject_errorOccurredConnect( &::mynamespace::ExternObjectCpp::errorOccurred, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard<::mynamespace::ExternObjectCpp> + const ::rust::cxxqt1::MaybeLockGuard<::mynamespace::ExternObjectCpp> guard(self); closure.template operator()<::mynamespace::ExternObjectCpp&>(self); }, @@ -175,7 +175,7 @@ ExternObject_errorOccurredConnect( // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { template<> SignalHandler< ::rust::cxxqtgen1::cxx_qt::multi_object:: @@ -209,7 +209,7 @@ static_assert( MyObjectCxxQtSignalParamspropertyNameChanged*>) == sizeof(::std::size_t[2]), "unexpected size"); -} // namespace rust::cxxqtlib1 +} // namespace rust::cxxqt1 namespace rust::cxxqtgen1::cxx_qt::multi_object { ::QMetaObject::Connection @@ -224,7 +224,7 @@ MyObject_propertyNameChangedConnect( &::cxx_qt::multi_object::MyObject::propertyNameChanged, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard<::cxx_qt::multi_object::MyObject> + const ::rust::cxxqt1::MaybeLockGuard<::cxx_qt::multi_object::MyObject> guard(self); closure.template operator()<::cxx_qt::multi_object::MyObject&>(self); }, @@ -234,7 +234,7 @@ MyObject_propertyNameChangedConnect( // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { template<> SignalHandler<::rust::cxxqtgen1::cxx_qt::multi_object:: MyObjectCxxQtSignalParamsready*>::~SignalHandler() noexcept @@ -265,7 +265,7 @@ static_assert(sizeof(SignalHandler<::rust::cxxqtgen1::cxx_qt::multi_object:: MyObjectCxxQtSignalParamsready*>) == sizeof(::std::size_t[2]), "unexpected size"); -} // namespace rust::cxxqtlib1 +} // namespace rust::cxxqt1 namespace rust::cxxqtgen1::cxx_qt::multi_object { ::QMetaObject::Connection @@ -280,7 +280,7 @@ MyObject_readyConnect( &::cxx_qt::multi_object::MyObject::ready, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard<::cxx_qt::multi_object::MyObject> + const ::rust::cxxqt1::MaybeLockGuard<::cxx_qt::multi_object::MyObject> guard(self); closure.template operator()<::cxx_qt::multi_object::MyObject&>(self); }, @@ -292,29 +292,29 @@ namespace cxx_qt::multi_object { ::std::int32_t const& MyObject::getPropertyName() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return getPropertyNameWrapper(); } void MyObject::setPropertyName(::std::int32_t const& value) { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); setPropertyNameWrapper(value); } void MyObject::invokableName() { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); invokableNameWrapper(); } MyObject::MyObject(QObject* parent) : QStringListModel(parent) - , ::rust::cxxqtlib1::CxxQtType( + , ::rust::cxxqt1::CxxQtType( ::cxx_qt::multi_object::cxx_qt_my_object::createRs()) - , ::rust::cxxqtlib1::CxxQtLocking() + , ::rust::cxxqt1::CxxQtLocking() { } @@ -322,7 +322,7 @@ MyObject::MyObject(QObject* parent) // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { template<> SignalHandler<::rust::cxxqtgen1::second_object:: SecondObjectCxxQtSignalParamspropertyNameChanged*>:: @@ -355,7 +355,7 @@ static_assert( SecondObjectCxxQtSignalParamspropertyNameChanged*>) == sizeof(::std::size_t[2]), "unexpected size"); -} // namespace rust::cxxqtlib1 +} // namespace rust::cxxqt1 namespace rust::cxxqtgen1::second_object { ::QMetaObject::Connection @@ -370,8 +370,8 @@ SecondObject_propertyNameChangedConnect( &::second_object::SecondObject::propertyNameChanged, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard<::second_object::SecondObject> - guard(self); + const ::rust::cxxqt1::MaybeLockGuard<::second_object::SecondObject> guard( + self); closure.template operator()<::second_object::SecondObject&>(self); }, type); @@ -380,7 +380,7 @@ SecondObject_propertyNameChangedConnect( // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { template<> SignalHandler<::rust::cxxqtgen1::second_object:: SecondObjectCxxQtSignalParamsready*>::~SignalHandler() noexcept @@ -414,7 +414,7 @@ static_assert( ::rust::cxxqtgen1::second_object::SecondObjectCxxQtSignalParamsready*>) == sizeof(::std::size_t[2]), "unexpected size"); -} // namespace rust::cxxqtlib1 +} // namespace rust::cxxqt1 namespace rust::cxxqtgen1::second_object { ::QMetaObject::Connection @@ -428,8 +428,8 @@ SecondObject_readyConnect( &::second_object::SecondObject::ready, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard<::second_object::SecondObject> - guard(self); + const ::rust::cxxqt1::MaybeLockGuard<::second_object::SecondObject> guard( + self); closure.template operator()<::second_object::SecondObject&>(self); }, type); @@ -440,27 +440,27 @@ namespace second_object { ::std::int32_t const& SecondObject::getPropertyName() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return getPropertyNameWrapper(); } void SecondObject::setPropertyName(::std::int32_t const& value) { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); setPropertyNameWrapper(value); } void SecondObject::invokableName() { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); invokableNameWrapper(); } SecondObject::SecondObject(QObject* parent) : QObject(parent) - , ::rust::cxxqtlib1::CxxQtType( + , ::rust::cxxqt1::CxxQtType( ::second_object::cxx_qt_second_object::createRs()) { } 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 44b6e4057..da4a136ba 100644 --- a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h +++ b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h @@ -1,9 +1,9 @@ #pragma once -#include -#include -#include -#include +#include +#include +#include +#include namespace cxx_qt::multi_object { class MyObject; @@ -12,13 +12,13 @@ class MyObject; namespace rust::cxxqtgen1::cxx_qt::multi_object { using MyObjectCxxQtSignalHandlerpropertyNameChanged = - ::rust::cxxqtlib1::SignalHandler< + ::rust::cxxqt1::SignalHandler< struct MyObjectCxxQtSignalParamspropertyNameChanged*>; } // namespace rust::cxxqtgen1::cxx_qt::multi_object namespace rust::cxxqtgen1::cxx_qt::multi_object { using MyObjectCxxQtSignalHandlerready = - ::rust::cxxqtlib1::SignalHandler; + ::rust::cxxqt1::SignalHandler; } // namespace rust::cxxqtgen1::cxx_qt::multi_object namespace second_object { @@ -28,29 +28,28 @@ class SecondObject; namespace rust::cxxqtgen1::second_object { using SecondObjectCxxQtSignalHandlerpropertyNameChanged = - ::rust::cxxqtlib1::SignalHandler< + ::rust::cxxqt1::SignalHandler< struct SecondObjectCxxQtSignalParamspropertyNameChanged*>; } // namespace rust::cxxqtgen1::second_object namespace rust::cxxqtgen1::second_object { using SecondObjectCxxQtSignalHandlerready = - ::rust::cxxqtlib1::SignalHandler; + ::rust::cxxqt1::SignalHandler; } // namespace rust::cxxqtgen1::second_object namespace rust::cxxqtgen1 { using QPushButtonCxxQtSignalHandlerclicked = - ::rust::cxxqtlib1::SignalHandler; + ::rust::cxxqt1::SignalHandler; } // namespace rust::cxxqtgen1 namespace rust::cxxqtgen1::mynamespace { using ExternObjectCxxQtSignalHandlerdataReady = - ::rust::cxxqtlib1::SignalHandler< - struct ExternObjectCxxQtSignalParamsdataReady*>; + ::rust::cxxqt1::SignalHandler; } // namespace rust::cxxqtgen1::mynamespace namespace rust::cxxqtgen1::mynamespace { using ExternObjectCxxQtSignalHandlererrorOccurred = - ::rust::cxxqtlib1::SignalHandler< + ::rust::cxxqt1::SignalHandler< struct ExternObjectCxxQtSignalParamserrorOccurred*>; } // namespace rust::cxxqtgen1::mynamespace @@ -103,8 +102,8 @@ MyObject_readyConnect( namespace cxx_qt::multi_object { class MyObject : public QStringListModel - , public ::rust::cxxqtlib1::CxxQtType - , public ::rust::cxxqtlib1::CxxQtLocking + , public ::rust::cxxqt1::CxxQtType + , public ::rust::cxxqt1::CxxQtLocking { Q_OBJECT public: @@ -153,7 +152,7 @@ SecondObject_readyConnect( namespace second_object { class SecondObject : public QObject - , public ::rust::cxxqtlib1::CxxQtType + , public ::rust::cxxqt1::CxxQtType { Q_OBJECT public: 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 5cdbc7d7b..8df225cd7 100644 --- a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs +++ b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs @@ -47,16 +47,15 @@ pub mod ffi { } unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt-lib/qt.h"); + include!("cxx-qt/cxxqt_connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] - type ConnectionType = cxx_qt_lib::ConnectionType; - include!("cxx-qt-lib/qmetaobjectconnection.h"); + type ConnectionType = cxx_qt::ConnectionType; #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[rust_name = "CxxQtQMetaObjectConnection"] - type QMetaObjectConnection = cxx_qt_lib::QMetaObjectConnection; + type QMetaObjectConnection = cxx_qt::QMetaObjectConnection; } unsafe extern "C++" { include!("cxx-qt-gen/multi_object.cxxqt.h"); @@ -395,19 +394,18 @@ impl ffi::MyObject { #[doc = "Connect the given function pointer to the signal "] #[doc = "propertyNameChanged"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] pub fn connect_property_name_changed) + 'static>( self: core::pin::Pin<&mut ffi::MyObject>, mut closure: F, - conn_type: cxx_qt_lib::ConnectionType, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::MyObject_connect_property_name_changed( + conn_type: cxx_qt::ConnectionType, + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_property_name_changed( self, cxx_qt::signalhandler::CxxQtSignalHandler::< MyObjectCxxQtSignalClosurepropertyNameChanged, >::new(Box::new(closure)), conn_type, - ) + )) } } impl ffi::MyObject { @@ -416,18 +414,17 @@ impl ffi::MyObject { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] pub fn on_property_name_changed) + 'static>( self: core::pin::Pin<&mut ffi::MyObject>, mut closure: F, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::MyObject_connect_property_name_changed( + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_property_name_changed( self, cxx_qt::signalhandler::CxxQtSignalHandler::< MyObjectCxxQtSignalClosurepropertyNameChanged, >::new(Box::new(closure)), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } #[doc(hidden)] @@ -461,19 +458,18 @@ impl ffi::MyObject { #[doc = "Connect the given function pointer to the signal "] #[doc = "ready"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] pub fn connect_ready) + 'static>( self: core::pin::Pin<&mut ffi::MyObject>, mut closure: F, - conn_type: cxx_qt_lib::ConnectionType, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::MyObject_connect_ready( + conn_type: cxx_qt::ConnectionType, + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new( Box::new(closure), ), conn_type, - ) + )) } } impl ffi::MyObject { @@ -482,18 +478,17 @@ impl ffi::MyObject { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] pub fn on_ready) + 'static>( self: core::pin::Pin<&mut ffi::MyObject>, mut closure: F, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::MyObject_connect_ready( + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new( Box::new(closure), ), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } #[doc(hidden)] @@ -561,21 +556,20 @@ impl ffi::SecondObject { #[doc = "Connect the given function pointer to the signal "] #[doc = "propertyNameChanged"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] pub fn connect_property_name_changed< F: FnMut(core::pin::Pin<&mut ffi::SecondObject>) + 'static, >( self: core::pin::Pin<&mut ffi::SecondObject>, mut closure: F, - conn_type: cxx_qt_lib::ConnectionType, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::SecondObject_connect_property_name_changed( + conn_type: cxx_qt::ConnectionType, + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::SecondObject_connect_property_name_changed( self, cxx_qt::signalhandler::CxxQtSignalHandler::< SecondObjectCxxQtSignalClosurepropertyNameChanged, >::new(Box::new(closure)), conn_type, - ) + )) } } impl ffi::SecondObject { @@ -584,18 +578,17 @@ impl ffi::SecondObject { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] pub fn on_property_name_changed) + 'static>( self: core::pin::Pin<&mut ffi::SecondObject>, mut closure: F, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::SecondObject_connect_property_name_changed( + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::SecondObject_connect_property_name_changed( self, cxx_qt::signalhandler::CxxQtSignalHandler::< SecondObjectCxxQtSignalClosurepropertyNameChanged, >::new(Box::new(closure)), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } #[doc(hidden)] @@ -629,19 +622,18 @@ impl ffi::SecondObject { #[doc = "Connect the given function pointer to the signal "] #[doc = "ready"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] pub fn connect_ready) + 'static>( self: core::pin::Pin<&mut ffi::SecondObject>, mut closure: F, - conn_type: cxx_qt_lib::ConnectionType, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::SecondObject_connect_ready( + conn_type: cxx_qt::ConnectionType, + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::SecondObject_connect_ready( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new( Box::new(closure), ), conn_type, - ) + )) } } impl ffi::SecondObject { @@ -650,18 +642,17 @@ impl ffi::SecondObject { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] pub fn on_ready) + 'static>( self: core::pin::Pin<&mut ffi::SecondObject>, mut closure: F, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::SecondObject_connect_ready( + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::SecondObject_connect_ready( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new( Box::new(closure), ), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } #[doc(hidden)] @@ -709,19 +700,18 @@ impl ffi::QPushButton { #[doc = "Connect the given function pointer to the signal "] #[doc = "clicked"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] pub fn connect_clicked, bool) + 'static>( self: core::pin::Pin<&mut ffi::QPushButton>, mut closure: F, - conn_type: cxx_qt_lib::ConnectionType, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::QPushButton_connect_clicked( + conn_type: cxx_qt::ConnectionType, + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::QPushButton_connect_clicked( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new( Box::new(closure), ), conn_type, - ) + )) } } impl ffi::QPushButton { @@ -730,18 +720,17 @@ impl ffi::QPushButton { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] pub fn on_clicked, bool) + 'static>( self: core::pin::Pin<&mut ffi::QPushButton>, mut closure: F, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::QPushButton_connect_clicked( + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::QPushButton_connect_clicked( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new( Box::new(closure), ), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } #[doc(hidden)] @@ -770,13 +759,12 @@ impl ffi::ExternObject { #[doc = "Connect the given function pointer to the signal "] #[doc = "dataReady"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] pub fn connect_data_ready) + 'static>( self: core::pin::Pin<&mut ffi::ExternObject>, mut closure: F, - conn_type: cxx_qt_lib::ConnectionType, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi :: ExternObject_connect_data_ready (self , cxx_qt :: signalhandler :: CxxQtSignalHandler :: < ExternObjectCxxQtSignalClosuredataReady > :: new (Box :: new (closure)) , conn_type ,) + conn_type: cxx_qt::ConnectionType, + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt :: QMetaObjectConnectionGuard :: from (ffi :: ExternObject_connect_data_ready (self , cxx_qt :: signalhandler :: CxxQtSignalHandler :: < ExternObjectCxxQtSignalClosuredataReady > :: new (Box :: new (closure)) , conn_type ,)) } } impl ffi::ExternObject { @@ -785,12 +773,11 @@ impl ffi::ExternObject { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] pub fn on_data_ready) + 'static>( self: core::pin::Pin<&mut ffi::ExternObject>, mut closure: F, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi :: ExternObject_connect_data_ready (self , cxx_qt :: signalhandler :: CxxQtSignalHandler :: < ExternObjectCxxQtSignalClosuredataReady > :: new (Box :: new (closure)) , cxx_qt_lib :: ConnectionType :: AutoConnection ,) + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt :: QMetaObjectConnectionGuard :: from (ffi :: ExternObject_connect_data_ready (self , cxx_qt :: signalhandler :: CxxQtSignalHandler :: < ExternObjectCxxQtSignalClosuredataReady > :: new (Box :: new (closure)) , cxx_qt :: ConnectionType :: AutoConnection ,)) } } #[doc(hidden)] @@ -821,13 +808,20 @@ impl ffi::ExternObject { #[doc = "Connect the given function pointer to the signal "] #[doc = "errorOccurred"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] pub fn connect_error_occurred) + 'static>( self: core::pin::Pin<&mut ffi::ExternObject>, mut closure: F, - conn_type: cxx_qt_lib::ConnectionType, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi :: ExternObject_connect_error_occurred (self , cxx_qt :: signalhandler :: CxxQtSignalHandler :: < ExternObjectCxxQtSignalClosureerrorOccurred > :: new (Box :: new (closure)) , conn_type ,) + conn_type: cxx_qt::ConnectionType, + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from( + ffi::ExternObject_connect_error_occurred( + self, + cxx_qt::signalhandler::CxxQtSignalHandler::< + ExternObjectCxxQtSignalClosureerrorOccurred, + >::new(Box::new(closure)), + conn_type, + ), + ) } } impl ffi::ExternObject { @@ -836,12 +830,19 @@ impl ffi::ExternObject { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] pub fn on_error_occurred) + 'static>( self: core::pin::Pin<&mut ffi::ExternObject>, mut closure: F, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi :: ExternObject_connect_error_occurred (self , cxx_qt :: signalhandler :: CxxQtSignalHandler :: < ExternObjectCxxQtSignalClosureerrorOccurred > :: new (Box :: new (closure)) , cxx_qt_lib :: ConnectionType :: AutoConnection ,) + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from( + ffi::ExternObject_connect_error_occurred( + self, + cxx_qt::signalhandler::CxxQtSignalHandler::< + ExternObjectCxxQtSignalClosureerrorOccurred, + >::new(Box::new(closure)), + cxx_qt::ConnectionType::AutoConnection, + ), + ) } } #[doc(hidden)] diff --git a/crates/cxx-qt-gen/test_outputs/properties.cpp b/crates/cxx-qt-gen/test_outputs/properties.cpp index 763c4fb08..ce2b466dd 100644 --- a/crates/cxx-qt-gen/test_outputs/properties.cpp +++ b/crates/cxx-qt-gen/test_outputs/properties.cpp @@ -2,7 +2,7 @@ // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { template<> SignalHandler< ::rust::cxxqtgen1::cxx_qt::my_object:: @@ -35,7 +35,7 @@ static_assert( MyObjectCxxQtSignalParamsprimitiveChanged*>) == sizeof(::std::size_t[2]), "unexpected size"); -} // namespace rust::cxxqtlib1 +} // namespace rust::cxxqt1 namespace rust::cxxqtgen1::cxx_qt::my_object { ::QMetaObject::Connection @@ -50,8 +50,8 @@ MyObject_primitiveChangedConnect( &::cxx_qt::my_object::MyObject::primitiveChanged, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard<::cxx_qt::my_object::MyObject> - guard(self); + const ::rust::cxxqt1::MaybeLockGuard<::cxx_qt::my_object::MyObject> guard( + self); closure.template operator()<::cxx_qt::my_object::MyObject&>(self); }, type); @@ -60,7 +60,7 @@ MyObject_primitiveChangedConnect( // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { template<> SignalHandler< ::rust::cxxqtgen1::cxx_qt::my_object:: @@ -93,7 +93,7 @@ static_assert( MyObjectCxxQtSignalParamstrivialChanged*>) == sizeof(::std::size_t[2]), "unexpected size"); -} // namespace rust::cxxqtlib1 +} // namespace rust::cxxqt1 namespace rust::cxxqtgen1::cxx_qt::my_object { ::QMetaObject::Connection @@ -108,8 +108,8 @@ MyObject_trivialChangedConnect( &::cxx_qt::my_object::MyObject::trivialChanged, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard<::cxx_qt::my_object::MyObject> - guard(self); + const ::rust::cxxqt1::MaybeLockGuard<::cxx_qt::my_object::MyObject> guard( + self); closure.template operator()<::cxx_qt::my_object::MyObject&>(self); }, type); @@ -120,36 +120,36 @@ namespace cxx_qt::my_object { ::std::int32_t const& MyObject::getPrimitive() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return getPrimitiveWrapper(); } void MyObject::setPrimitive(::std::int32_t const& value) { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); setPrimitiveWrapper(value); } QPoint const& MyObject::getTrivial() const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); return getTrivialWrapper(); } void MyObject::setTrivial(QPoint const& value) { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); setTrivialWrapper(value); } MyObject::MyObject(QObject* parent) : QObject(parent) - , ::rust::cxxqtlib1::CxxQtType( + , ::rust::cxxqt1::CxxQtType( ::cxx_qt::my_object::cxx_qt_my_object::createRs()) - , ::rust::cxxqtlib1::CxxQtLocking() + , ::rust::cxxqt1::CxxQtLocking() { } diff --git a/crates/cxx-qt-gen/test_outputs/properties.h b/crates/cxx-qt-gen/test_outputs/properties.h index 100dd0df6..d61e52146 100644 --- a/crates/cxx-qt-gen/test_outputs/properties.h +++ b/crates/cxx-qt-gen/test_outputs/properties.h @@ -1,9 +1,9 @@ #pragma once -#include -#include -#include -#include +#include +#include +#include +#include namespace cxx_qt::my_object { class MyObject; @@ -12,14 +12,13 @@ class MyObject; namespace rust::cxxqtgen1::cxx_qt::my_object { using MyObjectCxxQtSignalHandlerprimitiveChanged = - ::rust::cxxqtlib1::SignalHandler< + ::rust::cxxqt1::SignalHandler< struct MyObjectCxxQtSignalParamsprimitiveChanged*>; } // namespace rust::cxxqtgen1::cxx_qt::my_object namespace rust::cxxqtgen1::cxx_qt::my_object { -using MyObjectCxxQtSignalHandlertrivialChanged = - ::rust::cxxqtlib1::SignalHandler< - struct MyObjectCxxQtSignalParamstrivialChanged*>; +using MyObjectCxxQtSignalHandlertrivialChanged = ::rust::cxxqt1::SignalHandler< + struct MyObjectCxxQtSignalParamstrivialChanged*>; } // namespace rust::cxxqtgen1::cxx_qt::my_object #include "cxx-qt-gen/ffi.cxx.h" @@ -45,8 +44,8 @@ MyObject_trivialChangedConnect( namespace cxx_qt::my_object { class MyObject : public QObject - , public ::rust::cxxqtlib1::CxxQtType - , public ::rust::cxxqtlib1::CxxQtLocking + , public ::rust::cxxqt1::CxxQtType + , public ::rust::cxxqt1::CxxQtLocking { Q_OBJECT public: diff --git a/crates/cxx-qt-gen/test_outputs/properties.rs b/crates/cxx-qt-gen/test_outputs/properties.rs index b56ee8974..f5f8ffc36 100644 --- a/crates/cxx-qt-gen/test_outputs/properties.rs +++ b/crates/cxx-qt-gen/test_outputs/properties.rs @@ -7,16 +7,15 @@ mod ffi { } unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt-lib/qt.h"); + include!("cxx-qt/cxxqt_connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] - type ConnectionType = cxx_qt_lib::ConnectionType; - include!("cxx-qt-lib/qmetaobjectconnection.h"); + type ConnectionType = cxx_qt::ConnectionType; #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[rust_name = "CxxQtQMetaObjectConnection"] - type QMetaObjectConnection = cxx_qt_lib::QMetaObjectConnection; + type QMetaObjectConnection = cxx_qt::QMetaObjectConnection; } unsafe extern "C++" { include!("cxx-qt-gen/ffi.cxxqt.h"); @@ -174,13 +173,20 @@ impl ffi::MyObject { #[doc = "Connect the given function pointer to the signal "] #[doc = "primitiveChanged"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] pub fn connect_primitive_changed) + 'static>( self: core::pin::Pin<&mut ffi::MyObject>, mut closure: F, - conn_type: cxx_qt_lib::ConnectionType, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi :: MyObject_connect_primitive_changed (self , cxx_qt :: signalhandler :: CxxQtSignalHandler :: < MyObjectCxxQtSignalClosureprimitiveChanged > :: new (Box :: new (closure)) , conn_type ,) + conn_type: cxx_qt::ConnectionType, + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from( + ffi::MyObject_connect_primitive_changed( + self, + cxx_qt::signalhandler::CxxQtSignalHandler::< + MyObjectCxxQtSignalClosureprimitiveChanged, + >::new(Box::new(closure)), + conn_type, + ), + ) } } impl ffi::MyObject { @@ -189,12 +195,19 @@ impl ffi::MyObject { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] pub fn on_primitive_changed) + 'static>( self: core::pin::Pin<&mut ffi::MyObject>, mut closure: F, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi :: MyObject_connect_primitive_changed (self , cxx_qt :: signalhandler :: CxxQtSignalHandler :: < MyObjectCxxQtSignalClosureprimitiveChanged > :: new (Box :: new (closure)) , cxx_qt_lib :: ConnectionType :: AutoConnection ,) + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from( + ffi::MyObject_connect_primitive_changed( + self, + cxx_qt::signalhandler::CxxQtSignalHandler::< + MyObjectCxxQtSignalClosureprimitiveChanged, + >::new(Box::new(closure)), + cxx_qt::ConnectionType::AutoConnection, + ), + ) } } #[doc(hidden)] @@ -228,13 +241,12 @@ impl ffi::MyObject { #[doc = "Connect the given function pointer to the signal "] #[doc = "trivialChanged"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] pub fn connect_trivial_changed) + 'static>( self: core::pin::Pin<&mut ffi::MyObject>, mut closure: F, - conn_type: cxx_qt_lib::ConnectionType, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi :: MyObject_connect_trivial_changed (self , cxx_qt :: signalhandler :: CxxQtSignalHandler :: < MyObjectCxxQtSignalClosuretrivialChanged > :: new (Box :: new (closure)) , conn_type ,) + conn_type: cxx_qt::ConnectionType, + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt :: QMetaObjectConnectionGuard :: from (ffi :: MyObject_connect_trivial_changed (self , cxx_qt :: signalhandler :: CxxQtSignalHandler :: < MyObjectCxxQtSignalClosuretrivialChanged > :: new (Box :: new (closure)) , conn_type ,)) } } impl ffi::MyObject { @@ -243,12 +255,11 @@ impl ffi::MyObject { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] pub fn on_trivial_changed) + 'static>( self: core::pin::Pin<&mut ffi::MyObject>, mut closure: F, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi :: MyObject_connect_trivial_changed (self , cxx_qt :: signalhandler :: CxxQtSignalHandler :: < MyObjectCxxQtSignalClosuretrivialChanged > :: new (Box :: new (closure)) , cxx_qt_lib :: ConnectionType :: AutoConnection ,) + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt :: QMetaObjectConnectionGuard :: from (ffi :: MyObject_connect_trivial_changed (self , cxx_qt :: signalhandler :: CxxQtSignalHandler :: < MyObjectCxxQtSignalClosuretrivialChanged > :: new (Box :: new (closure)) , cxx_qt :: ConnectionType :: AutoConnection ,)) } } #[doc(hidden)] diff --git a/crates/cxx-qt-gen/test_outputs/qenum.cpp b/crates/cxx-qt-gen/test_outputs/qenum.cpp index 740cbf774..a7daf6ea0 100644 --- a/crates/cxx-qt-gen/test_outputs/qenum.cpp +++ b/crates/cxx-qt-gen/test_outputs/qenum.cpp @@ -5,15 +5,15 @@ void MyObject::myInvokable(::cxx_qt::my_object::MyEnum qenum, ::cxx_qt::my_object::MyOtherEnum other_qenum) const { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); myInvokableWrapper(qenum, other_qenum); } MyObject::MyObject(QObject* parent) : QObject(parent) - , ::rust::cxxqtlib1::CxxQtType( + , ::rust::cxxqt1::CxxQtType( ::cxx_qt::my_object::cxx_qt_my_object::createRs()) - , ::rust::cxxqtlib1::CxxQtLocking() + , ::rust::cxxqt1::CxxQtLocking() { } diff --git a/crates/cxx-qt-gen/test_outputs/qenum.h b/crates/cxx-qt-gen/test_outputs/qenum.h index 6f40e243d..899a37b05 100644 --- a/crates/cxx-qt-gen/test_outputs/qenum.h +++ b/crates/cxx-qt-gen/test_outputs/qenum.h @@ -3,9 +3,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include namespace cxx_qt::my_object { class MyObject; @@ -58,8 +58,8 @@ Q_ENUM_NS(MyOtherNamespacedEnum) namespace cxx_qt::my_object { class MyObject : public QObject - , public ::rust::cxxqtlib1::CxxQtType - , public ::rust::cxxqtlib1::CxxQtLocking + , public ::rust::cxxqt1::CxxQtType + , public ::rust::cxxqt1::CxxQtLocking { Q_OBJECT public: diff --git a/crates/cxx-qt-gen/test_outputs/qenum.rs b/crates/cxx-qt-gen/test_outputs/qenum.rs index a039a8a45..946da526a 100644 --- a/crates/cxx-qt-gen/test_outputs/qenum.rs +++ b/crates/cxx-qt-gen/test_outputs/qenum.rs @@ -2,16 +2,15 @@ mod ffi { unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt-lib/qt.h"); + include!("cxx-qt/cxxqt_connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] - type ConnectionType = cxx_qt_lib::ConnectionType; - include!("cxx-qt-lib/qmetaobjectconnection.h"); + type ConnectionType = cxx_qt::ConnectionType; #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[rust_name = "CxxQtQMetaObjectConnection"] - type QMetaObjectConnection = cxx_qt_lib::QMetaObjectConnection; + type QMetaObjectConnection = cxx_qt::QMetaObjectConnection; } #[repr(i32)] enum MyNamespacedEnum { diff --git a/crates/cxx-qt-gen/test_outputs/signals.cpp b/crates/cxx-qt-gen/test_outputs/signals.cpp index 9db13c8d5..385908bf8 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.cpp +++ b/crates/cxx-qt-gen/test_outputs/signals.cpp @@ -2,7 +2,7 @@ // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { template<> SignalHandler<::rust::cxxqtgen1::cxx_qt::my_object:: QTimerCxxQtSignalParamstimeout*>::~SignalHandler() noexcept @@ -36,7 +36,7 @@ static_assert( ::rust::cxxqtgen1::cxx_qt::my_object::QTimerCxxQtSignalParamstimeout*>) == sizeof(::std::size_t[2]), "unexpected size"); -} // namespace rust::cxxqtlib1 +} // namespace rust::cxxqt1 namespace rust::cxxqtgen1::cxx_qt::my_object { ::QMetaObject::Connection @@ -50,8 +50,8 @@ QTimer_timeoutConnect( &::cxx_qt::my_object::QTimer::timeout, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard<::cxx_qt::my_object::QTimer> - guard(self); + const ::rust::cxxqt1::MaybeLockGuard<::cxx_qt::my_object::QTimer> guard( + self); closure.template operator()<::cxx_qt::my_object::QTimer&>(self); }, type); @@ -60,7 +60,7 @@ QTimer_timeoutConnect( // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { template<> SignalHandler<::rust::cxxqtgen1::cxx_qt::my_object:: MyObjectCxxQtSignalParamsready*>::~SignalHandler() noexcept @@ -94,7 +94,7 @@ static_assert( ::rust::cxxqtgen1::cxx_qt::my_object::MyObjectCxxQtSignalParamsready*>) == sizeof(::std::size_t[2]), "unexpected size"); -} // namespace rust::cxxqtlib1 +} // namespace rust::cxxqt1 namespace rust::cxxqtgen1::cxx_qt::my_object { ::QMetaObject::Connection @@ -108,8 +108,8 @@ MyObject_readyConnect( &::cxx_qt::my_object::MyObject::ready, &self, [&, closure = ::std::move(closure)]() mutable { - const ::rust::cxxqtlib1::MaybeLockGuard<::cxx_qt::my_object::MyObject> - guard(self); + const ::rust::cxxqt1::MaybeLockGuard<::cxx_qt::my_object::MyObject> guard( + self); closure.template operator()<::cxx_qt::my_object::MyObject&>(self); }, type); @@ -118,7 +118,7 @@ MyObject_readyConnect( // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { template<> SignalHandler< ::rust::cxxqtgen1::cxx_qt::my_object::MyObjectCxxQtSignalParamsdataChanged*>:: @@ -162,7 +162,7 @@ static_assert(sizeof(SignalHandler<::rust::cxxqtgen1::cxx_qt::my_object:: MyObjectCxxQtSignalParamsdataChanged*>) == sizeof(::std::size_t[2]), "unexpected size"); -} // namespace rust::cxxqtlib1 +} // namespace rust::cxxqt1 namespace rust::cxxqtgen1::cxx_qt::my_object { ::QMetaObject::Connection @@ -180,8 +180,8 @@ MyObject_dataChangedConnect( ::std::unique_ptr second, QPoint third, QPoint const& fourth) mutable { - const ::rust::cxxqtlib1::MaybeLockGuard<::cxx_qt::my_object::MyObject> - guard(self); + const ::rust::cxxqt1::MaybeLockGuard<::cxx_qt::my_object::MyObject> guard( + self); closure.template operator()<::cxx_qt::my_object::MyObject&, ::std::int32_t, ::std::unique_ptr, @@ -198,7 +198,7 @@ MyObject_dataChangedConnect( // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { template<> SignalHandler<::rust::cxxqtgen1::cxx_qt::my_object:: MyObjectCxxQtSignalParamsnewData*>::~SignalHandler() noexcept @@ -241,7 +241,7 @@ static_assert(sizeof(SignalHandler<::rust::cxxqtgen1::cxx_qt::my_object:: MyObjectCxxQtSignalParamsnewData*>) == sizeof(::std::size_t[2]), "unexpected size"); -} // namespace rust::cxxqtlib1 +} // namespace rust::cxxqt1 namespace rust::cxxqtgen1::cxx_qt::my_object { ::QMetaObject::Connection @@ -259,8 +259,8 @@ MyObject_newDataConnect( ::std::unique_ptr second, QPoint third, QPoint const& fourth) mutable { - const ::rust::cxxqtlib1::MaybeLockGuard<::cxx_qt::my_object::MyObject> - guard(self); + const ::rust::cxxqt1::MaybeLockGuard<::cxx_qt::my_object::MyObject> guard( + self); closure.template operator()<::cxx_qt::my_object::MyObject&, ::std::int32_t, ::std::unique_ptr, @@ -279,15 +279,15 @@ namespace cxx_qt::my_object { void MyObject::invokable() { - const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); + const ::rust::cxxqt1::MaybeLockGuard guard(*this); invokableWrapper(); } MyObject::MyObject(QObject* parent) : QObject(parent) - , ::rust::cxxqtlib1::CxxQtType( + , ::rust::cxxqt1::CxxQtType( ::cxx_qt::my_object::cxx_qt_my_object::createRs()) - , ::rust::cxxqtlib1::CxxQtLocking() + , ::rust::cxxqt1::CxxQtLocking() { } diff --git a/crates/cxx-qt-gen/test_outputs/signals.h b/crates/cxx-qt-gen/test_outputs/signals.h index d5ac7cd7f..a9eb79ebc 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.h +++ b/crates/cxx-qt-gen/test_outputs/signals.h @@ -1,9 +1,9 @@ #pragma once -#include -#include -#include -#include +#include +#include +#include +#include namespace cxx_qt::my_object { class MyObject; @@ -12,22 +12,22 @@ class MyObject; namespace rust::cxxqtgen1::cxx_qt::my_object { using MyObjectCxxQtSignalHandlerready = - ::rust::cxxqtlib1::SignalHandler; + ::rust::cxxqt1::SignalHandler; } // namespace rust::cxxqtgen1::cxx_qt::my_object namespace rust::cxxqtgen1::cxx_qt::my_object { -using MyObjectCxxQtSignalHandlerdataChanged = ::rust::cxxqtlib1::SignalHandler< - struct MyObjectCxxQtSignalParamsdataChanged*>; +using MyObjectCxxQtSignalHandlerdataChanged = + ::rust::cxxqt1::SignalHandler; } // namespace rust::cxxqtgen1::cxx_qt::my_object namespace rust::cxxqtgen1::cxx_qt::my_object { using MyObjectCxxQtSignalHandlernewData = - ::rust::cxxqtlib1::SignalHandler; + ::rust::cxxqt1::SignalHandler; } // namespace rust::cxxqtgen1::cxx_qt::my_object namespace rust::cxxqtgen1::cxx_qt::my_object { using QTimerCxxQtSignalHandlertimeout = - ::rust::cxxqtlib1::SignalHandler; + ::rust::cxxqt1::SignalHandler; } // namespace rust::cxxqtgen1::cxx_qt::my_object #include "cxx-qt-gen/ffi.cxx.h" @@ -69,8 +69,8 @@ MyObject_newDataConnect( namespace cxx_qt::my_object { class MyObject : public QObject - , public ::rust::cxxqtlib1::CxxQtType - , public ::rust::cxxqtlib1::CxxQtLocking + , public ::rust::cxxqt1::CxxQtType + , public ::rust::cxxqt1::CxxQtLocking { Q_OBJECT public: diff --git a/crates/cxx-qt-gen/test_outputs/signals.rs b/crates/cxx-qt-gen/test_outputs/signals.rs index 31c084fbd..02e0e85c1 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.rs +++ b/crates/cxx-qt-gen/test_outputs/signals.rs @@ -7,16 +7,15 @@ mod ffi { } unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt-lib/qt.h"); + include!("cxx-qt/cxxqt_connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] - type ConnectionType = cxx_qt_lib::ConnectionType; - include!("cxx-qt-lib/qmetaobjectconnection.h"); + type ConnectionType = cxx_qt::ConnectionType; #[doc(hidden)] - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] #[rust_name = "CxxQtQMetaObjectConnection"] - type QMetaObjectConnection = cxx_qt_lib::QMetaObjectConnection; + type QMetaObjectConnection = cxx_qt::QMetaObjectConnection; } unsafe extern "C++" { include!("cxx-qt-gen/ffi.cxxqt.h"); @@ -196,19 +195,18 @@ impl ffi::MyObject { #[doc = "Connect the given function pointer to the signal "] #[doc = "ready"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] pub fn connect_ready) + 'static>( self: core::pin::Pin<&mut ffi::MyObject>, mut closure: F, - conn_type: cxx_qt_lib::ConnectionType, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::MyObject_connect_ready( + conn_type: cxx_qt::ConnectionType, + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new( Box::new(closure), ), conn_type, - ) + )) } } impl ffi::MyObject { @@ -217,18 +215,17 @@ impl ffi::MyObject { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] pub fn on_ready) + 'static>( self: core::pin::Pin<&mut ffi::MyObject>, mut closure: F, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::MyObject_connect_ready( + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_ready( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new( Box::new(closure), ), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } #[doc(hidden)] @@ -257,7 +254,6 @@ impl ffi::MyObject { #[doc = "Connect the given function pointer to the signal "] #[doc = "dataChanged"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] pub fn connect_data_changed< F: FnMut( core::pin::Pin<&mut ffi::MyObject>, @@ -269,15 +265,15 @@ impl ffi::MyObject { >( self: core::pin::Pin<&mut ffi::MyObject>, mut closure: F, - conn_type: cxx_qt_lib::ConnectionType, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::MyObject_connect_data_changed( + conn_type: cxx_qt::ConnectionType, + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_data_changed( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new( Box::new(closure), ), conn_type, - ) + )) } } impl ffi::MyObject { @@ -286,7 +282,6 @@ impl ffi::MyObject { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] pub fn on_data_changed< F: FnMut( core::pin::Pin<&mut ffi::MyObject>, @@ -298,14 +293,14 @@ impl ffi::MyObject { >( self: core::pin::Pin<&mut ffi::MyObject>, mut closure: F, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::MyObject_connect_data_changed( + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_data_changed( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new( Box::new(closure), ), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } #[doc(hidden)] @@ -345,7 +340,6 @@ impl ffi::MyObject { #[doc = "Connect the given function pointer to the signal "] #[doc = "newData"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] pub fn connect_base_class_new_data< F: FnMut( core::pin::Pin<&mut ffi::MyObject>, @@ -357,15 +351,15 @@ impl ffi::MyObject { >( self: core::pin::Pin<&mut ffi::MyObject>, mut closure: F, - conn_type: cxx_qt_lib::ConnectionType, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::MyObject_connect_base_class_new_data( + conn_type: cxx_qt::ConnectionType, + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_base_class_new_data( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new( Box::new(closure), ), conn_type, - ) + )) } } impl ffi::MyObject { @@ -374,7 +368,6 @@ impl ffi::MyObject { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] pub fn on_base_class_new_data< F: FnMut( core::pin::Pin<&mut ffi::MyObject>, @@ -386,14 +379,14 @@ impl ffi::MyObject { >( self: core::pin::Pin<&mut ffi::MyObject>, mut closure: F, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::MyObject_connect_base_class_new_data( + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::MyObject_connect_base_class_new_data( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new( Box::new(closure), ), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } #[doc(hidden)] @@ -452,19 +445,18 @@ impl ffi::QTimer { #[doc = "Connect the given function pointer to the signal "] #[doc = "timeout"] #[doc = ", so that when the signal is emitted the function pointer is executed."] - #[must_use] pub fn connect_timeout) + 'static>( self: core::pin::Pin<&mut ffi::QTimer>, mut closure: F, - conn_type: cxx_qt_lib::ConnectionType, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::QTimer_connect_timeout( + conn_type: cxx_qt::ConnectionType, + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::QTimer_connect_timeout( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new( Box::new(closure), ), conn_type, - ) + )) } } impl ffi::QTimer { @@ -473,18 +465,17 @@ impl ffi::QTimer { #[doc = ", so that when the signal is emitted the function pointer is executed."] #[doc = "\n"] #[doc = "Note that this method uses a AutoConnection connection type."] - #[must_use] pub fn on_timeout) + 'static>( self: core::pin::Pin<&mut ffi::QTimer>, mut closure: F, - ) -> cxx_qt_lib::QMetaObjectConnection { - ffi::QTimer_connect_timeout( + ) -> cxx_qt::QMetaObjectConnectionGuard { + cxx_qt::QMetaObjectConnectionGuard::from(ffi::QTimer_connect_timeout( self, cxx_qt::signalhandler::CxxQtSignalHandler::::new( Box::new(closure), ), - cxx_qt_lib::ConnectionType::AutoConnection, - ) + cxx_qt::ConnectionType::AutoConnection, + )) } } #[doc(hidden)] diff --git a/crates/cxx-qt-lib-headers/include/core/qmetaobjectconnection.h b/crates/cxx-qt-lib-headers/include/core/qmetaobjectconnection.h index cb406378d..a0cbd291b 100644 --- a/crates/cxx-qt-lib-headers/include/core/qmetaobjectconnection.h +++ b/crates/cxx-qt-lib-headers/include/core/qmetaobjectconnection.h @@ -6,30 +6,5 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 #pragma once -#include - -#include - -#include "rust/cxx.h" - -// Define namespace otherwise we hit a GCC bug -// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 -namespace rust { - -template<> -struct IsRelocatable<::QMetaObject::Connection> : ::std::true_type -{ -}; - -} // namespace rust - -namespace rust { -namespace cxxqtlib1 { - -using QMetaObjectConnection = ::QMetaObject::Connection; - -void -qmetaobjectconnectionDisconnect(const ::QMetaObject::Connection& conn); - -} -} +// Re-export QMetaObjectConnection from cxx-qt +#include "cxx-qt/cxxqt_connection.h" diff --git a/crates/cxx-qt-lib/Cargo.toml b/crates/cxx-qt-lib/Cargo.toml index 3dd929912..5c0d71887 100644 --- a/crates/cxx-qt-lib/Cargo.toml +++ b/crates/cxx-qt-lib/Cargo.toml @@ -18,6 +18,7 @@ exclude = [ "**/generate.sh" ] [dependencies] cxx.workspace = true +cxx-qt.workspace = true bytes = { version = "1.4", optional = true } chrono = { version = "0.4.27", optional = true } http = { version = "1.0", optional = true } diff --git a/crates/cxx-qt-lib/build.rs b/crates/cxx-qt-lib/build.rs index b71d383b2..fc2d13338 100644 --- a/crates/cxx-qt-lib/build.rs +++ b/crates/cxx-qt-lib/build.rs @@ -68,7 +68,6 @@ fn main() { "core/qmap/qmap_qstring_qvariant", "core/qmargins", "core/qmarginsf", - "core/qmetaobjectconnection", "core/qmodelindex", "core/qpersistentmodelindex", "core/qpoint", @@ -214,7 +213,6 @@ fn main() { "core/qmap/qmap", "core/qmargins", "core/qmarginsf", - "core/qmetaobjectconnection", "core/qmodelindex", "core/qpersistentmodelindex", "core/qpoint", @@ -280,7 +278,7 @@ fn main() { builder.define("CXX_QT_QML_FEATURE", None); } - // Note, ensure our settings stay in sync across cxx-qt-build and cxx-qt-lib + // Note, ensure our settings stay in sync across cxx-qt, cxx-qt-build, and cxx-qt-lib builder.cpp(true); // MSVC builder.flag_if_supported("/std:c++17"); diff --git a/crates/cxx-qt-lib/src/core/mod.rs b/crates/cxx-qt-lib/src/core/mod.rs index cd2d2e315..58214834b 100644 --- a/crates/cxx-qt-lib/src/core/mod.rs +++ b/crates/cxx-qt-lib/src/core/mod.rs @@ -38,8 +38,8 @@ pub use qmargins::QMargins; mod qmarginsf; pub use qmarginsf::QMarginsF; -mod qmetaobjectconnection; -pub use qmetaobjectconnection::QMetaObjectConnection; +// Reexport QMetaObjectConnection and guard from cxx-qt +pub use cxx_qt::{QMetaObjectConnection, QMetaObjectConnectionGuard}; mod qmodelindex; pub use qmodelindex::QModelIndex; diff --git a/crates/cxx-qt-lib/src/core/qmetaobjectconnection.cpp b/crates/cxx-qt-lib/src/core/qmetaobjectconnection.cpp deleted file mode 100644 index 94a7a0b19..000000000 --- a/crates/cxx-qt-lib/src/core/qmetaobjectconnection.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// clang-format off -// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company -// clang-format on -// SPDX-FileContributor: Andrew Hayzen -// -// SPDX-License-Identifier: MIT OR Apache-2.0 -#include "cxx-qt-lib/qmetaobjectconnection.h" - -#include "../assertion_utils.h" - -// ::QMetaObject::Connection is the size of one pointer -// -// https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qobjectdefs.h?h=v5.15.6-lts-lgpl#n620 -// https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qobjectdefs.h?h=v6.2.4#n444 -assert_alignment_and_size(::QMetaObject::Connection, - alignof(::std::size_t), - sizeof(::std::size_t)); - -static_assert( - !::std::is_trivially_destructible<::QMetaObject::Connection>::value); - -namespace rust { -namespace cxxqtlib1 { - -void -qmetaobjectconnectionDisconnect(const ::QMetaObject::Connection& conn) -{ - ::QObject::disconnect(conn); -} - -} -} diff --git a/crates/cxx-qt-lib/src/core/qmetaobjectconnection.rs b/crates/cxx-qt-lib/src/core/qmetaobjectconnection.rs deleted file mode 100644 index 17cfd3b51..000000000 --- a/crates/cxx-qt-lib/src/core/qmetaobjectconnection.rs +++ /dev/null @@ -1,69 +0,0 @@ -// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company -// SPDX-FileContributor: Andrew Hayzen -// -// SPDX-License-Identifier: MIT OR Apache-2.0 -use cxx::{type_id, ExternType}; -use std::mem::MaybeUninit; - -#[cxx::bridge] -mod ffi { - #[namespace = "rust::cxxqtlib1"] - unsafe extern "C++" { - include!("cxx-qt-lib/qmetaobjectconnection.h"); - - #[doc(hidden)] - type QMetaObjectConnection = crate::QMetaObjectConnection; - - #[doc(hidden)] - #[rust_name = "qmetaobjectconnection_disconnect"] - fn qmetaobjectconnectionDisconnect(conn: &QMetaObjectConnection); - } - - #[namespace = "rust::cxxqtlib1"] - unsafe extern "C++" { - include!("cxx-qt-lib/common.h"); - - #[doc(hidden)] - #[rust_name = "qmetaobjectconnection_drop"] - fn drop(conn: &mut QMetaObjectConnection); - } -} - -/// Represents a handle to a signal-slot (or signal-functor) connection. -/// -/// This struct is returned when a connection is made using `on_SIGNAL_NAME`. -/// -/// Note that when this struct is dropped the connection is disconnected. -/// So so keep a connection active either hold onto the struct for the duration -/// that the connection should be active or call `release`. -#[repr(C)] -pub struct QMetaObjectConnection { - _space: MaybeUninit, -} - -impl Drop for QMetaObjectConnection { - /// Disconnect and deconstruct the [QMetaObjectConnection] - fn drop(&mut self) { - ffi::qmetaobjectconnection_disconnect(self); - ffi::qmetaobjectconnection_drop(self); - } -} - -impl QMetaObjectConnection { - /// Release the [QMetaObjectConnection] without disconnecting - pub fn release(mut self) { - // Manually call drop in C++ and then forget - // - // As our Drop implementation disconnects automatically whereas we just want to release - ffi::qmetaobjectconnection_drop(&mut self); - std::mem::forget(self); - } -} - -// Safety: -// -// Static checks on the C++ side to ensure the size is the same. -unsafe impl ExternType for QMetaObjectConnection { - type Id = type_id!("rust::cxxqtlib1::QMetaObjectConnection"); - type Kind = cxx::kind::Trivial; -} diff --git a/crates/cxx-qt-lib/src/core/qt.rs b/crates/cxx-qt-lib/src/core/qt.rs index 3dfaf18dd..6903f64fc 100644 --- a/crates/cxx-qt-lib/src/core/qt.rs +++ b/crates/cxx-qt-lib/src/core/qt.rs @@ -22,25 +22,6 @@ mod ffi { CaseSensitive, } - /// This enum describes the types of connection that can be used with signals. - /// - /// Note that UniqueConnection is not supported. - #[repr(i32)] - enum ConnectionType { - /// If the receiver lives in the thread that emits the signal, Qt::DirectConnection is used. - /// Otherwise, Qt::QueuedConnection is used. The connection type is determined when the signal is emitted. - AutoConnection, - /// The slot is invoked immediately when the signal is emitted. - /// The slot is executed in the signalling thread. - DirectConnection, - /// The slot is invoked when control returns to the event loop of the receiver's thread. - /// The slot is executed in the receiver's thread. - QueuedConnection, - /// Same as Qt::QueuedConnection, except that the signalling thread blocks until the slot returns. - /// This connection must not be used if the receiver lives in the signalling thread, or else the application will deadlock. - BlockingQueuedConnection, - } - #[repr(i32)] enum DateFormat { TextDate = 0, @@ -157,7 +138,6 @@ mod ffi { include!("cxx-qt-lib/qt.h"); type AspectRatioMode; type CaseSensitivity; - type ConnectionType; type DateFormat; type SplitBehaviorFlags; type TimeSpec; @@ -173,7 +153,9 @@ mod ffi { } pub use ffi::{ - AspectRatioMode, BGMode, CaseSensitivity, ClipOperation, ConnectionType, DateFormat, FillRule, - LayoutDirection, PenCapStyle, PenJoinStyle, PenStyle, SplitBehaviorFlags, TimeSpec, - TransformationMode, + AspectRatioMode, BGMode, CaseSensitivity, ClipOperation, DateFormat, FillRule, LayoutDirection, + PenCapStyle, PenJoinStyle, PenStyle, SplitBehaviorFlags, TimeSpec, TransformationMode, }; + +// Reexport ConnectionType from cxx-qt +pub use cxx_qt::ConnectionType; diff --git a/crates/cxx-qt/Cargo.toml b/crates/cxx-qt/Cargo.toml index 463442fa4..b828d3a86 100644 --- a/crates/cxx-qt/Cargo.toml +++ b/crates/cxx-qt/Cargo.toml @@ -22,6 +22,10 @@ cxx.workspace = true cxx-qt-macro.workspace = true static_assertions = "1.1.0" +[build-dependencies] +cxx-build.workspace = true +qt-build-utils.workspace = true + [dev-dependencies] cxx.workspace = true cxx-qt-lib.workspace = true diff --git a/crates/cxx-qt/build.rs b/crates/cxx-qt/build.rs new file mode 100644 index 000000000..08e7f200d --- /dev/null +++ b/crates/cxx-qt/build.rs @@ -0,0 +1,78 @@ +// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company +// SPDX-FileContributor: Andrew Hayzen +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use std::{fs::File, io::Write}; + +fn main() { + let qtbuild = qt_build_utils::QtBuild::new(vec!["Core".to_owned()]) + .expect("Could not find Qt installation"); + + // Required for tests + qt_build_utils::setup_linker(); + + let cpp_files = ["src/cxxqt_connection.cpp"]; + let rust_bridges = ["src/connection.rs"]; + + for bridge in &rust_bridges { + println!("cargo:rerun-if-changed={bridge}"); + } + + let mut builder = cxx_build::bridges(rust_bridges); + + qtbuild.cargo_link_libraries(&mut builder); + + for cpp_file in &cpp_files { + builder.file(cpp_file); + println!("cargo:rerun-if-changed={cpp_file}"); + } + + // Write this library's manually written C++ headers to files and add them to include paths + let out_dir = std::env::var("OUT_DIR").unwrap(); + let directory = format!("{out_dir}/cxx-qt"); + std::fs::create_dir_all(&directory).expect("Could not create cxx-qt header directory"); + // Note we only need cxxqt_connection.h for now, but lets move all headers to be consistent + // ensure src/lib write_headers is consistent + for (file_contents, file_name) in [ + ( + include_str!("include/cxxqt_connection.h"), + "cxxqt_connection.h", + ), + (include_str!("include/cxxqt_locking.h"), "cxxqt_locking.h"), + ( + include_str!("include/cxxqt_maybelockguard.h"), + "cxxqt_maybelockguard.h", + ), + ( + include_str!("include/cxxqt_signalhandler.h"), + "cxxqt_signalhandler.h", + ), + (include_str!("include/cxxqt_thread.h"), "cxxqt_thread.h"), + ( + include_str!("include/cxxqt_threading.h"), + "cxxqt_threading.h", + ), + (include_str!("include/cxxqt_type.h"), "cxxqt_type.h"), + ] { + let h_path = format!("{directory}/{file_name}"); + let mut header = File::create(h_path).expect("Could not create cxx-qt header"); + write!(header, "{file_contents}").expect("Could not write cxx-qt header"); + } + builder.include(out_dir); + builder.includes(qtbuild.include_paths()); + + // Note, ensure our settings stay in sync across cxx-qt, cxx-qt-build, and cxx-qt-lib + builder.cpp(true); + // MSVC + builder.flag_if_supported("/std:c++17"); + builder.flag_if_supported("/Zc:__cplusplus"); + builder.flag_if_supported("/permissive-"); + builder.flag_if_supported("/bigobj"); + // GCC + Clang + builder.flag_if_supported("-std=c++17"); + // MinGW requires big-obj otherwise debug builds fail + builder.flag_if_supported("-Wa,-mbig-obj"); + + builder.compile("cxx-qt"); +} diff --git a/crates/cxx-qt/include/cxxqt_connection.h b/crates/cxx-qt/include/cxxqt_connection.h new file mode 100644 index 000000000..7754573ea --- /dev/null +++ b/crates/cxx-qt/include/cxxqt_connection.h @@ -0,0 +1,40 @@ +// clang-format off +// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company +// clang-format on +// SPDX-FileContributor: Andrew Hayzen +// +// SPDX-License-Identifier: MIT OR Apache-2.0 +#pragma once + +#include +#include + +#include "rust/cxx.h" + +// Define namespace otherwise we hit a GCC bug +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 +namespace rust { + +template<> +struct IsRelocatable<::QMetaObject::Connection> : ::std::true_type +{ +}; + +} // namespace rust + +namespace rust { +namespace cxxqt1 { + +using QMetaObjectConnection = ::QMetaObject::Connection; + +::QMetaObject::Connection +qmetaobjectconnectionDefault(); + +bool +qmetaobjectconnectionDisconnect(const ::QMetaObject::Connection& connection); + +void +qmetaobjectconnectionDrop(::QMetaObject::Connection& connection); + +} +} diff --git a/crates/cxx-qt-gen/include/cxxqt_locking.h b/crates/cxx-qt/include/cxxqt_locking.h similarity index 96% rename from crates/cxx-qt-gen/include/cxxqt_locking.h rename to crates/cxx-qt/include/cxxqt_locking.h index c2f84fa8a..059aee92d 100644 --- a/crates/cxx-qt-gen/include/cxxqt_locking.h +++ b/crates/cxx-qt/include/cxxqt_locking.h @@ -10,7 +10,7 @@ #include #include -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { class CxxQtLocking { diff --git a/crates/cxx-qt-gen/include/cxxqt_maybelockguard.h b/crates/cxx-qt/include/cxxqt_maybelockguard.h similarity index 92% rename from crates/cxx-qt-gen/include/cxxqt_maybelockguard.h rename to crates/cxx-qt/include/cxxqt_maybelockguard.h index 0dc482489..01ad6f3f1 100644 --- a/crates/cxx-qt-gen/include/cxxqt_maybelockguard.h +++ b/crates/cxx-qt/include/cxxqt_maybelockguard.h @@ -7,12 +7,12 @@ #pragma once -#include +#include #include #include #include -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { // An empty implementation of MaybeLockGuard // diff --git a/crates/cxx-qt-gen/include/cxxqt_signalhandler.h b/crates/cxx-qt/include/cxxqt_signalhandler.h similarity index 90% rename from crates/cxx-qt-gen/include/cxxqt_signalhandler.h rename to crates/cxx-qt/include/cxxqt_signalhandler.h index 2a0c641e4..06dd9f7d8 100644 --- a/crates/cxx-qt-gen/include/cxxqt_signalhandler.h +++ b/crates/cxx-qt/include/cxxqt_signalhandler.h @@ -11,7 +11,7 @@ #include "rust/cxx.h" -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { // This represents a Rust Box // @@ -39,14 +39,14 @@ class SignalHandler void* data[2]; }; -} // rust::cxxqtlib1 +} // rust::cxxqt1 // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 namespace rust { template -struct IsRelocatable> +struct IsRelocatable> : ::std::true_type { }; diff --git a/crates/cxx-qt-gen/include/cxxqt_thread.h b/crates/cxx-qt/include/cxxqt_thread.h similarity index 96% rename from crates/cxx-qt-gen/include/cxxqt_thread.h rename to crates/cxx-qt/include/cxxqt_thread.h index 5a0728eb2..8903019ca 100644 --- a/crates/cxx-qt-gen/include/cxxqt_thread.h +++ b/crates/cxx-qt/include/cxxqt_thread.h @@ -17,7 +17,7 @@ #include "rust/cxx.h" namespace rust { -namespace cxxqtlib1 { +namespace cxxqt1 { template class CxxQtGuardedPointer final @@ -115,7 +115,7 @@ cxxQtThreadQueue(const CxxQtThread& cxxQtThread, cxxQtThread.queue(::std::move(func), ::std::move(arg)); } -} // namespace cxxqtlib1 +} // namespace cxxqt1 } // namespace rust // Define namespace otherwise we hit a GCC bug @@ -123,7 +123,7 @@ cxxQtThreadQueue(const CxxQtThread& cxxQtThread, namespace rust { template -struct IsRelocatable<::rust::cxxqtlib1::CxxQtThread> : ::std::true_type +struct IsRelocatable<::rust::cxxqt1::CxxQtThread> : ::std::true_type { }; diff --git a/crates/cxx-qt-gen/include/cxxqt_threading.h b/crates/cxx-qt/include/cxxqt_threading.h similarity index 88% rename from crates/cxx-qt-gen/include/cxxqt_threading.h rename to crates/cxx-qt/include/cxxqt_threading.h index aa2f212ac..86f1eb020 100644 --- a/crates/cxx-qt-gen/include/cxxqt_threading.h +++ b/crates/cxx-qt/include/cxxqt_threading.h @@ -10,10 +10,10 @@ #include #include -#include -#include +#include +#include -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { template class CxxQtThreading : public CxxQtLocking diff --git a/crates/cxx-qt-gen/include/cxxqt_type.h b/crates/cxx-qt/include/cxxqt_type.h similarity index 95% rename from crates/cxx-qt-gen/include/cxxqt_type.h rename to crates/cxx-qt/include/cxxqt_type.h index 29f82fa22..ce1b63b72 100644 --- a/crates/cxx-qt-gen/include/cxxqt_type.h +++ b/crates/cxx-qt/include/cxxqt_type.h @@ -12,7 +12,7 @@ #include "rust/cxx.h" -namespace rust::cxxqtlib1 { +namespace rust::cxxqt1 { template class CxxQtType diff --git a/crates/cxx-qt/src/connection.rs b/crates/cxx-qt/src/connection.rs new file mode 100644 index 000000000..d469aff80 --- /dev/null +++ b/crates/cxx-qt/src/connection.rs @@ -0,0 +1,97 @@ +// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company +// SPDX-FileContributor: Andrew Hayzen +// +// SPDX-License-Identifier: MIT OR Apache-2.0 +use cxx::{type_id, ExternType}; +use std::mem::MaybeUninit; + +#[cxx::bridge] +mod ffi { + #[namespace = "rust::cxxqt1"] + unsafe extern "C++" { + include!("cxx-qt/cxxqt_connection.h"); + + #[doc(hidden)] + type QMetaObjectConnection = crate::QMetaObjectConnection; + + #[doc(hidden)] + #[rust_name = "qmetaobjectconnection_default"] + fn qmetaobjectconnectionDefault() -> QMetaObjectConnection; + + #[doc(hidden)] + #[rust_name = "qmetaobjectconnection_disconnect"] + fn qmetaobjectconnectionDisconnect(connection: &QMetaObjectConnection) -> bool; + + #[doc(hidden)] + #[rust_name = "qmetaobjectconnection_drop"] + fn qmetaobjectconnectionDrop(connection: &mut QMetaObjectConnection); + } + + /// This enum describes the types of connection that can be used with signals. + /// + /// Note that UniqueConnection is not supported. + #[namespace = "Qt"] + #[repr(i32)] + enum ConnectionType { + /// If the receiver lives in the thread that emits the signal, Qt::DirectConnection is used. + /// Otherwise, Qt::QueuedConnection is used. The connection type is determined when the signal is emitted. + AutoConnection, + /// The slot is invoked immediately when the signal is emitted. + /// The slot is executed in the signalling thread. + DirectConnection, + /// The slot is invoked when control returns to the event loop of the receiver's thread. + /// The slot is executed in the receiver's thread. + QueuedConnection, + /// Same as Qt::QueuedConnection, except that the signalling thread blocks until the slot returns. + /// This connection must not be used if the receiver lives in the signalling thread, or else the application will deadlock. + BlockingQueuedConnection, + } + + // We need to tell CXX that the type already exists, otherwise the following error ocucrs + // "scoped/unscoped mismatch in enum" + #[namespace = "Qt"] + unsafe extern "C++" { + type ConnectionType; + } +} + +/// Represents a handle to a signal-slot (or signal-functor) connection. +/// +/// This struct is returned when a connection is made using `on_SIGNAL_NAME`. +/// +/// Note that when this struct is dropped the connection is disconnected. +/// So so keep a connection active either hold onto the struct for the duration +/// that the connection should be active or call `release`. +#[repr(C)] +pub struct QMetaObjectConnection { + _space: MaybeUninit, +} + +impl Default for QMetaObjectConnection { + fn default() -> Self { + ffi::qmetaobjectconnection_default() + } +} + +impl Drop for QMetaObjectConnection { + fn drop(&mut self) { + ffi::qmetaobjectconnection_drop(self); + } +} + +impl QMetaObjectConnection { + /// Disconnect the signal + pub fn disconnect(&self) -> bool { + ffi::qmetaobjectconnection_disconnect(self) + } +} + +// Safety: +// +// Static checks on the C++ side to ensure the size is the same. +unsafe impl ExternType for QMetaObjectConnection { + type Id = type_id!("rust::cxxqt1::QMetaObjectConnection"); + type Kind = cxx::kind::Trivial; +} + +pub use ffi::ConnectionType; diff --git a/crates/cxx-qt/src/connectionguard.rs b/crates/cxx-qt/src/connectionguard.rs new file mode 100644 index 000000000..463b5466c --- /dev/null +++ b/crates/cxx-qt/src/connectionguard.rs @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company +// SPDX-FileContributor: Andrew Hayzen +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use crate::QMetaObjectConnection; + +/// Represents a guard to a signal-slot (or signal-functor) connection. +/// +/// This struct can be created from a [QMetaObjectConnection]. +/// +/// Note that when this struct is dropped the connection is disconnected. +/// So to keep a connection active either hold onto the struct for the duration +/// that the connection should be active or call `release`. +pub struct QMetaObjectConnectionGuard { + connection: QMetaObjectConnection, +} + +impl From for QMetaObjectConnectionGuard { + fn from(connection: QMetaObjectConnection) -> Self { + Self { connection } + } +} + +impl Drop for QMetaObjectConnectionGuard { + /// Disconnect and deconstruct the connection + fn drop(&mut self) { + self.connection.disconnect(); + } +} + +impl QMetaObjectConnectionGuard { + /// Release the connection without disconnecting + pub fn release(mut self) -> QMetaObjectConnection { + // Take the connection as our Drop implementation disconnects automatically + // whereas we just want to release + core::mem::take(&mut self.connection) + } +} diff --git a/crates/cxx-qt/src/cxxqt_connection.cpp b/crates/cxx-qt/src/cxxqt_connection.cpp new file mode 100644 index 000000000..2a35e68fe --- /dev/null +++ b/crates/cxx-qt/src/cxxqt_connection.cpp @@ -0,0 +1,49 @@ +// clang-format off +// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company +// clang-format on +// SPDX-FileContributor: Andrew Hayzen +// +// SPDX-License-Identifier: MIT OR Apache-2.0 +#include "cxx-qt/cxxqt_connection.h" + +#include + +// ::QMetaObject::Connection is the size of one pointer +// +// https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qobjectdefs.h?h=v5.15.6-lts-lgpl#n620 +// https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qobjectdefs.h?h=v6.2.4#n444 +static_assert(alignof(::QMetaObject::Connection) <= (alignof(::std::size_t)), + "unexpectedly large ::QMetaObject::Connection alignment!"); +static_assert(sizeof(::QMetaObject::Connection) == (sizeof(::std::size_t)), + "unexpected ::QMetaObject::Connection size!"); + +static_assert( + !::std::is_trivially_copy_assignable<::QMetaObject::Connection>::value); +static_assert( + !::std::is_trivially_copy_constructible<::QMetaObject::Connection>::value); +static_assert( + !::std::is_trivially_destructible<::QMetaObject::Connection>::value); + +namespace rust { +namespace cxxqt1 { + +::QMetaObject::Connection +qmetaobjectconnectionDefault() +{ + return ::QMetaObject::Connection(); +} + +bool +qmetaobjectconnectionDisconnect(const ::QMetaObject::Connection& connection) +{ + return ::QObject::disconnect(connection); +} + +void +qmetaobjectconnectionDrop(::QMetaObject::Connection& connection) +{ + connection.~QMetaObjectConnection(); +} + +} +} diff --git a/crates/cxx-qt/src/lib.rs b/crates/cxx-qt/src/lib.rs index ef2ffe916..37a5e157a 100644 --- a/crates/cxx-qt/src/lib.rs +++ b/crates/cxx-qt/src/lib.rs @@ -9,6 +9,10 @@ //! //! See the [book](https://kdab.github.io/cxx-qt/book/) for more information. +use std::{fs::File, io::Write, path::Path}; + +mod connection; +mod connectionguard; #[doc(hidden)] pub mod signalhandler; mod threading; @@ -16,6 +20,8 @@ mod threading; pub use cxx_qt_macro::bridge; pub use cxx_qt_macro::qobject; +pub use connection::{ConnectionType, QMetaObjectConnection}; +pub use connectionguard::QMetaObjectConnectionGuard; pub use threading::CxxQtThread; // Export static assertions that can then be used in cxx-qt-gen generation @@ -357,3 +363,42 @@ where Self::initialize(self); } } + +#[doc(hidden)] +// Write the cxx-qt headers to the specified directory. +pub fn write_headers(directory: impl AsRef) { + let directory = directory.as_ref(); + std::fs::create_dir_all(directory).expect("Could not create cxx-qt header directory"); + // Note ensure that the build script is consistent with files that are copied + for (file_contents, file_name) in [ + ( + include_str!("../include/cxxqt_connection.h"), + "cxxqt_connection.h", + ), + ( + include_str!("../include/cxxqt_locking.h"), + "cxxqt_locking.h", + ), + ( + include_str!("../include/cxxqt_maybelockguard.h"), + "cxxqt_maybelockguard.h", + ), + ( + include_str!("../include/cxxqt_signalhandler.h"), + "cxxqt_signalhandler.h", + ), + (include_str!("../include/cxxqt_thread.h"), "cxxqt_thread.h"), + ( + include_str!("../include/cxxqt_threading.h"), + "cxxqt_threading.h", + ), + (include_str!("../include/cxxqt_type.h"), "cxxqt_type.h"), + ] { + // Note that we do not need rerun-if-changed for these files + // as include_str causes a rerun when the header changes + // and the files are always written to the target. + let h_path = format!("{}/{file_name}", directory.display()); + let mut header = File::create(h_path).expect("Could not create cxx-qt header"); + write!(header, "{file_contents}").expect("Could not write cxx-qt header"); + } +} diff --git a/examples/qml_features/rust/src/signals.rs b/examples/qml_features/rust/src/signals.rs index 1289ea8b0..49257fd13 100644 --- a/examples/qml_features/rust/src/signals.rs +++ b/examples/qml_features/rust/src/signals.rs @@ -66,12 +66,12 @@ pub mod qobject { use core::pin::Pin; use cxx_qt::CxxQtType; -use cxx_qt_lib::{ConnectionType, QString, QUrl}; +use cxx_qt_lib::{ConnectionType, QMetaObjectConnectionGuard, QString, QUrl}; /// A QObject which has Q_SIGNALs #[derive(Default)] pub struct RustSignalsRust { - pub(crate) connections: Option<[cxx_qt_lib::QMetaObjectConnection; 3]>, + pub(crate) connections: Option<[QMetaObjectConnectionGuard; 3]>, logging_enabled: bool, } diff --git a/tests/qt_types_standalone/cpp/qmetaobjectconnection.h b/tests/qt_types_standalone/cpp/qmetaobjectconnection.h index da6b61160..b030e2229 100644 --- a/tests/qt_types_standalone/cpp/qmetaobjectconnection.h +++ b/tests/qt_types_standalone/cpp/qmetaobjectconnection.h @@ -35,6 +35,8 @@ private Q_SLOTS: auto handle = QObject::connect( &obj, &MyObject::mySignal, &obj, &MyObject::anotherSignal); + auto guard = create_qmetaobjectconnectionguard(handle); + QSignalSpy mySignalSpy(&obj, &MyObject::mySignal); QSignalSpy anotherSignalSpy(&obj, &MyObject::anotherSignal); QCOMPARE(mySignalSpy.count(), 0); @@ -44,7 +46,7 @@ private Q_SLOTS: QCOMPARE(mySignalSpy.count(), 1); QCOMPARE(anotherSignalSpy.count(), 1); - qmetaobjectconnection_drop(std::move(handle)); + qmetaobjectconnection_drop(*guard); obj.trigger(); QCOMPARE(mySignalSpy.count(), 2); @@ -57,6 +59,8 @@ private Q_SLOTS: auto handle = QObject::connect( &obj, &MyObject::mySignal, &obj, &MyObject::anotherSignal); + auto guard = create_qmetaobjectconnectionguard(handle); + QSignalSpy mySignalSpy(&obj, &MyObject::mySignal); QSignalSpy anotherSignalSpy(&obj, &MyObject::anotherSignal); QCOMPARE(mySignalSpy.count(), 0); @@ -66,10 +70,17 @@ private Q_SLOTS: QCOMPARE(mySignalSpy.count(), 1); QCOMPARE(anotherSignalSpy.count(), 1); - qmetaobjectconnection_release(std::move(handle)); + auto conn = qmetaobjectconnection_release(*guard); obj.trigger(); QCOMPARE(mySignalSpy.count(), 2); QCOMPARE(anotherSignalSpy.count(), 2); + + // Ensure that disconnect still works on the connection + QVERIFY(qmetaobjectconnection_disconnect(conn)); + + obj.trigger(); + QCOMPARE(mySignalSpy.count(), 3); + QCOMPARE(anotherSignalSpy.count(), 2); } }; diff --git a/tests/qt_types_standalone/rust/src/qmetaobjectconnection.rs b/tests/qt_types_standalone/rust/src/qmetaobjectconnection.rs index d3fc93f3a..8976a0edc 100644 --- a/tests/qt_types_standalone/rust/src/qmetaobjectconnection.rs +++ b/tests/qt_types_standalone/rust/src/qmetaobjectconnection.rs @@ -3,26 +3,60 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 -use cxx_qt_lib::QMetaObjectConnection; +use cxx_qt_lib::{QMetaObjectConnection, QMetaObjectConnectionGuard}; #[cxx::bridge] mod qmetaobjectconnection_cxx { - #[namespace = "rust::cxxqtlib1"] + #[namespace = "rust::cxxqt1"] // note that QMetaObjectConnection is reexported unsafe extern "C++" { include!("cxx-qt-lib/qmetaobjectconnection.h"); type QMetaObjectConnection = cxx_qt_lib::QMetaObjectConnection; } extern "Rust" { - fn qmetaobjectconnection_drop(conn: QMetaObjectConnection); - fn qmetaobjectconnection_release(conn: QMetaObjectConnection); + type QMetaObjectConnectionGuardWrapper; + + fn create_qmetaobjectconnectionguard( + conn: QMetaObjectConnection, + ) -> Box; + + fn qmetaobjectconnection_disconnect(conn: &QMetaObjectConnection) -> bool; + fn qmetaobjectconnection_drop(wrapper: &mut QMetaObjectConnectionGuardWrapper); + fn qmetaobjectconnection_release( + wrapper: &mut QMetaObjectConnectionGuardWrapper, + ) -> QMetaObjectConnection; } } -fn qmetaobjectconnection_drop(conn: QMetaObjectConnection) { - drop(conn); +// CXX doesn't support Rust alias so we need to have a new type +struct QMetaObjectConnectionGuardWrapper { + guard: Option, +} + +fn create_qmetaobjectconnectionguard( + conn: QMetaObjectConnection, +) -> Box { + Box::new(QMetaObjectConnectionGuardWrapper { + guard: Some(QMetaObjectConnectionGuard::from(conn)), + }) +} + +fn qmetaobjectconnection_disconnect(conn: &QMetaObjectConnection) -> bool { + conn.disconnect() } -fn qmetaobjectconnection_release(conn: QMetaObjectConnection) { - conn.release(); +fn qmetaobjectconnection_drop(wrapper: &mut QMetaObjectConnectionGuardWrapper) { + if let Some(guard) = wrapper.guard.take() { + drop(guard); + } +} + +fn qmetaobjectconnection_release( + wrapper: &mut QMetaObjectConnectionGuardWrapper, +) -> QMetaObjectConnection { + if let Some(guard) = wrapper.guard.take() { + guard.release() + } else { + unreachable!(); + } }