Skip to content

Commit aad8060

Browse files
BenFordTytheringtonahayzen-kdab
authored andcommitted
Remove use of convert_case
1 parent 190ade0 commit aad8060

File tree

7 files changed

+19
-53
lines changed

7 files changed

+19
-53
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ cc = { version = "1.0.89", features = ["parallel"] }
5050
cxx = "1.0.95"
5151
cxx-build = { version = "1.0.95", features = [ "parallel" ] }
5252
cxx-gen = "0.7.121"
53-
convert_case = "0.6"
5453
proc-macro2 = "1.0"
5554
syn = { version = "2.0", features = ["extra-traits", "full"] }
5655
quote = "1.0"

crates/cxx-qt-gen/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ exclude = ["update_expected.sh"]
2222
proc-macro2.workspace = true
2323
syn.workspace = true
2424
quote.workspace = true
25-
convert_case.workspace = true
2625
clang-format = "0.3"
2726
indoc = "2.0"
2827

crates/cxx-qt-gen/src/naming/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ mod name;
1616
pub(crate) mod rust;
1717
mod type_names;
1818

19-
pub use name::{AutoCamel, Name};
19+
pub use name::Name;
2020
pub use type_names::TypeNames;

crates/cxx-qt-gen/src/naming/name.rs

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,9 @@
44
// SPDX-License-Identifier: MIT OR Apache-2.0
55

66
use crate::syntax::{attribute::attribute_get_path, expr::expr_to_string};
7-
use convert_case::{Case, Casing};
87
use quote::format_ident;
98
use syn::{spanned::Spanned, Attribute, Error, Ident, Path, Result};
109

11-
pub enum AutoCamel {
12-
Enabled,
13-
Disabled,
14-
}
15-
16-
impl AutoCamel {
17-
pub fn as_bool(&self) -> bool {
18-
match self {
19-
AutoCamel::Enabled => true,
20-
AutoCamel::Disabled => false,
21-
}
22-
}
23-
}
24-
2510
/// This struct contains all names a certain syntax element may have
2611
///
2712
/// This includes the rust_name, cxx_name, as well as qualifications like
@@ -144,35 +129,18 @@ impl Name {
144129
namespace,
145130
module: module.cloned().map(Path::from),
146131
}
147-
.with_options(cxx_name, rust_name, AutoCamel::Disabled))
132+
.with_options(cxx_name, rust_name))
148133
}
149134

