diff options
author | Kevin Ottens <kevin.ottens@enioka.com> | 2019-10-08 13:19:31 +0200 |
---|---|---|
committer | Kevin Ottens <kevin.ottens@enioka.com> | 2019-10-08 18:13:01 +0200 |
commit | 5fa1a3312ab24908d870ce2a2399695ac98d828d (patch) | |
tree | e08e4d3134ae2318d65dcb50bee930831f3a6403 /src | |
parent | db2315d79a1565c4dedf97af36c873f42a286bb2 (diff) | |
download | kconfig-5fa1a3312ab24908d870ce2a2399695ac98d828d.tar.gz kconfig-5fa1a3312ab24908d870ce2a2399695ac98d828d.tar.bz2 |
Make kconfig_compiler generate ctors with the optional parent arg
Reviewers: #plasma, #frameworks, dfaure, mart, apol
Reviewed By: apol
Subscribers: kossebau, apol, kde-frameworks-devel
Tags: #frameworks
Differential Revision: https://phabricator.kde.org/D24490
Diffstat (limited to 'src')
-rw-r--r-- | src/kconfig_compiler/kconfig_compiler.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/kconfig_compiler/kconfig_compiler.cpp b/src/kconfig_compiler/kconfig_compiler.cpp index c7f2d9d9..c648d7d0 100644 --- a/src/kconfig_compiler/kconfig_compiler.cpp +++ b/src/kconfig_compiler/kconfig_compiler.cpp @@ -80,6 +80,7 @@ public: if (!visibility.isEmpty()) { visibility += ' '; } + parentInConstructor = codegenConfig.value(QStringLiteral("ParentInConstructor"), false).toBool(); forceStringFilename = codegenConfig.value(QStringLiteral("ForceStringFilename"), false).toBool(); singleton = codegenConfig.value(QStringLiteral("Singleton"), false).toBool(); staticAccessors = singleton; @@ -125,6 +126,7 @@ public: QString className; // The class name to be generated QString inherits; // The class the generated class inherits (if empty, from KConfigSkeleton) QString visibility; + bool parentInConstructor; // The class has the optional parent parameter in its constructor bool forceStringFilename; bool singleton; // The class will be a singleton bool staticAccessors; // provide or not static accessors @@ -1895,6 +1897,12 @@ int main(int argc, char **argv) } h << " " << param((*it).type) << " " << (*it).name; } + if (cfg.parentInConstructor) { + if (cfgFileNameArg || !parameters.isEmpty()) { + h << ","; + } + h << " QObject *parent = nullptr"; + } h << " );" << endl; } else { h << " static " << cfg.className << " *self();" << endl; @@ -2125,6 +2133,12 @@ int main(int argc, char **argv) if (cfgFileNameArg) { h << "KSharedConfig::Ptr config"; } + if (cfg.parentInConstructor) { + if (cfgFileNameArg) { + h << ", "; + } + h << "QObject *parent = nullptr"; + } h << ");" << endl; h << " friend class " << cfg.className << "Helper;" << endl << endl; } @@ -2357,14 +2371,14 @@ int main(int argc, char **argv) } // Constructor - cpp << cfg.className << "::" << cfg.className << "( "; + cpp << cfg.className << "::" << cfg.className << "("; if (cfgFileNameArg) { if (! cfg.forceStringFilename) { cpp << " KSharedConfig::Ptr config"; } else { cpp << " const QString& config"; } - cpp << (parameters.isEmpty() ? " " : ", "); + cpp << (parameters.isEmpty() ? "" : ","); } for (QList<Param>::ConstIterator it = parameters.constBegin(); @@ -2374,6 +2388,13 @@ int main(int argc, char **argv) } cpp << " " << param((*it).type) << " " << (*it).name; } + + if (cfg.parentInConstructor) { + if (cfgFileNameArg || !parameters.isEmpty()) { + cpp << ","; + } + cpp << " QObject *parent"; + } cpp << " )" << endl; cpp << " : " << cfg.inherits << "("; @@ -2400,6 +2421,10 @@ int main(int argc, char **argv) cpp << "{" << endl; + if (cfg.parentInConstructor) { + cpp << " setParent(parent);" << endl; + } + if (cfg.dpointer) { cpp << " d = new " + cfg.className + "Private;" << endl; if (hasNonModifySignals) { |