diff --git a/src/kconfig_compiler/CMakeLists.txt b/src/kconfig_compiler/CMakeLists.txt --- a/src/kconfig_compiler/CMakeLists.txt +++ b/src/kconfig_compiler/CMakeLists.txt @@ -1,6 +1,11 @@ -set(kconfig_compiler_SRCS kconfig_compiler.cpp) +set(kconfig_compiler_SRCS + KConfigXTParameters.cpp + KConfigCodeGenerator.cpp + KConfigHeaderGenerator.cpp + kconfig_compiler.cpp +) add_executable(kconfig_compiler ${kconfig_compiler_SRCS}) diff --git a/src/kconfig_compiler/KConfigCodeGenerator.h b/src/kconfig_compiler/KConfigCodeGenerator.h new file mode 100644 --- /dev/null +++ b/src/kconfig_compiler/KConfigCodeGenerator.h @@ -0,0 +1,78 @@ +/* + This file is part of KDE. + + Copyright (c) 2019 Tomaz Canabrava + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include + +#include "KConfigXTParameters.h" + +class CfgEntry; +struct ParseResult; + +/* This class manages the base of writting a C - Based code */ +class KConfigCodeGenerator { +public: + KConfigCodeGenerator( + const QString& inputFileName, // The kcfg file + const QString& baseDir, // where we should store the generated file + const QString& fileName, // the name of the generated file + const KConfigXTParameters ¶meters, // parameters passed to the generator + const ParseResult &parseResult // The pre processed configuration entries + ); + virtual ~KConfigCodeGenerator() = default; + + void addHeaders(const QStringList& header); + + void beginNamespaces(); + void endNamespaces(); + + void indent(); + void unindent(); + + // Add the correct amount of whitespace in the code. + void whitespace(); + + // start a block scope `{` and increase indentation level. + void endScope(); + + // end a block scope `}` and decrease indentation level. + void startScope(); + + virtual void start(); + +protected: + QString inputFile; + QString baseDir; + QString fileName; + const KConfigXTParameters &cfg; + const ParseResult &parseResult; + QTextStream stream; + QFile file; + + // Special access to `this->` and `const` thru the code. + QString This; + QString Const; + +public: + int indentLevel = 0; +}; diff --git a/src/kconfig_compiler/KConfigCodeGenerator.cpp b/src/kconfig_compiler/KConfigCodeGenerator.cpp new file mode 100644 --- /dev/null +++ b/src/kconfig_compiler/KConfigCodeGenerator.cpp @@ -0,0 +1,115 @@ +#include "KConfigCodeGenerator.h" +#include "KConfigXTParameters.h" +#include "KConfigCommonStructs.h" + +#include +#include +#include + +#include + +using std::endl; + +namespace +{ +QTextStream cout(stdout); +QTextStream cerr(stderr); +} + +KConfigCodeGenerator::KConfigCodeGenerator( + const QString& inputFile, + const QString& baseDir, + const QString& fileName, + const KConfigXTParameters ¶meters, + const ParseResult &parseResult) + : inputFile(inputFile), baseDir(baseDir), fileName(fileName), cfg(parameters), parseResult(parseResult) +{ + file.setFileName(baseDir + fileName); + if (!file.open(QIODevice::WriteOnly)) { + cerr << "Can not open '" << baseDir << fileName << "for writing." << endl; + exit(1); + } + stream.setDevice(&file); + stream.setCodec("utf-8"); + + if (cfg.staticAccessors) { + This = QStringLiteral("self()->"); + } else { + Const = QStringLiteral(" const"); + } +} + +void KConfigCodeGenerator::indent() +{ + indentLevel += 4; +} + +void KConfigCodeGenerator::unindent() +{ + indentLevel -= 4; +} + +void KConfigCodeGenerator::whitespace() +{ + for (int i = 0; i < indentLevel; i++) { + stream << QLatin1Char(' '); + } +} + +void KConfigCodeGenerator::startScope() +{ + stream << QLatin1Char('{'); + stream << endl; + indent(); +} + +void KConfigCodeGenerator::endScope() +{ + unindent(); + stream << QLatin1Char('}'); + stream << endl; +} + +void KConfigCodeGenerator::start() +{ + const QString fileName = QFileInfo(inputFile).fileName(); + stream << "// This file is generated by kconfig_compiler_kf5 from " << fileName << "." << endl; + stream << "// All changes you do to this file will be lost." << endl; + stream << endl; +} + +void KConfigCodeGenerator::addHeaders(const QStringList& headerList) +{ + for (auto include : headerList) { + if (include.startsWith(QLatin1Char('"'))) { + stream << "#include " << include << endl; + } else { + stream << "#include <" << include << ">" << endl; + } + } +} + +// adds as many 'namespace foo {' lines to p_out as +// there are namespaces in p_ns +void KConfigCodeGenerator::beginNamespaces() +{ + if (!cfg.nameSpace.isEmpty()) { + for (const QString &ns : cfg.nameSpace.split(QStringLiteral("::"))) { + stream << "namespace " << ns << " {" << endl; + } + stream << endl; + } +} + +// adds as many '}' lines to p_out as +// there are namespaces in p_ns +void KConfigCodeGenerator::endNamespaces() +{ + if (!cfg.nameSpace.isEmpty()) { + const int namespaceCount = cfg.nameSpace.count(QStringLiteral("::")) + 1; + for (int i = 0; i < namespaceCount; ++i) { + stream << "}" << endl; + } + stream << endl; + } +} diff --git a/src/kconfig_compiler/KConfigCommonStructs.h b/src/kconfig_compiler/KConfigCommonStructs.h new file mode 100644 --- /dev/null +++ b/src/kconfig_compiler/KConfigCommonStructs.h @@ -0,0 +1,107 @@ +#ifndef KCONFIGCOMMONSTRUCTS_H +#define KCONFIGCOMMONSTRUCTS_H + +#include +#include + +struct SignalArguments { + QString type; + QString variableName; +}; + +// TODO: Remove Signal Arguments for `Param` +struct Param +{ + QString name; + QString type; +}; + +struct Signal +{ + QString name; + QString label; + QList arguments; + bool modify = false; +}; + +class CfgEntry +{ +public: + struct Choice { + QString name; + QString context; + QString label; + QString toolTip; + QString whatsThis; + }; + class Choices + { + public: + Choices() {} + Choices(const QList &d, const QString &n, const QString &p) + : prefix(p), choices(d), mName(n) + { + int i = n.indexOf(QLatin1String("::")); + if (i >= 0) { + mExternalQual = n.left(i + 2); + } + } + QString prefix; + QList choices; + const QString &name() const + { + return mName; + } + const QString &externalQualifier() const + { + return mExternalQual; + } + bool external() const + { + return !mExternalQual.isEmpty(); + } + private: + QString mName; + QString mExternalQual; + }; + +public: + QString group; + QString type; + QString key; + QString name; + QString labelContext; + QString label; + QString toolTipContext; + QString toolTip; + QString whatsThisContext; + QString whatsThis; + QString code; + QString defaultValue; + QString param; + QString paramName; + QString paramType; + Choices choices; + QList signalList; + QStringList paramValues; + QStringList paramDefaultValues; + int paramMax; + bool hidden; + QString min; + QString max; +}; + +struct ParseResult { + QString cfgFileName; + bool cfgFileNameArg = false; + QList parameters; + QList signalList; + QStringList includes; + QList entries; +}; + +QString enumName(const QString &n); +QString enumName(const QString &n, const CfgEntry::Choices &c); +QString param(const QString &t); + +#endif \ No newline at end of file diff --git a/src/kconfig_compiler/KConfigHeaderGenerator.h b/src/kconfig_compiler/KConfigHeaderGenerator.h new file mode 100644 --- /dev/null +++ b/src/kconfig_compiler/KConfigHeaderGenerator.h @@ -0,0 +1,64 @@ +/* + This file is part of KDE. + + Copyright (c) 2019 Tomaz Canabrava + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KCONFIGHEADERGENERATOR_H +#define KCONFIGHEADERGENERATOR_H + +#include "KConfigCodeGenerator.h" +#include "KConfigCommonStructs.h" + +#include +#include + +class KConfigXTParameters; +class CfgEntry; +class QTextStream; +struct ParseResult; + +class KConfigHeaderGenerator : public KConfigCodeGenerator { +public: + KConfigHeaderGenerator( + const QString& inputFile, + const QString& baseDir, + const QString& fileName, + const KConfigXTParameters ¶meters, + const ParseResult &parseResult); + + void startHeaderGuards(); + void endHeaderGuards(); + + void implementEnums(); + void implementChoiceEnums(CfgEntry *entry, const CfgEntry::Choices &choices); + void implementValueEnums(CfgEntry *entry, const QStringList &values); + + void doClassDefinition(); + void createHeaders(); + void createProperties(); + void createSlots(); + void createSignals(); + void createDPointer(); + void createConstructor(); + void createDestructor(); + void createForwardDeclarations(); + void start() override; +}; + +#endif \ No newline at end of file diff --git a/src/kconfig_compiler/KConfigHeaderGenerator.cpp b/src/kconfig_compiler/KConfigHeaderGenerator.cpp new file mode 100644 --- /dev/null +++ b/src/kconfig_compiler/KConfigHeaderGenerator.cpp @@ -0,0 +1,232 @@ +#include "KConfigHeaderGenerator.h" +#include "KConfigCommonStructs.h" + +#include + +KConfigHeaderGenerator::KConfigHeaderGenerator( + const QString& inputFile, + const QString& baseDir, + const QString& fileName, + const KConfigXTParameters ¶meters, + const ParseResult &parseResult) + : KConfigCodeGenerator(inputFile, baseDir, fileName, parameters, parseResult) +{ +} + +void KConfigHeaderGenerator::start() +{ + KConfigCodeGenerator::start(); + startHeaderGuards(); + createHeaders(); + beginNamespaces(); + + createForwardDeclarations(); + + doClassDefinition(); + + endNamespaces(); + endHeaderGuards(); +} + +void KConfigHeaderGenerator::doClassDefinition() +{ + stream << "class " << cfg.visibility << cfg.className << " : public " << cfg.inherits << endl; + startScope(); + + // Add Q_OBJECT macro if the config need signals. + if (!parseResult.signalList.isEmpty() || cfg.generateProperties) { + stream << " Q_OBJECT" << endl; + } + stream << " public:" << endl; + + createConstructor(); + createDestructor(); + + endScope(); +} + +void KConfigHeaderGenerator::createHeaders() +{ + addHeaders(cfg.headerIncludes); + + if (!cfg.headerIncludes.isEmpty()) { + stream << endl; + } + + if (!cfg.singleton && parseResult.parameters.isEmpty()) { + stream << "#include " << endl; + } + + if (cfg.inherits == QLatin1String("KCoreConfigSkeleton")) { + stream << "#include " << endl; + } else { + stream << "#include " << endl; + } + + stream << "#include " << endl; + stream << "#include " << endl << endl; + + addHeaders(parseResult.includes); +} + +void KConfigHeaderGenerator::startHeaderGuards() +{ + const bool hasNamespace = cfg.nameSpace.isEmpty(); + const QString namespaceName = QString(QString(cfg.nameSpace).replace(QLatin1String("::"), QLatin1String("_"))).toUpper(); + const QString namespaceStr = hasNamespace ? namespaceName + QLatin1Char('_') : QStringLiteral(""); + const QString defineName = namespaceStr + cfg.className.toUpper() + QStringLiteral("_H"); + + stream << "#ifndef " << defineName << endl; + stream << "#define " << defineName << endl; + stream << endl; +} + +void KConfigHeaderGenerator::endHeaderGuards() +{ + stream << "#ifndef "; + stream << endl; +} + +void KConfigHeaderGenerator::implementChoiceEnums(CfgEntry *entry, const CfgEntry::Choices &choices) +{ + const QList chlist = choices.choices; + + if (chlist.isEmpty()) { + return; + } + + QStringList values; + for (const auto choice : chlist) { + values.append(choices.prefix + choice.name); + } + + if (choices.name().isEmpty()) { + if (cfg.globalEnums) { + stream << " enum " << enumName(entry->name, entry->choices) << " { " << values.join(QStringLiteral(", ")) << " };" << endl; + } else { + // Create an automatically named enum + stream << " class " << enumName(entry->name, entry->choices) << endl; + stream << " {" << endl; + stream << " public:" << endl; + stream << " enum type { " << values.join(QStringLiteral(", ")) << ", COUNT };" << endl; + stream << " };" << endl; + } + } else if (!choices.external()) { + // Create a named enum + stream << " enum " << enumName(entry->name, entry->choices) << " { " << values.join(QStringLiteral(", ")) << " };" << endl; + } +} + +void KConfigHeaderGenerator::implementValueEnums(CfgEntry *entry, const QStringList &values) +{ + if (values.isEmpty()) { + return; + } + + if (cfg.globalEnums) { + // ### FIXME!! + // make the following string table an index-based string search! + // ### + stream << " enum " << enumName(entry->param) << " { " << values.join(QStringLiteral(", ")) << " };" << endl; + stream << " static const char* const " << enumName(entry->param) << "ToString[];" << endl; + +// TODO: Port This. +// cppPreamble += "const char* const " + cfg.className + "::" + enumName(entry->param) + +// "ToString[] = { \"" + values.join(QStringLiteral("\", \"")) + "\" };\n"; + } else { + stream << " class " << enumName(entry->param) << endl; + stream << " {" << endl; + stream << " public:" << endl; + stream << " enum type { " << values.join(QStringLiteral(", ")) << ", COUNT };" << endl; + stream << " static const char* const enumToString[];" << endl; + stream << " };" << endl; + +// TODO: Port This. +// cppPreamble += "const char* const " + cfg.className + "::" + enumName(entry->param) + +// "::enumToString[] = { \"" + values.join(QStringLiteral("\", \"")) + "\" };\n"; + } +} + +void KConfigHeaderGenerator::implementEnums() +{ + for (const auto entry : qAsConst(parseResult.entries)) { + const CfgEntry::Choices &choices = entry->choices; + const QStringList values = entry->paramValues; + + implementChoiceEnums(entry, choices); + implementValueEnums(entry, values); + } + stream << endl; +} + +void KConfigHeaderGenerator::createProperties() +{ + +} + +void KConfigHeaderGenerator::createSlots() +{ + +} + +void KConfigHeaderGenerator::createSignals() +{ + +} + +void KConfigHeaderGenerator::createDPointer() +{ + +} + +void KConfigHeaderGenerator::createConstructor() +{ + if (cfg.singleton) { + stream << " static " << cfg.className << " *self();" << endl; + if (parseResult.cfgFileNameArg) { + stream << " static void instance(const QString& cfgfilename);" << endl; + stream << " static void instance(KSharedConfig::Ptr config);" << endl; + } + return; + } + + stream << " " << cfg.className << "("; + if (parseResult.cfgFileNameArg) { + if (cfg.forceStringFilename) + stream << " const QString &cfgfilename" << (parseResult.parameters.isEmpty() ? " = QString()" : ", "); + else + stream << " KSharedConfig::Ptr config" << (parseResult.parameters.isEmpty() ? " = KSharedConfig::openConfig()" : ", "); + } + + bool first = true; + for (const auto parameter : parseResult.parameters) { + if (first) { + first = false; + } else { + stream << ","; + } + + stream << " " << param(parameter.type) << " " << parameter.name; + } + + if (cfg.parentInConstructor) { + if (parseResult.cfgFileNameArg || !parseResult.parameters.isEmpty()) { + stream << ","; + } + stream << " QObject *parent = nullptr"; + } + stream << " );" << endl; +} + +void KConfigHeaderGenerator::createDestructor() +{ + stream << " ~" << cfg.className << "();" << endl << endl; +} + +void KConfigHeaderGenerator::createForwardDeclarations() +{ + // Private class declaration + if (cfg.dpointer) { + stream << "class " << cfg.className << "Private;" << endl << endl; + } +} \ No newline at end of file diff --git a/src/kconfig_compiler/KConfigXTParameters.h b/src/kconfig_compiler/KConfigXTParameters.h new file mode 100644 --- /dev/null +++ b/src/kconfig_compiler/KConfigXTParameters.h @@ -0,0 +1,75 @@ +/* + This file is part of KDE. + + Copyright (c) 2019 Tomaz Canabrava + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KCOFIGXTPARAMETERS_H +#define KCOFIGXTPARAMETERS_H + +#include +#include +#include + +/** + Configuration Compiler Configuration +*/ +class KConfigXTParameters +{ +public: + KConfigXTParameters(const QString &codegenFilename); + +public: + enum TranslationSystem { + QtTranslation, + KdeTranslation + }; + + // These are read from the .kcfgc configuration file + QString nameSpace; // The namespace for the class to be generated + 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 + bool customAddons; + QString memberVariables; + QStringList headerIncludes; + QStringList sourceIncludes; + QStringList mutators; + QStringList defaultGetters; + QStringList notifiers; + QString qCategoryLoggingName; + QString headerExtension; + QString sourceExtension; + bool allMutators; + bool setUserTexts; + bool allDefaultGetters; + bool dpointer; + bool globalEnums; + bool useEnumTypes; + bool itemAccessors; + bool allNotifiers; + TranslationSystem translationSystem; + QString translationDomain; + bool generateProperties; +}; + +#endif \ No newline at end of file diff --git a/src/kconfig_compiler/KConfigXTParameters.cpp b/src/kconfig_compiler/KConfigXTParameters.cpp new file mode 100644 --- /dev/null +++ b/src/kconfig_compiler/KConfigXTParameters.cpp @@ -0,0 +1,66 @@ +#include "KConfigXTParameters.h" + +// TODO: Remove this. +#undef QT_NO_CAST_FROM_ASCII + +#include + +namespace +{ +QTextStream cout(stdout); +QTextStream cerr(stderr); +} + +KConfigXTParameters::KConfigXTParameters(const QString &codegenFilename) + { + // Configure the compiler with some settings + QSettings codegenConfig(codegenFilename, QSettings::IniFormat); + + nameSpace = codegenConfig.value(QStringLiteral("NameSpace")).toString(); + className = codegenConfig.value(QStringLiteral("ClassName")).toString(); + if (className.isEmpty()) { + cerr << "Class name missing" << endl; + exit(1); + } + inherits = codegenConfig.value(QStringLiteral("Inherits")).toString(); + if (inherits.isEmpty()) { + inherits = QStringLiteral("KConfigSkeleton"); + } + visibility = codegenConfig.value(QStringLiteral("Visibility")).toString(); + if (!visibility.isEmpty()) { + visibility += QLatin1Char(' '); + } + parentInConstructor = codegenConfig.value(QStringLiteral("ParentInConstructor"), false).toBool(); + forceStringFilename = codegenConfig.value(QStringLiteral("ForceStringFilename"), false).toBool(); + singleton = codegenConfig.value(QStringLiteral("Singleton"), false).toBool(); + staticAccessors = singleton; + customAddons = codegenConfig.value(QStringLiteral("CustomAdditions"), false).toBool(); + memberVariables = codegenConfig.value(QStringLiteral("MemberVariables")).toString(); + dpointer = (memberVariables == QLatin1String("dpointer")); + headerIncludes = codegenConfig.value(QStringLiteral("IncludeFiles"), QStringList()).toStringList(); + sourceIncludes = codegenConfig.value(QStringLiteral("SourceIncludeFiles"), QStringList()).toStringList(); + mutators = codegenConfig.value(QStringLiteral("Mutators"), QStringList()).toStringList(); + allMutators = ((mutators.count() == 1) && (mutators.at(0).toLower() == QLatin1String("true"))); + itemAccessors = codegenConfig.value(QStringLiteral("ItemAccessors"), false).toBool(); + setUserTexts = codegenConfig.value(QStringLiteral("SetUserTexts"), false).toBool(); + defaultGetters = codegenConfig.value(QStringLiteral("DefaultValueGetters"), QStringList()).toStringList(); + allDefaultGetters = (defaultGetters.count() == 1) && (defaultGetters.at(0).toLower() == QLatin1String("true")); + notifiers = codegenConfig.value(QStringLiteral("Notifiers"), QStringList()).toStringList(); + allNotifiers = ((notifiers.count() == 1) && (notifiers.at(0).toLower() == QLatin1String("true"))); + globalEnums = codegenConfig.value(QStringLiteral("GlobalEnums"), false).toBool(); + useEnumTypes = codegenConfig.value(QStringLiteral("UseEnumTypes"), false).toBool(); + const QString trString = codegenConfig.value(QStringLiteral("TranslationSystem")).toString().toLower(); + generateProperties = codegenConfig.value(QStringLiteral("GenerateProperties"), false).toBool(); + if (trString == QLatin1String("kde")) { + translationSystem = KdeTranslation; + translationDomain = codegenConfig.value(QStringLiteral("TranslationDomain")).toString(); + } else { + if (!trString.isEmpty() && trString != QLatin1String("qt")) { + cerr << "Unknown translation system, falling back to Qt tr()" << endl; + } + translationSystem = QtTranslation; + } + qCategoryLoggingName = codegenConfig.value(QStringLiteral("CategoryLoggingName"), QString()).toString(); + headerExtension = codegenConfig.value(QStringLiteral("HeaderExtension"), QStringLiteral("h")).toString(); + sourceExtension = codegenConfig.value(QStringLiteral("SourceExtension"), QStringLiteral("cpp")).toString(); + } \ No newline at end of file diff --git a/src/kconfig_compiler/kconfig_compiler.cpp b/src/kconfig_compiler/kconfig_compiler.cpp --- a/src/kconfig_compiler/kconfig_compiler.cpp +++ b/src/kconfig_compiler/kconfig_compiler.cpp @@ -43,6 +43,9 @@ #include #include "../../kconfig_version.h" +#include "KConfigXTParameters.h" +#include "KConfigCommonStructs.h" +#include "KConfigHeaderGenerator.h" namespace { @@ -55,439 +58,11 @@ QString This; QString Const; -/** - Configuration Compiler Configuration -*/ -class CfgConfig -{ -public: - CfgConfig(const QString &codegenFilename) - { - // Configure the compiler with some settings - QSettings codegenConfig(codegenFilename, QSettings::IniFormat); - - nameSpace = codegenConfig.value(QStringLiteral("NameSpace")).toString(); - className = codegenConfig.value(QStringLiteral("ClassName")).toString(); - if (className.isEmpty()) { - cerr << "Class name missing" << endl; - exit(1); - } - inherits = codegenConfig.value(QStringLiteral("Inherits")).toString(); - if (inherits.isEmpty()) { - inherits = QStringLiteral("KConfigSkeleton"); - } - visibility = codegenConfig.value(QStringLiteral("Visibility")).toString(); - 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; - customAddons = codegenConfig.value(QStringLiteral("CustomAdditions"), false).toBool(); - memberVariables = codegenConfig.value(QStringLiteral("MemberVariables")).toString(); - dpointer = (memberVariables == QLatin1String("dpointer")); - headerIncludes = codegenConfig.value(QStringLiteral("IncludeFiles"), QStringList()).toStringList(); - sourceIncludes = codegenConfig.value(QStringLiteral("SourceIncludeFiles"), QStringList()).toStringList(); - mutators = codegenConfig.value(QStringLiteral("Mutators"), QStringList()).toStringList(); - allMutators = ((mutators.count() == 1) && (mutators.at(0).toLower() == QLatin1String("true"))); - itemAccessors = codegenConfig.value(QStringLiteral("ItemAccessors"), false).toBool(); - setUserTexts = codegenConfig.value(QStringLiteral("SetUserTexts"), false).toBool(); - defaultGetters = codegenConfig.value(QStringLiteral("DefaultValueGetters"), QStringList()).toStringList(); - allDefaultGetters = (defaultGetters.count() == 1) && (defaultGetters.at(0).toLower() == QLatin1String("true")); - notifiers = codegenConfig.value(QStringLiteral("Notifiers"), QStringList()).toStringList(); - allNotifiers = ((notifiers.count() == 1) && (notifiers.at(0).toLower() == QLatin1String("true"))); - globalEnums = codegenConfig.value(QStringLiteral("GlobalEnums"), false).toBool(); - useEnumTypes = codegenConfig.value(QStringLiteral("UseEnumTypes"), false).toBool(); - const QString trString = codegenConfig.value(QStringLiteral("TranslationSystem")).toString().toLower(); - generateProperties = codegenConfig.value(QStringLiteral("GenerateProperties"), false).toBool(); - if (trString == QLatin1String("kde")) { - translationSystem = KdeTranslation; - translationDomain = codegenConfig.value(QStringLiteral("TranslationDomain")).toString(); - } else { - if (!trString.isEmpty() && trString != QLatin1String("qt")) { - cerr << "Unknown translation system, falling back to Qt tr()" << endl; - } - translationSystem = QtTranslation; - } - qCategoryLoggingName = codegenConfig.value(QStringLiteral("CategoryLoggingName"), QString()).toString(); - headerExtension = codegenConfig.value(QStringLiteral("HeaderExtension"), QStringLiteral("h")).toString(); - sourceExtension = codegenConfig.value(QStringLiteral("SourceExtension"), QStringLiteral("cpp")).toString(); - } - -public: - enum TranslationSystem { - QtTranslation, - KdeTranslation - }; - - // These are read from the .kcfgc configuration file - QString nameSpace; // The namespace for the class to be generated - 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 - bool customAddons; - QString memberVariables; - QStringList headerIncludes; - QStringList sourceIncludes; - QStringList mutators; - QStringList defaultGetters; - QStringList notifiers; - QString qCategoryLoggingName; - QString headerExtension; - QString sourceExtension; - bool allMutators; - bool setUserTexts; - bool allDefaultGetters; - bool dpointer; - bool globalEnums; - bool useEnumTypes; - bool itemAccessors; - bool allNotifiers; - TranslationSystem translationSystem; - QString translationDomain; - bool generateProperties; -}; - -struct SignalArguments { - QString type; - QString variableName; -}; - -class Signal -{ -public: - Signal() : modify(false) {} - - QString name; - QString label; - QList arguments; - bool modify; -}; - -class CfgEntry -{ -public: - struct Choice { - QString name; - QString context; - QString label; - QString toolTip; - QString whatsThis; - }; - class Choices - { - public: - Choices() {} - Choices(const QList &d, const QString &n, const QString &p) - : prefix(p), choices(d), mName(n) - { - int i = n.indexOf(QLatin1String("::")); - if (i >= 0) { - mExternalQual = n.left(i + 2); - } - } - QString prefix; - QList choices; - const QString &name() const - { - return mName; - } - const QString &externalQualifier() const - { - return mExternalQual; - } - bool external() const - { - return !mExternalQual.isEmpty(); - } - private: - QString mName; - QString mExternalQual; - }; - - CfgEntry(const QString &group, const QString &type, const QString &key, - const QString &name, const QString &labelContext, const QString &label, - const QString &toolTipContext, const QString &toolTip, const QString &whatsThisContext, const QString &whatsThis, const QString &code, - const QString &defaultValue, const Choices &choices, const QList &signalList, - bool hidden) - : mGroup(group), mType(type), mKey(key), mName(name), - mLabelContext(labelContext), mLabel(label), mToolTipContext(toolTipContext), mToolTip(toolTip), - mWhatsThisContext(whatsThisContext), mWhatsThis(whatsThis), - mCode(code), mDefaultValue(defaultValue), mChoices(choices), - mSignalList(signalList), mParamMax(0), mHidden(hidden) - { - } - - void setGroup(const QString &group) - { - mGroup = group; - } - QString group() const - { - return mGroup; - } - - void setType(const QString &type) - { - mType = type; - } - QString type() const - { - return mType; - } - - void setKey(const QString &key) - { - mKey = key; - } - QString key() const - { - return mKey; - } - - void setName(const QString &name) - { - mName = name; - } - QString name() const - { - return mName; - } - - void setLabelContext(const QString &labelContext) - { - mLabelContext = labelContext; - } - QString labelContext() const - { - return mLabelContext; - } - - void setLabel(const QString &label) - { - mLabel = label; - } - QString label() const - { - return mLabel; - } - - void setToolTipContext(const QString &toolTipContext) - { - mToolTipContext = toolTipContext; - } - QString toolTipContext() const - { - return mToolTipContext; - } - - void setToolTip(const QString &toolTip) - { - mToolTip = toolTip; - } - QString toolTip() const - { - return mToolTip; - } - - void setWhatsThisContext(const QString &whatsThisContext) - { - mWhatsThisContext = whatsThisContext; - } - QString whatsThisContext() const - { - return mWhatsThisContext; - } - - void setWhatsThis(const QString &whatsThis) - { - mWhatsThis = whatsThis; - } - QString whatsThis() const - { - return mWhatsThis; - } - - void setDefaultValue(const QString &d) - { - mDefaultValue = d; - } - QString defaultValue() const - { - return mDefaultValue; - } - - void setCode(const QString &d) - { - mCode = d; - } - QString code() const - { - return mCode; - } - - void setMinValue(const QString &d) - { - mMin = d; - } - QString minValue() const - { - return mMin; - } - - void setMaxValue(const QString &d) - { - mMax = d; - } - QString maxValue() const - { - return mMax; - } - - void setParam(const QString &d) - { - mParam = d; - } - QString param() const - { - return mParam; - } - - void setParamName(const QString &d) - { - mParamName = d; - } - QString paramName() const - { - return mParamName; - } - - void setParamType(const QString &d) - { - mParamType = d; - } - QString paramType() const - { - return mParamType; - } - - void setChoices(const QList &d, const QString &n, const QString &p) - { - mChoices = Choices(d, n, p); - } - Choices choices() const - { - return mChoices; - } - - void setParamValues(const QStringList &d) - { - mParamValues = d; - } - QStringList paramValues() const - { - return mParamValues; - } - - void setParamDefaultValues(const QStringList &d) - { - mParamDefaultValues = d; - } - QString paramDefaultValue(int i) const - { - return mParamDefaultValues[i]; - } - - void setParamMax(int d) - { - mParamMax = d; - } - int paramMax() const - { - return mParamMax; - } - - void setSignalList(const QList &value) - { - mSignalList = value; - } - QList signalList() const - { - return mSignalList; - } - - bool hidden() const - { - return mHidden; - } - - void dump() const - { - cerr << "" << endl; - cerr << " group: " << mGroup << endl; - cerr << " type: " << mType << endl; - cerr << " key: " << mKey << endl; - cerr << " name: " << mName << endl; - cerr << " label context: " << mLabelContext << endl; - cerr << " label: " << mLabel << endl; -// whatsthis - cerr << " code: " << mCode << endl; -// cerr << " values: " << mValues.join(":") << endl; - - if (!param().isEmpty()) { - cerr << " param name: " << mParamName << endl; - cerr << " param type: " << mParamType << endl; - cerr << " paramvalues: " << mParamValues.join(QChar::fromLatin1(':')) << endl; - } - cerr << " default: " << mDefaultValue << endl; - cerr << " hidden: " << mHidden << endl; - cerr << " min: " << mMin << endl; - cerr << " max: " << mMax << endl; - cerr << "" << endl; - } - -private: - QString mGroup; - QString mType; - QString mKey; - QString mName; - QString mLabelContext; - QString mLabel; - QString mToolTipContext; - QString mToolTip; - QString mWhatsThisContext; - QString mWhatsThis; - QString mCode; - QString mDefaultValue; - QString mParam; - QString mParamName; - QString mParamType; - Choices mChoices; - QList mSignalList; - QStringList mParamValues; - QStringList mParamDefaultValues; - int mParamMax; - bool mHidden; - QString mMin; - QString mMax; -}; - -class Param -{ -public: - QString name; - QString type; -}; // returns the name of an member variable // use itemPath to know the full path // like using d-> in case of dpointer -static QString varName(const QString &n, const CfgConfig &cfg) +static QString varName(const QString &n, const KConfigXTParameters &cfg) { QString result; if (!cfg.dpointer) { @@ -500,7 +75,7 @@ return result; } -static QString varPath(const QString &n, const CfgConfig &cfg) +static QString varPath(const QString &n, const KConfigXTParameters &cfg) { QString result; if (cfg.dpointer) { @@ -511,14 +86,14 @@ return result; } -static QString enumName(const QString &n) +QString enumName(const QString &n) { QString result = QLatin1String("Enum") + n; result[4] = result[4].toUpper(); return result; } -static QString enumName(const QString &n, const CfgEntry::Choices &c) +QString enumName(const QString &n, const CfgEntry::Choices &c) { QString result = c.name(); if (result.isEmpty()) { @@ -530,9 +105,9 @@ static QString enumType(const CfgEntry *e, bool globalEnums) { - QString result = e->choices().name(); + QString result = e->choices.name(); if (result.isEmpty()) { - result = QLatin1String("Enum") + e->name(); + result = QLatin1String("Enum") + e->name; if (!globalEnums) { result += QLatin1String("::type"); } @@ -662,7 +237,7 @@ static void preProcessDefault(QString &defaultValue, const QString &name, const QString &type, const CfgEntry::Choices &choices, - QString &code, const CfgConfig &cfg) + QString &code, const KConfigXTParameters &cfg) { if (type == QLatin1String("String") && !defaultValue.isEmpty()) { defaultValue = literalString(defaultValue); @@ -738,7 +313,7 @@ } } -CfgEntry *parseEntry(const QString &group, const QDomElement &element, const CfgConfig &cfg) +CfgEntry *parseEntry(const QString &group, const QDomElement &element, const KConfigXTParameters &cfg) { bool defaultCode = false; QString type = element.attribute(QStringLiteral("type")); @@ -978,19 +553,33 @@ preProcessDefault(defaultValue, name, type, choices, code, cfg); } - CfgEntry *result = new CfgEntry(group, type, key, name, labelContext, label, toolTipContext, toolTip, whatsThisContext, whatsThis, - code, defaultValue, choices, signalList, - hidden == QLatin1String("true")); + CfgEntry *result = new CfgEntry(); + result->group = group; + result->type = type; + result->key = key; + result->name = name; + result->labelContext = labelContext; + result->label = label; + result->toolTipContext = toolTipContext; + result->toolTip = toolTip; + result->whatsThisContext = whatsThisContext; + result->whatsThis = whatsThis; + result->code = code; + result->defaultValue = defaultValue; + result->choices = choices; + result->signalList = signalList; + result->hidden = hidden == QLatin1String("true"); + if (!param.isEmpty()) { - result->setParam(param); - result->setParamName(paramName); - result->setParamType(paramType); - result->setParamValues(paramValues); - result->setParamDefaultValues(paramDefaultValues); - result->setParamMax(paramMax); + result->param = param; + result->paramName = paramName; + result->paramType = paramType; + result->paramValues = paramValues; + result->paramDefaultValues = paramDefaultValues; + result->paramMax = paramMax; } - result->setMinValue(minValue); - result->setMaxValue(maxValue); + result->min = minValue; + result->max = maxValue; return result; } @@ -1175,47 +764,47 @@ return t; } -static QString itemDeclaration(const CfgEntry *e, const CfgConfig &cfg) +static QString itemDeclaration(const CfgEntry *e, const KConfigXTParameters &cfg) { if (cfg.itemAccessors) { return QString(); } QString type; - if (!e->signalList().isEmpty()) { + if (!e->signalList.isEmpty()) { type = QStringLiteral("KConfigCompilerSignallingItem"); } else { - type = cfg.inherits + "::Item" + itemType(e->type()); + type = cfg.inherits + "::Item" + itemType(e->type); } - QString fCap = e->name(); + QString fCap = e->name; fCap[0] = fCap[0].toUpper(); return " " + type + " *item" + fCap + - ( (!e->param().isEmpty())?(QStringLiteral("[%1]").arg(e->paramMax()+1)) : QString()) + ";\n"; + ( (!e->param.isEmpty())?(QStringLiteral("[%1]").arg(e->paramMax+1)) : QString()) + ";\n"; } // returns the name of an item variable // use itemPath to know the full path // like using d-> in case of dpointer -static QString itemVar(const CfgEntry *e, const CfgConfig &cfg) +static QString itemVar(const CfgEntry *e, const KConfigXTParameters &cfg) { QString result; if (cfg.itemAccessors) { if (!cfg.dpointer) { - result = 'm' + e->name() + "Item"; + result = 'm' + e->name + "Item"; result[1] = result[1].toUpper(); } else { - result = e->name() + "Item"; + result = e->name + "Item"; result[0] = result[0].toLower(); } } else { - result = "item" + e->name(); + result = "item" + e->name; result[4] = result[4].toUpper(); } return result; } -static QString itemPath(const CfgEntry *e, const CfgConfig &cfg) +static QString itemPath(const CfgEntry *e, const KConfigXTParameters &cfg) { QString result; if (cfg.dpointer) { @@ -1227,18 +816,18 @@ } QString newItem(const CfgEntry* entry, const QString &key, const QString& defaultValue, - const CfgConfig &cfg, const QString ¶m = QString()) { + const KConfigXTParameters &cfg, const QString ¶m = QString()) { - QList sigs = entry->signalList(); + QList sigs = entry->signalList; QString t; if (!sigs.isEmpty()) { t += QLatin1String("new KConfigCompilerSignallingItem("); } - t += "new "+ cfg.inherits + "::Item" + itemType(entry->type()) + "( currentGroup(), " - + key + ", " + varPath( entry->name(), cfg ) + param; + t += "new "+ cfg.inherits + "::Item" + itemType(entry->type) + "( currentGroup(), " + + key + ", " + varPath( entry->name, cfg ) + param; - if (entry->type() == QLatin1String("Enum")) { - t += ", values" + entry->name(); + if (entry->type == QLatin1String("Enum")) { + t += ", values" + entry->name; } if (!defaultValue.isEmpty()) { t += QLatin1String(", ") + defaultValue; @@ -1262,11 +851,11 @@ QString paramString(const QString &s, const CfgEntry *e, int i) { QString result = s; - QString needle = "$(" + e->param() + ')'; + QString needle = "$(" + e->param + ')'; if (result.contains(needle)) { QString tmp; - if (e->paramType() == QLatin1String("Enum")) { - tmp = e->paramValues().at(i); + if (e->paramType == QLatin1String("Enum")) { + tmp = e->paramValues.at(i); } else { tmp = QString::number(i); } @@ -1296,21 +885,21 @@ return "QStringLiteral( \"" + paramString + "\" )" + arguments; } -QString translatedString(const CfgConfig &cfg, const QString &string, const QString &context = QString(), const QString ¶m = QString(), const QString ¶mValue = QString()) +QString translatedString(const KConfigXTParameters &cfg, const QString &string, const QString &context = QString(), const QString ¶m = QString(), const QString ¶mValue = QString()) { QString result; switch (cfg.translationSystem) { - case CfgConfig::QtTranslation: + case KConfigXTParameters::QtTranslation: if (!context.isEmpty()) { result += "/*: " + context + " */ QCoreApplication::translate(\""; } else { result += QLatin1String("QCoreApplication::translate(\""); } result += cfg.className + "\", "; break; - case CfgConfig::KdeTranslation: + case KConfigXTParameters::KdeTranslation: if (!cfg.translationDomain.isEmpty() && !context.isEmpty()) { result += "i18ndc(" + quoteString(cfg.translationDomain) + ", " + quoteString(context) + ", "; } else if (!cfg.translationDomain.isEmpty()) { @@ -1337,47 +926,47 @@ } /* int i is the value of the parameter */ -QString userTextsFunctions(CfgEntry *e, const CfgConfig &cfg, QString itemVarStr = QString(), const QString &i = QString()) +QString userTextsFunctions(CfgEntry *e, const KConfigXTParameters &cfg, QString itemVarStr = QString(), const QString &i = QString()) { QString txt; if (itemVarStr.isNull()) { itemVarStr = itemPath(e, cfg); } - if (!e->label().isEmpty()) { + if (!e->label.isEmpty()) { txt += " " + itemVarStr + "->setLabel( "; - txt += translatedString(cfg, e->label(), e->labelContext(), e->param(), i); + txt += translatedString(cfg, e->label, e->labelContext, e->param, i); txt += QLatin1String(" );\n"); } - if (!e->toolTip().isEmpty()) { + if (!e->toolTip.isEmpty()) { txt += " " + itemVarStr + "->setToolTip( "; - txt += translatedString(cfg, e->toolTip(), e->toolTipContext(), e->param(), i); + txt += translatedString(cfg, e->toolTip, e->toolTipContext, e->param, i); txt += QLatin1String(" );\n"); } - if (!e->whatsThis().isEmpty()) { + if (!e->whatsThis.isEmpty()) { txt += " " + itemVarStr + "->setWhatsThis( "; - txt += translatedString(cfg, e->whatsThis(), e->whatsThisContext(), e->param(), i); + txt += translatedString(cfg, e->whatsThis, e->whatsThisContext, e->param, i); txt += QLatin1String(" );\n"); } return txt; } // returns the member accesor implementation // which should go in the h file if inline // or the cpp file if not inline -QString memberAccessorBody(CfgEntry *e, bool globalEnums, const CfgConfig &cfg) +QString memberAccessorBody(CfgEntry *e, bool globalEnums, const KConfigXTParameters &cfg) { QString result; QTextStream out(&result, QIODevice::WriteOnly); - QString n = e->name(); - QString t = e->type(); + QString n = e->name; + QString t = e->type; bool useEnumType = cfg.useEnumTypes && t == QLatin1String("Enum"); out << "return "; if (useEnumType) { out << "static_cast<" << enumType(e, globalEnums) << ">("; } out << This << varPath(n, cfg); - if (!e->param().isEmpty()) { + if (!e->param.isEmpty()) { out << "[i]"; } if (useEnumType) { @@ -1392,61 +981,61 @@ // which should go in the h file if inline // or the cpp file if not inline -void addDebugMethod(QTextStream &out, const CfgConfig &cfg, const QString &n) +void addDebugMethod(QTextStream &out, const KConfigXTParameters &cfg, const QString &n) { if (cfg.qCategoryLoggingName.isEmpty()) { out << " qDebug() << \"" << setFunction(n); } else { out << " qCDebug(" << cfg.qCategoryLoggingName << ") << \"" << setFunction(n); } } -QString memberMutatorBody(CfgEntry *e, const CfgConfig &cfg) +QString memberMutatorBody(CfgEntry *e, const KConfigXTParameters &cfg) { QString result; QTextStream out(&result, QIODevice::WriteOnly); - QString n = e->name(); - QString t = e->type(); + QString n = e->name; + QString t = e->type; - if (!e->minValue().isEmpty()) { - if (e->minValue() != QLatin1String("0") || !isUnsigned(t)) { // skip writing "if uint<0" (#187579) - out << "if (v < " << e->minValue() << ")" << endl; + if (!e->min.isEmpty()) { + if (e->min != QLatin1String("0") || !isUnsigned(t)) { // skip writing "if uint<0" (#187579) + out << "if (v < " << e->min << ")" << endl; out << "{" << endl; addDebugMethod(out, cfg, n); out << ": value \" << v << \" is less than the minimum value of "; - out << e->minValue() << "\";" << endl; - out << " v = " << e->minValue() << ";" << endl; + out << e->min << "\";" << endl; + out << " v = " << e->min << ";" << endl; out << "}" << endl; } } - if (!e->maxValue().isEmpty()) { - out << endl << "if (v > " << e->maxValue() << ")" << endl; + if (!e->max.isEmpty()) { + out << endl << "if (v > " << e->max << ")" << endl; out << "{" << endl; addDebugMethod(out, cfg, n); out << ": value \" << v << \" is greater than the maximum value of "; - out << e->maxValue() << "\";" << endl; - out << " v = " << e->maxValue() << ";" << endl; + out << e->max << "\";" << endl; + out << " v = " << e->max << ";" << endl; out << "}" << endl << endl; } - const QString varExpression = This + varPath(n, cfg) + (e->param().isEmpty() ? QString() : QStringLiteral("[i]")); + const QString varExpression = This + varPath(n, cfg) + (e->param.isEmpty() ? QString() : QStringLiteral("[i]")); - const bool hasBody = !e->signalList().empty() || cfg.generateProperties; + const bool hasBody = !e->signalList.empty() || cfg.generateProperties; out << "if ("; if (hasBody) { out << "v != " << varExpression << " && "; } out << "!" << This << "isImmutable( QStringLiteral( \""; - if (!e->param().isEmpty()) { - out << e->paramName().replace("$(" + e->param() + ")", QLatin1String("%1")) << "\" ).arg( "; - if (e->paramType() == QLatin1String("Enum")) { + if (!e->param.isEmpty()) { + out << e->paramName.replace("$(" + e->param + ")", QLatin1String("%1")) << "\" ).arg( "; + if (e->paramType == QLatin1String("Enum")) { out << "QLatin1String( "; if (cfg.globalEnums) { - out << enumName(e->param()) << "ToString[i]"; + out << enumName(e->param) << "ToString[i]"; } else { - out << enumName(e->param()) << "::enumToString[i]"; + out << enumName(e->param) << "::enumToString[i]"; } out << " )"; @@ -1460,7 +1049,7 @@ out << " ))" << (hasBody ? " {" : "") << endl; out << " " << varExpression << " = v;" << endl; - const auto listSignal = e->signalList(); + const auto listSignal = e->signalList; for (const Signal &signal : listSignal) { if (signal.modify) { out << " Q_EMIT " << This << signal.name << "();" << endl; @@ -1480,37 +1069,37 @@ // or the cpp file if not inline QString memberGetDefaultBody(CfgEntry *e) { - QString result = e->code(); + QString result = e->code; QTextStream out(&result, QIODevice::WriteOnly); out << endl; - if (!e->param().isEmpty()) { + if (!e->param.isEmpty()) { out << " switch (i) {" << endl; - for (int i = 0; i <= e->paramMax(); ++i) { - if (!e->paramDefaultValue(i).isEmpty()) { - out << " case " << i << ": return " << e->paramDefaultValue(i) << ';' << endl; + for (int i = 0; i <= e->paramMax; ++i) { + if (!e->paramDefaultValues[i].isEmpty()) { + out << " case " << i << ": return " << e->paramDefaultValues[i] << ';' << endl; } } out << " default:" << endl; - out << " return " << e->defaultValue().replace("$(" + e->param() + ')', QLatin1String("i")) << ';' << endl; + out << " return " << e->defaultValue.replace("$(" + e->param + ')', QLatin1String("i")) << ';' << endl; out << " }" << endl; } else { - out << " return " << e->defaultValue() << ';'; + out << " return " << e->defaultValue << ';'; } return result; } // returns the item accesor implementation // which should go in the h file if inline // or the cpp file if not inline -QString itemAccessorBody(CfgEntry *e, const CfgConfig &cfg) +QString itemAccessorBody(CfgEntry *e, const KConfigXTParameters &cfg) { QString result; QTextStream out(&result, QIODevice::WriteOnly); out << "return " << itemPath(e, cfg); - if (!e->param().isEmpty()) { + if (!e->param.isEmpty()) { out << "[i]"; } out << ";" << endl; @@ -1627,7 +1216,7 @@ QString baseName = QFileInfo(codegenFilename).fileName(); baseName = baseName.left(baseName.length() - 6); - CfgConfig cfg = CfgConfig(codegenFilename); + KConfigXTParameters cfg = KConfigXTParameters(codegenFilename); QFile input(inputFilename); @@ -1648,35 +1237,29 @@ return 1; } - QString cfgFileName; - bool cfgFileNameArg = false; - QList parameters; - QList signalList; - QStringList includes; - - QList entries; + ParseResult parseResult; for (QDomElement e = cfgElement.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) { QString tag = e.tagName(); if (tag == QLatin1String("include")) { QString includeFile = e.text(); if (!includeFile.isEmpty()) { - includes.append(includeFile); + parseResult.includes.append(includeFile); } } else if (tag == QLatin1String("kcfgfile")) { - cfgFileName = e.attribute(QStringLiteral("name")); - cfgFileNameArg = e.attribute(QStringLiteral("arg")).toLower() == QLatin1String("true"); + parseResult.cfgFileName = e.attribute(QStringLiteral("name")); + parseResult.cfgFileNameArg = e.attribute(QStringLiteral("arg")).toLower() == QLatin1String("true"); for (QDomElement e2 = e.firstChildElement(); !e2.isNull(); e2 = e2.nextSiblingElement()) { if (e2.tagName() == QLatin1String("parameter")) { Param p; p.name = e2.attribute(QStringLiteral("name")); p.type = e2.attribute(QStringLiteral("type")); if (p.type.isEmpty()) { p.type = QStringLiteral("String"); } - parameters.append(p); + parseResult.parameters.append(p); } } @@ -1692,7 +1275,7 @@ } CfgEntry *entry = parseEntry(group, e2, cfg); if (entry) { - entries.append(entry); + parseResult.entries.append(entry); } else { cerr << "Can not parse entry." << endl; return 1; @@ -1721,222 +1304,54 @@ theSignal.label = e2.text(); } } - signalList.append(theSignal); + parseResult.signalList.append(theSignal); } } if (cfg.className.isEmpty()) { cerr << "Class name missing" << endl; return 1; } - if (cfg.singleton && !parameters.isEmpty()) { + if (cfg.singleton && !parseResult.parameters.isEmpty()) { cerr << "Singleton class can not have parameters" << endl; return 1; } - if (!cfgFileName.isEmpty() && cfgFileNameArg) { + if (!parseResult.cfgFileName.isEmpty() && parseResult.cfgFileNameArg) { cerr << "Having both a fixed filename and a filename as argument is not possible." << endl; return 1; } - if (entries.isEmpty()) { + if (parseResult.entries.isEmpty()) { cerr << "No entries." << endl; } -#if 0 - CfgEntry *cfg; - for (cfg = entries.first(); cfg; cfg = entries.next()) { - cfg->dump(); - } -#endif - QString headerFileName = baseName + '.' + cfg.headerExtension; QString implementationFileName = baseName + '.' + cfg.sourceExtension; QString mocFileName = baseName + ".moc"; QString cppPreamble; // code to be inserted at the beginnin of the cpp file, e.g. initialization of static values - QFile header(baseDir + headerFileName); - if (!header.open(QIODevice::WriteOnly)) { - cerr << "Can not open '" << baseDir << headerFileName << "for writing." << endl; - return 1; - } - - QTextStream h(&header); - - h.setCodec("utf-8"); - - h << "// This file is generated by kconfig_compiler_kf5 from " << QFileInfo(inputFilename).fileName() << "." << endl; - h << "// All changes you do to this file will be lost." << endl; - - h << "#ifndef " << (!cfg.nameSpace.isEmpty() ? QString(QString(cfg.nameSpace).replace(QLatin1String("::"), QLatin1String("_")).toUpper() + '_') : QLatin1String("")) - << cfg.className.toUpper() << "_H" << endl; - h << "#define " << (!cfg.nameSpace.isEmpty() ? QString(QString(cfg.nameSpace).replace(QLatin1String("::"), QLatin1String("_")).toUpper() + '_') : QLatin1String("")) - << cfg.className.toUpper() << "_H" << endl << endl; - - // Includes - QStringList::ConstIterator it; - for (it = cfg.headerIncludes.constBegin(); it != cfg.headerIncludes.constEnd(); ++it) { - if ((*it).startsWith('"')) { - h << "#include " << *it << endl; - } else { - h << "#include <" << *it << ">" << endl; - } - } - - if (!cfg.headerIncludes.isEmpty()) { - h << endl; - } - - if (!cfg.singleton && parameters.isEmpty()) { - h << "#include " << endl; - } - - if (cfg.inherits == QLatin1String("KCoreConfigSkeleton")) { - h << "#include " << endl; - } else { - h << "#include " << endl; - } - - h << "#include " << endl; - h << "#include " << endl << endl; - - // Includes - for (it = includes.constBegin(); it != includes.constEnd(); ++it) { - if ((*it).startsWith('"')) { - h << "#include " << *it << endl; - } else { - h << "#include <" << *it << ">" << endl; - } - } - - beginNamespaces(cfg.nameSpace, h); - - // Private class declaration - if (cfg.dpointer) { - h << "class " << cfg.className << "Private;" << endl << endl; - } - - // Class declaration header - h << "class " << cfg.visibility << cfg.className << " : public " << cfg.inherits << endl; - - h << "{" << endl; - // Add Q_OBJECT macro if the config need signals. - if (!signalList.isEmpty() || cfg.generateProperties) { - h << " Q_OBJECT" << endl; - } - h << " public:" << endl; - - // enums - QList::ConstIterator itEntry; - for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - const CfgEntry::Choices &choices = (*itEntry)->choices(); - const QList chlist = choices.choices; - if (!chlist.isEmpty()) { - QStringList values; - QList::ConstIterator itChoice; - for (itChoice = chlist.constBegin(); itChoice != chlist.constEnd(); ++itChoice) { - values.append(choices.prefix + (*itChoice).name); - } - if (choices.name().isEmpty()) { - if (cfg.globalEnums) { - h << " enum " << enumName((*itEntry)->name(), (*itEntry)->choices()) << " { " << values.join(QStringLiteral(", ")) << " };" << endl; - } else { - // Create an automatically named enum - h << " class " << enumName((*itEntry)->name(), (*itEntry)->choices()) << endl; - h << " {" << endl; - h << " public:" << endl; - h << " enum type { " << values.join(QStringLiteral(", ")) << ", COUNT };" << endl; - h << " };" << endl; - } - } else if (!choices.external()) { - // Create a named enum - h << " enum " << enumName((*itEntry)->name(), (*itEntry)->choices()) << " { " << values.join(QStringLiteral(", ")) << " };" << endl; - } - } - const QStringList values = (*itEntry)->paramValues(); - if (!values.isEmpty()) { - if (cfg.globalEnums) { - // ### FIXME!! - // make the following string table an index-based string search! - // ### - h << " enum " << enumName((*itEntry)->param()) << " { " << values.join(QStringLiteral(", ")) << " };" << endl; - h << " static const char* const " << enumName((*itEntry)->param()) << "ToString[];" << endl; - cppPreamble += "const char* const " + cfg.className + "::" + enumName((*itEntry)->param()) + - "ToString[] = { \"" + values.join(QStringLiteral("\", \"")) + "\" };\n"; - } else { - h << " class " << enumName((*itEntry)->param()) << endl; - h << " {" << endl; - h << " public:" << endl; - h << " enum type { " << values.join(QStringLiteral(", ")) << ", COUNT };" << endl; - h << " static const char* const enumToString[];" << endl; - h << " };" << endl; - cppPreamble += "const char* const " + cfg.className + "::" + enumName((*itEntry)->param()) + - "::enumToString[] = { \"" + values.join(QStringLiteral("\", \"")) + "\" };\n"; - } - } - } - h << endl; - + KConfigHeaderGenerator headerGenerator(inputFilename, baseDir, headerFileName, cfg, parseResult); + headerGenerator.start(); - // Constructor or singleton accessor - if (!cfg.singleton) { - h << " " << cfg.className << "("; - if (cfgFileNameArg) { - if (cfg.forceStringFilename) - h << " const QString &cfgfilename" - << (parameters.isEmpty() ? " = QString()" : ", "); - else - h << " KSharedConfig::Ptr config" - << (parameters.isEmpty() ? " = KSharedConfig::openConfig()" : ", "); - } - for (QList::ConstIterator it = parameters.constBegin(); - it != parameters.constEnd(); ++it) { - if (it != parameters.constBegin()) { - h << ","; - } - 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; - if (cfgFileNameArg) { - h << " static void instance(const QString& cfgfilename);" << endl; - h << " static void instance(KSharedConfig::Ptr config);" << endl; - } - } - - // Destructor - h << " ~" << cfg.className << "();" << endl << endl; - - // global variables - if (cfg.staticAccessors) { - This = QStringLiteral("self()->"); - } else { - Const = QStringLiteral(" const"); - } +#if 0 for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - QString n = (*itEntry)->name(); - QString t = (*itEntry)->type(); + QString n = (*itEntry)->name; + QString t = (*itEntry)->type; // Manipulator if (cfg.allMutators || cfg.mutators.contains(n)) { h << " /**" << endl; - h << " Set " << (*itEntry)->label() << endl; + h << " Set " << (*itEntry)->label << endl; h << " */" << endl; if (cfg.staticAccessors) { h << " static" << endl; } h << " void " << setFunction(n) << "( "; - if (!(*itEntry)->param().isEmpty()) { - h << cppType((*itEntry)->paramType()) << " i, "; + if (!(*itEntry)->param.isEmpty()) { + h << cppType((*itEntry)->paramType) << " i, "; } if (cfg.useEnumTypes && t == QLatin1String("Enum")) { h << enumType(*itEntry, cfg.globalEnums); @@ -1984,16 +1399,16 @@ } // Accessor h << " /**" << endl; - h << " Get " << (*itEntry)->label() << endl; + h << " Get " << (*itEntry)->label << endl; h << " */" << endl; if (cfg.staticAccessors) { h << " static" << endl; } h << " "; h << returnType; h << " " << getFunction(n) << "("; - if (!(*itEntry)->param().isEmpty()) { - h << " " << cppType((*itEntry)->paramType()) << " i "; + if (!(*itEntry)->param.isEmpty()) { + h << " " << cppType((*itEntry)->paramType) << " i "; } h << ")" << Const; // function body inline only if not using dpointer @@ -2007,10 +1422,10 @@ } // Default value Accessor - if ((cfg.allDefaultGetters || cfg.defaultGetters.contains(n)) && !(*itEntry)->defaultValue().isEmpty()) { + if ((cfg.allDefaultGetters || cfg.defaultGetters.contains(n)) && !(*itEntry)->defaultValue.isEmpty()) { h << endl; h << " /**" << endl; - h << " Get " << (*itEntry)->label() << " default value" << endl; + h << " Get " << (*itEntry)->label << " default value" << endl; h << " */" << endl; if (cfg.staticAccessors) { h << " static" << endl; @@ -2022,17 +1437,17 @@ h << cppType(t); } h << " " << getDefaultFunction(n) << "("; - if (!(*itEntry)->param().isEmpty()) { - h << " " << cppType((*itEntry)->paramType()) << " i "; + if (!(*itEntry)->param.isEmpty()) { + h << " " << cppType((*itEntry)->paramType) << " i "; } h << ")" << Const << endl; h << " {" << endl; h << " return "; if (cfg.useEnumTypes && t == QLatin1String("Enum")) { h << "static_cast<" << enumType(*itEntry, cfg.globalEnums) << ">("; } h << getDefaultFunction(n) << "_helper("; - if (!(*itEntry)->param().isEmpty()) { + if (!(*itEntry)->param.isEmpty()) { h << " i "; } h << ")"; @@ -2050,10 +1465,10 @@ h << " Get Item object corresponding to " << n << "()" << endl; h << " */" << endl; - h << " Item" << itemType((*itEntry)->type()) << " *" + h << " Item" << itemType((*itEntry)->type) << " *" << getFunction(n) << "Item("; - if (!(*itEntry)->param().isEmpty()) { - h << " " << cppType((*itEntry)->paramType()) << " i "; + if (!(*itEntry)->param.isEmpty()) { + h << " " << cppType((*itEntry)->paramType) << " i "; } h << ")"; if (!cfg.dpointer) { @@ -2105,7 +1520,7 @@ QString type = param(argument.type); if (cfg.useEnumTypes && argument.type == QLatin1String("Enum")) { for (int i = 0, end = entries.count(); i < end; ++i) { - if (entries[i]->name() == argument.variableName) { + if (entries[i]->name == argument.variableName) { type = enumType(entries[i], cfg.globalEnums); break; } @@ -2161,36 +1576,36 @@ if (cfg.memberVariables != QLatin1String("dpointer")) { QString group; for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - if ((*itEntry)->group() != group) { - group = (*itEntry)->group(); + if ((*itEntry)->group != group) { + group = (*itEntry)->group; h << endl; h << " // " << group << endl; } - h << " " << cppType((*itEntry)->type()) << " " << varName((*itEntry)->name(), cfg); - if (!(*itEntry)->param().isEmpty()) { - h << QStringLiteral("[%1]").arg((*itEntry)->paramMax() + 1); + h << " " << cppType((*itEntry)->type) << " " << varName((*itEntry)->name, cfg); + if (!(*itEntry)->param.isEmpty()) { + h << QStringLiteral("[%1]").arg((*itEntry)->paramMax + 1); } h << ";" << endl; - if (cfg.allDefaultGetters || cfg.defaultGetters.contains((*itEntry)->name())) { + if (cfg.allDefaultGetters || cfg.defaultGetters.contains((*itEntry)->name)) { h << " "; if (cfg.staticAccessors) { h << "static "; } - h << cppType((*itEntry)->type()) << " " << getDefaultFunction((*itEntry)->name()) << "_helper("; - if (!(*itEntry)->param().isEmpty()) { - h << " " << cppType((*itEntry)->paramType()) << " i "; + h << cppType((*itEntry)->type) << " " << getDefaultFunction((*itEntry)->name) << "_helper("; + if (!(*itEntry)->param.isEmpty()) { + h << " " << cppType((*itEntry)->paramType) << " i "; } h << ")" << Const << ";" << endl; } } h << endl << " private:" << endl; if (cfg.itemAccessors) { for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - h << " Item" << itemType((*itEntry)->type()) << " *" << itemVar(*itEntry, cfg); - if (!(*itEntry)->param().isEmpty()) { - h << QStringLiteral("[%1]").arg((*itEntry)->paramMax() + 1); + h << " Item" << itemType((*itEntry)->type) << " *" << itemVar(*itEntry, cfg); + if (!(*itEntry)->param.isEmpty()) { + h << QStringLiteral("[%1]").arg((*itEntry)->paramMax + 1); } h << ";" << endl; } @@ -2203,14 +1618,14 @@ // use a private class for both member variables and items h << " private:" << endl; for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - if (cfg.allDefaultGetters || cfg.defaultGetters.contains((*itEntry)->name())) { + if (cfg.allDefaultGetters || cfg.defaultGetters.contains((*itEntry)->name)) { h << " "; if (cfg.staticAccessors) { h << "static "; } - h << cppType((*itEntry)->type()) << " " << getDefaultFunction((*itEntry)->name()) << "_helper("; - if (!(*itEntry)->param().isEmpty()) { - h << " " << cppType((*itEntry)->paramType()) << " i "; + h << cppType((*itEntry)->type) << " " << getDefaultFunction((*itEntry)->name) << "_helper("; + if (!(*itEntry)->param.isEmpty()) { + h << " " << cppType((*itEntry)->paramType) << " i "; } h << ")" << Const << ";" << endl; } @@ -2259,7 +1674,7 @@ cpp << endl; } - if (cfg.setUserTexts && cfg.translationSystem == CfgConfig::KdeTranslation) { + if (cfg.setUserTexts && cfg.translationSystem == KConfigXTParameters::KdeTranslation) { cpp << "#include " << endl << endl; } @@ -2284,25 +1699,25 @@ cpp << "{" << endl; cpp << " public:" << endl; for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - if ((*itEntry)->group() != group) { - group = (*itEntry)->group(); + if ((*itEntry)->group != group) { + group = (*itEntry)->group; cpp << endl; cpp << " // " << group << endl; } - cpp << " " << cppType((*itEntry)->type()) << " " << varName((*itEntry)->name(), cfg); - if (!(*itEntry)->param().isEmpty()) { - cpp << QStringLiteral("[%1]").arg((*itEntry)->paramMax() + 1); + cpp << " " << cppType((*itEntry)->type) << " " << varName((*itEntry)->name, cfg); + if (!(*itEntry)->param.isEmpty()) { + cpp << QStringLiteral("[%1]").arg((*itEntry)->paramMax + 1); } cpp << ";" << endl; } cpp << endl << " // items" << endl; for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - const QString declType = (*itEntry)->signalList().isEmpty() - ? QString(cfg.inherits + "::Item" + itemType((*itEntry)->type())) + const QString declType = (*itEntry)->signalList.isEmpty() + ? QString(cfg.inherits + "::Item" + itemType((*itEntry)->type)) : QStringLiteral("KConfigCompilerSignallingItem"); cpp << " " << declType << " *" << itemVar( *itEntry, cfg ); - if (!(*itEntry)->param().isEmpty()) { - cpp << QStringLiteral("[%1]").arg((*itEntry)->paramMax() + 1); + if (!(*itEntry)->param.isEmpty()) { + cpp << QStringLiteral("[%1]").arg((*itEntry)->paramMax + 1); } cpp << ";" << endl; } @@ -2453,22 +1868,22 @@ } for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - if ((*itEntry)->group() != group) { + if ((*itEntry)->group != group) { if (!group.isEmpty()) { cpp << endl; } - group = (*itEntry)->group(); + group = (*itEntry)->group; cpp << " setCurrentGroup( " << paramString(group, parameters) << " );" << endl << endl; } - QString key = paramString((*itEntry)->key(), parameters); - if (!(*itEntry)->code().isEmpty()) { - cpp << (*itEntry)->code() << endl; + QString key = paramString((*itEntry)->key, parameters); + if (!(*itEntry)->code.isEmpty()) { + cpp << (*itEntry)->code << endl; } - if ((*itEntry)->type() == QLatin1String("Enum")) { + if ((*itEntry)->type == QLatin1String("Enum")) { cpp << " QList<" + cfg.inherits + "::ItemEnum::Choice> values" - << (*itEntry)->name() << ";" << endl; - const QList choices = (*itEntry)->choices().choices; + << (*itEntry)->name << ";" << endl; + const QList choices = (*itEntry)->choices.choices; QList::ConstIterator it; for (it = choices.constBegin(); it != choices.constEnd(); ++it) { cpp << " {" << endl; @@ -2491,72 +1906,72 @@ << ";" << endl; } } - cpp << " values" << (*itEntry)->name() << ".append( choice );" << endl; + cpp << " values" << (*itEntry)->name << ".append( choice );" << endl; cpp << " }" << endl; } } if (!cfg.dpointer) { cpp << itemDeclaration(*itEntry, cfg); } - if ((*itEntry)->param().isEmpty()) { + if ((*itEntry)->param.isEmpty()) { // Normal case cpp << " " << itemPath(*itEntry, cfg) << " = " - << newItem((*itEntry), key, (*itEntry)->defaultValue(), cfg) << endl; + << newItem((*itEntry), key, (*itEntry)->defaultValue, cfg) << endl; - if (!(*itEntry)->minValue().isEmpty()) { - cpp << " " << itemPath(*itEntry, cfg) << "->setMinValue(" << (*itEntry)->minValue() << ");" << endl; + if (!(*itEntry)->min.isEmpty()) { + cpp << " " << itemPath(*itEntry, cfg) << "->setMinValue(" << (*itEntry)->min << ");" << endl; } - if (!(*itEntry)->maxValue().isEmpty()) { - cpp << " " << itemPath(*itEntry, cfg) << "->setMaxValue(" << (*itEntry)->maxValue() << ");" << endl; + if (!(*itEntry)->max.isEmpty()) { + cpp << " " << itemPath(*itEntry, cfg) << "->setMaxValue(" << (*itEntry)->max << ");" << endl; } if (cfg.setUserTexts) { cpp << userTextsFunctions((*itEntry), cfg); } - if (cfg.allNotifiers || cfg.notifiers.contains((*itEntry)->name())) { + if (cfg.allNotifiers || cfg.notifiers.contains((*itEntry)->name)) { cpp << " " << itemPath(*itEntry, cfg) << "->setWriteFlags(KConfigBase::Notify);" << endl; } cpp << " addItem( " << itemPath(*itEntry, cfg); - QString quotedName = (*itEntry)->name(); + QString quotedName = (*itEntry)->name; addQuotes(quotedName); if (quotedName != key) { - cpp << ", QStringLiteral( \"" << (*itEntry)->name() << "\" )"; + cpp << ", QStringLiteral( \"" << (*itEntry)->name << "\" )"; } cpp << " );" << endl; } else { // Indexed - for (int i = 0; i <= (*itEntry)->paramMax(); i++) { + for (int i = 0; i <= (*itEntry)->paramMax; i++) { QString defaultStr; QString itemVarStr(itemPath(*itEntry, cfg) + QStringLiteral("[%1]").arg(i)); - if (!(*itEntry)->paramDefaultValue(i).isEmpty()) { - defaultStr = (*itEntry)->paramDefaultValue(i); - } else if (!(*itEntry)->defaultValue().isEmpty()) { - defaultStr = paramString((*itEntry)->defaultValue(), (*itEntry), i); + if (!(*itEntry)->paramDefaultValues[i].isEmpty()) { + defaultStr = (*itEntry)->paramDefaultValues[i]; + } else if (!(*itEntry)->defaultValue.isEmpty()) { + defaultStr = paramString((*itEntry)->defaultValue, (*itEntry), i); } else { - defaultStr = defaultValue((*itEntry)->type()); + defaultStr = defaultValue((*itEntry)->type); } cpp << " " << itemVarStr << " = " << newItem((*itEntry), paramString(key, *itEntry, i), defaultStr, cfg, QStringLiteral("[%1]").arg(i)) << endl; if (cfg.setUserTexts) { - cpp << userTextsFunctions(*itEntry, cfg, itemVarStr, (*itEntry)->paramName()); + cpp << userTextsFunctions(*itEntry, cfg, itemVarStr, (*itEntry)->paramName); } // Make mutators for enum parameters work by adding them with $(..) replaced by the // param name. The check for isImmutable in the set* functions doesn't have the param // name available, just the corresponding enum value (int), so we need to store the // param names in a separate static list!. cpp << " addItem( " << itemVarStr << ", QStringLiteral( \""; - if ((*itEntry)->paramType() == QLatin1String("Enum")) { - cpp << (*itEntry)->paramName().replace("$(" + (*itEntry)->param() + ')', QLatin1String("%1")).arg((*itEntry)->paramValues()[i]); + if ((*itEntry)->paramType == QLatin1String("Enum")) { + cpp << (*itEntry)->paramName.replace("$(" + (*itEntry)->param + ')', QLatin1String("%1")).arg((*itEntry)->paramValues[i]); } else { - cpp << (*itEntry)->paramName().replace("$(" + (*itEntry)->param() + ')', QLatin1String("%1")).arg(i); + cpp << (*itEntry)->paramName.replace("$(" + (*itEntry)->param + ')', QLatin1String("%1")).arg(i); } cpp << "\" ) );" << endl; } @@ -2568,14 +1983,14 @@ if (cfg.dpointer) { // setters and getters go in Cpp if in dpointer mode for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - QString n = (*itEntry)->name(); - QString t = (*itEntry)->type(); + QString n = (*itEntry)->name; + QString t = (*itEntry)->type; // Manipulator if (cfg.allMutators || cfg.mutators.contains(n)) { cpp << "void " << setFunction(n, cfg.className) << "( "; - if (!(*itEntry)->param().isEmpty()) { - cpp << cppType((*itEntry)->paramType()) << " i, "; + if (!(*itEntry)->param.isEmpty()) { + cpp << cppType((*itEntry)->paramType) << " i, "; } if (cfg.useEnumTypes && t == QLatin1String("Enum")) { cpp << enumType(*itEntry, cfg.globalEnums); @@ -2597,8 +2012,8 @@ cpp << cppType(t); } cpp << " " << getFunction(n, cfg.className) << "("; - if (!(*itEntry)->param().isEmpty()) { - cpp << " " << cppType((*itEntry)->paramType()) << " i "; + if (!(*itEntry)->param.isEmpty()) { + cpp << " " << cppType((*itEntry)->paramType) << " i "; } cpp << ")" << Const << endl; // function body inline only if not using dpointer @@ -2612,10 +2027,10 @@ // Item accessor if (cfg.itemAccessors) { cpp << endl; - cpp << cfg.inherits + "::Item" << itemType((*itEntry)->type()) << " *" + cpp << cfg.inherits + "::Item" << itemType((*itEntry)->type) << " *" << getFunction(n, cfg.className) << "Item("; - if (!(*itEntry)->param().isEmpty()) { - cpp << " " << cppType((*itEntry)->paramType()) << " i "; + if (!(*itEntry)->param.isEmpty()) { + cpp << " " << cppType((*itEntry)->paramType) << " i "; } cpp << ")" << endl; cpp << "{" << endl; @@ -2629,14 +2044,14 @@ // default value getters always go in Cpp for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - QString n = (*itEntry)->name(); - QString t = (*itEntry)->type(); + QString n = (*itEntry)->name; + QString t = (*itEntry)->type; // Default value Accessor, as "helper" function - if ((cfg.allDefaultGetters || cfg.defaultGetters.contains(n)) && !(*itEntry)->defaultValue().isEmpty()) { + if ((cfg.allDefaultGetters || cfg.defaultGetters.contains(n)) && !(*itEntry)->defaultValue.isEmpty()) { cpp << cppType(t) << " " << getDefaultFunction(n, cfg.className) << "_helper("; - if (!(*itEntry)->param().isEmpty()) { - cpp << " " << cppType((*itEntry)->paramType()) << " i "; + if (!(*itEntry)->param.isEmpty()) { + cpp << " " << cppType((*itEntry)->paramType) << " i "; } cpp << ")" << Const << endl; cpp << "{" << endl; @@ -2674,7 +2089,7 @@ bool cast = false; if (cfg.useEnumTypes && argument.type == QLatin1String("Enum")) { for (int i = 0, end = entries.count(); i < end; ++i) { - if (entries[i]->name() == argument.variableName) { + if (entries[i]->name == argument.variableName) { cpp << "static_cast<" << enumType(entries[i], cfg.globalEnums) << ">("; cast = true; break; @@ -2728,4 +2143,5 @@ qDeleteAll(entries); implementation.close(); +#endif }