Skip to content

Commit 781de19

Browse files
ahayzen-kdabBe-ing
authored andcommitted
cxx-qt-gen: load namespace from qobject macro in same place as specifiers
1 parent 82eec23 commit 781de19

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

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

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

66
use crate::parser::{qobject::ParsedQObject, signals::ParsedSignalsEnum};
7-
use crate::syntax::attribute::{
8-
attribute_tokens_to_map, attribute_tokens_to_value, AttributeDefault,
9-
};
7+
use crate::syntax::attribute::attribute_tokens_to_value;
108
use crate::syntax::foreignmod::{foreign_mod_to_foreign_item_types, verbatim_to_foreign_mod};
119
use crate::syntax::{
1210
attribute::{attribute_find_path, attribute_tokens_to_ident},
@@ -74,17 +72,10 @@ impl ParsedCxxQtData {
7472
// Load the QObject
7573
let mut qobject = ParsedQObject::from_struct(qobject_struct, index)?;
7674

77-
// Parse any namespaces
78-
let attr_map = attribute_tokens_to_map::<Ident, LitStr>(
79-
&qobject_struct.attrs[index],
80-
AttributeDefault::None,
81-
)?;
82-
qobject.namespace =
83-
if let Some(lit_str) = attr_map.get(&quote::format_ident!("namespace")) {
84-
lit_str.value()
85-
} else {
86-
self.namespace.clone()
87-
};
75+
// Inject the bridge namespace if the qobject one is empty
76+
if qobject.namespace.is_empty() && !self.namespace.is_empty() {
77+
qobject.namespace = self.namespace.clone();
78+
}
8879

8980
// Note that we assume a compiler error will occur later
9081
// if you had two structs with the same name

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ impl ParsedQObject {
7878
.get(&quote::format_ident!("base"))
7979
.map(|base| base.value());
8080

81+
// Load the namespace, if it is empty then the ParsedCxxQtData will inject any global namespace
82+
let namespace = attrs_map
83+
.get(&quote::format_ident!("namespace"))
84+
.map_or_else(|| "".to_owned(), |base| base.value());
85+
8186
// Remove the macro from the struct
8287
let mut qobject_struct = qobject_struct.clone();
8388
qobject_struct.attrs.remove(attr_index);
@@ -89,8 +94,7 @@ impl ParsedQObject {
8994
Ok(Self {
9095
base_class,
9196
qobject_struct,
92-
// TODO: read from the qobject macro later
93-
namespace: "".to_owned(),
97+
namespace,
9498
signals: None,
9599
invokables: vec![],
96100
methods: vec![],

0 commit comments

Comments
 (0)