foreach => for

This commit is contained in:
Gres 2020-01-26 22:14:06 +03:00
parent 9356f4cb1f
commit 5a980b4365
6 changed files with 19 additions and 19 deletions

View File

@ -11,7 +11,7 @@ LanguageHelper::LanguageHelper () {
QStringList LanguageHelper::availableOcrLanguagesUi () const { QStringList LanguageHelper::availableOcrLanguagesUi () const {
QStringList uiItems; QStringList uiItems;
foreach (const QString &item, availableOcrLanguages_) { for (const QString &item: availableOcrLanguages_) {
uiItems << ocrCodeToUi (item); uiItems << ocrCodeToUi (item);
} }
uiItems.sort (); uiItems.sort ();
@ -29,7 +29,7 @@ QStringList LanguageHelper::availableOcrLanguages (const QString &path) const {
} }
QStringList items; QStringList items;
QStringList files = dir.entryList ({"*.traineddata"}, QDir::Files); QStringList files = dir.entryList ({"*.traineddata"}, QDir::Files);
foreach (const QString &file, files) { for (const QString &file: files) {
QString lang = file.left (file.indexOf (".")); QString lang = file.left (file.indexOf ("."));
items << lang; items << lang;
} }
@ -39,7 +39,7 @@ QStringList LanguageHelper::availableOcrLanguages (const QString &path) const {
QStringList LanguageHelper::availableOcrLanguagesUi (const QString &path) const { QStringList LanguageHelper::availableOcrLanguagesUi (const QString &path) const {
QStringList uiItems, items; QStringList uiItems, items;
items = availableOcrLanguages (path); items = availableOcrLanguages (path);
foreach (const QString &item, items) { for (const QString &item: items) {
uiItems << ocrCodeToUi (item); uiItems << ocrCodeToUi (item);
} }
uiItems.sort (); uiItems.sort ();
@ -113,7 +113,7 @@ void LanguageHelper::updateMenu (QMenu *menu, const QStringList &languages, int
} }
if (languages.size () <= groupSize) { if (languages.size () <= groupSize) {
foreach (const QString &language, languages) { for (const QString &language: languages) {
menu->addAction (language); menu->addAction (language);
} }
} }
@ -121,7 +121,7 @@ void LanguageHelper::updateMenu (QMenu *menu, const QStringList &languages, int
int subIndex = groupSize; int subIndex = groupSize;
QMenu *subMenu = NULL; QMenu *subMenu = NULL;
QString prevLetter; QString prevLetter;
foreach (const QString &language, languages) { for (const QString &language: languages) {
QString curLetter = language.left (1); QString curLetter = language.left (1);
if (++subIndex >= groupSize && prevLetter != curLetter) { if (++subIndex >= groupSize && prevLetter != curLetter) {
if (subMenu != NULL) { if (subMenu != NULL) {

View File

@ -117,7 +117,7 @@ void Manager::updateActionsState (bool isEnabled) {
QList<QAction *> actions; QList<QAction *> actions;
actions << captureAction_ << repeatCaptureAction_ << repeatAction_ << clipboardAction_; actions << captureAction_ << repeatCaptureAction_ << repeatAction_ << clipboardAction_;
QList<bool> states; QList<bool> states;
foreach (const QAction * action, actions) { for (const QAction *action: actions) {
states << action->isEnabled (); states << action->isEnabled ();
} }
#endif #endif
@ -230,13 +230,13 @@ void Manager::checkForUpdates () {
} }
Manager::~Manager () { Manager::~Manager () {
foreach (SelectionDialog * selection, selections_.values ()) { for (SelectionDialog *selection: selections_.values ()) {
selection->hide (); selection->hide ();
delete selection; delete selection;
} }
trayIcon_->hide (); trayIcon_->hide ();
delete trayIcon_->contextMenu (); delete trayIcon_->contextMenu ();
foreach (QThread * thread, threads_) { for (QThread *thread: threads_) {
thread->quit (); thread->quit ();
thread->wait (1000000); thread->wait (1000000);
} }
@ -244,7 +244,7 @@ Manager::~Manager () {
void Manager::capture () { void Manager::capture () {
QList<QScreen *> screens = QApplication::screens (); QList<QScreen *> screens = QApplication::screens ();
foreach (QScreen * screen, screens) { for (QScreen *screen: screens) {
QRect geometry = screen->availableGeometry (); QRect geometry = screen->availableGeometry ();
#if QT_VERSION >= QT_VERSION_CHECK (5,10,0) #if QT_VERSION >= QT_VERSION_CHECK (5,10,0)
QPixmap pixmap = screen->grabWindow (0, 0, 0, QPixmap pixmap = screen->grabWindow (0, 0, 0,
@ -309,7 +309,7 @@ void Manager::repeatCapture () {
return; return;
} }
QList<QScreen *> screens = QApplication::screens (); QList<QScreen *> screens = QApplication::screens ();
foreach (QScreen * screen, screens) { for (QScreen *screen: screens) {
QString name = screen->name (); QString name = screen->name ();
if (!selections_.contains (name)) { if (!selections_.contains (name)) {
continue; continue;

View File

@ -25,7 +25,7 @@ void RecognizerHelper::load () {
QByteArray data = f.readAll (); QByteArray data = f.readAll ();
f.close (); f.close ();
QStringList lines = QString::fromUtf8 (data).split ('\n', QString::SkipEmptyParts); QStringList lines = QString::fromUtf8 (data).split ('\n', QString::SkipEmptyParts);
foreach (const QString &line, lines) { for (const QString &line: lines) {
QStringList parts = line.mid (1, line.size () - 2).split ("\",\""); // remove " QStringList parts = line.mid (1, line.size () - 2).split ("\",\""); // remove "
if (parts.size () < 3) { if (parts.size () < 3) {
continue; continue;
@ -39,7 +39,7 @@ void RecognizerHelper::save () {
if (!f.open (QFile::WriteOnly)) { if (!f.open (QFile::WriteOnly)) {
return; return;
} }
foreach (const Sub &sub, subs_) { for (const Sub &sub: subs_) {
QStringList parts = QStringList () << sub.language << sub.source << sub.target; QStringList parts = QStringList () << sub.language << sub.source << sub.target;
QString line = "\"" + parts.join ("\",\"") + "\"\n"; QString line = "\"" + parts.join ("\",\"") + "\"\n";
f.write (line.toUtf8 ()); f.write (line.toUtf8 ());
@ -53,7 +53,7 @@ QString RecognizerHelper::substitute (const QString &source, const QString &lang
int bestMatchIndex = -1; int bestMatchIndex = -1;
int bestMatchLen = 0; int bestMatchLen = 0;
int index = -1; int index = -1;
foreach (const Sub &sub, subs_) { for (const Sub &sub: subs_) {
++index; ++index;
if (sub.language != language || !result.contains (sub.source)) { if (sub.language != language || !result.contains (sub.source)) {
continue; continue;

View File

@ -43,7 +43,7 @@ SettingsEditor::SettingsEditor (const LanguageHelper &dictionary, QWidget *paren
proxyTypeNames.insert (QNetworkProxy::Socks5Proxy, tr ("SOCKS 5")); proxyTypeNames.insert (QNetworkProxy::Socks5Proxy, tr ("SOCKS 5"));
proxyTypeNames.insert (QNetworkProxy::HttpProxy, tr ("HTTP")); proxyTypeNames.insert (QNetworkProxy::HttpProxy, tr ("HTTP"));
QList<int> proxyOrder = proxyTypeOrder (); QList<int> proxyOrder = proxyTypeOrder ();
foreach (int type, proxyOrder) { for (int type: proxyOrder) {
ui->proxyTypeCombo->addItem (proxyTypeNames.value (QNetworkProxy::ProxyType (type))); ui->proxyTypeCombo->addItem (proxyTypeNames.value (QNetworkProxy::ProxyType (type)));
} }
@ -196,7 +196,7 @@ void SettingsEditor::loadSettings () {
RecognizerHelper::Subs subs = recognizerHelper_->subs (); RecognizerHelper::Subs subs = recognizerHelper_->subs ();
ui->recognizerFixTable->setRowCount (subs.size ()); ui->recognizerFixTable->setRowCount (subs.size ());
int row = 0; int row = 0;
foreach (const RecognizerHelper::Sub &sub, subs) { for (const RecognizerHelper::Sub &sub: subs) {
if (!initSubsTableRow (row, sub.language)) { if (!initSubsTableRow (row, sub.language)) {
continue; continue;
} }

View File

@ -42,7 +42,7 @@ QStringList TranslatorHelper::enabledTranslatorScripts () const {
QStringList enabled; QStringList enabled;
possibleTranslators (enabled); possibleTranslators (enabled);
QStringList scripts; QStringList scripts;
foreach (const QString &name, enabled) { for (const QString &name: enabled) {
QFile f (translatorsDir_ + QDir::separator () + name); QFile f (translatorsDir_ + QDir::separator () + name);
if (f.open (QFile::ReadOnly)) { if (f.open (QFile::ReadOnly)) {
QString script = QString::fromUtf8 (f.readAll ()); QString script = QString::fromUtf8 (f.readAll ());

View File

@ -94,7 +94,7 @@ void Updater::updateCurrentVersion () {
} }
QJsonObject updated = QJsonDocument::fromJson (f.readAll ()).object (); QJsonObject updated = QJsonDocument::fromJson (f.readAll ()).object ();
f.close (); f.close ();
foreach (const QString &component, updated.keys ()) { for (const QString &component: updated.keys ()) {
QJsonObject current = currentVersion_[component].toObject (); QJsonObject current = currentVersion_[component].toObject ();
int updatedVersion = updated[component].toInt (); int updatedVersion = updated[component].toInt ();
if (current[_built_in].toBool () || current[_version].toInt () >= updatedVersion) { if (current[_built_in].toBool () || current[_version].toInt () >= updatedVersion) {
@ -140,7 +140,7 @@ void Updater::parseAvailableVersion () {
QStringList inaccessible, incompatible; QStringList inaccessible, incompatible;
QStringList updateList; QStringList updateList;
QDir currentDir; QDir currentDir;
foreach (const QString &component, availableVersion_.keys ()) { for (const QString &component: availableVersion_.keys ()) {
QJsonObject available = availableVersion_[component].toObject (); QJsonObject available = availableVersion_[component].toObject ();
QJsonObject current = currentVersion_[component].toObject (); QJsonObject current = currentVersion_[component].toObject ();
QString path = versionField (available, _path); QString path = versionField (available, _path);
@ -190,7 +190,7 @@ void Updater::parseAvailableVersion () {
int result = QMessageBox::question (NULL, tr ("Обновление"), message, buttons); int result = QMessageBox::question (NULL, tr ("Обновление"), message, buttons);
if (result == QMessageBox::Yes) { if (result == QMessageBox::Yes) {
componentsUpdating_ = updateList.size (); componentsUpdating_ = updateList.size ();
foreach (const QString &component, updateList) { for (const QString &component: updateList) {
getComponent (component); getComponent (component);
} }
} }