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

View File

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

View File

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

View File

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

View File

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

View File

@ -39,7 +39,7 @@ void TranslationManager::setupTranslation()
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))) {
const QString localeName = fileInfo.completeBaseName().mid(prefixLen);
const QLocale locale(localeName);
@ -57,7 +57,7 @@ QStringList TranslationManager::naturalLabels() const
QStringList list;
list.reserve(m_locales.size());
foreach (const QLocale &locale, m_locales) {
for (const QLocale &locale : m_locales) {
list.append(StringUtil::capitalize(
locale.nativeLanguageName()));
}
@ -67,7 +67,7 @@ QStringList TranslationManager::naturalLabels() const
int TranslationManager::getLanguageByName(const QString &localeName) const
{
int index = 0;
foreach (const QLocale &locale, m_locales) {
for (const QLocale &locale : m_locales) {
if (localeName == locale.name()) {
return index;
}

View File

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

View File

@ -19,7 +19,7 @@ QString FileUtil::kernelNameToDrive(const QString &kernelName)
{
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 driveKernelName = driveToKernelName(driveName);

View File

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

View File

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

View File

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