Commit a910acb7 authored by Ahmad Samir's avatar Ahmad Samir

kcm_keyboard: Port foreach (deprecated) to range-for and qDeleteAll

parent e725782c
......@@ -106,15 +106,15 @@ QList<QAction*> LayoutsMenu::contextualActions()
actionGroup = new QActionGroup(this);
X11Helper::getLayoutsList(); //UGLY: seems to be more reliable with extra call
QList<LayoutUnit> currentLayouts = X11Helper::getLayoutsList();
foreach(const LayoutUnit& layoutUnit, currentLayouts) {
const QList<LayoutUnit> currentLayouts = X11Helper::getLayoutsList();
for (const auto &layoutUnit : currentLayouts) {
QAction* action = createAction(layoutUnit);
actionGroup->addAction(action);
}
if( keyboardConfig.configureLayouts ) {
QList<LayoutUnit> extraLayouts = keyboardConfig.layouts;
foreach(const LayoutUnit& layoutUnit, currentLayouts) {
for (const auto &layoutUnit : currentLayouts) {
extraLayouts.removeOne(layoutUnit);
}
if( extraLayouts.size() > 0 ) {
......@@ -122,7 +122,7 @@ QList<QAction*> LayoutsMenu::contextualActions()
separator->setSeparator(true);
actionGroup->addAction(separator);
foreach(const LayoutUnit& layoutUnit, extraLayouts) {
for (const auto &layoutUnit : qAsConst(extraLayouts)) {
QAction* action = createAction(layoutUnit);
actionGroup->addAction(action);
}
......
......@@ -92,7 +92,7 @@ void X11Helper::scrollLayouts(int delta)
QStringList X11Helper::getLayoutsListAsString(const QList<LayoutUnit>& layoutsList)
{
QStringList stringList;
foreach(const LayoutUnit& layoutUnit, layoutsList) {
for (const auto &layoutUnit : layoutsList) {
stringList << layoutUnit.toString();
}
return stringList;
......
......@@ -168,7 +168,7 @@ struct LayoutSet {
QString toString() const {
QString str(currentLayout.toString());
str += QLatin1String(": ");
foreach(const LayoutUnit& layoutUnit, layouts) {
for (const auto &layoutUnit : qAsConst(layouts)) {
str += layoutUnit.toString() + QLatin1Char(' ');
}
return str;
......@@ -176,7 +176,7 @@ struct LayoutSet {
static QString toString(const QList<LayoutUnit>& layoutUnits) {
QString str;
foreach(const LayoutUnit& layoutUnit, layoutUnits) {
for (const auto &layoutUnit : layoutUnits) {
str += layoutUnit.toString() + QLatin1Char(',');
}
return str;
......
......@@ -124,7 +124,7 @@ bool XkbHelper::initializeKeyboardLayouts(const QList<LayoutUnit>& layoutUnits)
{
QStringList layouts;
QStringList variants;
foreach (const LayoutUnit& layoutUnit, layoutUnits) {
for (const auto &layoutUnit : layoutUnits) {
layouts.append(layoutUnit.layout());
variants.append(layoutUnit.variant());
}
......@@ -154,8 +154,8 @@ bool XkbHelper::initializeKeyboardLayouts(KeyboardConfig& config)
if( config.configureLayouts ) {
QStringList layouts;
QStringList variants;
QList<LayoutUnit> defaultLayouts = config.getDefaultLayouts();
foreach (const LayoutUnit& layoutUnit, defaultLayouts) {
const QList<LayoutUnit> defaultLayouts = config.getDefaultLayouts();
for (const auto &layoutUnit : defaultLayouts) {
layouts.append(layoutUnit.layout());
variants.append(layoutUnit.variant());
}
......
......@@ -117,24 +117,24 @@ void postProcess(Rules* rules)
// setlocale(LC_ALL, "");
// bindtextdomain("xkeyboard-config", LOCALE_DIR);
foreach(ModelInfo* modelInfo, rules->modelInfos) {
for (ModelInfo *modelInfo : qAsConst(rules->modelInfos)) {
modelInfo->vendor = translate_xml_item(modelInfo->vendor);
modelInfo->description = translate_description(modelInfo);
}
foreach(LayoutInfo* layoutInfo, rules->layoutInfos) {
for (LayoutInfo *layoutInfo : qAsConst(rules->layoutInfos)) {
layoutInfo->description = translate_description(layoutInfo);
removeEmptyItems(layoutInfo->variantInfos);
foreach(VariantInfo* variantInfo, layoutInfo->variantInfos) {
for (VariantInfo *variantInfo : qAsConst(layoutInfo->variantInfos)) {
variantInfo->description = translate_description(variantInfo);
}
}
foreach(OptionGroupInfo* optionGroupInfo, rules->optionGroupInfos) {
for (OptionGroupInfo *optionGroupInfo : qAsConst(rules->optionGroupInfos)) {
optionGroupInfo->description = translate_description(optionGroupInfo);
removeEmptyItems(optionGroupInfo->optionInfos);
foreach(OptionInfo* optionInfo, optionGroupInfo->optionInfos) {
for (OptionInfo *optionInfo : qAsConst(optionGroupInfo->optionInfos)) {
optionInfo->description = translate_description(optionInfo);
}
}
......@@ -192,7 +192,7 @@ void mergeRules(Rules* rules, Rules* extraRules)
rules->optionGroupInfos.append( extraRules->optionGroupInfos ); // need to iterate and merge?
QList<LayoutInfo*> layoutsToAdd;
foreach(LayoutInfo* extraLayoutInfo, extraRules->layoutInfos) {
for (LayoutInfo *extraLayoutInfo : qAsConst(extraRules->layoutInfos)) {
LayoutInfo* layoutInfo = findByName(rules->layoutInfos, extraLayoutInfo->name);
if( layoutInfo != nullptr ) {
layoutInfo->variantInfos.append( extraLayoutInfo->variantInfos );
......@@ -380,7 +380,7 @@ bool LayoutInfo::isLanguageSupportedByLayout(const QString& lang) const
bool LayoutInfo::isLanguageSupportedByVariants(const QString& lang) const
{
foreach(const VariantInfo* info, variantInfos) {
for (const VariantInfo *info : qAsConst(variantInfos)) {
if( info->languages.contains(lang) )
return true;
}
......
......@@ -33,7 +33,7 @@ struct ConfigItem {
template <class T>
inline T* findByName(QList<T*> list, QString name) {
foreach(T* info, list) {
for (T *info : qAsConst(list)) {
if( info->name == name )
return info;
}
......@@ -56,7 +56,7 @@ struct LayoutInfo: public ConfigItem {
// LayoutInfo() {}
LayoutInfo(bool fromExtras_):
fromExtras(fromExtras_) {}
~LayoutInfo() { foreach(VariantInfo* variantInfo, variantInfos) delete variantInfo; }
~LayoutInfo() { qDeleteAll(variantInfos); }
VariantInfo* getVariantInfo(const QString& variantName) const {
return findByName(variantInfos, variantName);
......@@ -79,7 +79,7 @@ struct OptionGroupInfo: public ConfigItem {
QList<OptionInfo*> optionInfos;
bool exclusive;
~OptionGroupInfo() { foreach(OptionInfo* opt, optionInfos) delete opt; }
~OptionGroupInfo() { qDeleteAll(optionInfos); }
const OptionInfo* getOptionInfo(const QString& optionName) const {
return findByName(optionInfos, optionName);
......@@ -99,9 +99,9 @@ struct Rules {
Rules();
~Rules() {
foreach(LayoutInfo* layoutInfo, layoutInfos) delete layoutInfo;
foreach(ModelInfo* modelInfo, modelInfos) delete modelInfo;
foreach(OptionGroupInfo* optionGroupInfo, optionGroupInfos) delete optionGroupInfo;
qDeleteAll(layoutInfos);
qDeleteAll(modelInfos);
qDeleteAll(optionGroupInfos);
}
const LayoutInfo* getLayoutInfo(const QString& layoutName) const {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment