Commit 15ca9d93 authored by Alexander Bikadorov's avatar Alexander Bikadorov
Browse files

Replace old-style for loops by range-based loops

Auto-correction using "clang-tidy -fix ...".
parent 531f0b4f
......@@ -1849,9 +1849,9 @@ QString kio_krarcProtocol::detectFullPathName(QString name)
name = name + EXEC_SUFFIX;
QStringList path = QString::fromLocal8Bit(qgetenv("PATH")).split(':');
for (QStringList::Iterator it = path.begin(); it != path.end(); ++it) {
if (QDir(*it).exists(name)) {
QString dir = *it;
for (auto & it : path) {
if (QDir(it).exists(name)) {
QString dir = it;
if (!dir.endsWith(DIR_SEPARATOR))
dir += DIR_SEPARATOR;
......
......@@ -178,8 +178,7 @@ QDomDocument UserActionListView::dumpSelectedActions(QDomDocument* mergeDoc) con
doc = UserAction::createEmptyDoc();
QDomElement root = doc.documentElement();
for (int i = 0; i < list.size(); ++i) {
QTreeWidgetItem* item = list.at(i);
for (auto item : list) {
if (auto* actionItem = dynamic_cast<UserActionListViewItem*>(item))
root.appendChild(actionItem->action()->xmlDump(doc));
}
......@@ -191,8 +190,7 @@ void UserActionListView::removeSelectedActions()
{
QList<QTreeWidgetItem*> list = selectedItems();
for (int i = 0; i < list.size(); ++i) {
QTreeWidgetItem* item = list.at(i);
for (auto item : list) {
if (auto* actionItem = dynamic_cast<UserActionListViewItem*>(item)) {
delete actionItem->action(); // remove the action itself
delete actionItem; // remove the action from the list
......
......@@ -525,8 +525,8 @@ bool KRarcHandler::pack(QStringList fileNames, QString type, QString dest, long
KrLinecountingProcess proc;
proc << packer << dest;
for (QStringList::Iterator file = fileNames.begin(); file != fileNames.end(); ++file) {
proc << *file;
for (auto & fileName : fileNames) {
proc << fileName;
}
// tell the user to wait
......
......@@ -202,12 +202,12 @@ void KrRemoteEncodingMenu::chooseDefault()
partList.erase(partList.begin());
}
for (QStringList::Iterator it = domains.begin(); it != domains.end(); ++it) {
for (auto & domain : domains) {
//qDebug() << "Domain to remove: " << *it;
if (config.hasGroup(*it))
config.deleteGroup(*it);
else if (config.group("").hasKey(*it))
config.group("").deleteEntry(*it); //don't know what group name is supposed to be XXX
if (config.hasGroup(domain))
config.deleteGroup(domain);
else if (config.group("").hasKey(domain))
config.group("").deleteEntry(domain); //don't know what group name is supposed to be XXX
}
}
config.sync();
......
......@@ -141,25 +141,25 @@ void MediaButton::createMediaList()
KMountPoint::List possibleMountList = KMountPoint::possibleMountPoints();
KMountPoint::List currentMountList = KMountPoint::currentMountPoints();
for (KMountPoint::List::iterator it = possibleMountList.begin(); it != possibleMountList.end(); ++it) {
if (krMtMan.networkFilesystem((*it)->mountType())) {
QString path = (*it)->mountPoint();
for (auto & it : possibleMountList) {
if (krMtMan.networkFilesystem(it->mountType())) {
QString path = it->mountPoint();
bool mounted = false;
for (KMountPoint::List::iterator it2 = currentMountList.begin(); it2 != currentMountList.end(); ++it2) {
if (krMtMan.networkFilesystem((*it2)->mountType()) &&
(*it)->mountPoint() == (*it2)->mountPoint()) {
for (auto & it2 : currentMountList) {
if (krMtMan.networkFilesystem(it2->mountType()) &&
it->mountPoint() == it2->mountPoint()) {
mounted = true;
break;
}
}
QString name = i18nc("%1 is the mount point of the remote share", "Remote Share [%1]", (*it)->mountPoint());
QString name = i18nc("%1 is the mount point of the remote share", "Remote Share [%1]", it->mountPoint());
QStringList overlays;
if (mounted)
overlays << "emblem-mounted";
QAction * act = popupMenu->addAction(Icon("network-wired", overlays), name);
QString udi = remotePrefix + (*it)->mountPoint();
QString udi = remotePrefix + it->mountPoint();
act->setData(QVariant(udi));
}
}
......@@ -409,9 +409,9 @@ void MediaButton::getStatus(QString udi, bool &mounted, QString *mountPointOut,
mountPoint = udi.mid(remotePrefix.length());
KMountPoint::List currentMountList = KMountPoint::currentMountPoints();
for (KMountPoint::List::iterator it = currentMountList.begin(); it != currentMountList.end(); ++it) {
if (krMtMan.networkFilesystem((*it)->mountType()) &&
(*it)->mountPoint() == mountPoint) {
for (auto & it : currentMountList) {
if (krMtMan.networkFilesystem(it->mountType()) &&
it->mountPoint() == mountPoint) {
mounted = true;
break;
}
......@@ -571,9 +571,9 @@ void MediaButton::slotCheckMounts()
QString mountPoint = act->data().toString().mid(remotePrefix.length());
bool available = false;
for (KMountPoint::List::iterator it = possibleMountList.begin(); it != possibleMountList.end(); ++it) {
if (krMtMan.networkFilesystem((*it)->mountType()) &&
(*it)->mountPoint() == mountPoint) {
for (auto & it : possibleMountList) {
if (krMtMan.networkFilesystem(it->mountType()) &&
it->mountPoint() == mountPoint) {
available = true;
break;
}
......@@ -586,9 +586,9 @@ void MediaButton::slotCheckMounts()
}
}
for (KMountPoint::List::iterator it = possibleMountList.begin(); it != possibleMountList.end(); ++it) {
if (krMtMan.networkFilesystem((*it)->mountType())) {
QString path = (*it)->mountPoint();
for (auto & it : possibleMountList) {
if (krMtMan.networkFilesystem(it->mountType())) {
QString path = it->mountPoint();
bool mounted = false;
QString udi = remotePrefix + path;
......@@ -599,15 +599,15 @@ void MediaButton::slotCheckMounts()
break;
}
}
for (KMountPoint::List::iterator it2 = currentMountList.begin(); it2 != currentMountList.end(); ++it2) {
if (krMtMan.networkFilesystem((*it2)->mountType()) &&
path == (*it2)->mountPoint()) {
for (auto & it2 : currentMountList) {
if (krMtMan.networkFilesystem(it2->mountType()) &&
path == it2->mountPoint()) {
mounted = true;
break;
}
}
QString name = i18nc("%1 is the mount point of the remote share", "Remote Share [%1]", (*it)->mountPoint());
QString name = i18nc("%1 is the mount point of the remote share", "Remote Share [%1]", it->mountPoint());
QStringList overlays;
if (mounted)
overlays << "emblem-mounted";
......
......@@ -469,15 +469,15 @@ void KgColors::generatePreview()
// copy over local settings to color settings instance, which does not affect the persisted krConfig settings
QList<QString> names = KrColorSettings::getColorNames();
for (QList<QString>::Iterator it = names.begin(); it != names.end(); ++it) {
KonfiguratorColorChooser * chooser = getColorSelector(*it);
for (auto & name : names) {
KonfiguratorColorChooser * chooser = getColorSelector(name);
if (!chooser)
continue;
colorSettings.setColorTextValue(*it, chooser->getValue());
colorSettings.setColorTextValue(name, chooser->getValue());
if (chooser->isValueRGB())
colorSettings.setColorValue(*it, chooser->getColor());
colorSettings.setColorValue(name, chooser->getColor());
else
colorSettings.setColorValue(*it, QColor());
colorSettings.setColorValue(name, QColor());
}
colorSettings.setBoolValue("KDE Default", generals->find("KDE Default")->isChecked());
......
......@@ -298,13 +298,13 @@ void KgProtocols::loadInitialValues()
KConfigGroup group(krConfig, "Protocols");
QStringList protList = group.readEntry("Handled Protocols", QStringList());
for (QStringList::Iterator it = protList.begin(); it != protList.end(); ++it) {
addProtocol(*it);
for (auto & it : protList) {
addProtocol(it);
QStringList mimes = group.readEntry(QString("Mimes For %1").arg(*it), QStringList());
QStringList mimes = group.readEntry(QString("Mimes For %1").arg(it), QStringList());
for (QStringList::Iterator it2 = mimes.begin(); it2 != mimes.end(); ++it2)
addMime(*it2, *it);
for (auto & mime : mimes)
addMime(mime, it);
}
if (linkList->topLevelItemCount() != 0)
......
......@@ -41,8 +41,8 @@ bool KonfiguratorPage::apply()
{
bool restartNeeded = false;
for (QList<KonfiguratorExtension *>::iterator item = itemList.begin(); item != itemList.end(); item ++)
restartNeeded = (*item)->apply() || restartNeeded;
for (auto & item : itemList)
restartNeeded = item->apply() || restartNeeded;
krConfig->sync();
return restartNeeded;
......@@ -52,24 +52,24 @@ void KonfiguratorPage::setDefaults()
{
int activePage = activeSubPage();
for (QList<KonfiguratorExtension *>::iterator item = itemList.begin(); item != itemList.end(); item ++) {
if ((*item)->subPage() == activePage)
(*item)->setDefaults();
for (auto & item : itemList) {
if (item->subPage() == activePage)
item->setDefaults();
}
}
void KonfiguratorPage::loadInitialValues()
{
for (QList<KonfiguratorExtension *>::iterator item = itemList.begin(); item != itemList.end(); item ++)
(*item)->loadInitialValue();
for (auto & item : itemList)
item->loadInitialValue();
}
bool KonfiguratorPage::isChanged()
{
bool isChanged = false;
for (QList<KonfiguratorExtension *>::iterator item = itemList.begin(); item != itemList.end(); item ++)
isChanged = isChanged || (*item)->isChanged();
for (auto & item : itemList)
isChanged = isChanged || item->isChanged();
return isChanged;
}
......
......@@ -59,8 +59,8 @@ QGridLayout* KrResultTable::initTable()
// +++ Build and add table header +++
int column = 0;
for (QStringList::Iterator it = _tableHeaders.begin(); it != _tableHeaders.end(); ++it) {
_label = new QLabel(*it, this);
for (auto & _tableHeader : _tableHeaders) {
_label = new QLabel(_tableHeader, this);
_label->setContentsMargins(5, 5, 5, 5);
_grid->addWidget(_label, 0, column);
......@@ -337,8 +337,8 @@ bool KrToolResultTable::addRow(SearchObject* search, QGridLayout* grid)
QWidget* toolBoxWidget = new QWidget(this);
auto * toolBox = new QVBoxLayout(toolBoxWidget);
for (QList<Application*>::Iterator it = _apps.begin(); it != _apps.end(); ++it) {
auto* l = new KUrlLabel((*it)->getWebsite(), (*it)->getAppName(), toolBoxWidget);
for (auto & _app : _apps) {
auto* l = new KUrlLabel(_app->getWebsite(), _app->getAppName(), toolBoxWidget);
toolBox->addWidget(l);
l->setAlignment(Qt::AlignLeft | Qt::AlignTop);
......@@ -351,8 +351,8 @@ bool KrToolResultTable::addRow(SearchObject* search, QGridLayout* grid)
QWidget* vboxWidget = new QWidget(this);
auto * vbox = new QVBoxLayout(vboxWidget);
for (QList<Application*>::Iterator it = _apps.begin(); it != _apps.end(); ++it) {
_label = new QLabel((*it)->getPath(), vboxWidget);
for (auto & _app : _apps) {
_label = new QLabel(_app->getPath(), vboxWidget);
_label->setContentsMargins(5, 5, 5, 5);
_label->setAlignment(Qt::AlignTop);
vbox->addWidget(_label);
......
......@@ -345,13 +345,13 @@ void LocateDlg::processStdout()
QStringList list = remaining.split('\n');
int items = list.size();
for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
for (auto & it : list) {
if (--items == 0 && !remaining.endsWith('\n'))
remaining = *it;
remaining = it;
else {
if (dontSearchPath) {
QRegExp regExp(pattern, isCs ? Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::Wildcard);
QString fileName = (*it).trimmed();
QString fileName = it.trimmed();
if (fileName.endsWith(QLatin1String("/")) && fileName != "/") {
fileName.truncate(fileName.length() - 1);
}
......@@ -361,7 +361,7 @@ void LocateDlg::processStdout()
continue;
}
if (onlyExist) {
KFileItem file(QUrl::fromLocalFile((*it).trimmed()));
KFileItem file(QUrl::fromLocalFile(it.trimmed()));
if (!file.isReadable())
continue;
}
......@@ -371,7 +371,7 @@ void LocateDlg::processStdout()
else
lastItem = new QTreeWidgetItem(resultList);
lastItem->setText(0, *it);
lastItem->setText(0, it);
}
}
}
......
......@@ -85,8 +85,8 @@ KMountMan::KMountMan(QWidget *parent) : QObject(), _operational(false), waiting(
QStringList nonmount = group.readEntry("Nonmount Points", _NonMountPoints).split(',');
nonmount_fs_mntpoint += nonmount;
// simplify the white space
for (QStringList::Iterator it = nonmount_fs_mntpoint.begin(); it != nonmount_fs_mntpoint.end(); ++it) {
*it = (*it).simplified();
for (auto & it : nonmount_fs_mntpoint) {
it = it.simplified();
}
}
......@@ -129,8 +129,8 @@ QExplicitlySharedDataPointer<KMountPoint> KMountMan::findInListByMntPoint(KMount
value = value.left(value.length() - 1);
QExplicitlySharedDataPointer<KMountPoint> m;
for (KMountPoint::List::iterator it = lst.begin(); it != lst.end(); ++it) {
m = it->data();
for (auto & it : lst) {
m = it.data();
QString mntPnt = m->mountPoint();
if (mntPnt.length() > 1 && mntPnt.endsWith('/'))
mntPnt = mntPnt.left(mntPnt.length() - 1);
......
......@@ -220,22 +220,22 @@ void KMountManGUI::getSpaceData()
return;
}
for (KMountPoint::List::iterator it = mounted.begin(); it != mounted.end(); ++it) {
for (auto & it : mounted) {
// don't bother with invalid file systems
if (mountMan->invalidFilesystem((*it)->mountType())) {
if (mountMan->invalidFilesystem(it->mountType())) {
continue;
}
KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo((*it) ->mountPoint());
KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(it ->mountPoint());
if(!info.isValid()) {
continue;
}
fsData data;
data.setMntPoint((*it) ->mountPoint());
data.setMntPoint(it ->mountPoint());
data.setMounted(true);
data.setTotalBlks(info.size() / 1024);
data.setFreeBlks(info.available() / 1024);
data.setName((*it)->mountedFrom());
data.setType((*it)->mountType());
data.setName(it->mountedFrom());
data.setType(it->mountType());
fileSystems.append(data);
}
addNonMounted();
......@@ -245,16 +245,16 @@ void KMountManGUI::getSpaceData()
void KMountManGUI::addNonMounted()
{
// handle the non-mounted ones
for (KMountPoint::List::iterator it = possible.begin(); it != possible.end(); ++it) {
for (auto & it : possible) {
// make sure we don't add things we've already added
if (KMountMan::findInListByMntPoint(mounted, (*it)->mountPoint())) {
if (KMountMan::findInListByMntPoint(mounted, it->mountPoint())) {
continue;
} else {
fsData data;
data.setMntPoint((*it)->mountPoint());
data.setMntPoint(it->mountPoint());
data.setMounted(false);
data.setType((*it)->mountType());
data.setName((*it)->mountedFrom());
data.setType(it->mountType());
data.setName(it->mountedFrom());
if (mountMan->invalidFilesystem(data.type()))
continue;
......@@ -316,8 +316,8 @@ void KMountManGUI::updateList()
mountList->clearSelection();
mountList->clear();
for (QList<fsData>::iterator it = fileSystems.begin(); it != fileSystems.end() ; ++it)
addItemToMountList(mountList, *it);
for (auto & fileSystem : fileSystems)
addItemToMountList(mountList, fileSystem);
currentItem = mountList->topLevelItem(currentIdx);
for(int i = 0; i < mountList->topLevelItemCount(); i++) {
......@@ -469,10 +469,10 @@ void KMountManGUI::slotEject()
fsData* KMountManGUI::getFsData(QTreeWidgetItem *item)
{
for (QList<fsData>::Iterator it = fileSystems.begin(); it != fileSystems.end(); ++it) {
for (auto & fileSystem : fileSystems) {
// the only thing which is unique is the mount point
if ((*it).mntPoint() == getMntPoint(item)) {
return & (*it);
if (fileSystem.mntPoint() == getMntPoint(item)) {
return & fileSystem;
}
}
//this point shouldn't be reached
......@@ -500,11 +500,11 @@ bool KrMountDetector::hasMountsChanged()
#endif
KMountPoint::List mountPoints = KMountPoint::currentMountPoints(KMountPoint::NeedRealDeviceName);
QCryptographicHash md5(QCryptographicHash::Md5);
for (KMountPoint::List::iterator i = mountPoints.begin(); i != mountPoints.end(); ++i) {
md5.addData((*i)->mountedFrom().toUtf8());
md5.addData((*i)->realDeviceName().toUtf8());
md5.addData((*i)->mountPoint().toUtf8());
md5.addData((*i)->mountType().toUtf8());
for (auto & mountPoint : mountPoints) {
md5.addData(mountPoint->mountedFrom().toUtf8());
md5.addData(mountPoint->realDeviceName().toUtf8());
md5.addData(mountPoint->mountPoint().toUtf8());
md5.addData(mountPoint->mountType().toUtf8());
}
QString s = md5.result();
result = s != checksum;
......
......@@ -49,9 +49,9 @@ void SortProps::init(FileItem *fileitem, int col, const KrViewProperties * props
int loc = fileitemName.lastIndexOf('.');
if (loc > 0) { // avoid mishandling of .bashrc and friend
// check if it has one of the predefined 'atomic extensions'
for (QStringList::const_iterator i = props->atomicExtensions.begin(); i != props->atomicExtensions.end(); ++i) {
if (fileitemName.endsWith(*i) && fileitemName != *i) {
loc = fileitemName.length() - (*i).length();
for (const auto & atomicExtension : props->atomicExtensions) {
if (fileitemName.endsWith(atomicExtension) && fileitemName != atomicExtension) {
loc = fileitemName.length() - atomicExtension.length();
break;
}
}
......
......@@ -927,8 +927,7 @@ void KrView::doRestoreSettings(KConfigGroup group)
void KrView::applySettingsToOthers()
{
for(int i = 0; i < _instance.m_objects.length(); i++) {
KrView *view = _instance.m_objects[i];
for(auto view : _instance.m_objects) {
if(this != view) {
view->_ignoreSettingsChange = true;
view->copySettingsFrom(this);
......
......@@ -47,11 +47,9 @@ KrViewItem::KrViewItem(FileItem *fileitem, KrInterView *parentView):
int loc = fileitemName.lastIndexOf('.');
if (loc > 0) { // avoid mishandling of .bashrc and friend
// check if it has one of the predefined 'atomic extensions'
for (QStringList::const_iterator i = _viewProperties->atomicExtensions.begin();
i != _viewProperties->atomicExtensions.end();
++i) {
if (fileitemName.endsWith(*i)) {
loc = fileitemName.length() - (*i).length();
for (const auto & atomicExtension : _viewProperties->atomicExtensions) {
if (fileitemName.endsWith(atomicExtension)) {
loc = fileitemName.length() - atomicExtension.length();
break;
}
}
......
......@@ -468,9 +468,9 @@ QString ListModel::nameWithoutExtension(const FileItem *fileItem, bool checkEnab
// and virtfs / search result names like "/dir/.file" which would become "/dir/"
if (loc > 0 && fileItemName.lastIndexOf('/') < loc) {
// check if it has one of the predefined 'atomic extensions'
for (QStringList::const_iterator i = properties()->atomicExtensions.begin(); i != properties()->atomicExtensions.end(); ++i) {
if (fileItemName.endsWith(*i) && fileItemName != *i) {
loc = fileItemName.length() - (*i).length();
for (const auto & atomicExtension : properties()->atomicExtensions) {
if (fileItemName.endsWith(atomicExtension) && fileItemName != atomicExtension) {
loc = fileItemName.length() - atomicExtension.length();
break;
}
}
......
......@@ -153,23 +153,23 @@ void KrColorSettingsImpl::loadFromConfig()
{
KConfigGroup group(krConfig, "Colors");
QStringList names = KrColorSettingNames::getColorNames();
for (QStringList::Iterator it = names.begin(); it != names.end(); ++it) {
m_colorTextValues[*it] = group.readEntry(*it, QString());
if (m_colorTextValues[*it].count(',') == 2)
m_colorValues[*it] = group.readEntry(*it, QColor());
for (auto & name : names) {
m_colorTextValues[name] = group.readEntry(name, QString());
if (m_colorTextValues[name].count(',') == 2)
m_colorValues[name] = group.readEntry(name, QColor());
else
m_colorValues[*it] = QColor();
m_colorValues[name] = QColor();
}
names = KrColorSettingNames::getNumNames();
for (QStringList::Iterator it = names.begin(); it != names.end(); ++it) {
if (!group.readEntry(*it, QString()).isEmpty()) {
m_numValues[*it] = group.readEntry(*it, (long long)0);
for (auto & name : names) {
if (!group.readEntry(name, QString()).isEmpty()) {
m_numValues[name] = group.readEntry(name, (long long)0);
}
}
names = KrColorSettingNames::getBoolNames();
for (QStringList::Iterator it = names.begin(); it != names.end(); ++it) {
if (!group.readEntry(*it, QString()).isEmpty()) {
m_boolValues[*it] = group.readEntry(*it, false);
for (auto & name : names) {
if (!group.readEntry(name, QString()).isEmpty()) {
m_boolValues[name] = group.readEntry(name, false);
}
}
}
......@@ -196,9 +196,9 @@ const KrColorSettings & KrColorSettings::operator= (const KrColorSettings & src)
if (this == & src)
return * this;
QStringList names = KrColorSettingNames::getColorNames();
for (QStringList::Iterator it = names.begin(); it != names.end(); ++it) {
m_impl->m_colorTextValues[*it] = src.m_impl->m_colorTextValues[*it];
m_impl->m_colorValues[*it] = src.m_impl->m_colorValues[*it];
for (auto & name : names) {
m_impl->m_colorTextValues[name] = src.m_impl->m_colorTextValues[name];
m_impl->m_colorValues[name] = src.m_impl->m_colorValues[name];
}
for (QMap<QString, int>::Iterator it = src.m_impl->m_numValues.begin(); it != src.m_impl->m_numValues.end(); ++it) {
m_impl->m_numValues[it.key()] = it.value();
......
......@@ -261,8 +261,8 @@ QString bashquote(QString s)
static const QString evilstuff = "\\\"'`()[]{}!?;$&<>| \t\r\n"; // stuff that should get escaped
for (int i = 0; i < evilstuff.length(); ++i)
s.replace(evilstuff[ i ], ('\\' + evilstuff[ i ]));
for (auto i : evilstuff)
s.replace(i, ('\\' + i));
return s;
}
......@@ -985,9 +985,9 @@ TagString exp_View::expFunc(const KrPanel*, const QStringList& parameter, const
TagString exp_simpleplaceholder::expFunc(const KrPanel* p, const TagStringList& parameter, const bool& useUrl, Expander& exp) const
{
QStringList lst;
for (TagStringList::const_iterator it = parameter.begin(), end = parameter.end();it != end;++it)
if ((*it).isSimple())
lst.push_back((*it).string());
for (const auto & it : parameter)
if (it.isSimple())
lst.push_back(it.string());
else {
setError(exp, Error(Error::exp_S_FATAL, Error::exp_C_SYNTAX, i18n("%Each% is not allowed in parameter to %1", description())));
return QString();
......@@ -1137,11 +1137,11 @@ TagStringList Expander::separateParameter(QString* const exp, bool useUrl)
}
parameter1.append(result.mid(begin, idx - begin)); //don't forget the last one