@@ -26,30 +26,41 @@ void QmlScanner::scanDir(const QString& path) {
26
26
qCDebug (logQmlScanner) << " Scanning directory" << path;
27
27
auto dir = QDir (path);
28
28
29
+ struct Entry {
30
+ QString name;
31
+ bool singleton = false ;
32
+ bool internal = false ;
33
+ };
34
+
29
35
bool seenQmldir = false ;
30
- auto singletons = QVector<QString >();
31
- auto entries = QVector<QString>();
32
- for (auto & entry : dir.entryList (QDir::Files | QDir::NoDotAndDotDot)) {
33
- if (entry == " qmldir" ) {
36
+ auto entries = QVector<Entry >();
37
+
38
+ for (auto & name : dir.entryList (QDir::Files | QDir::NoDotAndDotDot)) {
39
+ if (name == " qmldir" ) {
34
40
qCDebug (logQmlScanner
35
41
) << " Found qmldir file, qmldir synthesization will be disabled for directory"
36
42
<< path;
37
43
seenQmldir = true ;
38
- } else if (entry.at (0 ).isUpper () && entry.endsWith (" .qml" )) {
39
- if (this ->scanQmlFile (dir.filePath (entry))) {
40
- singletons.push_back (entry);
44
+ } else if (name.at (0 ).isUpper () && name.endsWith (" .qml" )) {
45
+ auto & entry = entries.emplaceBack ();
46
+
47
+ if (this ->scanQmlFile (dir.filePath (name), entry.singleton , entry.internal )) {
48
+ entry.name = name;
41
49
} else {
42
- entries.push_back (entry);
50
+ entries.pop_back ();
51
+ }
52
+ } else if (name.at (0 ).isUpper () && name.endsWith (" .qml.json" )) {
53
+ if (this ->scanQmlJson (dir.filePath (name))) {
54
+ entries.push_back ({
55
+ .name = name.first (name.length () - 5 ),
56
+ .singleton = true ,
57
+ });
43
58
}
44
- } else if (entry.at (0 ).isUpper () && entry.endsWith (" .qml.json" )) {
45
- this ->scanQmlJson (dir.filePath (entry));
46
- singletons.push_back (entry.first (entry.length () - 5 ));
47
59
}
48
60
}
49
61
50
62
if (!seenQmldir) {
51
- qCDebug (logQmlScanner) << " Synthesizing qmldir for directory" << path << " singletons"
52
- << singletons;
63
+ qCDebug (logQmlScanner) << " Synthesizing qmldir for directory" << path;
53
64
54
65
QString qmldir;
55
66
auto stream = QTextStream (&qmldir);
@@ -77,21 +88,18 @@ void QmlScanner::scanDir(const QString& path) {
77
88
qCWarning (logQmlScanner) << " Module path" << path << " is outside of the config folder." ;
78
89
}
79
90
80
- for (auto & singleton: singletons) {
81
- stream << " singleton " << singleton.sliced (0 , singleton.length () - 4 ) << " 1.0 " << singleton
82
- << " \n " ;
83
- }
84
-
85
- for (auto & entry: entries) {
86
- stream << entry.sliced (0 , entry.length () - 4 ) << " 1.0 " << entry << " \n " ;
91
+ for (const auto & entry: entries) {
92
+ if (entry.internal ) stream << " internal " ;
93
+ if (entry.singleton ) stream << " singleton " ;
94
+ stream << entry.name .sliced (0 , entry.name .length () - 4 ) << " 1.0 " << entry.name << ' \n ' ;
87
95
}
88
96
89
97
qCDebug (logQmlScanner) << " Synthesized qmldir for" << path << qPrintable (" \n " + qmldir);
90
98
this ->fileIntercepts .insert (QDir (path).filePath (" qmldir" ), qmldir);
91
99
}
92
100
}
93
101
94
- bool QmlScanner::scanQmlFile (const QString& path) {
102
+ bool QmlScanner::scanQmlFile (const QString& path, bool & singleton, bool & internal ) {
95
103
if (this ->scannedFiles .contains (path)) return false ;
96
104
this ->scannedFiles .push_back (path);
97
105
@@ -106,13 +114,12 @@ bool QmlScanner::scanQmlFile(const QString& path) {
106
114
auto stream = QTextStream (&file);
107
115
auto imports = QVector<QString>();
108
116
109
- bool singleton = false ;
110
-
111
117
while (!stream.atEnd ()) {
112
118
auto line = stream.readLine ().trimmed ();
113
119
if (!singleton && line == " pragma Singleton" ) {
114
- qCDebug (logQmlScanner) << " Discovered singleton" << path;
115
120
singleton = true ;
121
+ } else if (!internal && line == " //@ pragma Internal" ) {
122
+ internal = true ;
116
123
} else if (line.startsWith (" import" )) {
117
124
// we dont care about "import qs" as we always load the root folder
118
125
if (auto importCursor = line.indexOf (" qs." ); importCursor != -1 ) {
@@ -188,16 +195,22 @@ bool QmlScanner::scanQmlFile(const QString& path) {
188
195
else this ->scanDir (cpath);
189
196
}
190
197
191
- return singleton;
198
+ return true ;
199
+ }
200
+
201
+ void QmlScanner::scanQmlRoot (const QString& path) {
202
+ bool singleton = false ;
203
+ bool internal = false ;
204
+ this ->scanQmlFile (path, singleton, internal);
192
205
}
193
206
194
- void QmlScanner::scanQmlJson (const QString& path) {
207
+ bool QmlScanner::scanQmlJson (const QString& path) {
195
208
qCDebug (logQmlScanner) << " Scanning qml.json file" << path;
196
209
197
210
auto file = QFile (path);
198
211
if (!file.open (QFile::ReadOnly | QFile::Text)) {
199
212
qCWarning (logQmlScanner) << " Failed to open file" << path;
200
- return ;
213
+ return false ;
201
214
}
202
215
203
216
auto data = file.readAll ();
@@ -209,7 +222,7 @@ void QmlScanner::scanQmlJson(const QString& path) {
209
222
if (error.error != QJsonParseError::NoError) {
210
223
qCCritical (logQmlScanner).nospace ()
211
224
<< " Failed to parse qml.json file at " << path << " : " << error.errorString ();
212
- return ;
225
+ return false ;
213
226
}
214
227
215
228
const QString body =
@@ -219,6 +232,7 @@ void QmlScanner::scanQmlJson(const QString& path) {
219
232
220
233
this ->fileIntercepts .insert (path.first (path.length () - 5 ), body);
221
234
this ->scannedFiles .push_back (path);
235
+ return true ;
222
236
}
223
237
224
238
QPair<QString, QString> QmlScanner::jsonToQml (const QJsonValue& value, int indent) {
0 commit comments