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