Skip to content

Commit

Permalink
cxx-qt-gen: remove String and &str as types for now, use QString instead
Browse files Browse the repository at this point in the history
For now remove Rust's strings as supported types as these need to
go through the UTF conversion. Instead require the developer to
invoke the conversion themselves. Once pattern matching is removed
we can support CxxString etc.
  • Loading branch information
ahayzen-kdab authored and Be-ing committed Aug 2, 2022
1 parent 933bd9a commit 031dfc3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 31 deletions.
4 changes: 0 additions & 4 deletions cxx-qt-gen/src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ pub(crate) enum QtTypes {
QRectF,
QSize,
QSizeF,
String,
Str,
QString,
QTime,
QUrl,
Expand Down Expand Up @@ -252,8 +250,6 @@ fn extract_qt_type(
"QRectF" => Ok(QtTypes::QRectF),
"QSize" => Ok(QtTypes::QSize),
"QSizeF" => Ok(QtTypes::QSizeF),
"str" => Ok(QtTypes::Str),
"String" => Ok(QtTypes::String),
"QString" => Ok(QtTypes::QString),
"QTime" => Ok(QtTypes::QTime),
"QUrl" => Ok(QtTypes::QUrl),
Expand Down
10 changes: 4 additions & 6 deletions cxx-qt-gen/src/gen_cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ impl CppType for QtTypes {
Self::QRectF => vec!["#include <QtCore/QRectF>".to_owned()],
Self::QSize => vec!["#include <QtCore/QSize>".to_owned()],
Self::QSizeF => vec!["#include <QtCore/QSizeF>".to_owned()],
Self::String | Self::Str | Self::QString => {
vec!["#include <QtCore/QString>".to_owned()]
}
Self::QString => vec!["#include <QtCore/QString>".to_owned()],
Self::QTime => vec!["#include <QtCore/QTime>".to_owned()],
Self::QUrl => vec!["#include <QtCore/QUrl>".to_owned()],
Self::QVariant => vec!["#include <QtCore/QVariant>".to_owned()],
Expand Down Expand Up @@ -120,7 +118,7 @@ impl CppType for QtTypes {
Self::QRectF => true,
Self::QSize => true,
Self::QSizeF => true,
Self::Str | Self::String | Self::QString => true,
Self::QString => true,
Self::QTime => true,
Self::QUrl => true,
Self::QVariant => true,
Expand Down Expand Up @@ -170,7 +168,7 @@ impl CppType for QtTypes {
Self::QRectF => true,
Self::QSize => true,
Self::QSizeF => true,
Self::Str | Self::String | Self::QString => true,
Self::QString => true,
Self::QTime => true,
Self::QUrl => true,
Self::QVariant => true,
Expand Down Expand Up @@ -211,7 +209,7 @@ impl CppType for QtTypes {
Self::QRectF => "QRectF",
Self::QSize => "QSize",
Self::QSizeF => "QSizeF",
Self::Str | Self::String | Self::QString => "QString",
Self::QString => "QString",
Self::QTime => "QTime",
Self::QUrl => "QUrl",
Self::QVariant => "QVariant",
Expand Down
23 changes: 2 additions & 21 deletions cxx-qt-gen/src/gen_rs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl RustType for QtTypes {
Self::QSize => true,
Self::QSizeF => true,
Self::QTime => true,
Self::String | Self::Str | Self::QString => true,
Self::QString => true,
Self::QUrl => true,
Self::QVariant => true,
Self::UniquePtr { .. } => true,
Expand Down Expand Up @@ -70,8 +70,6 @@ impl RustType for QtTypes {
Self::QRectF => format_ident!("QRectF"),
Self::QSize => format_ident!("QSize"),
Self::QSizeF => format_ident!("QSizeF"),
Self::Str => format_ident!("QString"),
Self::String => format_ident!("QString"),
Self::QString => format_ident!("QString"),
Self::QTime => format_ident!("QTime"),
Self::QUrl => format_ident!("QUrl"),
Expand Down Expand Up @@ -113,14 +111,6 @@ impl RustType for QtTypes {
Self::QRectF => quote! {cxx_qt_lib::QRectF},
Self::QSize => quote! {cxx_qt_lib::QSize},
Self::QSizeF => quote! {cxx_qt_lib::QSizeF},
Self::Str => match target_type {
TargetType::Cpp => quote! {cxx_qt_lib::QString},
TargetType::Rust => quote! {str},
},
Self::String => match target_type {
TargetType::Cpp => quote! {cxx_qt_lib::QString},
TargetType::Rust => quote! {String},
},
Self::QString => match target_type {
TargetType::Cpp => quote! {cxx_qt_lib::QString},
TargetType::Rust => quote! {cxx_qt_lib::QString},
Expand Down Expand Up @@ -692,15 +682,6 @@ fn generate_property_methods_rs(obj: &QObject) -> Result<Vec<TokenStream>, Token
// Generate a setter using the rust ident
let setter_ident = &setter.rust_ident;
if qt_type.is_opaque() {
// Special case where instead of generating &String
// we use &str as the input for setter methods.
//
// FIXME: can we make this generic in the RustType trait somewhere?
let rust_param_type = match qt_type {
QtTypes::String => quote! {&str},
_others => rust_param_type,
};

property_methods.push(quote! {
pub fn #setter_ident(&mut self, value: #rust_param_type) {
self.cpp.as_mut().#cpp_setter_ident(&value);
Expand Down Expand Up @@ -1098,7 +1079,7 @@ pub fn generate_qobject_rs(
let field_name = field_ident.clone();
let setter_name = format_ident!("set_{}", field_name);

if qt_type.is_opaque() && !matches!(qt_type, QtTypes::String | QtTypes::Str) {
if qt_type.is_opaque() {
grab_values.push(quote! {
self.#setter_name(data.#field_name.as_ref().unwrap());
});
Expand Down

0 comments on commit 031dfc3

Please sign in to comment.