Skip to content

Commit 6493b93

Browse files
ahayzen-kdabBe-ing
authored andcommitted
cxx-qt-gen: do not remove CXX attributes from original signal method
This allows us later to pass through the original method in the generation. Related to KDAB#662
1 parent 746fb7a commit 6493b93

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

crates/cxx-qt-gen/src/parser/signals.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// SPDX-License-Identifier: MIT OR Apache-2.0
55

66
use crate::parser::parameter::ParsedFunctionParameter;
7-
use crate::syntax::attribute::attribute_take_path;
7+
use crate::syntax::attribute::{attribute_find_path, attribute_take_path};
88
use crate::syntax::expr::expr_to_string;
99
use crate::syntax::foreignmod;
1010
use crate::syntax::safety::Safety;
@@ -70,10 +70,17 @@ impl ParsedSignal {
7070

7171
let mut ident = CombinedIdent::from_rust_function(method.sig.ident.clone());
7272

73-
if let Some(attr) = attribute_take_path(&mut method.attrs, &["cxx_name"]) {
73+
if let Some(index) = attribute_find_path(&method.attrs, &["cxx_name"]) {
7474
ident.cpp = format_ident!(
7575
"{}",
76-
expr_to_string(&attr.meta.require_name_value()?.value)?
76+
expr_to_string(&method.attrs[index].meta.require_name_value()?.value)?
77+
);
78+
}
79+
80+
if let Some(index) = attribute_find_path(&method.attrs, &["rust_name"]) {
81+
ident.rust = format_ident!(
82+
"{}",
83+
expr_to_string(&method.attrs[index].meta.require_name_value()?.value)?
7784
);
7885
}
7986

@@ -130,6 +137,7 @@ mod tests {
130137
let signal = ParsedSignal::parse(method, Safety::Safe).unwrap();
131138

132139
let expected_method: ForeignItemFn = parse_quote! {
140+
#[cxx_name = "cppReady"]
133141
fn ready(self: Pin<&mut MyObject>);
134142
};
135143
assert_eq!(signal.method, expected_method);

crates/cxx-qt-gen/test_outputs/signals.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ mod ffi {
8484
) -> CxxQtQMetaObjectConnection;
8585
}
8686
unsafe extern "C++" {
87+
#[cxx_name = "newData"]
8788
#[rust_name = "base_class_new_data"]
8889
fn newData(
8990
self: Pin<&mut MyObject>,

0 commit comments

Comments
 (0)