Changeset View
Changeset View
Standalone View
Standalone View
src/kconfig_compiler/KConfigSourceGenerator.cpp
Show All 33 Lines | 30 | KConfigSourceGenerator::KConfigSourceGenerator( | |||
---|---|---|---|---|---|
34 | ParseResult &result) | 34 | ParseResult &result) | ||
35 | : KConfigCodeGeneratorBase(inputFile, baseDir, baseDir + cfg.baseName + QLatin1Char('.') + cfg.sourceExtension, cfg, result) | 35 | : KConfigCodeGeneratorBase(inputFile, baseDir, baseDir + cfg.baseName + QLatin1Char('.') + cfg.sourceExtension, cfg, result) | ||
36 | { | 36 | { | ||
37 | } | 37 | } | ||
38 | 38 | | |||
39 | void KConfigSourceGenerator::start() | 39 | void KConfigSourceGenerator::start() | ||
40 | { | 40 | { | ||
41 | KConfigCodeGeneratorBase::start(); | 41 | KConfigCodeGeneratorBase::start(); | ||
42 | stream() << endl; | 42 | stream() << '\n'; | ||
43 | createHeaders(); | 43 | createHeaders(); | ||
44 | 44 | | |||
45 | if (!cfg().nameSpace.isEmpty()) { | 45 | if (!cfg().nameSpace.isEmpty()) { | ||
46 | stream() << "using namespace " << cfg().nameSpace << ";"; | 46 | stream() << "using namespace " << cfg().nameSpace << ";"; | ||
47 | stream() << endl << endl; | 47 | stream() << endl << '\n'; | ||
48 | } | 48 | } | ||
49 | 49 | | |||
50 | createPrivateDPointerImplementation(); | 50 | createPrivateDPointerImplementation(); | ||
51 | createSingletonImplementation(); | 51 | createSingletonImplementation(); | ||
52 | createPreamble(); | 52 | createPreamble(); | ||
53 | doConstructor(); | 53 | doConstructor(); | ||
54 | doGetterSetterDPointerMode(); | 54 | doGetterSetterDPointerMode(); | ||
55 | createDefaultValueGetterSetter(); | 55 | createDefaultValueGetterSetter(); | ||
56 | createDestructor(); | 56 | createDestructor(); | ||
57 | createNonModifyingSignalsHelper(); | 57 | createNonModifyingSignalsHelper(); | ||
58 | createSignalFlagsHandler(); | 58 | createSignalFlagsHandler(); | ||
59 | includeMoc(); | 59 | includeMoc(); | ||
60 | } | 60 | } | ||
61 | 61 | | |||
62 | void KConfigSourceGenerator::createHeaders() | 62 | void KConfigSourceGenerator::createHeaders() | ||
63 | { | 63 | { | ||
64 | QString headerName = cfg().baseName + QLatin1Char('.') + cfg().headerExtension; | 64 | QString headerName = cfg().baseName + QLatin1Char('.') + cfg().headerExtension; | ||
65 | 65 | | |||
66 | // TODO: Make addQuotes return a string instead of replacing it inplace. | 66 | // TODO: Make addQuotes return a string instead of replacing it inplace. | ||
67 | addQuotes(headerName); | 67 | addQuotes(headerName); | ||
68 | 68 | | |||
69 | addHeaders({ headerName }); | 69 | addHeaders({ headerName }); | ||
70 | stream() << endl; | 70 | stream() << '\n'; | ||
71 | 71 | | |||
72 | addHeaders(cfg().sourceIncludes); | 72 | addHeaders(cfg().sourceIncludes); | ||
73 | if (cfg().setUserTexts && cfg().translationSystem == KConfigParameters::KdeTranslation) { | 73 | if (cfg().setUserTexts && cfg().translationSystem == KConfigParameters::KdeTranslation) { | ||
74 | addHeaders({QStringLiteral("klocalizedstring.h")}); | 74 | addHeaders({QStringLiteral("klocalizedstring.h")}); | ||
75 | stream() << endl; | 75 | stream() << '\n'; | ||
76 | } | 76 | } | ||
77 | 77 | | |||
78 | // Header required by singleton implementation | 78 | // Header required by singleton implementation | ||
79 | if (cfg().singleton) { | 79 | if (cfg().singleton) { | ||
80 | addHeaders({QStringLiteral("qglobal.h"), QStringLiteral("QFile")}); | 80 | addHeaders({QStringLiteral("qglobal.h"), QStringLiteral("QFile")}); | ||
81 | 81 | | |||
82 | // HACK: Add single line to fix test. | 82 | // HACK: Add single line to fix test. | ||
83 | if (cfg().singleton && parseResult.cfgFileNameArg) { | 83 | if (cfg().singleton && parseResult.cfgFileNameArg) { | ||
84 | stream() << endl; | 84 | stream() << '\n'; | ||
85 | } | 85 | } | ||
86 | } | 86 | } | ||
87 | 87 | | |||
88 | if (cfg().singleton && parseResult.cfgFileNameArg) { | 88 | if (cfg().singleton && parseResult.cfgFileNameArg) { | ||
89 | addHeaders({QStringLiteral("QDebug")}); | 89 | addHeaders({QStringLiteral("QDebug")}); | ||
90 | } | 90 | } | ||
91 | 91 | | |||
92 | if (cfg().singleton) { | 92 | if (cfg().singleton) { | ||
93 | stream() << endl; | 93 | stream() << '\n'; | ||
94 | } | 94 | } | ||
95 | } | 95 | } | ||
96 | 96 | | |||
97 | void KConfigSourceGenerator::createPrivateDPointerImplementation() | 97 | void KConfigSourceGenerator::createPrivateDPointerImplementation() | ||
98 | { | 98 | { | ||
99 | // private class implementation | 99 | // private class implementation | ||
100 | if (!cfg().dpointer) { | 100 | if (!cfg().dpointer) { | ||
101 | return; | 101 | return; | ||
102 | } | 102 | } | ||
103 | 103 | | |||
104 | QString group; | 104 | QString group; | ||
105 | beginNamespaces(); | 105 | beginNamespaces(); | ||
106 | stream() << "class " << cfg().className << "Private" << endl; | 106 | stream() << "class " << cfg().className << "Private\n"; | ||
107 | stream() << "{" << endl; | 107 | stream() << "{\n"; | ||
108 | stream() << " public:" << endl; | 108 | stream() << " public:\n"; | ||
109 | 109 | | |||
110 | // Create Members | 110 | // Create Members | ||
111 | for (auto *entry : parseResult.entries) { | 111 | for (auto *entry : parseResult.entries) { | ||
112 | if (entry->group != group) { | 112 | if (entry->group != group) { | ||
113 | group = entry->group; | 113 | group = entry->group; | ||
114 | stream() << endl; | 114 | stream() << '\n'; | ||
115 | stream() << " // " << group << endl; | 115 | stream() << " // " << group << '\n'; | ||
116 | } | 116 | } | ||
117 | stream() << " " << cppType(entry->type) << " " << varName(entry->name, cfg()); | 117 | stream() << " " << cppType(entry->type) << " " << varName(entry->name, cfg()); | ||
118 | if (!entry->param.isEmpty()) { | 118 | if (!entry->param.isEmpty()) { | ||
119 | stream() << QStringLiteral("[%1]").arg(entry->paramMax + 1); | 119 | stream() << QStringLiteral("[%1]").arg(entry->paramMax + 1); | ||
120 | } | 120 | } | ||
121 | stream() << ";" << endl; | 121 | stream() << ";\n"; | ||
122 | } | 122 | } | ||
123 | stream() << endl << " // items" << endl; | 123 | stream() << endl << " // items\n"; | ||
124 | 124 | | |||
125 | // Create Items. | 125 | // Create Items. | ||
126 | for (auto *entry : parseResult.entries) { | 126 | for (auto *entry : parseResult.entries) { | ||
127 | const QString declType = entry->signalList.isEmpty() | 127 | const QString declType = entry->signalList.isEmpty() | ||
128 | ? QString(cfg().inherits + QStringLiteral("::Item") + itemType(entry->type)) | 128 | ? QString(cfg().inherits + QStringLiteral("::Item") + itemType(entry->type)) | ||
129 | : QStringLiteral("KConfigCompilerSignallingItem"); | 129 | : QStringLiteral("KConfigCompilerSignallingItem"); | ||
130 | 130 | | |||
131 | stream() << " " << declType << " *" << itemVar( entry, cfg() ); | 131 | stream() << " " << declType << " *" << itemVar( entry, cfg() ); | ||
132 | if (!entry->param.isEmpty()) { | 132 | if (!entry->param.isEmpty()) { | ||
133 | stream() << QStringLiteral("[%1]").arg(entry->paramMax + 1); | 133 | stream() << QStringLiteral("[%1]").arg(entry->paramMax + 1); | ||
134 | } | 134 | } | ||
135 | stream() << ";" << endl; | 135 | stream() << ";\n"; | ||
136 | } | 136 | } | ||
137 | 137 | | |||
138 | if (parseResult.hasNonModifySignals) { | 138 | if (parseResult.hasNonModifySignals) { | ||
139 | stream() << " uint " << varName(QStringLiteral("settingsChanged"), cfg()) << ";" << endl; | 139 | stream() << " uint " << varName(QStringLiteral("settingsChanged"), cfg()) << ";\n"; | ||
140 | } | 140 | } | ||
141 | 141 | | |||
142 | stream() << "};" << endl << endl; | 142 | stream() << "};" << endl << '\n'; | ||
143 | endNamespaces(); | 143 | endNamespaces(); | ||
144 | } | 144 | } | ||
145 | 145 | | |||
146 | void KConfigSourceGenerator::createSingletonImplementation() | 146 | void KConfigSourceGenerator::createSingletonImplementation() | ||
147 | { | 147 | { | ||
148 | // Singleton implementation | 148 | // Singleton implementation | ||
149 | if (!cfg().singleton) { | 149 | if (!cfg().singleton) { | ||
150 | return; | 150 | return; | ||
151 | } | 151 | } | ||
152 | 152 | | |||
153 | beginNamespaces(); | 153 | beginNamespaces(); | ||
154 | stream() << "class " << cfg().className << "Helper" << endl; | 154 | stream() << "class " << cfg().className << "Helper\n"; | ||
155 | stream() << '{' << endl; | 155 | stream() << '{' << '\n'; | ||
156 | stream() << " public:" << endl; | 156 | stream() << " public:\n"; | ||
157 | stream() << " " << cfg().className << "Helper() : q(nullptr) {}" << endl; | 157 | stream() << " " << cfg().className << "Helper() : q(nullptr) {}\n"; | ||
158 | stream() << " ~" << cfg().className << "Helper() { delete q; }" << endl; | 158 | stream() << " ~" << cfg().className << "Helper() { delete q; }\n"; | ||
159 | stream() << " " << cfg().className << "Helper(const " << cfg().className << "Helper&) = delete;" << endl; | 159 | stream() << " " << cfg().className << "Helper(const " << cfg().className << "Helper&) = delete;\n"; | ||
160 | stream() << " " << cfg().className << "Helper& operator=(const " << cfg().className << "Helper&) = delete;" << endl; | 160 | stream() << " " << cfg().className << "Helper& operator=(const " << cfg().className << "Helper&) = delete;\n"; | ||
161 | stream() << " " << cfg().className << " *q;" << endl; | 161 | stream() << " " << cfg().className << " *q;\n"; | ||
162 | stream() << "};" << endl; | 162 | stream() << "};\n"; | ||
163 | endNamespaces(); | 163 | endNamespaces(); | ||
164 | 164 | | |||
165 | stream() << "Q_GLOBAL_STATIC(" << cfg().className << "Helper, s_global" << cfg().className << ")" << endl; | 165 | stream() << "Q_GLOBAL_STATIC(" << cfg().className << "Helper, s_global" << cfg().className << ")\n"; | ||
166 | 166 | | |||
167 | stream() << cfg().className << " *" << cfg().className << "::self()" << endl; | 167 | stream() << cfg().className << " *" << cfg().className << "::self()\n"; | ||
168 | stream() << "{" << endl; | 168 | stream() << "{\n"; | ||
169 | if (parseResult.cfgFileNameArg) { | 169 | if (parseResult.cfgFileNameArg) { | ||
170 | stream() << " if (!s_global" << cfg().className << "()->q)" << endl; | 170 | stream() << " if (!s_global" << cfg().className << "()->q)\n"; | ||
171 | stream() << " qFatal(\"you need to call " << cfg().className << "::instance before using\");" << endl; | 171 | stream() << " qFatal(\"you need to call " << cfg().className << "::instance before using\");\n"; | ||
172 | } else { | 172 | } else { | ||
173 | stream() << " if (!s_global" << cfg().className << "()->q) {" << endl; | 173 | stream() << " if (!s_global" << cfg().className << "()->q) {\n"; | ||
174 | stream() << " new " << cfg().className << ';' << endl; | 174 | stream() << " new " << cfg().className << ';' << '\n'; | ||
175 | stream() << " s_global" << cfg().className << "()->q->read();" << endl; | 175 | stream() << " s_global" << cfg().className << "()->q->read();\n"; | ||
176 | stream() << " }" << endl << endl; | 176 | stream() << " }" << endl << '\n'; | ||
177 | } | 177 | } | ||
178 | stream() << " return s_global" << cfg().className << "()->q;" << endl; | 178 | stream() << " return s_global" << cfg().className << "()->q;\n"; | ||
179 | stream() << "}" << endl << endl; | 179 | stream() << "}" << endl << '\n'; | ||
180 | 180 | | |||
181 | if (parseResult.cfgFileNameArg) { | 181 | if (parseResult.cfgFileNameArg) { | ||
182 | auto instance = [this] (const QString &type, const QString &arg, bool isString) { | 182 | auto instance = [this] (const QString &type, const QString &arg, bool isString) { | ||
183 | stream() << "void " << cfg().className << "::instance(" << type << " " << arg << ")" << endl; | 183 | stream() << "void " << cfg().className << "::instance(" << type << " " << arg << ")\n"; | ||
184 | stream() << "{" << endl; | 184 | stream() << "{\n"; | ||
185 | stream() << " if (s_global" << cfg().className << "()->q) {" << endl; | 185 | stream() << " if (s_global" << cfg().className << "()->q) {\n"; | ||
186 | stream() << " qDebug() << \"" << cfg().className << "::instance called after the first use - ignoring\";" << endl; | 186 | stream() << " qDebug() << \"" << cfg().className << "::instance called after the first use - ignoring\";\n"; | ||
187 | stream() << " return;" << endl; | 187 | stream() << " return;\n"; | ||
188 | stream() << " }" << endl; | 188 | stream() << " }\n"; | ||
189 | stream() << " new " << cfg().className << "("; | 189 | stream() << " new " << cfg().className << "("; | ||
190 | if (isString) { | 190 | if (isString) { | ||
191 | stream() << "KSharedConfig::openConfig(" << arg << ")"; | 191 | stream() << "KSharedConfig::openConfig(" << arg << ")"; | ||
192 | } else { | 192 | } else { | ||
193 | stream() << "std::move(" << arg << ")"; | 193 | stream() << "std::move(" << arg << ")"; | ||
194 | } | 194 | } | ||
195 | stream() << ");" << endl; | 195 | stream() << ");\n"; | ||
196 | stream() << " s_global" << cfg().className << "()->q->read();" << endl; | 196 | stream() << " s_global" << cfg().className << "()->q->read();\n"; | ||
197 | stream() << "}" << endl << endl; | 197 | stream() << "}" << endl << '\n'; | ||
198 | }; | 198 | }; | ||
199 | instance(QStringLiteral("const QString&"), QStringLiteral("cfgfilename"), true); | 199 | instance(QStringLiteral("const QString&"), QStringLiteral("cfgfilename"), true); | ||
200 | instance(QStringLiteral("KSharedConfig::Ptr"), QStringLiteral("config"), false); | 200 | instance(QStringLiteral("KSharedConfig::Ptr"), QStringLiteral("config"), false); | ||
201 | } | 201 | } | ||
202 | } | 202 | } | ||
203 | 203 | | |||
204 | void KConfigSourceGenerator::createPreamble() | 204 | void KConfigSourceGenerator::createPreamble() | ||
205 | { | 205 | { | ||
206 | QString cppPreamble; | 206 | QString cppPreamble; | ||
207 | for (const auto entry : parseResult.entries) { | 207 | for (const auto entry : parseResult.entries) { | ||
208 | if (entry->paramValues.isEmpty()) { | 208 | if (entry->paramValues.isEmpty()) { | ||
209 | continue; | 209 | continue; | ||
210 | } | 210 | } | ||
211 | 211 | | |||
212 | cppPreamble += QStringLiteral("const char* const ") + cfg().className + QStringLiteral("::") + enumName(entry->param); | 212 | cppPreamble += QStringLiteral("const char* const ") + cfg().className + QStringLiteral("::") + enumName(entry->param); | ||
213 | cppPreamble += cfg().globalEnums | 213 | cppPreamble += cfg().globalEnums | ||
214 | ? QStringLiteral("ToString[] = { \"") + entry->paramValues.join(QStringLiteral("\", \"")) + QStringLiteral("\" };\n") | 214 | ? QStringLiteral("ToString[] = { \"") + entry->paramValues.join(QStringLiteral("\", \"")) + QStringLiteral("\" };\n") | ||
215 | : QStringLiteral("::enumToString[] = { \"") + entry->paramValues.join(QStringLiteral("\", \"")) + QStringLiteral("\" };\n"); | 215 | : QStringLiteral("::enumToString[] = { \"") + entry->paramValues.join(QStringLiteral("\", \"")) + QStringLiteral("\" };\n"); | ||
216 | } | 216 | } | ||
217 | 217 | | |||
218 | if (!cppPreamble.isEmpty()) { | 218 | if (!cppPreamble.isEmpty()) { | ||
219 | stream() << cppPreamble << endl; | 219 | stream() << cppPreamble << '\n'; | ||
220 | } | 220 | } | ||
221 | } | 221 | } | ||
222 | 222 | | |||
223 | void KConfigSourceGenerator::createConstructorParameterList() | 223 | void KConfigSourceGenerator::createConstructorParameterList() | ||
224 | { | 224 | { | ||
225 | if (parseResult.cfgFileNameArg) { | 225 | if (parseResult.cfgFileNameArg) { | ||
226 | if (!cfg().forceStringFilename) { | 226 | if (!cfg().forceStringFilename) { | ||
227 | stream() << " KSharedConfig::Ptr config"; | 227 | stream() << " KSharedConfig::Ptr config"; | ||
Show All 31 Lines | 258 | if (! cfg().forceStringFilename) { | |||
259 | stream() << " std::move( config ) "; | 259 | stream() << " std::move( config ) "; | ||
260 | } else { | 260 | } else { | ||
261 | stream() << " config "; | 261 | stream() << " config "; | ||
262 | } | 262 | } | ||
263 | } | 263 | } | ||
264 | if (!parseResult.cfgFileName.isEmpty()) { | 264 | if (!parseResult.cfgFileName.isEmpty()) { | ||
265 | stream() << ") "; | 265 | stream() << ") "; | ||
266 | } | 266 | } | ||
267 | stream() << ")" << endl; | 267 | stream() << ")\n"; | ||
268 | } | 268 | } | ||
269 | 269 | | |||
270 | void KConfigSourceGenerator::createInitializerList() | 270 | void KConfigSourceGenerator::createInitializerList() | ||
271 | { | 271 | { | ||
272 | for (const auto ¶meter : parseResult.parameters) { | 272 | for (const auto ¶meter : parseResult.parameters) { | ||
273 | stream() << " , mParam" << parameter.name << "(" << parameter.name << ")" << endl; | 273 | stream() << " , mParam" << parameter.name << "(" << parameter.name << ")\n"; | ||
274 | } | 274 | } | ||
275 | 275 | | |||
276 | if (parseResult.hasNonModifySignals && !cfg().dpointer) { | 276 | if (parseResult.hasNonModifySignals && !cfg().dpointer) { | ||
277 | stream() << " , " << varName(QStringLiteral("settingsChanged"), cfg()) << "(0)" << endl; | 277 | stream() << " , " << varName(QStringLiteral("settingsChanged"), cfg()) << "(0)\n"; | ||
278 | } | 278 | } | ||
279 | } | 279 | } | ||
280 | 280 | | |||
281 | void KConfigSourceGenerator::createEnums(const CfgEntry *entry) | 281 | void KConfigSourceGenerator::createEnums(const CfgEntry *entry) | ||
282 | { | 282 | { | ||
283 | if (entry->type != QLatin1String("Enum")) { | 283 | if (entry->type != QLatin1String("Enum")) { | ||
284 | return; | 284 | return; | ||
285 | } | 285 | } | ||
286 | stream() << " QList<" << cfg().inherits << "::ItemEnum::Choice> values" << entry->name << ";" << endl; | 286 | stream() << " QList<" << cfg().inherits << "::ItemEnum::Choice> values" << entry->name << ";\n"; | ||
287 | 287 | | |||
288 | for (const auto &choice : qAsConst(entry->choices.choices)) { | 288 | for (const auto &choice : qAsConst(entry->choices.choices)) { | ||
289 | stream() << " {" << endl; | 289 | stream() << " {\n"; | ||
290 | stream() << " " << cfg().inherits << "::ItemEnum::Choice choice;" << endl; | 290 | stream() << " " << cfg().inherits << "::ItemEnum::Choice choice;\n"; | ||
291 | stream() << " choice.name = QStringLiteral(\"" << choice.name << "\");" << endl; | 291 | stream() << " choice.name = QStringLiteral(\"" << choice.name << "\");\n"; | ||
292 | if (cfg().setUserTexts) { | 292 | if (cfg().setUserTexts) { | ||
293 | if (!choice.label.isEmpty()) { | 293 | if (!choice.label.isEmpty()) { | ||
294 | stream() << " choice.label = " | 294 | stream() << " choice.label = " | ||
295 | << translatedString(cfg(), choice.label, choice.context) | 295 | << translatedString(cfg(), choice.label, choice.context) | ||
296 | << ";" << endl; | 296 | << ";\n"; | ||
297 | } | 297 | } | ||
298 | if (!choice.toolTip.isEmpty()) { | 298 | if (!choice.toolTip.isEmpty()) { | ||
299 | stream() << " choice.toolTip = " | 299 | stream() << " choice.toolTip = " | ||
300 | << translatedString(cfg(), choice.toolTip, choice.context) | 300 | << translatedString(cfg(), choice.toolTip, choice.context) | ||
301 | << ";" << endl; | 301 | << ";\n"; | ||
302 | } | 302 | } | ||
303 | if (!choice.whatsThis.isEmpty()) { | 303 | if (!choice.whatsThis.isEmpty()) { | ||
304 | stream() << " choice.whatsThis = " | 304 | stream() << " choice.whatsThis = " | ||
305 | << translatedString(cfg(), choice.whatsThis, choice.context) | 305 | << translatedString(cfg(), choice.whatsThis, choice.context) | ||
306 | << ";" << endl; | 306 | << ";\n"; | ||
307 | } | 307 | } | ||
308 | } | 308 | } | ||
309 | stream() << " values" << entry->name << ".append( choice );" << endl; | 309 | stream() << " values" << entry->name << ".append( choice );\n"; | ||
310 | stream() << " }" << endl; | 310 | stream() << " }\n"; | ||
311 | } | 311 | } | ||
312 | } | 312 | } | ||
313 | 313 | | |||
314 | void KConfigSourceGenerator::createNormalEntry(const CfgEntry *entry, const QString &key) | 314 | void KConfigSourceGenerator::createNormalEntry(const CfgEntry *entry, const QString &key) | ||
315 | { | 315 | { | ||
316 | stream() << " " << itemPath(entry, cfg()) << " = " | 316 | stream() << " " << itemPath(entry, cfg()) << " = " | ||
317 | << newItem(entry, key, entry->defaultValue, cfg()) << endl; | 317 | << newItem(entry, key, entry->defaultValue, cfg()) << '\n'; | ||
318 | 318 | | |||
319 | if (!entry->min.isEmpty()) { | 319 | if (!entry->min.isEmpty()) { | ||
320 | stream() << " " << itemPath(entry, cfg()) << "->setMinValue(" << entry->min << ");" << endl; | 320 | stream() << " " << itemPath(entry, cfg()) << "->setMinValue(" << entry->min << ");\n"; | ||
321 | } | 321 | } | ||
322 | if (!entry->max.isEmpty()) { | 322 | if (!entry->max.isEmpty()) { | ||
323 | stream() << " " << itemPath(entry, cfg()) << "->setMaxValue(" << entry->max << ");" << endl; | 323 | stream() << " " << itemPath(entry, cfg()) << "->setMaxValue(" << entry->max << ");\n"; | ||
324 | } | 324 | } | ||
325 | 325 | | |||
326 | if (cfg().setUserTexts) { | 326 | if (cfg().setUserTexts) { | ||
327 | stream() << userTextsFunctions(entry, cfg()); | 327 | stream() << userTextsFunctions(entry, cfg()); | ||
328 | } | 328 | } | ||
329 | 329 | | |||
330 | if (cfg().allNotifiers || cfg().notifiers.contains(entry->name)) { | 330 | if (cfg().allNotifiers || cfg().notifiers.contains(entry->name)) { | ||
331 | stream() << " " << itemPath(entry, cfg()) << "->setWriteFlags(KConfigBase::Notify);" << endl; | 331 | stream() << " " << itemPath(entry, cfg()) << "->setWriteFlags(KConfigBase::Notify);\n"; | ||
332 | } | 332 | } | ||
333 | 333 | | |||
334 | stream() << " addItem( " << itemPath(entry, cfg()); | 334 | stream() << " addItem( " << itemPath(entry, cfg()); | ||
335 | QString quotedName = entry->name; | 335 | QString quotedName = entry->name; | ||
336 | addQuotes(quotedName); | 336 | addQuotes(quotedName); | ||
337 | if (quotedName != key) { | 337 | if (quotedName != key) { | ||
338 | stream() << ", QStringLiteral( \"" << entry->name << "\" )"; | 338 | stream() << ", QStringLiteral( \"" << entry->name << "\" )"; | ||
339 | } | 339 | } | ||
340 | stream() << " );" << endl; | 340 | stream() << " );\n"; | ||
341 | } | 341 | } | ||
342 | 342 | | |||
343 | void KConfigSourceGenerator::createIndexedEntry(const CfgEntry *entry, const QString &key) | 343 | void KConfigSourceGenerator::createIndexedEntry(const CfgEntry *entry, const QString &key) | ||
344 | { | 344 | { | ||
345 | for (int i = 0; i <= entry->paramMax; i++) { | 345 | for (int i = 0; i <= entry->paramMax; i++) { | ||
346 | QString itemVarStr(itemPath(entry, cfg()) + QStringLiteral("[%1]").arg(i)); | 346 | QString itemVarStr(itemPath(entry, cfg()) + QStringLiteral("[%1]").arg(i)); | ||
347 | 347 | | |||
348 | QString defaultStr = !entry->paramDefaultValues[i].isEmpty() ? entry->paramDefaultValues[i] | 348 | QString defaultStr = !entry->paramDefaultValues[i].isEmpty() ? entry->paramDefaultValues[i] | ||
349 | : !entry->defaultValue.isEmpty() ? paramString(entry->defaultValue, entry, i) | 349 | : !entry->defaultValue.isEmpty() ? paramString(entry->defaultValue, entry, i) | ||
350 | : defaultValue(entry->type); | 350 | : defaultValue(entry->type); | ||
351 | 351 | | |||
352 | stream() << " " << itemVarStr << " = " | 352 | stream() << " " << itemVarStr << " = " | ||
353 | << newItem(entry, paramString(key, entry, i), defaultStr, cfg(), QStringLiteral("[%1]").arg(i)) << endl; | 353 | << newItem(entry, paramString(key, entry, i), defaultStr, cfg(), QStringLiteral("[%1]").arg(i)) << '\n'; | ||
354 | 354 | | |||
355 | if (cfg().setUserTexts) { | 355 | if (cfg().setUserTexts) { | ||
356 | stream() << userTextsFunctions(entry, cfg(), itemVarStr, entry->paramName); | 356 | stream() << userTextsFunctions(entry, cfg(), itemVarStr, entry->paramName); | ||
357 | } | 357 | } | ||
358 | 358 | | |||
359 | // Make mutators for enum parameters work by adding them with $(..) replaced by the | 359 | // Make mutators for enum parameters work by adding them with $(..) replaced by the | ||
360 | // param name. The check for isImmutable in the set* functions doesn't have the param | 360 | // param name. The check for isImmutable in the set* functions doesn't have the param | ||
361 | // name available, just the corresponding enum value (int), so we need to store the | 361 | // name available, just the corresponding enum value (int), so we need to store the | ||
362 | // param names in a separate static list!. | 362 | // param names in a separate static list!. | ||
363 | const bool isEnum = entry->paramType == QLatin1String("Enum"); | 363 | const bool isEnum = entry->paramType == QLatin1String("Enum"); | ||
364 | const QString arg = isEnum ? entry->paramValues[i] : QString::number(i); | 364 | const QString arg = isEnum ? entry->paramValues[i] : QString::number(i); | ||
365 | 365 | | |||
366 | QString paramName = entry->paramName; | 366 | QString paramName = entry->paramName; | ||
367 | 367 | | |||
368 | stream() << " addItem( " << itemVarStr << ", QStringLiteral( \""; | 368 | stream() << " addItem( " << itemVarStr << ", QStringLiteral( \""; | ||
369 | stream() << paramName.replace(QStringLiteral("$(") + entry->param + QLatin1Char(')'), QLatin1String("%1")).arg( arg ); | 369 | stream() << paramName.replace(QStringLiteral("$(") + entry->param + QLatin1Char(')'), QLatin1String("%1")).arg( arg ); | ||
370 | stream() << "\" ) );" << endl; | 370 | stream() << "\" ) );\n"; | ||
371 | } | 371 | } | ||
372 | } | 372 | } | ||
373 | 373 | | |||
374 | void KConfigSourceGenerator::handleCurrentGroupChange(const CfgEntry *entry) | 374 | void KConfigSourceGenerator::handleCurrentGroupChange(const CfgEntry *entry) | ||
375 | { | 375 | { | ||
376 | if (entry->group == mCurrentGroup) { | 376 | if (entry->group == mCurrentGroup) { | ||
377 | return; | 377 | return; | ||
378 | } | 378 | } | ||
379 | 379 | | |||
380 | // HACK: This fixes one spacing line in the diff. Remove this in the future and adapt the testcases. | 380 | // HACK: This fixes one spacing line in the diff. Remove this in the future and adapt the testcases. | ||
381 | static bool first = true; | 381 | static bool first = true; | ||
382 | if (!entry->group.isEmpty()) { | 382 | if (!entry->group.isEmpty()) { | ||
383 | if (!first) { | 383 | if (!first) { | ||
384 | stream() << endl; | 384 | stream() << '\n'; | ||
385 | } | 385 | } | ||
386 | first = false; | 386 | first = false; | ||
387 | } | 387 | } | ||
388 | 388 | | |||
389 | mCurrentGroup = entry->group; | 389 | mCurrentGroup = entry->group; | ||
390 | stream() << " setCurrentGroup( " << paramString(mCurrentGroup, parseResult.parameters) << " );"; | 390 | stream() << " setCurrentGroup( " << paramString(mCurrentGroup, parseResult.parameters) << " );"; | ||
391 | stream() << endl << endl; | 391 | stream() << endl << '\n'; | ||
392 | } | 392 | } | ||
393 | 393 | | |||
394 | void KConfigSourceGenerator::doConstructor() | 394 | void KConfigSourceGenerator::doConstructor() | ||
395 | { | 395 | { | ||
396 | // Constructor | 396 | // Constructor | ||
397 | stream() << cfg().className << "::" << cfg().className << "("; | 397 | stream() << cfg().className << "::" << cfg().className << "("; | ||
398 | createConstructorParameterList(); | 398 | createConstructorParameterList(); | ||
399 | stream() << " )" << endl; | 399 | stream() << " )\n"; | ||
400 | stream() << " : "; | 400 | stream() << " : "; | ||
401 | createParentConstructorCall(); | 401 | createParentConstructorCall(); | ||
402 | createInitializerList(); | 402 | createInitializerList(); | ||
403 | 403 | | |||
404 | stream() << "{" << endl; | 404 | stream() << "{\n"; | ||
405 | 405 | | |||
406 | if (cfg().parentInConstructor) { | 406 | if (cfg().parentInConstructor) { | ||
407 | stream() << " setParent(parent);" << endl; | 407 | stream() << " setParent(parent);\n"; | ||
408 | } | 408 | } | ||
409 | 409 | | |||
410 | if (cfg().dpointer) { | 410 | if (cfg().dpointer) { | ||
411 | stream() << " d = new " << cfg().className << "Private;" << endl; | 411 | stream() << " d = new " << cfg().className << "Private;\n"; | ||
412 | if (parseResult.hasNonModifySignals) { | 412 | if (parseResult.hasNonModifySignals) { | ||
413 | stream() << " " << varPath(QStringLiteral("settingsChanged"), cfg()) << " = 0;" << endl; | 413 | stream() << " " << varPath(QStringLiteral("settingsChanged"), cfg()) << " = 0;\n"; | ||
414 | } | 414 | } | ||
415 | } | 415 | } | ||
416 | 416 | | |||
417 | // Needed in case the singleton class is used as baseclass for | 417 | // Needed in case the singleton class is used as baseclass for | ||
418 | // another singleton. | 418 | // another singleton. | ||
419 | if (cfg().singleton) { | 419 | if (cfg().singleton) { | ||
420 | stream() << " Q_ASSERT(!s_global" << cfg().className << "()->q);" << endl; | 420 | stream() << " Q_ASSERT(!s_global" << cfg().className << "()->q);\n"; | ||
421 | stream() << " s_global" << cfg().className << "()->q = this;" << endl; | 421 | stream() << " s_global" << cfg().className << "()->q = this;\n"; | ||
422 | } | 422 | } | ||
423 | 423 | | |||
424 | if (!parseResult.signalList.isEmpty()) { | 424 | if (!parseResult.signalList.isEmpty()) { | ||
425 | // this cast to base-class pointer-to-member is valid C++ | 425 | // this cast to base-class pointer-to-member is valid C++ | ||
426 | // https://stackoverflow.com/questions/4272909/is-it-safe-to-upcast-a-method-pointer-and-use-it-with-base-class-pointer/ | 426 | // https://stackoverflow.com/questions/4272909/is-it-safe-to-upcast-a-method-pointer-and-use-it-with-base-class-pointer/ | ||
427 | stream() << " KConfigCompilerSignallingItem::NotifyFunction notifyFunction =" | 427 | stream() << " KConfigCompilerSignallingItem::NotifyFunction notifyFunction =" | ||
428 | << " static_cast<KConfigCompilerSignallingItem::NotifyFunction>(&" | 428 | << " static_cast<KConfigCompilerSignallingItem::NotifyFunction>(&" | ||
429 | << cfg().className << "::itemChanged);" << endl; | 429 | << cfg().className << "::itemChanged);\n"; | ||
430 | 430 | | |||
431 | stream() << endl; | 431 | stream() << '\n'; | ||
432 | } | 432 | } | ||
433 | 433 | | |||
434 | for (auto *entry : parseResult.entries) { | 434 | for (auto *entry : parseResult.entries) { | ||
435 | handleCurrentGroupChange(entry); | 435 | handleCurrentGroupChange(entry); | ||
436 | 436 | | |||
437 | const QString key = paramString(entry->key, parseResult.parameters); | 437 | const QString key = paramString(entry->key, parseResult.parameters); | ||
438 | if (!entry->code.isEmpty()) { | 438 | if (!entry->code.isEmpty()) { | ||
439 | stream() << entry->code << endl; | 439 | stream() << entry->code << '\n'; | ||
440 | } | 440 | } | ||
441 | createEnums(entry); | 441 | createEnums(entry); | ||
442 | 442 | | |||
443 | if (!cfg().dpointer) { | 443 | if (!cfg().dpointer) { | ||
444 | stream() << itemDeclaration(entry, cfg()); | 444 | stream() << itemDeclaration(entry, cfg()); | ||
445 | } | 445 | } | ||
446 | 446 | | |||
447 | if (entry->param.isEmpty()) { | 447 | if (entry->param.isEmpty()) { | ||
448 | createNormalEntry(entry, key); | 448 | createNormalEntry(entry, key); | ||
449 | } else { | 449 | } else { | ||
450 | createIndexedEntry(entry, key); | 450 | createIndexedEntry(entry, key); | ||
451 | } | 451 | } | ||
452 | } | 452 | } | ||
453 | 453 | | |||
454 | stream() << "}" << endl << endl; | 454 | stream() << "}\n\n"; | ||
455 | } | 455 | } | ||
456 | 456 | | |||
457 | void KConfigSourceGenerator::createGetterDPointerMode(const CfgEntry *entry) | 457 | void KConfigSourceGenerator::createGetterDPointerMode(const CfgEntry *entry) | ||
458 | { | 458 | { | ||
459 | // Accessor | 459 | // Accessor | ||
460 | if (cfg().useEnumTypes && entry->type == QLatin1String("Enum")) { | 460 | if (cfg().useEnumTypes && entry->type == QLatin1String("Enum")) { | ||
461 | stream() << enumType(entry, cfg().globalEnums); | 461 | stream() << enumType(entry, cfg().globalEnums); | ||
462 | } else { | 462 | } else { | ||
463 | stream() << cppType(entry->type); | 463 | stream() << cppType(entry->type); | ||
464 | } | 464 | } | ||
465 | 465 | | |||
466 | stream() << " " << getFunction(entry->name, cfg().className) << "("; | 466 | stream() << " " << getFunction(entry->name, cfg().className) << "("; | ||
467 | if (!entry->param.isEmpty()) { | 467 | if (!entry->param.isEmpty()) { | ||
468 | stream() << " " << cppType(entry->paramType) << " i "; | 468 | stream() << " " << cppType(entry->paramType) << " i "; | ||
469 | } | 469 | } | ||
470 | stream() << ")" << Const() << endl; | 470 | stream() << ")" << Const() << '\n'; | ||
471 | 471 | | |||
472 | // function body inline only if not using dpointer | 472 | // function body inline only if not using dpointer | ||
473 | // for BC mode | 473 | // for BC mode | ||
474 | startScope(); | 474 | startScope(); | ||
475 | // HACK: Fix memberAccessorBody | 475 | // HACK: Fix memberAccessorBody | ||
476 | stream() << " " << memberAccessorBody(entry, cfg().globalEnums); | 476 | stream() << " " << memberAccessorBody(entry, cfg().globalEnums); | ||
477 | endScope(); | 477 | endScope(); | ||
478 | stream() << endl; | 478 | stream() << '\n'; | ||
479 | } | 479 | } | ||
480 | 480 | | |||
481 | void KConfigSourceGenerator::createSetterDPointerMode(const CfgEntry *entry) | 481 | void KConfigSourceGenerator::createSetterDPointerMode(const CfgEntry *entry) | ||
482 | { | 482 | { | ||
483 | // Manipulator | 483 | // Manipulator | ||
484 | if (!(cfg().allMutators || cfg().mutators.contains(entry->name))) { | 484 | if (!(cfg().allMutators || cfg().mutators.contains(entry->name))) { | ||
485 | return; | 485 | return; | ||
486 | } | 486 | } | ||
487 | 487 | | |||
488 | stream() << "void " << setFunction(entry->name, cfg().className) << "( "; | 488 | stream() << "void " << setFunction(entry->name, cfg().className) << "( "; | ||
489 | if (!entry->param.isEmpty()) { | 489 | if (!entry->param.isEmpty()) { | ||
490 | stream() << cppType(entry->paramType) << " i, "; | 490 | stream() << cppType(entry->paramType) << " i, "; | ||
491 | } | 491 | } | ||
492 | 492 | | |||
493 | if (cfg().useEnumTypes && entry->type == QLatin1String("Enum")) { | 493 | if (cfg().useEnumTypes && entry->type == QLatin1String("Enum")) { | ||
494 | stream() << enumType(entry, cfg().globalEnums); | 494 | stream() << enumType(entry, cfg().globalEnums); | ||
495 | } else { | 495 | } else { | ||
496 | stream() << param(entry->type); | 496 | stream() << param(entry->type); | ||
497 | } | 497 | } | ||
498 | stream() << " v )" << endl; | 498 | stream() << " v )\n"; | ||
499 | 499 | | |||
500 | // function body inline only if not using dpointer | 500 | // function body inline only if not using dpointer | ||
501 | // for BC mode | 501 | // for BC mode | ||
502 | startScope(); | 502 | startScope(); | ||
503 | memberMutatorBody(entry); | 503 | memberMutatorBody(entry); | ||
504 | endScope(); | 504 | endScope(); | ||
505 | stream() << endl; | 505 | stream() << '\n'; | ||
506 | } | 506 | } | ||
507 | 507 | | |||
508 | void KConfigSourceGenerator::createItemGetterDPointerMode(const CfgEntry *entry) | 508 | void KConfigSourceGenerator::createItemGetterDPointerMode(const CfgEntry *entry) | ||
509 | { | 509 | { | ||
510 | // Item accessor | 510 | // Item accessor | ||
511 | if (!cfg().itemAccessors) { | 511 | if (!cfg().itemAccessors) { | ||
512 | return; | 512 | return; | ||
513 | } | 513 | } | ||
514 | stream() << endl; | 514 | stream() << '\n'; | ||
515 | stream() << cfg().inherits << "::Item" << itemType(entry->type) << " *" | 515 | stream() << cfg().inherits << "::Item" << itemType(entry->type) << " *" | ||
516 | << getFunction(entry->name, cfg().className) << "Item("; | 516 | << getFunction(entry->name, cfg().className) << "Item("; | ||
517 | if (!entry->param.isEmpty()) { | 517 | if (!entry->param.isEmpty()) { | ||
518 | stream() << " " << cppType(entry->paramType) << " i "; | 518 | stream() << " " << cppType(entry->paramType) << " i "; | ||
519 | } | 519 | } | ||
520 | stream() << ")" << endl; | 520 | stream() << ")\n"; | ||
521 | startScope(); | 521 | startScope(); | ||
522 | stream() << " " << itemAccessorBody(entry, cfg()); | 522 | stream() << " " << itemAccessorBody(entry, cfg()); | ||
523 | endScope(); | 523 | endScope(); | ||
524 | } | 524 | } | ||
525 | 525 | | |||
526 | void KConfigSourceGenerator::doGetterSetterDPointerMode() | 526 | void KConfigSourceGenerator::doGetterSetterDPointerMode() | ||
527 | { | 527 | { | ||
528 | if (!cfg().dpointer) { | 528 | if (!cfg().dpointer) { | ||
529 | return; | 529 | return; | ||
530 | } | 530 | } | ||
531 | 531 | | |||
532 | // setters and getters go in Cpp if in dpointer mode | 532 | // setters and getters go in Cpp if in dpointer mode | ||
533 | for (auto *entry : parseResult.entries) { | 533 | for (auto *entry : parseResult.entries) { | ||
534 | createSetterDPointerMode(entry); | 534 | createSetterDPointerMode(entry); | ||
535 | createGetterDPointerMode(entry); | 535 | createGetterDPointerMode(entry); | ||
536 | createItemGetterDPointerMode(entry); | 536 | createItemGetterDPointerMode(entry); | ||
537 | stream() << endl; | 537 | stream() << '\n'; | ||
538 | } | 538 | } | ||
539 | } | 539 | } | ||
540 | 540 | | |||
541 | void KConfigSourceGenerator::createDefaultValueGetterSetter() | 541 | void KConfigSourceGenerator::createDefaultValueGetterSetter() | ||
542 | { | 542 | { | ||
543 | // default value getters always go in Cpp | 543 | // default value getters always go in Cpp | ||
544 | for (auto *entry : parseResult.entries) { | 544 | for (auto *entry : parseResult.entries) { | ||
545 | QString n = entry->name; | 545 | QString n = entry->name; | ||
546 | QString t = entry->type; | 546 | QString t = entry->type; | ||
547 | 547 | | |||
548 | // Default value Accessor, as "helper" function | 548 | // Default value Accessor, as "helper" function | ||
549 | if ((cfg().allDefaultGetters || cfg().defaultGetters.contains(n)) && !entry->defaultValue.isEmpty()) { | 549 | if ((cfg().allDefaultGetters || cfg().defaultGetters.contains(n)) && !entry->defaultValue.isEmpty()) { | ||
550 | stream() << cppType(t) << " " << getDefaultFunction(n, cfg().className) << "_helper("; | 550 | stream() << cppType(t) << " " << getDefaultFunction(n, cfg().className) << "_helper("; | ||
551 | if (!entry->param.isEmpty()) { | 551 | if (!entry->param.isEmpty()) { | ||
552 | stream() << " " << cppType(entry->paramType) << " i "; | 552 | stream() << " " << cppType(entry->paramType) << " i "; | ||
553 | } | 553 | } | ||
554 | stream() << ")" << Const() << endl; | 554 | stream() << ")" << Const() << '\n'; | ||
555 | startScope(); | 555 | startScope(); | ||
556 | stream() << memberGetDefaultBody(entry) << endl; | 556 | stream() << memberGetDefaultBody(entry) << '\n'; | ||
557 | endScope(); | 557 | endScope(); | ||
558 | stream() << endl; | 558 | stream() << '\n'; | ||
559 | } | 559 | } | ||
560 | } | 560 | } | ||
561 | } | 561 | } | ||
562 | 562 | | |||
563 | void KConfigSourceGenerator::createDestructor() | 563 | void KConfigSourceGenerator::createDestructor() | ||
564 | { | 564 | { | ||
565 | stream() << cfg().className << "::~" << cfg().className << "()" << endl; | 565 | stream() << cfg().className << "::~" << cfg().className << "()\n"; | ||
566 | startScope(); | 566 | startScope(); | ||
567 | if (cfg().dpointer) { | 567 | if (cfg().dpointer) { | ||
568 | stream() << " delete d;" << endl; | 568 | stream() << " delete d;\n"; | ||
569 | } | 569 | } | ||
570 | if (cfg().singleton) { | 570 | if (cfg().singleton) { | ||
571 | stream() << " s_global" << cfg().className << "()->q = nullptr;" << endl; | 571 | stream() << " s_global" << cfg().className << "()->q = nullptr;\n"; | ||
572 | } | 572 | } | ||
573 | endScope(); | 573 | endScope(); | ||
574 | stream() << endl; | 574 | stream() << '\n'; | ||
575 | } | 575 | } | ||
576 | 576 | | |||
577 | void KConfigSourceGenerator::createNonModifyingSignalsHelper() | 577 | void KConfigSourceGenerator::createNonModifyingSignalsHelper() | ||
578 | { | 578 | { | ||
579 | if (!parseResult.hasNonModifySignals) { | 579 | if (!parseResult.hasNonModifySignals) { | ||
580 | return; | 580 | return; | ||
581 | } | 581 | } | ||
582 | stream() << "bool " << cfg().className << "::" << "usrSave()" << endl; | 582 | stream() << "bool " << cfg().className << "::" << "usrSave()\n"; | ||
583 | startScope(); | 583 | startScope(); | ||
584 | stream() << " const bool res = " << cfg().inherits << "::usrSave();" << endl; | 584 | stream() << " const bool res = " << cfg().inherits << "::usrSave();\n"; | ||
585 | stream() << " if (!res) return false;" << endl << endl; | 585 | stream() << " if (!res) return false;\n\n"; | ||
586 | for (const Signal &signal : parseResult.signalList) { | 586 | for (const Signal &signal : parseResult.signalList) { | ||
587 | if (signal.modify) { | 587 | if (signal.modify) { | ||
588 | continue; | 588 | continue; | ||
589 | } | 589 | } | ||
590 | 590 | | |||
591 | stream() << " if ( " << varPath(QStringLiteral("settingsChanged"), cfg()) << " & " << signalEnumName(signal.name) << " )" << endl; | 591 | stream() << " if ( " << varPath(QStringLiteral("settingsChanged"), cfg()) << " & " << signalEnumName(signal.name) << " )\n"; | ||
592 | stream() << " Q_EMIT " << signal.name << "("; | 592 | stream() << " Q_EMIT " << signal.name << "("; | ||
593 | QList<Param>::ConstIterator it, itEnd = signal.arguments.constEnd(); | 593 | QList<Param>::ConstIterator it, itEnd = signal.arguments.constEnd(); | ||
594 | for (it = signal.arguments.constBegin(); it != itEnd;) { | 594 | for (it = signal.arguments.constBegin(); it != itEnd;) { | ||
595 | Param argument = *it; | 595 | Param argument = *it; | ||
596 | bool cast = false; | 596 | bool cast = false; | ||
597 | if (cfg().useEnumTypes && argument.type == QLatin1String("Enum")) { | 597 | if (cfg().useEnumTypes && argument.type == QLatin1String("Enum")) { | ||
598 | for (int i = 0, end = parseResult.entries.count(); i < end; ++i) { | 598 | for (int i = 0, end = parseResult.entries.count(); i < end; ++i) { | ||
599 | if (parseResult.entries.at(i)->name == argument.name) { | 599 | if (parseResult.entries.at(i)->name == argument.name) { | ||
600 | stream() << "static_cast<" << enumType(parseResult.entries.at(i), cfg().globalEnums) << ">("; | 600 | stream() << "static_cast<" << enumType(parseResult.entries.at(i), cfg().globalEnums) << ">("; | ||
601 | cast = true; | 601 | cast = true; | ||
602 | break; | 602 | break; | ||
603 | } | 603 | } | ||
604 | } | 604 | } | ||
605 | } | 605 | } | ||
606 | stream() << varPath(argument.name, cfg()); | 606 | stream() << varPath(argument.name, cfg()); | ||
607 | if (cast) { | 607 | if (cast) { | ||
608 | stream() << ")"; | 608 | stream() << ")"; | ||
609 | } | 609 | } | ||
610 | if (++it != itEnd) { | 610 | if (++it != itEnd) { | ||
611 | stream() << ", "; | 611 | stream() << ", "; | ||
612 | } | 612 | } | ||
613 | } | 613 | } | ||
614 | 614 | | |||
615 | stream() << ");" << endl; | 615 | stream() << ");\n"; | ||
616 | } | 616 | } | ||
617 | 617 | | |||
618 | stream() << " " << varPath(QStringLiteral("settingsChanged"), cfg()) << " = 0;" << endl; | 618 | stream() << " " << varPath(QStringLiteral("settingsChanged"), cfg()) << " = 0;\n"; | ||
619 | stream() << " return true;" << endl; | 619 | stream() << " return true;\n"; | ||
620 | endScope(); | 620 | endScope(); | ||
621 | } | 621 | } | ||
622 | 622 | | |||
623 | void KConfigSourceGenerator::createSignalFlagsHandler() | 623 | void KConfigSourceGenerator::createSignalFlagsHandler() | ||
624 | { | 624 | { | ||
625 | if (parseResult.signalList.isEmpty()) { | 625 | if (parseResult.signalList.isEmpty()) { | ||
626 | return; | 626 | return; | ||
627 | } | 627 | } | ||
628 | 628 | | |||
629 | stream() << endl; | 629 | stream() << '\n'; | ||
630 | stream() << "void " << cfg().className << "::" << "itemChanged(quint64 flags) {" << endl; | 630 | stream() << "void " << cfg().className << "::" << "itemChanged(quint64 flags) {\n"; | ||
631 | if (parseResult.hasNonModifySignals) | 631 | if (parseResult.hasNonModifySignals) | ||
632 | stream() << " " << varPath(QStringLiteral("settingsChanged"), cfg()) << " |= flags;" << endl; | 632 | stream() << " " << varPath(QStringLiteral("settingsChanged"), cfg()) << " |= flags;\n"; | ||
633 | 633 | | |||
634 | if (!parseResult.signalList.isEmpty()) | 634 | if (!parseResult.signalList.isEmpty()) | ||
635 | stream() << endl; | 635 | stream() << '\n'; | ||
636 | 636 | | |||
637 | for (const Signal &signal : parseResult.signalList) { | 637 | for (const Signal &signal : parseResult.signalList) { | ||
638 | if (signal.modify) { | 638 | if (signal.modify) { | ||
639 | stream() << " if ( flags & " << signalEnumName(signal.name) << " ) {" << endl; | 639 | stream() << " if ( flags & " << signalEnumName(signal.name) << " ) {\n"; | ||
640 | stream() << " Q_EMIT " << signal.name << "();" << endl; | 640 | stream() << " Q_EMIT " << signal.name << "();\n"; | ||
641 | stream() << " }" << endl; | 641 | stream() << " }\n"; | ||
642 | } | 642 | } | ||
643 | } | 643 | } | ||
644 | 644 | | |||
645 | stream() << "}" << endl; | 645 | stream() << "}\n"; | ||
646 | } | 646 | } | ||
647 | 647 | | |||
648 | void KConfigSourceGenerator::includeMoc() { | 648 | void KConfigSourceGenerator::includeMoc() { | ||
649 | const QString mocFileName = cfg().baseName + QStringLiteral(".moc"); | 649 | const QString mocFileName = cfg().baseName + QStringLiteral(".moc"); | ||
650 | 650 | | |||
651 | if (parseResult.signalList.count() || cfg().generateProperties) { | 651 | if (parseResult.signalList.count() || cfg().generateProperties) { | ||
652 | // Add includemoc if they are signals defined. | 652 | // Add includemoc if they are signals defined. | ||
653 | stream() << endl; | 653 | stream() << '\n'; | ||
654 | stream() << "#include \"" << mocFileName << "\"" << endl; | 654 | stream() << "#include \"" << mocFileName << "\"\n"; | ||
655 | stream() << endl; | 655 | stream() << '\n'; | ||
656 | } | 656 | } | ||
657 | } | 657 | } |