File tree Expand file tree Collapse file tree 2 files changed +11
-16
lines changed
crates/cxx-qt-gen/src/parser Expand file tree Collapse file tree 2 files changed +11
-16
lines changed Original file line number Diff line number Diff line change 4
4
// SPDX-License-Identifier: MIT OR Apache-2.0
5
5
6
6
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;
10
8
use crate :: syntax:: foreignmod:: { foreign_mod_to_foreign_item_types, verbatim_to_foreign_mod} ;
11
9
use crate :: syntax:: {
12
10
attribute:: { attribute_find_path, attribute_tokens_to_ident} ,
@@ -74,17 +72,10 @@ impl ParsedCxxQtData {
74
72
// Load the QObject
75
73
let mut qobject = ParsedQObject :: from_struct ( qobject_struct, index) ?;
76
74
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
+ }
88
79
89
80
// Note that we assume a compiler error will occur later
90
81
// if you had two structs with the same name
Original file line number Diff line number Diff line change @@ -78,6 +78,11 @@ impl ParsedQObject {
78
78
. get ( & quote:: format_ident!( "base" ) )
79
79
. map ( |base| base. value ( ) ) ;
80
80
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
+
81
86
// Remove the macro from the struct
82
87
let mut qobject_struct = qobject_struct. clone ( ) ;
83
88
qobject_struct. attrs . remove ( attr_index) ;
@@ -89,8 +94,7 @@ impl ParsedQObject {
89
94
Ok ( Self {
90
95
base_class,
91
96
qobject_struct,
92
- // TODO: read from the qobject macro later
93
- namespace : "" . to_owned ( ) ,
97
+ namespace,
94
98
signals : None ,
95
99
invokables : vec ! [ ] ,
96
100
methods : vec ! [ ] ,
You can’t perform that action at this time.
0 commit comments