150135
/// Applies naming options to an existing name, applying logic about what should cause renaming
151-
pub fn with_options(
152-
self,
153-
cxx: Option<String>,
154-
rust: Option<Ident>,
155-
auto_camel: AutoCamel,
156-
) -> Self {
157-
let mut cxx_ident = cxx.clone();
158-
let rust_ident = if let Some(rust_ident) = rust {
159-
// If we have a rust_name, but no cxx_name, the original ident is the cxx_name.
160-
if cxx.is_none() {
161-
cxx_ident = Some(self.rust.to_string());
162-
};
163-
164-
rust_ident
136+
pub fn with_options(self, cxx: Option<String>, rust: Option<Ident>) -> Self {
137+
let cxx_ident = if cxx.is_none() && rust.is_some() {
138+
Some(self.rust.to_string())
165139
} else {
166-
// If we have no rust_name and no cxx_name, the original ident is the cxx_name ONLY if auto converting.
167-
// Otherwise it stays as the original cxx Option
168-
if cxx.is_none() && auto_camel.as_bool() {
169-
cxx_ident = Some(self.rust.to_string().to_case(Case::Camel));
170-
}
171-
self.rust.clone()
140+
cxx.clone()
172141
};
173-
174142
Self {
175-
rust: rust_ident,
143+
rust: rust.unwrap_or_else(|| self.rust.clone()),
176144
cxx: cxx_ident,
177145
..self
178146
}

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

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

6-
use crate::naming::{AutoCamel, Name};
6+
use crate::naming::Name;
77
use crate::syntax::expr::expr_to_string;
88
use syn::{
99
parse::{Error, ParseStream},
@@ -189,7 +189,7 @@ impl ParsedQProperty {
189189
))
190190
}
191191

192-
let name = Name::new(ident).with_options(cxx_name.map(|ident| ident.to_string()), rust_name, AutoCamel::Enabled);
192+
let name = Name::new(ident).with_options(cxx_name.map(|ident| ident.to_string()), rust_name);
193193

194194
// This check is needed otherwise this fn would error unless READ, WRITE, etc... was passed with cxx_name
195195
if read_required {

crates/cxx-qt-gen/test_inputs/properties.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ mod ffi {
1010
#[qobject]
1111
#[qproperty(i32, primitive)]
1212
#[qproperty(QPoint, trivial)]
13-
#[qproperty(i32, custom_function_prop, READ = my_getter, WRITE = my_setter, NOTIFY)]
14-
#[qproperty(i32, readonly_prop, READ)]
13+
#[qproperty(i32, custom_function_prop, cxx_name = "customFunctionProp", READ = my_getter, WRITE = my_setter, NOTIFY)]
14+
#[qproperty(i32, readonly_prop, cxx_name = "readonlyProp", READ)]
1515
#[qproperty(
1616
i32,
1717
named_prop,
1818
cxx_name = "renamedProperty",
1919
rust_name = "renamed_property"
2020
)]
2121
#[qproperty(i32, named_prop_2, rust_name = "renamed_property_2")]
22-
#[qproperty(i32, custom_on_changed_prop, READ, WRITE, NOTIFY = my_on_changed)]
23-
#[qproperty(i32, const_prop, READ, CONSTANT)]
24-
#[qproperty(i32, resettable_prop, READ, WRITE, RESET = myResetFn)]
25-
#[qproperty(i32, required_prop, READ, WRITE, REQUIRED)]
26-
#[qproperty(i32, final_prop, READ, WRITE, FINAL)]
22+
#[qproperty(i32, custom_on_changed_prop, cxx_name = "customOnChangedProp", READ, WRITE, NOTIFY = my_on_changed)]
23+
#[qproperty(i32, const_prop, cxx_name = "constProp", READ, CONSTANT)]
24+
#[qproperty(i32, resettable_prop, cxx_name = "resettableProp", READ, WRITE, RESET = myResetFn)]
25+
#[qproperty(i32, required_prop, cxx_name = "requiredProp", READ, WRITE, REQUIRED)]
26+
#[qproperty(i32, final_prop, cxx_name = "finalProp", READ, WRITE, FINAL)]
2727
type MyObject = super::MyObjectRust;
2828
}
2929

examples/qml_features/rust/src/properties.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ pub mod qobject {
2222
#[qobject]
2323
#[qml_element]
2424
#[qproperty(bool, connected, READ, NOTIFY = connected_state_changed)]
25-
#[qproperty(QUrl, connected_url, READ, WRITE = set_url, NOTIFY = connected_state_changed, RESET = reset_url)]
26-
#[qproperty(QUrl, previous_connected_url, READ, NOTIFY = connected_state_changed)]
27-
#[qproperty(QString, status_message, READ, NOTIFY = connected_state_changed)]
25+
#[qproperty(QUrl, connected_url, cxx_name = "connectedUrl", READ, WRITE = set_url, NOTIFY = connected_state_changed, RESET = reset_url)]
26+
#[qproperty(QUrl, previous_connected_url, cxx_name = "previousConnectedUrl", READ, NOTIFY = connected_state_changed)]
27+
#[qproperty(QString, status_message, cxx_name = "statusMessage", READ, NOTIFY = connected_state_changed)]
2828
type RustProperties = super::RustPropertiesRust;
2929
// ANCHOR_END: book_properties_signature
3030

0 commit comments

Comments
 (0)