Changeset View
Changeset View
Standalone View
Standalone View
src/kconfig_compiler/kconfig_compiler.cpp
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | 65 | { | |||
---|---|---|---|---|---|
75 | inherits = codegenConfig.value(QStringLiteral("Inherits")).toString(); | 75 | inherits = codegenConfig.value(QStringLiteral("Inherits")).toString(); | ||
76 | if (inherits.isEmpty()) { | 76 | if (inherits.isEmpty()) { | ||
77 | inherits = QStringLiteral("KConfigSkeleton"); | 77 | inherits = QStringLiteral("KConfigSkeleton"); | ||
78 | } | 78 | } | ||
79 | visibility = codegenConfig.value(QStringLiteral("Visibility")).toString(); | 79 | visibility = codegenConfig.value(QStringLiteral("Visibility")).toString(); | ||
80 | if (!visibility.isEmpty()) { | 80 | if (!visibility.isEmpty()) { | ||
81 | visibility += ' '; | 81 | visibility += ' '; | ||
82 | } | 82 | } | ||
83 | parentInConstructor = codegenConfig.value(QStringLiteral("ParentInConstructor"), false).toBool(); | ||||
83 | forceStringFilename = codegenConfig.value(QStringLiteral("ForceStringFilename"), false).toBool(); | 84 | forceStringFilename = codegenConfig.value(QStringLiteral("ForceStringFilename"), false).toBool(); | ||
84 | singleton = codegenConfig.value(QStringLiteral("Singleton"), false).toBool(); | 85 | singleton = codegenConfig.value(QStringLiteral("Singleton"), false).toBool(); | ||
85 | staticAccessors = singleton; | 86 | staticAccessors = singleton; | ||
86 | customAddons = codegenConfig.value(QStringLiteral("CustomAdditions"), false).toBool(); | 87 | customAddons = codegenConfig.value(QStringLiteral("CustomAdditions"), false).toBool(); | ||
87 | memberVariables = codegenConfig.value(QStringLiteral("MemberVariables")).toString(); | 88 | memberVariables = codegenConfig.value(QStringLiteral("MemberVariables")).toString(); | ||
88 | dpointer = (memberVariables == QLatin1String("dpointer")); | 89 | dpointer = (memberVariables == QLatin1String("dpointer")); | ||
89 | headerIncludes = codegenConfig.value(QStringLiteral("IncludeFiles"), QStringList()).toStringList(); | 90 | headerIncludes = codegenConfig.value(QStringLiteral("IncludeFiles"), QStringList()).toStringList(); | ||
90 | sourceIncludes = codegenConfig.value(QStringLiteral("SourceIncludeFiles"), QStringList()).toStringList(); | 91 | sourceIncludes = codegenConfig.value(QStringLiteral("SourceIncludeFiles"), QStringList()).toStringList(); | ||
Show All 29 Lines | 119 | enum TranslationSystem { | |||
120 | KdeTranslation | 121 | KdeTranslation | ||
121 | }; | 122 | }; | ||
122 | 123 | | |||
123 | // These are read from the .kcfgc configuration file | 124 | // These are read from the .kcfgc configuration file | ||
124 | QString nameSpace; // The namespace for the class to be generated | 125 | QString nameSpace; // The namespace for the class to be generated | ||
125 | QString className; // The class name to be generated | 126 | QString className; // The class name to be generated | ||
126 | QString inherits; // The class the generated class inherits (if empty, from KConfigSkeleton) | 127 | QString inherits; // The class the generated class inherits (if empty, from KConfigSkeleton) | ||
127 | QString visibility; | 128 | QString visibility; | ||
129 | bool parentInConstructor; // The class has the optional parent parameter in its constructor | ||||
128 | bool forceStringFilename; | 130 | bool forceStringFilename; | ||
129 | bool singleton; // The class will be a singleton | 131 | bool singleton; // The class will be a singleton | ||
130 | bool staticAccessors; // provide or not static accessors | 132 | bool staticAccessors; // provide or not static accessors | ||
131 | bool customAddons; | 133 | bool customAddons; | ||
132 | QString memberVariables; | 134 | QString memberVariables; | ||
133 | QStringList headerIncludes; | 135 | QStringList headerIncludes; | ||
134 | QStringList sourceIncludes; | 136 | QStringList sourceIncludes; | ||
135 | QStringList mutators; | 137 | QStringList mutators; | ||
▲ Show 20 Lines • Show All 1754 Lines • ▼ Show 20 Line(s) | 1883 | if (!cfg.singleton) { | |||
1890 | } | 1892 | } | ||
1891 | for (QList<Param>::ConstIterator it = parameters.constBegin(); | 1893 | for (QList<Param>::ConstIterator it = parameters.constBegin(); | ||
1892 | it != parameters.constEnd(); ++it) { | 1894 | it != parameters.constEnd(); ++it) { | ||
1893 | if (it != parameters.constBegin()) { | 1895 | if (it != parameters.constBegin()) { | ||
1894 | h << ","; | 1896 | h << ","; | ||
1895 | } | 1897 | } | ||
1896 | h << " " << param((*it).type) << " " << (*it).name; | 1898 | h << " " << param((*it).type) << " " << (*it).name; | ||
1897 | } | 1899 | } | ||
1900 | if (cfg.parentInConstructor) { | ||||
1901 | if (cfgFileNameArg || !parameters.isEmpty()) { | ||||
1902 | h << ","; | ||||
1903 | } | ||||
1904 | h << " QObject *parent = nullptr"; | ||||
1905 | } | ||||
1898 | h << " );" << endl; | 1906 | h << " );" << endl; | ||
1899 | } else { | 1907 | } else { | ||
1900 | h << " static " << cfg.className << " *self();" << endl; | 1908 | h << " static " << cfg.className << " *self();" << endl; | ||
1901 | if (cfgFileNameArg) { | 1909 | if (cfgFileNameArg) { | ||
1902 | h << " static void instance(const QString& cfgfilename);" << endl; | 1910 | h << " static void instance(const QString& cfgfilename);" << endl; | ||
1903 | h << " static void instance(KSharedConfig::Ptr config);" << endl; | 1911 | h << " static void instance(KSharedConfig::Ptr config);" << endl; | ||
1904 | } | 1912 | } | ||
1905 | } | 1913 | } | ||
▲ Show 20 Lines • Show All 214 Lines • ▼ Show 20 Line(s) | |||||
2120 | h << " protected:" << endl; | 2128 | h << " protected:" << endl; | ||
2121 | 2129 | | |||
2122 | // Private constructor for singleton | 2130 | // Private constructor for singleton | ||
2123 | if (cfg.singleton) { | 2131 | if (cfg.singleton) { | ||
2124 | h << " " << cfg.className << "("; | 2132 | h << " " << cfg.className << "("; | ||
2125 | if (cfgFileNameArg) { | 2133 | if (cfgFileNameArg) { | ||
2126 | h << "KSharedConfig::Ptr config"; | 2134 | h << "KSharedConfig::Ptr config"; | ||
2127 | } | 2135 | } | ||
2136 | if (cfg.parentInConstructor) { | ||||
2137 | if (cfgFileNameArg) { | ||||
2138 | h << ", "; | ||||
2139 | } | ||||
2140 | h << "QObject *parent = nullptr"; | ||||
2141 | } | ||||
2128 | h << ");" << endl; | 2142 | h << ");" << endl; | ||
2129 | h << " friend class " << cfg.className << "Helper;" << endl << endl; | 2143 | h << " friend class " << cfg.className << "Helper;" << endl << endl; | ||
2130 | } | 2144 | } | ||
2131 | 2145 | | |||
2132 | if (hasNonModifySignals) { | 2146 | if (hasNonModifySignals) { | ||
2133 | h << " bool usrSave() override;" << endl; | 2147 | h << " bool usrSave() override;" << endl; | ||
2134 | } | 2148 | } | ||
2135 | 2149 | | |||
▲ Show 20 Lines • Show All 216 Lines • ▼ Show 20 Line(s) | 2318 | if (cfg.singleton) { | |||
2352 | } | 2366 | } | ||
2353 | } | 2367 | } | ||
2354 | 2368 | | |||
2355 | if (!cppPreamble.isEmpty()) { | 2369 | if (!cppPreamble.isEmpty()) { | ||
2356 | cpp << cppPreamble << endl; | 2370 | cpp << cppPreamble << endl; | ||
2357 | } | 2371 | } | ||
2358 | 2372 | | |||
2359 | // Constructor | 2373 | // Constructor | ||
2360 | cpp << cfg.className << "::" << cfg.className << "( "; | 2374 | cpp << cfg.className << "::" << cfg.className << "("; | ||
2361 | if (cfgFileNameArg) { | 2375 | if (cfgFileNameArg) { | ||
2362 | if (! cfg.forceStringFilename) { | 2376 | if (! cfg.forceStringFilename) { | ||
2363 | cpp << " KSharedConfig::Ptr config"; | 2377 | cpp << " KSharedConfig::Ptr config"; | ||
2364 | } else { | 2378 | } else { | ||
2365 | cpp << " const QString& config"; | 2379 | cpp << " const QString& config"; | ||
2366 | } | 2380 | } | ||
2367 | cpp << (parameters.isEmpty() ? " " : ", "); | 2381 | cpp << (parameters.isEmpty() ? "" : ","); | ||
2368 | } | 2382 | } | ||
2369 | 2383 | | |||
2370 | for (QList<Param>::ConstIterator it = parameters.constBegin(); | 2384 | for (QList<Param>::ConstIterator it = parameters.constBegin(); | ||
2371 | it != parameters.constEnd(); ++it) { | 2385 | it != parameters.constEnd(); ++it) { | ||
2372 | if (it != parameters.constBegin()) { | 2386 | if (it != parameters.constBegin()) { | ||
2373 | cpp << ","; | 2387 | cpp << ","; | ||
2374 | } | 2388 | } | ||
2375 | cpp << " " << param((*it).type) << " " << (*it).name; | 2389 | cpp << " " << param((*it).type) << " " << (*it).name; | ||
2376 | } | 2390 | } | ||
2391 | | ||||
2392 | if (cfg.parentInConstructor) { | ||||
2393 | if (cfgFileNameArg || !parameters.isEmpty()) { | ||||
2394 | cpp << ","; | ||||
2395 | } | ||||
2396 | cpp << " QObject *parent"; | ||||
2397 | } | ||||
2377 | cpp << " )" << endl; | 2398 | cpp << " )" << endl; | ||
2378 | 2399 | | |||
2379 | cpp << " : " << cfg.inherits << "("; | 2400 | cpp << " : " << cfg.inherits << "("; | ||
2380 | if (!cfgFileName.isEmpty()) { | 2401 | if (!cfgFileName.isEmpty()) { | ||
2381 | cpp << " QStringLiteral( \"" << cfgFileName << "\" "; | 2402 | cpp << " QStringLiteral( \"" << cfgFileName << "\" "; | ||
2382 | } | 2403 | } | ||
2383 | if (cfgFileNameArg) { | 2404 | if (cfgFileNameArg) { | ||
2384 | cpp << " config "; | 2405 | cpp << " config "; | ||
Show All 10 Lines | |||||
2395 | } | 2416 | } | ||
2396 | 2417 | | |||
2397 | if (hasNonModifySignals && !cfg.dpointer) { | 2418 | if (hasNonModifySignals && !cfg.dpointer) { | ||
2398 | cpp << " , " << varName(QStringLiteral("settingsChanged"), cfg) << "(0)" << endl; | 2419 | cpp << " , " << varName(QStringLiteral("settingsChanged"), cfg) << "(0)" << endl; | ||
2399 | } | 2420 | } | ||
2400 | 2421 | | |||
2401 | cpp << "{" << endl; | 2422 | cpp << "{" << endl; | ||
2402 | 2423 | | |||
2424 | if (cfg.parentInConstructor) { | ||||
2425 | cpp << " setParent(parent);" << endl; | ||||
2426 | } | ||||
2427 | | ||||
2403 | if (cfg.dpointer) { | 2428 | if (cfg.dpointer) { | ||
2404 | cpp << " d = new " + cfg.className + "Private;" << endl; | 2429 | cpp << " d = new " + cfg.className + "Private;" << endl; | ||
2405 | if (hasNonModifySignals) { | 2430 | if (hasNonModifySignals) { | ||
2406 | cpp << " " << varPath(QStringLiteral("settingsChanged"), cfg) << " = 0;" << endl; | 2431 | cpp << " " << varPath(QStringLiteral("settingsChanged"), cfg) << " = 0;" << endl; | ||
2407 | } | 2432 | } | ||
2408 | } | 2433 | } | ||
2409 | // Needed in case the singleton class is used as baseclass for | 2434 | // Needed in case the singleton class is used as baseclass for | ||
2410 | // another singleton. | 2435 | // another singleton. | ||
▲ Show 20 Lines • Show All 292 Lines • Show Last 20 Lines |