Commit 31d5ae5b authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Port foreach to range-for; clean up old commented out code

The removed code has been commented out since around the split from
kde-workspace, circa 2014.
parent 7f3ea068
...@@ -146,7 +146,7 @@ QString Flags::getShortText(const LayoutUnit& layoutUnit, const KeyboardConfig& ...@@ -146,7 +146,7 @@ QString Flags::getShortText(const LayoutUnit& layoutUnit, const KeyboardConfig&
QString layoutText = layoutUnit.layout(); QString layoutText = layoutUnit.layout();
foreach(const LayoutUnit& lu, keyboardConfig.layouts) { for (const LayoutUnit &lu : keyboardConfig.layouts) {
if( layoutUnit.layout() == lu.layout() && layoutUnit.variant() == lu.variant() ) { if( layoutUnit.layout() == lu.layout() && layoutUnit.variant() == lu.variant() ) {
layoutText = lu.getDisplayName(); layoutText = lu.getDisplayName();
break; break;
......
...@@ -41,12 +41,12 @@ AddLayoutDialog::AddLayoutDialog(const Rules* rules_, Flags* flags_, const QStri ...@@ -41,12 +41,12 @@ AddLayoutDialog::AddLayoutDialog(const Rules* rules_, Flags* flags_, const QStri
layoutDialogUi->setupUi(this); layoutDialogUi->setupUi(this);
QSet<QString> languages; QSet<QString> languages;
foreach(const LayoutInfo* layoutInfo, rules->layoutInfos) { for (const LayoutInfo *layoutInfo : rules->layoutInfos) {
QSet<QString> langs = QSet<QString>(layoutInfo->languages.constBegin(), layoutInfo->languages.constEnd()); QSet<QString> langs = QSet<QString>(layoutInfo->languages.constBegin(), layoutInfo->languages.constEnd());
languages.unite( langs ); languages.unite( langs );
} }
IsoCodes isoCodes(IsoCodes::iso_639_3); IsoCodes isoCodes(IsoCodes::iso_639_3);
foreach(const QString& lang, languages) { for (const QString &lang : qAsConst(languages)) {
const IsoCodeEntry* isoCodeEntry = isoCodes.getEntry(IsoCodes::attr_iso_639_3_id, lang); const IsoCodeEntry* isoCodeEntry = isoCodes.getEntry(IsoCodes::attr_iso_639_3_id, lang);
// const IsoCodeEntry* isoCodeEntry = isoCodes.getEntry(IsoCodes::attr_iso_639_2B_code, lang); // const IsoCodeEntry* isoCodeEntry = isoCodes.getEntry(IsoCodes::attr_iso_639_2B_code, lang);
// if( isoCodeEntry == NULL ) { // if( isoCodeEntry == NULL ) {
...@@ -87,7 +87,7 @@ void AddLayoutDialog::languageChanged(int langIdx) ...@@ -87,7 +87,7 @@ void AddLayoutDialog::languageChanged(int langIdx)
layoutDialogUi->layoutComboBox->clear(); layoutDialogUi->layoutComboBox->clear();
int defaultIndex = -1; int defaultIndex = -1;
int i = 0; int i = 0;
foreach(const LayoutInfo* layoutInfo, rules->layoutInfos) { for (const LayoutInfo *layoutInfo : qAsConst(rules->layoutInfos)) {
if( lang.isEmpty() || layoutInfo->isLanguageSupportedByLayout(lang) ) { if( lang.isEmpty() || layoutInfo->isLanguageSupportedByLayout(lang) ) {
if( flags ) { if( flags ) {
QIcon icon(flags->getIcon(layoutInfo->name)); QIcon icon(flags->getIcon(layoutInfo->name));
...@@ -128,7 +128,7 @@ void AddLayoutDialog::layoutChanged(int layoutIdx) ...@@ -128,7 +128,7 @@ void AddLayoutDialog::layoutChanged(int layoutIdx)
layoutDialogUi->variantComboBox->clear(); layoutDialogUi->variantComboBox->clear();
const LayoutInfo* layoutInfo = rules->getLayoutInfo(layoutName); const LayoutInfo* layoutInfo = rules->getLayoutInfo(layoutName);
foreach(const VariantInfo* variantInfo, layoutInfo->variantInfos) { for (const VariantInfo *variantInfo : layoutInfo->variantInfos) {
if( lang.isEmpty() || layoutInfo->isLanguageSupportedByVariant(variantInfo, lang) ) { if( lang.isEmpty() || layoutInfo->isLanguageSupportedByVariant(variantInfo, lang) ) {
layoutDialogUi->variantComboBox->addItem(variantInfo->description, variantInfo->name); layoutDialogUi->variantComboBox->addItem(variantInfo->description, variantInfo->name);
} }
......
...@@ -97,9 +97,9 @@ void KCMKeyboardWidget::handleParameters(const QVariantList &args) ...@@ -97,9 +97,9 @@ void KCMKeyboardWidget::handleParameters(const QVariantList &args)
{ {
// TODO: improve parameter handling // TODO: improve parameter handling
setCurrentIndex(TAB_HARDWARE); setCurrentIndex(TAB_HARDWARE);
foreach(const QVariant& arg, args) { for (const auto &arg : args) {
if( arg.type() == QVariant::String ) { if( arg.type() == QVariant::String ) {
QString str = arg.toString(); const QString str = arg.toString();
if( str == QLatin1String("--tab=layouts") ) { if( str == QLatin1String("--tab=layouts") ) {
setCurrentIndex(TAB_LAYOUTS); setCurrentIndex(TAB_LAYOUTS);
} }
...@@ -208,7 +208,7 @@ void KCMKeyboardWidget::uiChanged() ...@@ -208,7 +208,7 @@ void KCMKeyboardWidget::uiChanged()
void KCMKeyboardWidget::initializeKeyboardModelUI() void KCMKeyboardWidget::initializeKeyboardModelUI()
{ {
foreach(ModelInfo* modelInfo, rules->modelInfos) { for (const ModelInfo *modelInfo : qAsConst(rules->modelInfos)) {
QString vendor = modelInfo->vendor; QString vendor = modelInfo->vendor;
if( vendor.isEmpty() ) { if( vendor.isEmpty() ) {
vendor = i18nc("unknown keyboard model vendor", "Unknown"); vendor = i18nc("unknown keyboard model vendor", "Unknown");
...@@ -405,7 +405,7 @@ static QPair<int, int> getSelectedRowRange(const QModelIndexList& selected) ...@@ -405,7 +405,7 @@ static QPair<int, int> getSelectedRowRange(const QModelIndexList& selected)
} }
QList<int> rows; QList<int> rows;
foreach(const QModelIndex& index, selected) { for (const auto &index : selected) {
rows << index.row(); rows << index.row();
} }
std::sort(rows.begin(), rows.end()); std::sort(rows.begin(), rows.end());
...@@ -428,9 +428,9 @@ void KCMKeyboardWidget::removeLayout() ...@@ -428,9 +428,9 @@ void KCMKeyboardWidget::removeLayout()
if( ! uiWidget->layoutsTableView->selectionModel()->hasSelection() ) if( ! uiWidget->layoutsTableView->selectionModel()->hasSelection() )
return; return;
QModelIndexList selected = uiWidget->layoutsTableView->selectionModel()->selectedIndexes(); const QModelIndexList selected = uiWidget->layoutsTableView->selectionModel()->selectedIndexes();
QPair<int, int> rowsRange( getSelectedRowRange(selected) ); QPair<int, int> rowsRange( getSelectedRowRange(selected) );
foreach(const QModelIndex& idx, selected) { for (const auto &idx : selected) {
if( idx.column() == 0 ) { if( idx.column() == 0 ) {
keyboardConfig->layouts.removeAt(rowsRange.first); keyboardConfig->layouts.removeAt(rowsRange.first);
} }
...@@ -472,7 +472,7 @@ void KCMKeyboardWidget::moveSelectedLayouts(int shift) ...@@ -472,7 +472,7 @@ void KCMKeyboardWidget::moveSelectedLayouts(int shift)
if( selectionModel == nullptr || !selectionModel->hasSelection() ) if( selectionModel == nullptr || !selectionModel->hasSelection() )
return; return;
QModelIndexList selected = selectionModel->selectedRows(); const QModelIndexList selected = selectionModel->selectedRows();
if( selected.count() < 1 ) if( selected.count() < 1 )
return; return;
...@@ -481,7 +481,7 @@ void KCMKeyboardWidget::moveSelectedLayouts(int shift) ...@@ -481,7 +481,7 @@ void KCMKeyboardWidget::moveSelectedLayouts(int shift)
if( newFirstRow >= 0 && newLastRow <= keyboardConfig->layouts.size() - 1 ) { if( newFirstRow >= 0 && newLastRow <= keyboardConfig->layouts.size() - 1 ) {
QList<int> selectionRows; QList<int> selectionRows;
foreach(const QModelIndex& index, selected) { for (const QModelIndex &index : selected) {
int newRowIndex = index.row() + shift; int newRowIndex = index.row() + shift;
keyboardConfig->layouts.move(index.row(), newRowIndex); keyboardConfig->layouts.move(index.row(), newRowIndex);
selectionRows << newRowIndex; selectionRows << newRowIndex;
...@@ -489,7 +489,7 @@ void KCMKeyboardWidget::moveSelectedLayouts(int shift) ...@@ -489,7 +489,7 @@ void KCMKeyboardWidget::moveSelectedLayouts(int shift)
uiChanged(); uiChanged();
QItemSelection selection; QItemSelection selection;
foreach(int row, selectionRows) { for (const int row : qAsConst(selectionRows)) {
QModelIndex topLeft = layoutsTableModel->index(row, 0, QModelIndex()); QModelIndex topLeft = layoutsTableModel->index(row, 0, QModelIndex());
QModelIndex bottomRight = layoutsTableModel->index(row, layoutsTableModel->columnCount(topLeft)-1, QModelIndex()); QModelIndex bottomRight = layoutsTableModel->index(row, layoutsTableModel->columnCount(topLeft)-1, QModelIndex());
selection << QItemSelectionRange(topLeft, bottomRight); selection << QItemSelectionRange(topLeft, bottomRight);
...@@ -554,7 +554,7 @@ bool xkbOptionLessThan(const OptionInfo* o1, const OptionInfo* o2) ...@@ -554,7 +554,7 @@ bool xkbOptionLessThan(const OptionInfo* o1, const OptionInfo* o2)
void KCMKeyboardWidget::initializeXkbOptionsUI() void KCMKeyboardWidget::initializeXkbOptionsUI()
{ {
std::sort(rules->optionGroupInfos.begin(), rules->optionGroupInfos.end(), xkbOptionGroupLessThan); std::sort(rules->optionGroupInfos.begin(), rules->optionGroupInfos.end(), xkbOptionGroupLessThan);
foreach(OptionGroupInfo* optionGroupInfo, rules->optionGroupInfos) { for (OptionGroupInfo *optionGroupInfo : qAsConst(rules->optionGroupInfos)) {
std::sort(optionGroupInfo->optionInfos.begin(), optionGroupInfo->optionInfos.end(), xkbOptionLessThan); std::sort(optionGroupInfo->optionInfos.begin(), optionGroupInfo->optionInfos.end(), xkbOptionLessThan);
} }
...@@ -682,8 +682,8 @@ void KCMKeyboardWidget::updateHardwareUI() ...@@ -682,8 +682,8 @@ void KCMKeyboardWidget::updateHardwareUI()
void KCMKeyboardWidget::populateWithCurrentLayouts() void KCMKeyboardWidget::populateWithCurrentLayouts()
{ {
QList<LayoutUnit> layouts = X11Helper::getLayoutsList(); const QList<LayoutUnit> layouts = X11Helper::getLayoutsList();
foreach(const LayoutUnit &layoutUnit, layouts) { for (const auto &layoutUnit : layouts) {
keyboardConfig->layouts.append(layoutUnit); keyboardConfig->layouts.append(layoutUnit);
} }
} }
...@@ -696,7 +696,7 @@ void KCMKeyboardWidget::populateWithCurrentXkbOptions() ...@@ -696,7 +696,7 @@ void KCMKeyboardWidget::populateWithCurrentXkbOptions()
} }
XkbConfig xkbConfig; XkbConfig xkbConfig;
if( X11Helper::getGroupNames(QX11Info::display(), &xkbConfig, X11Helper::ALL) ) { if( X11Helper::getGroupNames(QX11Info::display(), &xkbConfig, X11Helper::ALL) ) {
foreach(const QString &xkbOption, xkbConfig.options) { for (const QString &xkbOption : qAsConst(xkbConfig.options)) {
keyboardConfig->xkbOptions.append(xkbOption); keyboardConfig->xkbOptions.append(xkbOption);
} }
} }
......
...@@ -173,7 +173,7 @@ void KeyboardConfig::save() ...@@ -173,7 +173,7 @@ void KeyboardConfig::save()
QStringList variants; QStringList variants;
QStringList displayNames; QStringList displayNames;
// QStringList shortcuts; // QStringList shortcuts;
foreach(const LayoutUnit& layoutUnit, layouts) { for (const LayoutUnit &layoutUnit : qAsConst(layouts)) {
layoutStrings.append(layoutUnit.layout()); layoutStrings.append(layoutUnit.layout());
variants.append(layoutUnit.variant()); variants.append(layoutUnit.variant());
displayNames.append(layoutUnit.getRawDisplayName()); displayNames.append(layoutUnit.getRawDisplayName());
...@@ -192,7 +192,6 @@ void KeyboardConfig::save() ...@@ -192,7 +192,6 @@ void KeyboardConfig::save()
config.writeEntry("LayoutList", layoutStrings.join(LIST_SEPARATOR)); config.writeEntry("LayoutList", layoutStrings.join(LIST_SEPARATOR));
config.writeEntry("VariantList", variants); config.writeEntry("VariantList", variants);
config.writeEntry("DisplayNames", displayNames.join(LIST_SEPARATOR)); config.writeEntry("DisplayNames", displayNames.join(LIST_SEPARATOR));
// config.writeEntry("LayoutShortcuts", shortcuts.join(LIST_SEPARATOR));
config.writeEntry("LayoutLoopCount", layoutLoopCount); config.writeEntry("LayoutLoopCount", layoutLoopCount);
...@@ -210,7 +209,7 @@ QList<LayoutUnit> KeyboardConfig::getDefaultLayouts() const ...@@ -210,7 +209,7 @@ QList<LayoutUnit> KeyboardConfig::getDefaultLayouts() const
{ {
QList<LayoutUnit> defaultLayoutList; QList<LayoutUnit> defaultLayoutList;
int i = 0; int i = 0;
foreach(const LayoutUnit& layoutUnit, layouts) { for (const LayoutUnit &layoutUnit : qAsConst(layouts)) {
defaultLayoutList.append(layoutUnit); defaultLayoutList.append(layoutUnit);
if( layoutLoopCount != KeyboardConfig::NO_LOOPING && i >= layoutLoopCount-1 ) if( layoutLoopCount != KeyboardConfig::NO_LOOPING && i >= layoutLoopCount-1 )
break; break;
......
...@@ -111,7 +111,7 @@ bool isExtraSubset(const QList<LayoutUnit>& allLayouts, const QList<LayoutUnit>& ...@@ -111,7 +111,7 @@ bool isExtraSubset(const QList<LayoutUnit>& allLayouts, const QList<LayoutUnit>&
{ {
if( allLayouts.first() != newList.first() ) if( allLayouts.first() != newList.first() )
return false; return false;
foreach(const LayoutUnit& layoutUnit, newList) { for (const LayoutUnit &layoutUnit : newList) {
if( ! allLayouts.contains(layoutUnit) ) if( ! allLayouts.contains(layoutUnit) )
return false; return false;
} }
......
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