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 @@ -156,6 +156,15 @@ struct SignalArguments { QString type; QString variableName; + + bool operator !=(const SignalArguments& argument) const { + return type != argument.type || variableName != argument.variableName; + } + + bool operator ==(const SignalArguments& argument) const { + return ! ((*this) != argument); + } + }; class Signal @@ -167,6 +176,10 @@ QString label; QList arguments; bool modify; + + bool operator != (const Signal& signal) const { + return name != signal.name || label != signal.label || arguments != signal.arguments || modify != signal.modify; + } }; class CfgEntry @@ -482,6 +495,10 @@ public: QString name; QString type; + + bool operator!=(const Param& param) const { + return name != param.name || type != param.type; + } }; // returns the name of an member variable @@ -683,14 +700,13 @@ } else { cpp << " QStringList default" << name << ";" << endl; } - const QStringList defaults = defaultValue.split(QLatin1Char(',')); - QStringList::ConstIterator it; - for (it = defaults.constBegin(); it != defaults.constEnd(); ++it) { + + for (const auto def : defaultValue.split(QLatin1Char(','))) { cpp << " default" << name << ".append( "; if (type == QLatin1String("UrlList")) { cpp << "QUrl::fromUserInput("; } - cpp << "QString::fromUtf8( \"" << *it << "\" ) "; + cpp << "QString::fromUtf8( \"" << def << "\" ) "; if (type == QLatin1String("UrlList")) { cpp << ") "; } @@ -707,30 +723,26 @@ } } else if (type == QLatin1String("Enum")) { - QList::ConstIterator it; - for (it = choices.choices.constBegin(); it != choices.choices.constEnd(); ++it) { - if ((*it).name == defaultValue) { + for (const auto &choice : choices.choices) { + if (choice.name == defaultValue) { if (cfg.globalEnums && choices.name().isEmpty()) { defaultValue.prepend(choices.prefix); } else { defaultValue.prepend(enumTypeQualifier(name, choices) + choices.prefix); } break; } } - } else if (type == QLatin1String("IntList")) { QTextStream cpp(&code, QIODevice::WriteOnly | QIODevice::Append); if (!code.isEmpty()) { cpp << endl; } cpp << " QList default" << name << ";" << endl; if (!defaultValue.isEmpty()) { - const QStringList defaults = defaultValue.split(QLatin1Char(',')); - QStringList::ConstIterator it; - for (it = defaults.constBegin(); it != defaults.constEnd(); ++it) { - cpp << " default" << name << ".append( " << *it << " );" + for (const auto &def : defaultValue.split(QLatin1Char(','))) { + cpp << " default" << name << ".append( " << def << " );" << endl; } } @@ -1281,12 +1293,11 @@ QString paramString = group; QString arguments; int i = 1; - for (QList::ConstIterator it = parameters.constBegin(); - it != parameters.constEnd(); ++it) { - if (paramString.contains("$(" + (*it).name + ')')) { + for (const auto ¶m : parameters) { + if (paramString.contains("$(" + param.name + ')')) { const QString tmp = QStringLiteral("%%1").arg(i++); - paramString.replace("$(" + (*it).name + ')', tmp); - arguments += ".arg( mParam" + (*it).name + " )"; + paramString.replace("$(" + param.name + ')', tmp); + arguments += ".arg( mParam" + param.name + " )"; } } if (arguments.isEmpty()) { @@ -1775,12 +1786,11 @@ << 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; + for(const auto &include : cfg.headerIncludes) { + if (include.startsWith('"')) { + h << "#include " << include << endl; } else { - h << "#include <" << *it << ">" << endl; + h << "#include <" << include << ">" << endl; } } @@ -1802,11 +1812,11 @@ h << "#include " << endl << endl; // Includes - for (it = includes.constBegin(); it != includes.constEnd(); ++it) { - if ((*it).startsWith('"')) { - h << "#include " << *it << endl; + for (const auto include : includes) { + if (include.startsWith('"')) { + h << "#include " << include << endl; } else { - h << "#include <" << *it << ">" << endl; + h << "#include <" << include << ">" << endl; } } @@ -1828,50 +1838,48 @@ h << " public:" << endl; // enums - QList::ConstIterator itEntry; - for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - const CfgEntry::Choices &choices = (*itEntry)->choices(); + for (auto *entry : entries) { + const CfgEntry::Choices &choices = entry->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); + for (const auto choice : chlist) { + values.append(choices.prefix + choice.name); } if (choices.name().isEmpty()) { if (cfg.globalEnums) { - h << " enum " << enumName((*itEntry)->name(), (*itEntry)->choices()) << " { " << values.join(QStringLiteral(", ")) << " };" << endl; + h << " enum " << enumName(entry->name(), entry->choices()) << " { " << values.join(QStringLiteral(", ")) << " };" << endl; } else { // Create an automatically named enum - h << " class " << enumName((*itEntry)->name(), (*itEntry)->choices()) << endl; + h << " class " << enumName(entry->name(), entry->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; + h << " enum " << enumName(entry->name(), entry->choices()) << " { " << values.join(QStringLiteral(", ")) << " };" << endl; } } - const QStringList values = (*itEntry)->paramValues(); + const QStringList values = entry->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()) + + h << " enum " << enumName(entry->param()) << " { " << values.join(QStringLiteral(", ")) << " };" << endl; + h << " static const char* const " << enumName(entry->param()) << "ToString[];" << endl; + cppPreamble += "const char* const " + cfg.className + "::" + enumName(entry->param()) + "ToString[] = { \"" + values.join(QStringLiteral("\", \"")) + "\" };\n"; } else { - h << " class " << enumName((*itEntry)->param()) << endl; + h << " class " << enumName(entry->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()) + + cppPreamble += "const char* const " + cfg.className + "::" + enumName(entry->param()) + "::enumToString[] = { \"" + values.join(QStringLiteral("\", \"")) + "\" };\n"; } } @@ -1890,12 +1898,11 @@ h << " KSharedConfig::Ptr config" << (parameters.isEmpty() ? " = KSharedConfig::openConfig()" : ", "); } - for (QList::ConstIterator it = parameters.constBegin(); - it != parameters.constEnd(); ++it) { - if (it != parameters.constBegin()) { + for (const auto ¶meter : parameters) { + if (parameter != parameters.first()) { h << ","; } - h << " " << param((*it).type) << " " << (*it).name; + h << " " << param(parameter.type) << " " << parameter.name; } if (cfg.parentInConstructor) { if (cfgFileNameArg || !parameters.isEmpty()) { @@ -1922,33 +1929,33 @@ Const = QStringLiteral(" const"); } - for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - QString n = (*itEntry)->name(); - QString t = (*itEntry)->type(); + for (auto *entry : entries) { + QString n = entry->name(); + QString t = entry->type(); // Manipulator if (cfg.allMutators || cfg.mutators.contains(n)) { h << " /**" << endl; - h << " Set " << (*itEntry)->label() << endl; + h << " Set " << entry->label() << endl; h << " */" << endl; if (cfg.staticAccessors) { h << " static" << endl; } h << " void " << setFunction(n) << "( "; - if (!(*itEntry)->param().isEmpty()) { - h << cppType((*itEntry)->paramType()) << " i, "; + if (!entry->param().isEmpty()) { + h << cppType(entry->paramType()) << " i, "; } if (cfg.useEnumTypes && t == QLatin1String("Enum")) { - h << enumType(*itEntry, cfg.globalEnums); + h << enumType(entry, cfg.globalEnums); } else { h << param(t); } h << " v )"; // function body inline only if not using dpointer // for BC mode if (!cfg.dpointer) { h << endl << " {" << endl; - h << indent(memberMutatorBody(*itEntry, cfg), 6); + h << indent(memberMutatorBody(entry, cfg), 6); h << " }" << endl; } else { h << ";" << endl; @@ -1958,7 +1965,7 @@ QString returnType; if (cfg.useEnumTypes && t == QLatin1String("Enum")) { - returnType = enumType(*itEntry, cfg.globalEnums); + returnType = enumType(entry, cfg.globalEnums); } else { returnType = cppType(t); } @@ -1984,55 +1991,55 @@ } // Accessor h << " /**" << endl; - h << " Get " << (*itEntry)->label() << endl; + h << " Get " << entry->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 (!entry->param().isEmpty()) { + h << " " << cppType(entry->paramType()) << " i "; } h << ")" << Const; // function body inline only if not using dpointer // for BC mode if (!cfg.dpointer) { h << endl << " {" << endl; - h << indent(memberAccessorBody(*itEntry, cfg.globalEnums, cfg), 6); + h << indent(memberAccessorBody(entry, cfg.globalEnums, cfg), 6); h << " }" << endl; } else { h << ";" << endl; } // Default value Accessor - if ((cfg.allDefaultGetters || cfg.defaultGetters.contains(n)) && !(*itEntry)->defaultValue().isEmpty()) { + if ((cfg.allDefaultGetters || cfg.defaultGetters.contains(n)) && !entry->defaultValue().isEmpty()) { h << endl; h << " /**" << endl; - h << " Get " << (*itEntry)->label() << " default value" << endl; + h << " Get " << entry->label() << " default value" << endl; h << " */" << endl; if (cfg.staticAccessors) { h << " static" << endl; } h << " "; if (cfg.useEnumTypes && t == QLatin1String("Enum")) { - h << enumType(*itEntry, cfg.globalEnums); + h << enumType(entry, cfg.globalEnums); } else { h << cppType(t); } h << " " << getDefaultFunction(n) << "("; - if (!(*itEntry)->param().isEmpty()) { - h << " " << cppType((*itEntry)->paramType()) << " i "; + if (!entry->param().isEmpty()) { + h << " " << cppType(entry->paramType()) << " i "; } h << ")" << Const << endl; h << " {" << endl; h << " return "; if (cfg.useEnumTypes && t == QLatin1String("Enum")) { - h << "static_cast<" << enumType(*itEntry, cfg.globalEnums) << ">("; + h << "static_cast<" << enumType(entry, cfg.globalEnums) << ">("; } h << getDefaultFunction(n) << "_helper("; - if (!(*itEntry)->param().isEmpty()) { + if (!entry->param().isEmpty()) { h << " i "; } h << ")"; @@ -2050,15 +2057,15 @@ h << " Get Item object corresponding to " << n << "()" << endl; h << " */" << endl; - h << " Item" << itemType((*itEntry)->type()) << " *" + h << " Item" << itemType(entry->type()) << " *" << getFunction(n) << "Item("; - if (!(*itEntry)->param().isEmpty()) { - h << " " << cppType((*itEntry)->paramType()) << " i "; + if (!entry->param().isEmpty()) { + h << " " << cppType(entry->paramType()) << " i "; } h << ")"; if (!cfg.dpointer) { h << endl << " {" << endl; - h << indent(itemAccessorBody((*itEntry), cfg), 6); + h << indent(itemAccessorBody(entry, cfg), 6); h << " }" << endl; } else { h << ";" << endl; @@ -2074,19 +2081,18 @@ if (hasSignals) { h << "\n enum {" << endl; unsigned val = 1; - QList::ConstIterator it, itEnd = signalList.constEnd(); - for (it = signalList.constBegin(); it != itEnd; val <<= 1) { - hasNonModifySignals |= !it->modify; + for (const auto &signal : signalList) { + hasNonModifySignals |= !signal.modify; if (!val) { cerr << "Too many signals to create unique bit masks" << endl; exit(1); } - Signal signal = *it; h << " " << signalEnumName(signal.name) << " = 0x" << hex << val; - if (++it != itEnd) { + if (signal != signalList.last()) { h << ","; } h << endl; + val <<= 1; } h << " };" << dec << endl << endl; @@ -2099,20 +2105,18 @@ h << " */" << endl; } h << " void " << signal.name << "("; - QList::ConstIterator it, itEnd = signal.arguments.constEnd(); - for (it = signal.arguments.constBegin(); it != itEnd;) { - SignalArguments argument = *it; + for (const auto argument : signal.arguments) { 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) { - type = enumType(entries[i], cfg.globalEnums); + for (auto *entry : entries) { + if (entry->name() == argument.variableName) { + type = enumType(entry, cfg.globalEnums); break; } } } h << type << " " << argument.variableName; - if (++it != itEnd) { + if (argument != signal.arguments.last()) { h << ", "; } } @@ -2153,44 +2157,43 @@ } // Class Parameters - for (QList::ConstIterator it = parameters.constBegin(); - it != parameters.constEnd(); ++it) { - h << " " << cppType((*it).type) << " mParam" << (*it).name << ";" << endl; + for (const auto ¶m : parameters) { + h << " " << cppType(param.type) << " mParam" << param.name << ";" << endl; } if (cfg.memberVariables != QLatin1String("dpointer")) { QString group; - for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - if ((*itEntry)->group() != group) { - group = (*itEntry)->group(); + for (auto *entry : entries) { + if (entry->group() != group) { + group = entry->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(entry->type()) << " " << varName(entry->name(), cfg); + if (!entry->param().isEmpty()) { + h << QStringLiteral("[%1]").arg(entry->paramMax() + 1); } h << ";" << endl; - if (cfg.allDefaultGetters || cfg.defaultGetters.contains((*itEntry)->name())) { + if (cfg.allDefaultGetters || cfg.defaultGetters.contains(entry->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(entry->type()) << " " << getDefaultFunction(entry->name()) << "_helper("; + if (!entry->param().isEmpty()) { + h << " " << cppType(entry->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); + for (auto *entry : entries) { + h << " Item" << itemType(entry->type()) << " *" << itemVar(entry, cfg); + if (!entry->param().isEmpty()) { + h << QStringLiteral("[%1]").arg(entry->paramMax() + 1); } h << ";" << endl; } @@ -2202,15 +2205,15 @@ } else { // 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())) { + for (auto *entry : entries) { + if (cfg.allDefaultGetters || cfg.defaultGetters.contains(entry->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(entry->type()) << " " << getDefaultFunction(entry->name()) << "_helper("; + if (!entry->param().isEmpty()) { + h << " " << cppType(entry->paramType()) << " i "; } h << ")" << Const << ";" << endl; } @@ -2247,11 +2250,11 @@ cpp << "#include \"" << headerFileName << "\"" << endl << endl; - for (it = cfg.sourceIncludes.constBegin(); it != cfg.sourceIncludes.constEnd(); ++it) { - if ((*it).startsWith('"')) { - cpp << "#include " << *it << endl; + for (const auto & include : cfg.sourceIncludes) { + if (include.startsWith('"')) { + cpp << "#include " << include << endl; } else { - cpp << "#include <" << *it << ">" << endl; + cpp << "#include <" << include << ">" << endl; } } @@ -2283,26 +2286,26 @@ cpp << "class " << cfg.className << "Private" << endl; cpp << "{" << endl; cpp << " public:" << endl; - for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - if ((*itEntry)->group() != group) { - group = (*itEntry)->group(); + for (auto *entry : entries) { + if (entry->group() != group) { + group = entry->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(entry->type()) << " " << varName(entry->name(), cfg); + if (!entry->param().isEmpty()) { + cpp << QStringLiteral("[%1]").arg(entry->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())) + for (auto *entry : entries) { + const QString declType = entry->signalList().isEmpty() + ? QString(cfg.inherits + "::Item" + itemType(entry->type())) : QStringLiteral("KConfigCompilerSignallingItem"); - cpp << " " << declType << " *" << itemVar( *itEntry, cfg ); - if (!(*itEntry)->param().isEmpty()) { - cpp << QStringLiteral("[%1]").arg((*itEntry)->paramMax() + 1); + cpp << " " << declType << " *" << itemVar( entry, cfg ); + if (!entry->param().isEmpty()) { + cpp << QStringLiteral("[%1]").arg(entry->paramMax() + 1); } cpp << ";" << endl; } @@ -2381,12 +2384,11 @@ cpp << (parameters.isEmpty() ? "" : ","); } - for (QList::ConstIterator it = parameters.constBegin(); - it != parameters.constEnd(); ++it) { - if (it != parameters.constBegin()) { + for (const auto ¶meter : parameters) { + if (parameter != parameters.first()) { cpp << ","; } - cpp << " " << param((*it).type) << " " << (*it).name; + cpp << " " << param(parameter.type) << " " << parameter.name; } if (cfg.parentInConstructor) { @@ -2414,9 +2416,8 @@ cpp << ")" << endl; // Store parameters - for (QList::ConstIterator it = parameters.constBegin(); - it != parameters.constEnd(); ++it) { - cpp << " , mParam" << (*it).name << "(" << (*it).name << ")" << endl; + for (const auto ¶meter : parameters ) { + cpp << " , mParam" << parameter.name << "(" << parameter.name << ")" << endl; } if (hasNonModifySignals && !cfg.dpointer) { @@ -2452,111 +2453,109 @@ << cfg.className << "::itemChanged);" << endl << endl; } - for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - if ((*itEntry)->group() != group) { + for (auto *entry : entries) { + if (entry->group() != group) { if (!group.isEmpty()) { cpp << endl; } - group = (*itEntry)->group(); + group = entry->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(entry->key(), parameters); + if (!entry->code().isEmpty()) { + cpp << entry->code() << endl; } - if ((*itEntry)->type() == QLatin1String("Enum")) { + if (entry->type() == QLatin1String("Enum")) { cpp << " QList<" + cfg.inherits + "::ItemEnum::Choice> values" - << (*itEntry)->name() << ";" << endl; - const QList choices = (*itEntry)->choices().choices; - QList::ConstIterator it; - for (it = choices.constBegin(); it != choices.constEnd(); ++it) { + << entry->name() << ";" << endl; + for (const auto &choice : entry->choices().choices) { cpp << " {" << endl; cpp << " " + cfg.inherits + "::ItemEnum::Choice choice;" << endl; - cpp << " choice.name = QStringLiteral(\"" << (*it).name << "\");" << endl; + cpp << " choice.name = QStringLiteral(\"" << choice.name << "\");" << endl; if (cfg.setUserTexts) { - if (!(*it).label.isEmpty()) { + if (!choice.label.isEmpty()) { cpp << " choice.label = " - << translatedString(cfg, (*it).label, (*it).context) + << translatedString(cfg, choice.label, choice.context) << ";" << endl; } - if (!(*it).toolTip.isEmpty()) { + if (!choice.toolTip.isEmpty()) { cpp << " choice.toolTip = " - << translatedString(cfg, (*it).toolTip, (*it).context) + << translatedString(cfg, choice.toolTip, choice.context) << ";" << endl; } - if (!(*it).whatsThis.isEmpty()) { + if (!choice.whatsThis.isEmpty()) { cpp << " choice.whatsThis = " - << translatedString(cfg, (*it).whatsThis, (*it).context) + << translatedString(cfg, choice.whatsThis, choice.context) << ";" << endl; } } - cpp << " values" << (*itEntry)->name() << ".append( choice );" << endl; + cpp << " values" << entry->name() << ".append( choice );" << endl; cpp << " }" << endl; } } if (!cfg.dpointer) { - cpp << itemDeclaration(*itEntry, cfg); + cpp << itemDeclaration(entry, cfg); } - if ((*itEntry)->param().isEmpty()) { + if (entry->param().isEmpty()) { // Normal case - cpp << " " << itemPath(*itEntry, cfg) << " = " - << newItem((*itEntry), key, (*itEntry)->defaultValue(), cfg) << endl; + cpp << " " << itemPath(entry, cfg) << " = " + << newItem(entry, key, entry->defaultValue(), cfg) << endl; - if (!(*itEntry)->minValue().isEmpty()) { - cpp << " " << itemPath(*itEntry, cfg) << "->setMinValue(" << (*itEntry)->minValue() << ");" << endl; + if (!entry->minValue().isEmpty()) { + cpp << " " << itemPath(entry, cfg) << "->setMinValue(" << entry->minValue() << ");" << endl; } - if (!(*itEntry)->maxValue().isEmpty()) { - cpp << " " << itemPath(*itEntry, cfg) << "->setMaxValue(" << (*itEntry)->maxValue() << ");" << endl; + if (!entry->maxValue().isEmpty()) { + cpp << " " << itemPath(entry, cfg) << "->setMaxValue(" << entry->maxValue() << ");" << endl; } if (cfg.setUserTexts) { - cpp << userTextsFunctions((*itEntry), cfg); + cpp << userTextsFunctions(entry, cfg); } - if (cfg.allNotifiers || cfg.notifiers.contains((*itEntry)->name())) { - cpp << " " << itemPath(*itEntry, cfg) << "->setWriteFlags(KConfigBase::Notify);" << endl; + if (cfg.allNotifiers || cfg.notifiers.contains(entry->name())) { + cpp << " " << itemPath(entry, cfg) << "->setWriteFlags(KConfigBase::Notify);" << endl; } - cpp << " addItem( " << itemPath(*itEntry, cfg); - QString quotedName = (*itEntry)->name(); + cpp << " addItem( " << itemPath(entry, cfg); + QString quotedName = entry->name(); addQuotes(quotedName); if (quotedName != key) { - cpp << ", QStringLiteral( \"" << (*itEntry)->name() << "\" )"; + cpp << ", QStringLiteral( \"" << entry->name() << "\" )"; } cpp << " );" << endl; } else { // Indexed - for (int i = 0; i <= (*itEntry)->paramMax(); i++) { + for (int i = 0; i <= entry->paramMax(); i++) { QString defaultStr; - QString itemVarStr(itemPath(*itEntry, cfg) + QStringLiteral("[%1]").arg(i)); + QString itemVarStr(itemPath(entry, 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 (!entry->paramDefaultValue(i).isEmpty()) { + defaultStr = entry->paramDefaultValue(i); + } else if (!entry->defaultValue().isEmpty()) { + defaultStr = paramString(entry->defaultValue(), entry, i); } else { - defaultStr = defaultValue((*itEntry)->type()); + defaultStr = defaultValue(entry->type()); } cpp << " " << itemVarStr << " = " - << newItem((*itEntry), paramString(key, *itEntry, i), defaultStr, cfg, QStringLiteral("[%1]").arg(i)) << endl; + << newItem(entry, paramString(key, entry, i), defaultStr, cfg, QStringLiteral("[%1]").arg(i)) << endl; if (cfg.setUserTexts) { - cpp << userTextsFunctions(*itEntry, cfg, itemVarStr, (*itEntry)->paramName()); + cpp << userTextsFunctions(entry, cfg, itemVarStr, entry->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 (entry->paramType() == QLatin1String("Enum")) { + cpp << entry->paramName().replace("$(" + entry->param() + ')', QLatin1String("%1")).arg(entry->paramValues()[i]); } else { - cpp << (*itEntry)->paramName().replace("$(" + (*itEntry)->param() + ')', QLatin1String("%1")).arg(i); + cpp << entry->paramName().replace("$(" + entry->param() + ')', QLatin1String("%1")).arg(i); } cpp << "\" ) );" << endl; } @@ -2567,80 +2566,80 @@ 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(); + for (auto *entry : entries) { + QString n = entry->name(); + QString t = entry->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 (!entry->param().isEmpty()) { + cpp << cppType(entry->paramType()) << " i, "; } if (cfg.useEnumTypes && t == QLatin1String("Enum")) { - cpp << enumType(*itEntry, cfg.globalEnums); + cpp << enumType(entry, cfg.globalEnums); } else { cpp << param(t); } cpp << " v )" << endl; // function body inline only if not using dpointer // for BC mode cpp << "{" << endl; - cpp << indent(memberMutatorBody(*itEntry, cfg), 6); + cpp << indent(memberMutatorBody(entry, cfg), 6); cpp << "}" << endl << endl; } // Accessor if (cfg.useEnumTypes && t == QLatin1String("Enum")) { - cpp << enumType(*itEntry, cfg.globalEnums); + cpp << enumType(entry, cfg.globalEnums); } else { cpp << cppType(t); } cpp << " " << getFunction(n, cfg.className) << "("; - if (!(*itEntry)->param().isEmpty()) { - cpp << " " << cppType((*itEntry)->paramType()) << " i "; + if (!entry->param().isEmpty()) { + cpp << " " << cppType(entry->paramType()) << " i "; } cpp << ")" << Const << endl; // function body inline only if not using dpointer // for BC mode cpp << "{" << endl; - cpp << indent(memberAccessorBody(*itEntry, cfg.globalEnums, cfg), 2); + cpp << indent(memberAccessorBody(entry, cfg.globalEnums, cfg), 2); cpp << "}" << endl << endl; // Default value Accessor -- written by the loop below // Item accessor if (cfg.itemAccessors) { cpp << endl; - cpp << cfg.inherits + "::Item" << itemType((*itEntry)->type()) << " *" + cpp << cfg.inherits + "::Item" << itemType(entry->type()) << " *" << getFunction(n, cfg.className) << "Item("; - if (!(*itEntry)->param().isEmpty()) { - cpp << " " << cppType((*itEntry)->paramType()) << " i "; + if (!entry->param().isEmpty()) { + cpp << " " << cppType(entry->paramType()) << " i "; } cpp << ")" << endl; cpp << "{" << endl; - cpp << indent(itemAccessorBody(*itEntry, cfg), 2); + cpp << indent(itemAccessorBody(entry, cfg), 2); cpp << "}" << endl; } cpp << endl; } } // default value getters always go in Cpp - for (itEntry = entries.constBegin(); itEntry != entries.constEnd(); ++itEntry) { - QString n = (*itEntry)->name(); - QString t = (*itEntry)->type(); + for (auto *entry : entries) { + QString n = entry->name(); + QString t = entry->type(); // Default value Accessor, as "helper" function - if ((cfg.allDefaultGetters || cfg.defaultGetters.contains(n)) && !(*itEntry)->defaultValue().isEmpty()) { + if ((cfg.allDefaultGetters || cfg.defaultGetters.contains(n)) && !entry->defaultValue().isEmpty()) { cpp << cppType(t) << " " << getDefaultFunction(n, cfg.className) << "_helper("; - if (!(*itEntry)->param().isEmpty()) { - cpp << " " << cppType((*itEntry)->paramType()) << " i "; + if (!entry->param().isEmpty()) { + cpp << " " << cppType(entry->paramType()) << " i "; } cpp << ")" << Const << endl; cpp << "{" << endl; - cpp << memberGetDefaultBody(*itEntry) << endl; + cpp << memberGetDefaultBody(entry) << endl; cpp << "}" << endl << endl; } } @@ -2668,14 +2667,13 @@ cpp << " if ( " << varPath(QStringLiteral("settingsChanged"), cfg) << " & " << signalEnumName(signal.name) << " )" << endl; cpp << " Q_EMIT " << signal.name << "("; - QList::ConstIterator it, itEnd = signal.arguments.constEnd(); - for (it = signal.arguments.constBegin(); it != itEnd;) { - SignalArguments argument = *it; + + for (const auto argument : signal.arguments) { 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) { - cpp << "static_cast<" << enumType(entries[i], cfg.globalEnums) << ">("; + for (auto *entry : entries) { + if (entry->name() == argument.variableName) { + cpp << "static_cast<" << enumType(entry, cfg.globalEnums) << ">("; cast = true; break; } @@ -2685,7 +2683,7 @@ if (cast) { cpp << ")"; } - if (++it != itEnd) { + if (argument != signal.arguments.last()) { cpp << ", "; } }