From dfe1cf8a78ed9caacbae31e17f4cc8ad7d6f79f6 Mon Sep 17 00:00:00 2001 From: otakuto Date: Feb 20 2019 07:31:03 +0000 Subject: Use range-based for instead of foreach (#2433) --- diff --git a/toonz/sources/toonz/castviewer.cpp b/toonz/sources/toonz/castviewer.cpp index 14ba6d3..44ad81c 100644 --- a/toonz/sources/toonz/castviewer.cpp +++ b/toonz/sources/toonz/castviewer.cpp @@ -695,7 +695,7 @@ bool CastBrowser::drop(const QMimeData *data) { if (data->hasUrls()) { IoCmd::LoadResourceArguments args; - foreach (const QUrl &url, data->urls()) { + for (const QUrl &url : data->urls()) { TFilePath fp(url.toLocalFile().toStdWString()); args.resourceDatas.push_back(fp); } diff --git a/toonz/sources/toonz/colormodelviewer.cpp b/toonz/sources/toonz/colormodelviewer.cpp index dd6c463..9bd2029 100644 --- a/toonz/sources/toonz/colormodelviewer.cpp +++ b/toonz/sources/toonz/colormodelviewer.cpp @@ -118,7 +118,7 @@ void ColorModelViewer::dragEnterEvent(QDragEnterEvent *event) { const QMimeData *mimeData = event->mimeData(); if (!acceptResourceDrop(mimeData->urls())) return; - foreach (QUrl url, mimeData->urls()) { + for (const QUrl &url : mimeData->urls()) { TFilePath fp(url.toLocalFile().toStdWString()); std::string type = fp.getType(); if (type == "scr" || type == "tpl") return; @@ -133,7 +133,7 @@ void ColorModelViewer::dragEnterEvent(QDragEnterEvent *event) { void ColorModelViewer::dropEvent(QDropEvent *event) { const QMimeData *mimeData = event->mimeData(); if (mimeData->hasUrls()) { - foreach (QUrl url, mimeData->urls()) { + for (const QUrl &url : mimeData->urls()) { TFilePath fp(url.toLocalFile().toStdWString()); loadImage(fp); setLevel(fp); diff --git a/toonz/sources/toonz/dvdirtreeview.cpp b/toonz/sources/toonz/dvdirtreeview.cpp index 6e38772..6ea0350 100644 --- a/toonz/sources/toonz/dvdirtreeview.cpp +++ b/toonz/sources/toonz/dvdirtreeview.cpp @@ -424,7 +424,7 @@ void DvDirTreeView::dropEvent(QDropEvent *e) { if (!folderNode || !folderNode->isFolder()) return; if (!mimeData->hasUrls()) return; int count = 0; - foreach (QUrl url, mimeData->urls()) { + for (const QUrl &url : mimeData->urls()) { TFilePath srcFp(url.toLocalFile().toStdWString()); TFilePath dstFp = folderNode->getPath(); diff --git a/toonz/sources/toonz/exportpanel.cpp b/toonz/sources/toonz/exportpanel.cpp index 36a631a..b2872e4 100644 --- a/toonz/sources/toonz/exportpanel.cpp +++ b/toonz/sources/toonz/exportpanel.cpp @@ -581,7 +581,7 @@ void ClipListViewer::setDropInsertionPoint(const QPoint &pos) { void ClipListViewer::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasUrls()) { - foreach (QUrl url, event->mimeData()->urls()) { + for (const QUrl &url : event->mimeData()->urls()) { TFilePath fp(url.toLocalFile().toStdString()); if (fp.getType() != "tnz") return; } @@ -611,7 +611,7 @@ void ClipListViewer::dropEvent(QDropEvent *event) { if (event->mimeData()->hasUrls()) { int j = m_dropInsertionPoint; if (j < 0) j = getItemCount(); - foreach (QUrl url, event->mimeData()->urls()) { + for (const QUrl &url : event->mimeData()->urls()) { TFilePath fp(url.toLocalFile().toStdString()); if (fp.getType() == "tnz") getController()->insertClipPath((j++), fp); } diff --git a/toonz/sources/toonz/filebrowser.cpp b/toonz/sources/toonz/filebrowser.cpp index a9ca57c..c0a4675 100644 --- a/toonz/sources/toonz/filebrowser.cpp +++ b/toonz/sources/toonz/filebrowser.cpp @@ -1577,7 +1577,7 @@ bool FileBrowser::drop(const QMimeData *mimeData) { return true; } else if (mimeData->hasUrls()) { int count = 0; - foreach (QUrl url, mimeData->urls()) { + for (const QUrl &url : mimeData->urls()) { TFilePath srcFp(url.toLocalFile().toStdWString()); TFilePath dstFp = srcFp.withParentDir(folderPath); if (dstFp != srcFp) { diff --git a/toonz/sources/toonz/filebrowserpopup.cpp b/toonz/sources/toonz/filebrowserpopup.cpp index 35c6f11..6fa3e9e 100644 --- a/toonz/sources/toonz/filebrowserpopup.cpp +++ b/toonz/sources/toonz/filebrowserpopup.cpp @@ -391,8 +391,7 @@ void FileBrowserPopup::showEvent(QShowEvent *) { void FileBrowserPopup::setModalBrowserToParent(QWidget *widget) { if (!widget) return; - QWidget *pwidget = NULL; - foreach (pwidget, QApplication::topLevelWidgets()) { + for (QWidget *pwidget : QApplication::topLevelWidgets()) { if ((pwidget->isWindow()) && (pwidget->isModal()) && (pwidget->isVisible())) { FileBrowserPopup *popup = qobject_cast(pwidget); @@ -2122,8 +2121,7 @@ void BrowserPopupController::openPopup(QStringList filters, m_browserPopup->setFileMode(isDirectoryOnly); if (parentWidget) { - QWidget *pwidget = NULL; - foreach (pwidget, QApplication::topLevelWidgets()) { + for (QWidget *pwidget : QApplication::topLevelWidgets()) { if (pwidget->isWindow() && pwidget->isVisible() && pwidget->isAncestorOf(parentWidget)) { Qt::WindowFlags flags = m_browserPopup->windowFlags(); diff --git a/toonz/sources/toonz/flipbook.cpp b/toonz/sources/toonz/flipbook.cpp index ad55025..4bc2e62 100644 --- a/toonz/sources/toonz/flipbook.cpp +++ b/toonz/sources/toonz/flipbook.cpp @@ -1765,7 +1765,7 @@ void FlipBook::dragEnterEvent(QDragEnterEvent *e) { !mimeData->hasFormat(CastItems::getMimeFormat())) return; - foreach (QUrl url, mimeData->urls()) { + for (const QUrl &url : mimeData->urls()) { TFilePath fp(url.toLocalFile().toStdWString()); std::string type = fp.getType(); if (type == "tzp" || type == "tzu" || type == "tnz" || type == "scr" || @@ -1792,7 +1792,7 @@ void FlipBook::dragEnterEvent(QDragEnterEvent *e) { void FlipBook::dropEvent(QDropEvent *e) { const QMimeData *mimeData = e->mimeData(); if (mimeData->hasUrls()) { - foreach (QUrl url, mimeData->urls()) { + for (const QUrl &url : mimeData->urls()) { TFilePath fp(url.toLocalFile().toStdWString()); if (TFileType::getInfo(fp) != TFileType::UNKNOW_FILE) setLevel(fp); e->acceptProposedAction(); diff --git a/toonz/sources/toonz/kis_tablet_support_win8.cpp b/toonz/sources/toonz/kis_tablet_support_win8.cpp index c196885..798be5a 100644 --- a/toonz/sources/toonz/kis_tablet_support_win8.cpp +++ b/toonz/sources/toonz/kis_tablet_support_win8.cpp @@ -341,7 +341,7 @@ bool KisTabletSupportWin8::isPenDeviceAvailable() { return false; } bool hasPenDevice = false; - Q_FOREACH (const POINTER_DEVICE_INFO &device, devices) { + for (const POINTER_DEVICE_INFO &device : devices) { #ifdef KRITA dbgTablet << "Found pointer device" << static_cast(device.device) << QString::fromWCharArray(device.productString) diff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cpp index 1d10fd4..192f250 100644 --- a/toonz/sources/toonz/sceneviewerevents.cpp +++ b/toonz/sources/toonz/sceneviewerevents.cpp @@ -1531,7 +1531,7 @@ void SceneViewer::dropEvent(QDropEvent *e) { if (mimeData->hasUrls()) { IoCmd::LoadResourceArguments args; - foreach (const QUrl &url, mimeData->urls()) { + for (const QUrl &url : mimeData->urls()) { TFilePath fp(url.toLocalFile().toStdWString()); args.resourceDatas.push_back(fp); } diff --git a/toonz/sources/toonz/styleshortcutswitchablepanel.cpp b/toonz/sources/toonz/styleshortcutswitchablepanel.cpp index d680521..2ad3607 100644 --- a/toonz/sources/toonz/styleshortcutswitchablepanel.cpp +++ b/toonz/sources/toonz/styleshortcutswitchablepanel.cpp @@ -92,7 +92,7 @@ void StyleShortcutSwitchablePanel::updateTabFocus() { QList widgets = findChildren(); if (Preferences::instance()->isUseNumpadForSwitchingStylesEnabled()) { // disable tab focus - foreach (QWidget *widget, widgets) { + for (QWidget *widget : widgets) { Qt::FocusPolicy policy = widget->focusPolicy(); if (policy == Qt::TabFocus || policy == Qt::StrongFocus || policy == Qt::WheelFocus) { diff --git a/toonz/sources/toonzlib/Naa2TlvConverter.cpp b/toonz/sources/toonzlib/Naa2TlvConverter.cpp index 7e610b1..239516f 100644 --- a/toonz/sources/toonzlib/Naa2TlvConverter.cpp +++ b/toonz/sources/toonzlib/Naa2TlvConverter.cpp @@ -477,7 +477,7 @@ void Naa2TlvConverter::findMainInks() { double ap2 = 100000.0 * (double)region.pixelCount / pow((double)region.perimeter, 2); if (ap2 > 100) continue; - foreach (int c, region.links.keys()) { + for (int c : region.links.keys()) { if (c >= 0 && (m_regions[c].isBackground() || m_regions[c].type == RegionInfo::LargePaint)) { int strength = region.links[c]; @@ -567,7 +567,7 @@ void Naa2TlvConverter::findPaints() { for (int i = 0; i < m_regions.count(); i++) { RegionInfo ®ion = m_regions[i]; if (region.type != RegionInfo::Unknown) continue; - foreach (int c, m_regions[i].links.keys()) { + for (int c : m_regions[i].links.keys()) { if (c >= 0 && m_regions[c].isInk()) { m_regions[i].type = RegionInfo::Paint; break; @@ -630,7 +630,7 @@ void Naa2TlvConverter::findThinPaints() { if (inkBoundary * 100 > region.perimeter * 80) regions.append(i); } - foreach (int c, regions) + for (int c : regions) m_regions[c].type = RegionInfo::SmallPaint; } diff --git a/toonz/sources/toonzlib/scriptbinding_centerline_vectorizer.cpp b/toonz/sources/toonzlib/scriptbinding_centerline_vectorizer.cpp index 4750fbc..8ad805b 100644 --- a/toonz/sources/toonzlib/scriptbinding_centerline_vectorizer.cpp +++ b/toonz/sources/toonzlib/scriptbinding_centerline_vectorizer.cpp @@ -90,7 +90,7 @@ QScriptValue CenterlineVectorizer::vectorize(QScriptValue arg) { QScriptValue newLevel = create(engine(), new Level()); QList fids; level->getFrameIds(fids); - foreach (TFrameId fid, fids) { + for (const TFrameId &fid : fids) { TImageP srcImg = level->getImg(fid); if (srcImg && (srcImg->getType() == TImage::RASTER || srcImg->getType() == TImage::TOONZ_RASTER)) { diff --git a/toonz/sources/toonzlib/scriptbinding_level.cpp b/toonz/sources/toonzlib/scriptbinding_level.cpp index 4185bbb..20e8bab 100644 --- a/toonz/sources/toonzlib/scriptbinding_level.cpp +++ b/toonz/sources/toonzlib/scriptbinding_level.cpp @@ -342,7 +342,7 @@ QScriptValue Level::getFrameIds() { getFrameIds(fids); QScriptValue result = engine()->newArray(); quint32 index = 0; - foreach (TFrameId fid, fids) { + for (const TFrameId &fid : fids) { QString fidStr = QString::fromStdString(fid.expand()); result.setProperty(index++, fidStr); } diff --git a/toonz/sources/toonzlib/scriptbinding_outline_vectorizer.cpp b/toonz/sources/toonzlib/scriptbinding_outline_vectorizer.cpp index 9dfb454..a470b10 100644 --- a/toonz/sources/toonzlib/scriptbinding_outline_vectorizer.cpp +++ b/toonz/sources/toonzlib/scriptbinding_outline_vectorizer.cpp @@ -84,7 +84,7 @@ QScriptValue OutlineVectorizer::vectorize(QScriptValue arg) { QScriptValue newLevel = create(engine(), new Level()); QList fids; level->getFrameIds(fids); - foreach (TFrameId fid, fids) { + for (const TFrameId &fid : fids) { TImageP srcImg = level->getImg(fid); if (srcImg && (srcImg->getType() == TImage::RASTER || srcImg->getType() == TImage::TOONZ_RASTER)) { diff --git a/toonz/sources/toonzlib/scriptbinding_renderer.cpp b/toonz/sources/toonzlib/scriptbinding_renderer.cpp index db9b640..72d6eff 100644 --- a/toonz/sources/toonzlib/scriptbinding_renderer.cpp +++ b/toonz/sources/toonzlib/scriptbinding_renderer.cpp @@ -80,7 +80,7 @@ public: oldStatus.append(xsh->getColumn(i)->isPreviewVisible()); newStatus.append(false); } - foreach (int i, m_columnList) { + for (int i : m_columnList) { if (0 <= i && i < xsh->getColumnCount()) newStatus[i] = true; } for (int i = 0; i < newStatus.length(); i++) { diff --git a/toonz/sources/toonzqt/dvdialog.cpp b/toonz/sources/toonzqt/dvdialog.cpp index caead58..ca87760 100644 --- a/toonz/sources/toonzqt/dvdialog.cpp +++ b/toonz/sources/toonzqt/dvdialog.cpp @@ -344,8 +344,7 @@ void Dialog::moveEvent(QMoveEvent *e) { void Dialog::resizeEvent(QResizeEvent *e) { if (Preferences::instance()->getCurrentLanguage() != "English") { QSize t = this->size(); - QLabel *s; - foreach (s, m_labelList) + for (QLabel *s : m_labelList) s->setFixedWidth(t.width() * .35); } diff --git a/toonz/sources/toonzqt/dvtextedit.cpp b/toonz/sources/toonzqt/dvtextedit.cpp index 14d8c0e..59d6a30 100644 --- a/toonz/sources/toonzqt/dvtextedit.cpp +++ b/toonz/sources/toonzqt/dvtextedit.cpp @@ -208,7 +208,7 @@ void DvTextEdit::createMiniToolBar() { m_sizeComboBox->setMinimumWidth(44); QFontDatabase db; - foreach (int size, db.standardSizes()) + for (int size : db.standardSizes()) m_sizeComboBox->addItem(QString::number(size)); connect(m_sizeComboBox, SIGNAL(activated(const QString &)), this, diff --git a/toonz/sources/toonzqt/gutil.cpp b/toonz/sources/toonzqt/gutil.cpp index 8c5e4c9..6e32a86 100644 --- a/toonz/sources/toonzqt/gutil.cpp +++ b/toonz/sources/toonzqt/gutil.cpp @@ -387,7 +387,7 @@ bool isResourceOrFolder(const QUrl &url) { bool acceptResourceDrop(const QList &urls) { int count = 0; - foreach (const QUrl &url, urls) { + for (const QUrl &url : urls) { if (isResource(url)) ++count; else @@ -401,7 +401,7 @@ bool acceptResourceDrop(const QList &urls) { bool acceptResourceOrFolderDrop(const QList &urls) { int count = 0; - foreach (const QUrl &url, urls) { + for (const QUrl &url : urls) { if (isResourceOrFolder(url)) ++count; else diff --git a/toonz/sources/toonzqt/paramfield.cpp b/toonz/sources/toonzqt/paramfield.cpp index 3c1f114..1b746fb 100644 --- a/toonz/sources/toonzqt/paramfield.cpp +++ b/toonz/sources/toonzqt/paramfield.cpp @@ -1578,8 +1578,7 @@ void FontParamField::findStyles(const QFont &font) { QString currentItem = m_styleCombo->currentText(); m_styleCombo->clear(); - QString style; - foreach (style, fontDatabase.styles(font.family())) + for (const QString &style : fontDatabase.styles(font.family())) m_styleCombo->addItem(style); int styleIndex = m_styleCombo->findText(currentItem);