Skip to content

Commit

Permalink
cxx-qt-gen: remove generation of wrapper for emitting signals
Browse files Browse the repository at this point in the history
This is now unused as the type conversion has been removed.

Related to #289
  • Loading branch information
ahayzen-kdab committed Jun 5, 2023
1 parent 2e41095 commit 0be3a72
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 257 deletions.
59 changes: 4 additions & 55 deletions crates/cxx-qt-gen/src/generator/cpp/property/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mod tests {
assert_str_eq!(generated.metaobjects[1], "Q_PROPERTY(::std::unique_ptr<QColor> opaqueProperty READ getOpaqueProperty WRITE setOpaqueProperty NOTIFY opaquePropertyChanged)");

// methods
assert_eq!(generated.methods.len(), 10);
assert_eq!(generated.methods.len(), 8);
let (header, source) = if let CppFragment::Pair { header, source } = &generated.methods[0] {
(header, source)
} else {
Expand Down Expand Up @@ -191,23 +191,6 @@ mod tests {
} else {
panic!("Expected Pair")
};
assert_str_eq!(header, "void emitTrivialPropertyChanged();");
assert_str_eq!(
source,
indoc! {r#"
void
MyObject::emitTrivialPropertyChanged()
{
Q_EMIT trivialPropertyChanged();
}
"#}
);

let (header, source) = if let CppFragment::Pair { header, source } = &generated.methods[6] {
(header, source)
} else {
panic!("Expected Pair")
};
assert_str_eq!(
header,
"::QMetaObject::Connection trivialPropertyChangedConnect(::rust::Fn<void(MyObject&)> func, ::Qt::ConnectionType type);"
Expand All @@ -229,31 +212,14 @@ mod tests {
"#}
);

let header = if let CppFragment::Header(header) = &generated.methods[7] {
let header = if let CppFragment::Header(header) = &generated.methods[6] {
header
} else {
panic!("Expected header!")
};
assert_str_eq!(header, "Q_SIGNAL void opaquePropertyChanged();");

let (header, source) = if let CppFragment::Pair { header, source } = &generated.methods[8] {
(header, source)
} else {
panic!("Expected Pair")
};
assert_str_eq!(header, "void emitOpaquePropertyChanged();");
assert_str_eq!(
source,
indoc! {r#"
void
MyObject::emitOpaquePropertyChanged()
{
Q_EMIT opaquePropertyChanged();
}
"#}
);

let (header, source) = if let CppFragment::Pair { header, source } = &generated.methods[9] {
let (header, source) = if let CppFragment::Pair { header, source } = &generated.methods[7] {
(header, source)
} else {
panic!("Expected Pair")
Expand Down Expand Up @@ -307,7 +273,7 @@ mod tests {
assert_str_eq!(generated.metaobjects[0], "Q_PROPERTY(A1 mappedProperty READ getMappedProperty WRITE setMappedProperty NOTIFY mappedPropertyChanged)");

// methods
assert_eq!(generated.methods.len(), 5);
assert_eq!(generated.methods.len(), 4);
let (header, source) = if let CppFragment::Pair { header, source } = &generated.methods[0] {
(header, source)
} else {
Expand Down Expand Up @@ -355,23 +321,6 @@ mod tests {
} else {
panic!("Expected Pair")
};
assert_str_eq!(header, "void emitMappedPropertyChanged();");
assert_str_eq!(
source,
indoc! {r#"
void
MyObject::emitMappedPropertyChanged()
{
Q_EMIT mappedPropertyChanged();
}
"#}
);

let (header, source) = if let CppFragment::Pair { header, source } = &generated.methods[4] {
(header, source)
} else {
panic!("Expected Pair")
};
assert_str_eq!(
header,
"::QMetaObject::Connection mappedPropertyChangedConnect(::rust::Fn<void(MyObject&)> func, ::Qt::ConnectionType type);"
Expand Down
85 changes: 4 additions & 81 deletions crates/cxx-qt-gen/src/generator/cpp/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub fn generate_cpp_signals(

// Prepare the idents
let idents = QSignalName::from(signal);
let emit_ident = idents.emit_name.cpp.to_string();
let signal_ident = idents.name.cpp.to_string();
let connect_ident = idents.connect_name.cpp.to_string();

Expand All @@ -53,29 +52,6 @@ pub fn generate_cpp_signals(
)));
}

// Generate the emitters
generated.methods.push(CppFragment::Pair {
header: format!(
"void {ident}({parameters});",
ident = emit_ident,
parameters = parameter_types_cpp.join(", "),
),
source: formatdoc! {
r#"
void
{qobject_ident}::{emit_ident}({parameters})
{{
Q_EMIT {ident}({parameter_values});
}}
"#,
ident = signal_ident,
parameters = parameter_types_cpp.join(", "),
parameter_values = parameter_values_emitter.join(", "),
emit_ident = emit_ident,
qobject_ident = qobject_ident,
},
});

// Generate connection
let mut parameter_types_rust = parameter_types_cpp.clone();
let mut parameter_values_connection = parameter_values_emitter.clone();
Expand Down Expand Up @@ -159,7 +135,7 @@ mod tests {
)
.unwrap();

assert_eq!(generated.methods.len(), 3);
assert_eq!(generated.methods.len(), 2);
let header = if let CppFragment::Header(header) = &generated.methods[0] {
header
} else {
Expand All @@ -175,26 +151,6 @@ mod tests {
} else {
panic!("Expected Pair")
};
assert_str_eq!(
header,
"void emitDataChanged(::std::int32_t trivial, ::std::unique_ptr<QColor> opaque);"
);
assert_str_eq!(
source,
indoc! {r#"
void
MyObject::emitDataChanged(::std::int32_t trivial, ::std::unique_ptr<QColor> opaque)
{
Q_EMIT dataChanged(::std::move(trivial), ::std::move(opaque));
}
"#}
);

let (header, source) = if let CppFragment::Pair { header, source } = &generated.methods[2] {
(header, source)
} else {
panic!("Expected Pair")
};
assert_str_eq!(
header,
"::QMetaObject::Connection dataChangedConnect(::rust::Fn<void(MyObject&, ::std::int32_t trivial, ::std::unique_ptr<QColor> opaque)> func, ::Qt::ConnectionType type);"
Expand Down Expand Up @@ -251,7 +207,7 @@ mod tests {
)
.unwrap();

assert_eq!(generated.methods.len(), 3);
assert_eq!(generated.methods.len(), 2);
let header = if let CppFragment::Header(header) = &generated.methods[0] {
header
} else {
Expand All @@ -264,23 +220,6 @@ mod tests {
} else {
panic!("Expected Pair")
};
assert_str_eq!(header, "void emitDataChanged(A1 mapped);");
assert_str_eq!(
source,
indoc! {r#"
void
MyObject::emitDataChanged(A1 mapped)
{
Q_EMIT dataChanged(::std::move(mapped));
}
"#}
);

let (header, source) = if let CppFragment::Pair { header, source } = &generated.methods[2] {
(header, source)
} else {
panic!("Expected Pair")
};
assert_str_eq!(
header,
"::QMetaObject::Connection dataChangedConnect(::rust::Fn<void(MyObject&, A1 mapped)> func, ::Qt::ConnectionType type);"
Expand Down Expand Up @@ -330,25 +269,9 @@ mod tests {
)
.unwrap();

assert_eq!(generated.methods.len(), 2);
let (header, source) = if let CppFragment::Pair { header, source } = &generated.methods[0] {
(header, source)
} else {
panic!("Expected Pair")
};
assert_str_eq!(header, "void emitBaseName();");
assert_str_eq!(
source,
indoc! {r#"
void
MyObject::emitBaseName()
{
Q_EMIT baseName();
}
"#}
);
assert_eq!(generated.methods.len(), 1);

let (header, source) = if let CppFragment::Pair { header, source } = &generated.methods[1] {
let (header, source) = if let CppFragment::Pair { header, source } = &generated.methods[0] {
(header, source)
} else {
panic!("Expected Pair")
Expand Down
16 changes: 0 additions & 16 deletions crates/cxx-qt-gen/src/generator/naming/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use syn::Ident;
/// Names for parts of a Q_SIGNAL
pub struct QSignalName {
pub name: CombinedIdent,
pub emit_name: CombinedIdent,
pub connect_name: CombinedIdent,
pub on_name: Ident,
}
Expand All @@ -20,7 +19,6 @@ impl From<&ParsedSignal> for QSignalName {
fn from(signal: &ParsedSignal) -> Self {
Self {
name: CombinedIdent::from_signal(&signal.ident),
emit_name: CombinedIdent::emit_from_signal(&signal.ident),
connect_name: CombinedIdent::connect_from_signal(&signal.ident),
on_name: on_from_signal(&signal.ident.rust),
}
Expand All @@ -41,16 +39,6 @@ impl CombinedIdent {
}
}

/// For a given signal ident generate the Rust and C++ emit name
fn emit_from_signal(ident: &CombinedIdent) -> Self {
Self {
cpp: format_ident!("emit{}", ident.cpp.to_string().to_case(Case::Pascal)),
// Note that the Rust emit name is the same name as the signal for now
// in the future this emit wrapper in C++ will be removed.
rust: format_ident!("{}", ident.rust.to_string().to_case(Case::Snake)),
}
}

fn connect_from_signal(ident: &CombinedIdent) -> Self {
Self {
// Use signalConnect instead of onSignal here so that we don't
Expand Down Expand Up @@ -87,8 +75,6 @@ mod tests {
let names = QSignalName::from(&qsignal);
assert_eq!(names.name.cpp, format_ident!("dataChanged"));
assert_eq!(names.name.rust, format_ident!("data_changed"));
assert_eq!(names.emit_name.cpp, format_ident!("emitDataChanged"));
assert_eq!(names.emit_name.rust, format_ident!("data_changed"));
assert_eq!(names.connect_name.cpp, format_ident!("dataChangedConnect"));
assert_eq!(
names.connect_name.rust,
Expand Down Expand Up @@ -118,8 +104,6 @@ mod tests {
let names = QSignalName::from(&qsignal);
assert_eq!(names.name.cpp, format_ident!("baseName"));
assert_eq!(names.name.rust, format_ident!("existing_signal"));
assert_eq!(names.emit_name.cpp, format_ident!("emitBaseName"));
assert_eq!(names.emit_name.rust, format_ident!("existing_signal"));
assert_eq!(names.connect_name.cpp, format_ident!("baseNameConnect"));
assert_eq!(
names.connect_name.rust,
Expand Down
6 changes: 3 additions & 3 deletions crates/cxx-qt-gen/src/generator/rust/property/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ mod tests {
unsafe extern "C++" {
#[doc = "Notify for the Q_PROPERTY"]
#[rust_name = "trivial_property_changed"]
fn emitTrivialPropertyChanged(self: Pin<&mut MyObjectQt>, );
fn trivialPropertyChanged(self: Pin<&mut MyObjectQt>, );
}
},
);
Expand Down Expand Up @@ -418,7 +418,7 @@ mod tests {
unsafe extern "C++" {
#[doc = "Notify for the Q_PROPERTY"]
#[rust_name = "opaque_property_changed"]
fn emitOpaquePropertyChanged(self: Pin<&mut MyObjectQt>, );
fn opaquePropertyChanged(self: Pin<&mut MyObjectQt>, );
}
},
);
Expand Down Expand Up @@ -459,7 +459,7 @@ mod tests {
unsafe extern "C++" {
#[doc = "Notify for the Q_PROPERTY"]
#[rust_name = "unsafe_property_changed"]
fn emitUnsafePropertyChanged(self: Pin<&mut MyObjectQt>, );
fn unsafePropertyChanged(self: Pin<&mut MyObjectQt>, );
}
},
);
Expand Down
24 changes: 12 additions & 12 deletions crates/cxx-qt-gen/src/generator/rust/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ pub fn generate_rust_signals(
// Create the methods for the other signals
for signal in signals {
let idents = QSignalName::from(signal);
let signal_ident_cpp_str = idents.name.cpp.to_string();
let emit_ident_cpp = &idents.emit_name.cpp;
let emit_ident_rust_str = idents.emit_name.rust.to_string();
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();
Expand Down Expand Up @@ -72,18 +73,17 @@ pub fn generate_rust_signals(

let fragment = RustFragmentPair {
cxx_bridge: vec![
// TODO: this will not call our wrapper in the future
quote! {
#unsafe_block extern "C++" {
#(#attrs)*
#[rust_name = #emit_ident_rust_str]
#unsafe_call fn #emit_ident_cpp(self: #self_type, #(#parameters),*);
#[rust_name = #signal_name_rust_str]
#unsafe_call fn #signal_name_cpp(self: #self_type, #(#parameters),*);
}
},
quote! {
unsafe extern "C++" {
#[doc = "Connect the given function pointer to the signal "]
#[doc = #signal_ident_cpp_str]
#[doc = #signal_name_cpp_str]
#[doc = ", so that when the signal is emitted the function pointer is executed."]
#[must_use]
#[rust_name = #connect_ident_rust_str]
Expand All @@ -96,7 +96,7 @@ pub fn generate_rust_signals(
implementation: vec![quote! {
impl #qobject_name {
#[doc = "Connect the given function pointer to the signal "]
#[doc = #signal_ident_cpp_str]
#[doc = #signal_name_cpp_str]
#[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."]
Expand Down Expand Up @@ -158,7 +158,7 @@ mod tests {
quote! {
unsafe extern "C++" {
#[rust_name = "ready"]
fn emitReady(self: Pin<&mut MyObjectQt>, );
fn ready(self: Pin<&mut MyObjectQt>, );
}
},
);
Expand Down Expand Up @@ -233,7 +233,7 @@ mod tests {
unsafe extern "C++" {
#[attribute]
#[rust_name = "data_changed"]
fn emitDataChanged(self: Pin<&mut MyObjectQt>, trivial: i32, opaque: UniquePtr<QColor>);
fn dataChanged(self: Pin<&mut MyObjectQt>, trivial: i32, opaque: UniquePtr<QColor>);
}
},
);
Expand Down Expand Up @@ -300,7 +300,7 @@ mod tests {
quote! {
extern "C++" {
#[rust_name = "unsafe_signal"]
unsafe fn emitUnsafeSignal(self: Pin<&mut MyObjectQt>, param: *mut T);
unsafe fn unsafeSignal(self: Pin<&mut MyObjectQt>, param: *mut T);
}
},
);
Expand Down Expand Up @@ -366,7 +366,7 @@ mod tests {
unsafe extern "C++" {
#[inherit]
#[rust_name = "existing_signal"]
fn emitBaseName(self: Pin<&mut MyObjectQt>, );
fn baseName(self: Pin<&mut MyObjectQt>, );
}
},
);
Expand Down
Loading

0 comments on commit 0be3a72

Please sign in to comment.