UI: Use for-range instead of foreach.

This commit is contained in:
Nodir Temirkhodjaev 2019-10-09 13:58:30 +05:00
parent 57a19edd5e
commit ffe4d7aaef
11 changed files with 24 additions and 24 deletions

View File

@ -202,7 +202,7 @@ quint32 FirewallConf::appGroupBits() const
{ {
quint32 groupBits = 0; quint32 groupBits = 0;
int i = 0; int i = 0;
foreach (const AppGroup *appGroup, appGroupsList()) { for (const AppGroup *appGroup : appGroupsList()) {
if (appGroup->enabled()) { if (appGroup->enabled()) {
groupBits |= (1 << i); groupBits |= (1 << i);
} }
@ -214,7 +214,7 @@ quint32 FirewallConf::appGroupBits() const
void FirewallConf::setAppGroupBits(quint32 groupBits) void FirewallConf::setAppGroupBits(quint32 groupBits)
{ {
int i = 0; int i = 0;
foreach (AppGroup *appGroup, appGroupsList()) { for (AppGroup *appGroup : appGroupsList()) {
appGroup->setEnabled(groupBits & (1 << i)); appGroup->setEnabled(groupBits & (1 << i));
++i; ++i;
} }
@ -227,7 +227,7 @@ QQmlListProperty<AddressGroup> FirewallConf::addressGroups()
AppGroup *FirewallConf::appGroupByName(const QString &name) const AppGroup *FirewallConf::appGroupByName(const QString &name) const
{ {
foreach (AppGroup *appGroup, appGroupsList()) { for (AppGroup *appGroup : appGroupsList()) {
if (appGroup->name() == name) if (appGroup->name() == name)
return appGroup; return appGroup;
} }
@ -317,13 +317,13 @@ QVariant FirewallConf::toVariant() const
map["passwordHash"] = m_passwordHash; map["passwordHash"] = m_passwordHash;
QVariantList addresses; QVariantList addresses;
foreach (const AddressGroup *addressGroup, addressGroupsList()) { for (const AddressGroup *addressGroup : addressGroupsList()) {
addresses.append(addressGroup->toVariant()); addresses.append(addressGroup->toVariant());
} }
map["addressGroups"] = addresses; map["addressGroups"] = addresses;
QVariantList groups; QVariantList groups;
foreach (const AppGroup *appGroup, appGroupsList()) { for (const AppGroup *appGroup : appGroupsList()) {
groups.append(appGroup->toVariant()); groups.append(appGroup->toVariant());
} }
map["appGroups"] = groups; map["appGroups"] = groups;
@ -339,13 +339,13 @@ void FirewallConf::fromVariant(const QVariant &v)
const QVariantList addresses = map["addressGroups"].toList(); const QVariantList addresses = map["addressGroups"].toList();
int addrGroupIndex = 0; int addrGroupIndex = 0;
foreach (const QVariant &av, addresses) { for (const QVariant &av : addresses) {
AddressGroup *addressGroup = m_addressGroups.at(addrGroupIndex++); AddressGroup *addressGroup = m_addressGroups.at(addrGroupIndex++);
addressGroup->fromVariant(av); addressGroup->fromVariant(av);
} }
const QVariantList groups = map["appGroups"].toList(); const QVariantList groups = map["appGroups"].toList();
foreach (const QVariant &gv, groups) { for (const QVariant &gv : groups) {
auto appGroup = new AppGroup(); auto appGroup = new AppGroup();
appGroup->fromVariant(gv); appGroup->fromVariant(gv);
addAppGroup(appGroup); addAppGroup(appGroup);

View File

@ -599,7 +599,7 @@ void FortManager::saveTrayFlags()
m_firewallConf->setStopInetTraffic(m_stopInetTrafficAction->isChecked()); m_firewallConf->setStopInetTraffic(m_stopInetTrafficAction->isChecked());
int i = 0; int i = 0;
foreach (AppGroup *appGroup, m_firewallConf->appGroupsList()) { for (AppGroup *appGroup : m_firewallConf->appGroupsList()) {
const QAction *action = m_appGroupActions.at(i); const QAction *action = m_appGroupActions.at(i);
appGroup->setEnabled(action->isChecked()); appGroup->setEnabled(action->isChecked());
++i; ++i;
@ -712,7 +712,7 @@ void FortManager::updateTrayMenu()
menu->addSeparator(); menu->addSeparator();
m_appGroupActions.clear(); m_appGroupActions.clear();
int appGroupIndex = 0; int appGroupIndex = 0;
foreach (const AppGroup *appGroup, conf.appGroupsList()) { for (const AppGroup *appGroup : conf.appGroupsList()) {
QAction *a = addAction( QAction *a = addAction(
menu, QIcon(":/images/application_double.png"), menu, QIcon(":/images/application_double.png"),
appGroup->label(), this, SLOT(saveTrayFlags()), appGroup->label(), this, SLOT(saveTrayFlags()),

View File

@ -127,7 +127,7 @@ TasksMap FortSettings::tasks() const
TasksMap map; TasksMap map;
const QString tasksPrefix("tasks"); const QString tasksPrefix("tasks");
foreach (const QString &taskName, iniChildKeys(tasksPrefix)) { for (const QString &taskName : iniChildKeys(tasksPrefix)) {
const QString taskKey(tasksPrefix + '/' + taskName); const QString taskKey(tasksPrefix + '/' + taskName);
map.insert(taskName, iniValue(taskKey).toByteArray()); map.insert(taskName, iniValue(taskKey).toByteArray());
} }

View File

@ -42,7 +42,7 @@ void TaskManager::loadSettings(const FortSettings *fortSettings)
{ {
const TasksMap tasksMap = fortSettings->tasks(); const TasksMap tasksMap = fortSettings->tasks();
foreach (TaskInfo *taskInfo, m_taskInfos) { for (TaskInfo *taskInfo : m_taskInfos) {
const QString taskName = TaskInfo::typeToString(taskInfo->type()); const QString taskName = TaskInfo::typeToString(taskInfo->type());
const QByteArray taskData = tasksMap.value(taskName); const QByteArray taskData = tasksMap.value(taskName);
@ -59,7 +59,7 @@ bool TaskManager::saveSettings(FortSettings *fortSettings)
TasksMap tasksMap; TasksMap tasksMap;
QByteArray taskData; QByteArray taskData;
foreach (const TaskInfo *taskInfo, m_taskInfos) { for (const TaskInfo *taskInfo : m_taskInfos) {
const QString taskName = TaskInfo::typeToString(taskInfo->type()); const QString taskName = TaskInfo::typeToString(taskInfo->type());
taskData.clear(); taskData.clear();
@ -90,7 +90,7 @@ void TaskManager::runExpiredTasks()
const QDateTime now = DateUtil::now(); const QDateTime now = DateUtil::now();
bool enabledTaskExists = false; bool enabledTaskExists = false;
foreach (TaskInfo *taskInfo, m_taskInfos) { for (TaskInfo *taskInfo : m_taskInfos) {
if (!taskInfo->enabled()) if (!taskInfo->enabled())
continue; continue;

View File

@ -73,7 +73,7 @@ QStringList TaskTasix::parseTasixBuffer(const QByteArray &buffer)
// Parse lines // Parse lines
const QString text = QString::fromLatin1(buffer); const QString text = QString::fromLatin1(buffer);
foreach (const QStringRef &line, text.splitRef( for (const QStringRef &line : text.splitRef(
'\n', QString::SkipEmptyParts)) { '\n', QString::SkipEmptyParts)) {
if (!line.startsWith('*')) if (!line.startsWith('*'))
continue; continue;

View File

@ -39,7 +39,7 @@ void TranslationManager::setupTranslation()
m_locales.append(QLocale(QLocale::English, QLocale::UnitedStates)); m_locales.append(QLocale(QLocale::English, QLocale::UnitedStates));
foreach (const QFileInfo &fileInfo, QDir(i18nDir()) for (const QFileInfo &fileInfo : QDir(i18nDir())
.entryInfoList(QStringList() << ("*" TRANSLATION_FILE_SUFFIX))) { .entryInfoList(QStringList() << ("*" TRANSLATION_FILE_SUFFIX))) {
const QString localeName = fileInfo.completeBaseName().mid(prefixLen); const QString localeName = fileInfo.completeBaseName().mid(prefixLen);
const QLocale locale(localeName); const QLocale locale(localeName);
@ -57,7 +57,7 @@ QStringList TranslationManager::naturalLabels() const
QStringList list; QStringList list;
list.reserve(m_locales.size()); list.reserve(m_locales.size());
foreach (const QLocale &locale, m_locales) { for (const QLocale &locale : m_locales) {
list.append(StringUtil::capitalize( list.append(StringUtil::capitalize(
locale.nativeLanguageName())); locale.nativeLanguageName()));
} }
@ -67,7 +67,7 @@ QStringList TranslationManager::naturalLabels() const
int TranslationManager::getLanguageByName(const QString &localeName) const int TranslationManager::getLanguageByName(const QString &localeName) const
{ {
int index = 0; int index = 0;
foreach (const QLocale &locale, m_locales) { for (const QLocale &locale : m_locales) {
if (localeName == locale.name()) { if (localeName == locale.name()) {
return index; return index;
} }

View File

@ -246,7 +246,7 @@ bool ConfUtil::parseApps(const QString &text, bool blocked,
appgroups_map_t &appGroupIndexes, appgroups_map_t &appGroupIndexes,
int groupOffset) int groupOffset)
{ {
foreach (const QStringRef &line, for (const QStringRef &line :
text.splitRef(QLatin1Char('\n'))) { text.splitRef(QLatin1Char('\n'))) {
const QStringRef lineTrimmed = line.trimmed(); const QStringRef lineTrimmed = line.trimmed();
if (lineTrimmed.isEmpty() if (lineTrimmed.isEmpty()
@ -373,7 +373,7 @@ void ConfUtil::writeFragmentBits(quint16 *fragmentBits,
{ {
*fragmentBits = 0; *fragmentBits = 0;
int i = 0; int i = 0;
foreach (const AppGroup *appGroup, conf.appGroupsList()) { for (const AppGroup *appGroup : conf.appGroupsList()) {
if (appGroup->fragmentPacket()) { if (appGroup->fragmentPacket()) {
*fragmentBits |= (1 << i); *fragmentBits |= (1 << i);
} }
@ -485,7 +485,7 @@ void ConfUtil::writeStrings(char **data, const QStringList &list)
*offp++ = 0; *offp++ = 0;
foreach (const QString &s, list) { for (const QString &s : list) {
const quint32 len = s.toWCharArray((wchar_t *) p) const quint32 len = s.toWCharArray((wchar_t *) p)
* sizeof(wchar_t); * sizeof(wchar_t);

View File

@ -19,7 +19,7 @@ QString FileUtil::kernelNameToDrive(const QString &kernelName)
{ {
const QString kernelNameLower = kernelName.toLower(); const QString kernelNameLower = kernelName.toLower();
foreach (const QFileInfo &fi, QDir::drives()) { for (const QFileInfo &fi : QDir::drives()) {
const QString driveName = fi.path().left(2); const QString driveName = fi.path().left(2);
const QString driveKernelName = driveToKernelName(driveName); const QString driveKernelName = driveToKernelName(driveName);

View File

@ -147,7 +147,7 @@ void Logger::checkLogFiles()
int count = LOGGER_KEEP_FILES; int count = LOGGER_KEEP_FILES;
// Remove old files // Remove old files
foreach (const QString &fileName, m_dir.entryList( for (const QString &fileName : m_dir.entryList(
QStringList() << (QLatin1String(LOGGER_FILE_PREFIX) + '*' QStringList() << (QLatin1String(LOGGER_FILE_PREFIX) + '*'
+ QLatin1String(LOGGER_FILE_SUFFIX)), + QLatin1String(LOGGER_FILE_SUFFIX)),
QDir::Files, QDir::Time)) { QDir::Files, QDir::Time)) {

View File

@ -56,7 +56,7 @@ void NativeEventFilter::unregisterHotKey(int hotKeyId)
void NativeEventFilter::unregisterHotKeys() void NativeEventFilter::unregisterHotKeys()
{ {
foreach (int hotKeyId, m_keyIdMap) { for (const int hotKeyId : m_keyIdMap) {
UnregisterHotKey(nullptr, hotKeyId); UnregisterHotKey(nullptr, hotKeyId);
} }

View File

@ -66,7 +66,7 @@ bool Ip4Range::fromText(const QString &text)
ip4range_map_t ipRangeMap; ip4range_map_t ipRangeMap;
int lineNo = 0; int lineNo = 0;
foreach (const QStringRef &line, for (const QStringRef &line :
text.splitRef(QLatin1Char('\n'))) { text.splitRef(QLatin1Char('\n'))) {
++lineNo; ++lineNo;