diff --git a/crates/cxx-qt-gen/src/generator/naming/signals.rs b/crates/cxx-qt-gen/src/generator/naming/signals.rs index 9ca8d2b59..223fd5351 100644 --- a/crates/cxx-qt-gen/src/generator/naming/signals.rs +++ b/crates/cxx-qt-gen/src/generator/naming/signals.rs @@ -4,7 +4,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use crate::generator::naming::CombinedIdent; use crate::parser::signals::ParsedSignal; -use convert_case::{Case, Casing}; use quote::format_ident; use syn::Ident; @@ -26,7 +25,7 @@ impl From<&ParsedSignal> for QSignalName { } fn on_from_signal(ident: &Ident) -> Ident { - format_ident!("on_{}", ident.to_string().to_case(Case::Snake)) + format_ident!("on_{}", ident.to_string()) } impl CombinedIdent { @@ -34,8 +33,8 @@ impl CombinedIdent { Self { // Use signalConnect instead of onSignal here so that we don't // create a C++ name that is similar to the QML naming scheme for signals - cpp: format_ident!("{}Connect", ident.cpp.to_string().to_case(Case::Camel)), - rust: format_ident!("connect_{}", ident.rust.to_string().to_case(Case::Snake)), + cpp: format_ident!("{}Connect", ident.cpp.to_string()), + rust: format_ident!("connect_{}", ident.rust.to_string()), } } } 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 e1215ceda..8bea72719 100644 --- a/crates/cxx-qt-gen/src/generator/rust/property/mod.rs +++ b/crates/cxx-qt-gen/src/generator/rust/property/mod.rs @@ -264,8 +264,8 @@ mod tests { parse_quote! { unsafe extern "C++" { #[doc = "Notify for the Q_PROPERTY"] - #[rust_name = "trivial_property_changed"] - fn trivialPropertyChanged(self: Pin<&mut MyObject>, ); + #[cxx_name = "trivialPropertyChanged"] + fn trivial_property_changed(self: Pin<&mut MyObject>); } }, ); @@ -305,8 +305,8 @@ mod tests { parse_quote! { unsafe extern "C++" { #[doc = "Notify for the Q_PROPERTY"] - #[rust_name = "opaque_property_changed"] - fn opaquePropertyChanged(self: Pin<&mut MyObject>, ); + #[cxx_name = "opaquePropertyChanged"] + fn opaque_property_changed(self: Pin<&mut MyObject>); } }, ); @@ -346,8 +346,8 @@ mod tests { parse_quote! { unsafe extern "C++" { #[doc = "Notify for the Q_PROPERTY"] - #[rust_name = "unsafe_property_changed"] - fn unsafePropertyChanged(self: Pin<&mut MyObject>, ); + #[cxx_name = "unsafePropertyChanged"] + fn unsafe_property_changed(self: Pin<&mut MyObject>); } }, ); diff --git a/crates/cxx-qt-gen/src/generator/rust/property/signal.rs b/crates/cxx-qt-gen/src/generator/rust/property/signal.rs index 1611e754a..60a974c6b 100644 --- a/crates/cxx-qt-gen/src/generator/rust/property/signal.rs +++ b/crates/cxx-qt-gen/src/generator/rust/property/signal.rs @@ -14,9 +14,11 @@ pub fn generate(idents: &QPropertyName, qobject_idents: &QObjectName) -> ParsedS // We build our signal in the generation phase as we need to use the naming // structs to build the signal name let cpp_class_rust = &qobject_idents.cpp_class.rust; + let notify_cpp_str = idents.notify.cpp.to_string(); let notify_rust = &idents.notify.rust; let method: ForeignItemFn = syn::parse_quote! { #[doc = "Notify for the Q_PROPERTY"] + #[cxx_name = #notify_cpp_str] fn #notify_rust(self: Pin<&mut #cpp_class_rust>); }; ParsedSignal::from_property_method( diff --git a/crates/cxx-qt-gen/src/generator/rust/signals.rs b/crates/cxx-qt-gen/src/generator/rust/signals.rs index 4891d14cd..78251c422 100644 --- a/crates/cxx-qt-gen/src/generator/rust/signals.rs +++ b/crates/cxx-qt-gen/src/generator/rust/signals.rs @@ -27,14 +27,13 @@ pub fn generate_rust_signals( // Create the methods for the other signals for signal in signals { let idents = QSignalName::from(signal); - let signal_name_rust = idents.name.rust; - let signal_name_rust_str = signal_name_rust.to_string(); let signal_name_cpp = idents.name.cpp; let signal_name_cpp_str = signal_name_cpp.to_string(); let connect_ident_cpp = idents.connect_name.cpp; let connect_ident_rust = idents.connect_name.rust; let connect_ident_rust_str = connect_ident_rust.to_string(); let on_ident_rust = idents.on_name; + let original_method = &signal.method; let parameters_cxx: Vec = signal .parameters @@ -73,15 +72,11 @@ pub fn generate_rust_signals( std::mem::swap(&mut unsafe_call, &mut unsafe_block); } - let attrs = &signal.method.attrs; - let fragment = RustFragmentPair { cxx_bridge: vec![ quote! { #unsafe_block extern "C++" { - #(#attrs)* - #[rust_name = #signal_name_rust_str] - #unsafe_call fn #signal_name_cpp(self: #self_type_cxx, #(#parameters_cxx),*); + #original_method } }, quote! { @@ -164,8 +159,7 @@ mod tests { &generated.cxx_mod_contents[0], quote! { unsafe extern "C++" { - #[rust_name = "ready"] - fn ready(self: Pin<&mut MyObject>, ); + fn ready(self: Pin<&mut MyObject>); } }, ); @@ -206,6 +200,7 @@ mod tests { let qsignal = ParsedSignal { method: parse_quote! { #[attribute] + #[cxx_name = "dataChanged"] fn data_changed(self: Pin<&mut MyObject>, trivial: i32, opaque: UniquePtr); }, qobject_ident: format_ident!("MyObject"), @@ -244,8 +239,8 @@ mod tests { quote! { unsafe extern "C++" { #[attribute] - #[rust_name = "data_changed"] - fn dataChanged(self: Pin<&mut MyObject>, trivial: i32, opaque: UniquePtr); + #[cxx_name = "dataChanged"] + fn data_changed(self: Pin<&mut MyObject>, trivial: i32, opaque: UniquePtr); } }, ); @@ -285,6 +280,7 @@ mod tests { fn test_generate_rust_signal_unsafe() { let qsignal = ParsedSignal { method: parse_quote! { + #[cxx_name = "unsafeSignal"] unsafe fn unsafe_signal(self: Pin<&mut MyObject>, param: *mut T); }, qobject_ident: format_ident!("MyObject"), @@ -316,8 +312,8 @@ mod tests { &generated.cxx_mod_contents[0], quote! { extern "C++" { - #[rust_name = "unsafe_signal"] - unsafe fn unsafeSignal(self: Pin<&mut MyObject>, param: *mut T); + #[cxx_name = "unsafeSignal"] + unsafe fn unsafe_signal(self: Pin<&mut MyObject>, param: *mut T); } }, ); @@ -358,6 +354,7 @@ mod tests { let qsignal = ParsedSignal { method: parse_quote! { #[inherit] + #[cxx_name = "baseName"] fn existing_signal(self: Pin<&mut MyObject>, ); }, qobject_ident: format_ident!("MyObject"), @@ -387,8 +384,8 @@ mod tests { quote! { unsafe extern "C++" { #[inherit] - #[rust_name = "existing_signal"] - fn baseName(self: Pin<&mut MyObject>, ); + #[cxx_name = "baseName"] + fn existing_signal(self: Pin<&mut MyObject>, ); } }, ); diff --git a/crates/cxx-qt-gen/test_inputs/signals.rs b/crates/cxx-qt-gen/test_inputs/signals.rs index ca53aecc4..7e2ac7a4f 100644 --- a/crates/cxx-qt-gen/test_inputs/signals.rs +++ b/crates/cxx-qt-gen/test_inputs/signals.rs @@ -11,10 +11,11 @@ mod ffi { type MyObject = super::MyObjectRust; #[qsignal] - fn ready(self: Pin<&mut MyObject>); + fn dataReady(self: Pin<&mut MyObject>); #[qsignal] - fn data_changed( + #[rust_name = "data_changed"] + fn dataChanged( self: Pin<&mut MyObject>, first: i32, second: UniquePtr, 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 b2ec89912..d52519ab6 100644 --- a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs +++ b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs @@ -84,8 +84,8 @@ pub mod ffi { } unsafe extern "C++" { #[doc = "Notify for the Q_PROPERTY"] - #[rust_name = "property_name_changed"] - fn propertyNameChanged(self: Pin<&mut MyObject>); + #[cxx_name = "propertyNameChanged"] + fn property_name_changed(self: Pin<&mut MyObject>); } unsafe extern "C++" { #[doc = "Connect the given function pointer to the signal "] @@ -105,7 +105,6 @@ pub mod ffi { fn invokable_name(self: Pin<&mut MyObject>); } unsafe extern "C++" { - #[rust_name = "ready"] fn ready(self: Pin<&mut MyObject>); } unsafe extern "C++" { @@ -158,8 +157,8 @@ pub mod ffi { } unsafe extern "C++" { #[doc = "Notify for the Q_PROPERTY"] - #[rust_name = "property_name_changed"] - fn propertyNameChanged(self: Pin<&mut SecondObject>); + #[cxx_name = "propertyNameChanged"] + fn property_name_changed(self: Pin<&mut SecondObject>); } unsafe extern "C++" { #[doc = "Connect the given function pointer to the signal "] @@ -180,7 +179,6 @@ pub mod ffi { } unsafe extern "C++" { #[my_attribute] - #[rust_name = "ready"] fn ready(self: Pin<&mut SecondObject>); } unsafe extern "C++" { diff --git a/crates/cxx-qt-gen/test_outputs/properties.rs b/crates/cxx-qt-gen/test_outputs/properties.rs index 206125dba..db2db230d 100644 --- a/crates/cxx-qt-gen/test_outputs/properties.rs +++ b/crates/cxx-qt-gen/test_outputs/properties.rs @@ -52,8 +52,8 @@ mod ffi { } unsafe extern "C++" { #[doc = "Notify for the Q_PROPERTY"] - #[rust_name = "primitive_changed"] - fn primitiveChanged(self: Pin<&mut MyObject>); + #[cxx_name = "primitiveChanged"] + fn primitive_changed(self: Pin<&mut MyObject>); } unsafe extern "C++" { #[doc = "Connect the given function pointer to the signal "] @@ -69,8 +69,8 @@ mod ffi { } unsafe extern "C++" { #[doc = "Notify for the Q_PROPERTY"] - #[rust_name = "trivial_changed"] - fn trivialChanged(self: Pin<&mut MyObject>); + #[cxx_name = "trivialChanged"] + fn trivial_changed(self: Pin<&mut MyObject>); } unsafe extern "C++" { #[doc = "Connect the given function pointer to the signal "] diff --git a/crates/cxx-qt-gen/test_outputs/signals.cpp b/crates/cxx-qt-gen/test_outputs/signals.cpp index 7dbb1dcfc..bbb859dd9 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.cpp +++ b/crates/cxx-qt-gen/test_outputs/signals.cpp @@ -9,12 +9,12 @@ MyObject::invokable() } ::QMetaObject::Connection -MyObject::readyConnect(::rust::Fn func, - ::Qt::ConnectionType type) +MyObject::dataReadyConnect(::rust::Fn func, + ::Qt::ConnectionType type) { return ::QObject::connect( this, - &MyObject::ready, + &MyObject::dataReady, this, [&, func = ::std::move(func)]() { const ::rust::cxxqtlib1::MaybeLockGuard guard(*this); diff --git a/crates/cxx-qt-gen/test_outputs/signals.h b/crates/cxx-qt-gen/test_outputs/signals.h index 8c3babd25..b36b3e776 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.h +++ b/crates/cxx-qt-gen/test_outputs/signals.h @@ -23,9 +23,9 @@ class MyObject public: Q_INVOKABLE void invokable(); - Q_SIGNAL void ready(); - ::QMetaObject::Connection readyConnect(::rust::Fn func, - ::Qt::ConnectionType type); + Q_SIGNAL void dataReady(); + ::QMetaObject::Connection dataReadyConnect(::rust::Fn func, + ::Qt::ConnectionType type); Q_SIGNAL void dataChanged(::std::int32_t first, ::std::unique_ptr second, QPoint third, diff --git a/crates/cxx-qt-gen/test_outputs/signals.rs b/crates/cxx-qt-gen/test_outputs/signals.rs index 1413f9fe8..b212007ec 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.rs +++ b/crates/cxx-qt-gen/test_outputs/signals.rs @@ -40,16 +40,15 @@ mod ffi { fn invokable(self: Pin<&mut MyObject>); } unsafe extern "C++" { - #[rust_name = "ready"] - fn ready(self: Pin<&mut MyObject>); + fn dataReady(self: Pin<&mut MyObject>); } unsafe extern "C++" { #[doc = "Connect the given function pointer to the signal "] - #[doc = "ready"] + #[doc = "dataReady"] #[doc = ", so that when the signal is emitted the function pointer is executed."] #[must_use] - #[rust_name = "connect_ready"] - fn readyConnect( + #[rust_name = "connect_dataReady"] + fn dataReadyConnect( self: Pin<&mut MyObject>, func: fn(Pin<&mut MyObject>), conn_type: CxxQtConnectionType, @@ -85,8 +84,7 @@ mod ffi { } unsafe extern "C++" { #[cxx_name = "newData"] - #[rust_name = "base_class_new_data"] - fn newData( + fn base_class_new_data( self: Pin<&mut MyObject>, first: i32, second: UniquePtr, @@ -130,16 +128,16 @@ mod ffi { } impl ffi::MyObject { #[doc = "Connect the given function pointer to the signal "] - #[doc = "ready"] + #[doc = "dataReady"] #[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( + pub fn on_dataReady( self: core::pin::Pin<&mut ffi::MyObject>, func: fn(core::pin::Pin<&mut ffi::MyObject>), ) -> cxx_qt_lib::QMetaObjectConnection { - self.connect_ready(func, cxx_qt_lib::ConnectionType::AutoConnection) + self.connect_dataReady(func, cxx_qt_lib::ConnectionType::AutoConnection) } } impl ffi::MyObject { diff --git a/examples/demo_threading/rust/src/lib.rs b/examples/demo_threading/rust/src/lib.rs index a726da8ee..f46e62de0 100644 --- a/examples/demo_threading/rust/src/lib.rs +++ b/examples/demo_threading/rust/src/lib.rs @@ -32,12 +32,15 @@ pub mod qobject { unsafe extern "RustQt" { /// A new sensor has been detected #[qsignal] + #[cxx_name = "sensorAdded"] fn sensor_added(self: Pin<&mut EnergyUsage>, uuid: QString); /// A value on an existing sensor has changed #[qsignal] + #[cxx_name = "sensorChanged"] fn sensor_changed(self: Pin<&mut EnergyUsage>, uuid: QString); /// An existing sensor has been removed #[qsignal] + #[cxx_name = "sensorRemoved"] fn sensor_removed(self: Pin<&mut EnergyUsage>, uuid: QString); } diff --git a/examples/qml_features/rust/src/custom_base_class.rs b/examples/qml_features/rust/src/custom_base_class.rs index 7b6cfb1a1..031db533f 100644 --- a/examples/qml_features/rust/src/custom_base_class.rs +++ b/examples/qml_features/rust/src/custom_base_class.rs @@ -69,6 +69,7 @@ pub mod qobject { /// Inherit the DataChanged signal from the QAbstractListModel base class #[inherit] #[qsignal] + #[cxx_name = "dataChanged"] fn data_changed( self: Pin<&mut CustomBaseClass>, top_left: &QModelIndex,