From 9f8402697be18724f42255c16af4fdc2565d99f1 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Sat, 18 Apr 2015 14:41:06 +0000 Subject: [PATCH] Use C++11 range-based `for` loops (Qt client) --- qt/app.cc | 16 ++++---- qt/column-resizer.cc | 6 +-- qt/details.cc | 93 ++++++++++++++++++++++---------------------- qt/favicon.cc | 4 +- qt/file-tree.cc | 18 ++++----- qt/filterbar.cc | 12 +++--- qt/mainwin.cc | 18 ++++----- qt/make-dialog.cc | 8 ++-- qt/options.cc | 10 ++--- qt/prefs-dialog.cc | 14 +++---- qt/relocate.cc | 2 +- qt/rpc-client.cc | 4 +- qt/session-dialog.cc | 4 +- qt/session.cc | 8 ++-- qt/torrent-filter.cc | 2 +- qt/torrent-model.cc | 14 +++---- qt/torrent.cc | 6 +-- qt/tracker-model.cc | 4 +- qt/utils.cc | 24 ++++++------ qt/utils.h | 2 +- qt/watchdir.cc | 6 +-- 21 files changed, 137 insertions(+), 138 deletions(-) diff --git a/qt/app.cc b/qt/app.cc index 405d2bb68..7372aa60d 100644 --- a/qt/app.cc +++ b/qt/app.cc @@ -77,7 +77,7 @@ namespace const QStringList& searchDirectories) { const QString filename = name + QLatin1Char ('_') + localeName; - foreach (const QString& directory, searchDirectories) + for (const QString& directory: searchDirectories) { if (translator.load (filename, directory)) return true; @@ -134,7 +134,7 @@ MyApp::MyApp (int& argc, char ** argv): { QList sizes; sizes << 16 << 22 << 24 << 32 << 48 << 64 << 72 << 96 << 128 << 192 << 256; - foreach (int size, sizes) + for (const int size: sizes) icon.addPixmap (QPixmap (QString::fromLatin1 (":/icons/transmission-%1.png").arg (size))); } setWindowIcon (icon); @@ -180,14 +180,14 @@ MyApp::MyApp (int& argc, char ** argv): if (bus.isConnected ()) { bool delegated = false; - for (int i=0, n=filenames.size (); i arguments; - AddData a (filenames[i]); + AddData a (filename); switch (a.type) { case AddData::URL: arguments.push_back (a.url.toString ()); break; @@ -267,7 +267,7 @@ MyApp::MyApp (int& argc, char ** argv): // init from preferences QList initKeys; initKeys << Prefs::DIR_WATCH; - foreach (int key, initKeys) + for (const int key: initKeys) refreshPref (key); connect (myPrefs, SIGNAL (changed (int)), this, SLOT (refreshPref (const int))); @@ -318,8 +318,8 @@ MyApp::MyApp (int& argc, char ** argv): dialog->show (); } - for (QStringList::const_iterator it=filenames.begin (), end=filenames.end (); it!=end; ++it) - addTorrent (*it); + for (const QString& filename: filenames) + addTorrent (filename); // register as the dbus handler for Transmission if (bus.isConnected ()) @@ -346,7 +346,7 @@ MyApp::onTorrentsAdded (const QSet& torrents) if (!myPrefs->getBool (Prefs::SHOW_NOTIFICATION_ON_ADD)) return; - foreach (int id, torrents) + for (const int id: torrents) { Torrent * tor = myModel->getTorrentFromId (id); diff --git a/qt/column-resizer.cc b/qt/column-resizer.cc index b227a4b8b..0661615e5 100644 --- a/qt/column-resizer.cc +++ b/qt/column-resizer.cc @@ -16,7 +16,7 @@ namespace { int - itemColumnSpan (QGridLayout * layout, const QLayoutItem * item) + itemColumnSpan (const QGridLayout * layout, const QLayoutItem * item) { for (int i = 0, count = layout->count (); i < count; ++i) { @@ -60,7 +60,7 @@ void ColumnResizer::update () { int maxWidth = 0; - foreach (QGridLayout * layout, myLayouts) + for (const QGridLayout * const layout: myLayouts) { for (int i = 0, count = layout->rowCount (); i < count; ++i) { @@ -71,7 +71,7 @@ ColumnResizer::update () } } - foreach (QGridLayout * layout, myLayouts) + for (QGridLayout * const layout: myLayouts) layout->setColumnMinimumWidth (0, maxWidth); } diff --git a/qt/details.cc b/qt/details.cc index 979df6f41..cd30f2ee4 100644 --- a/qt/details.cc +++ b/qt/details.cc @@ -198,7 +198,7 @@ Details::Details (Session & session, QList initKeys; initKeys << Prefs::SHOW_TRACKER_SCRAPES << Prefs::SHOW_BACKUP_TRACKERS; - foreach (int key, initKeys) + for (const int key: initKeys) refreshPref (key); connect (&myTimer, SIGNAL (timeout ()), this, SLOT (onTimer ())); @@ -225,7 +225,7 @@ Details::setIds (const QSet& ids) myChangedTorrents = true; // stop listening to the old torrents - foreach (int id, myIds) + for (const int id: myIds) { const Torrent * tor = myModel.getTorrentFromId (id); if (tor) @@ -237,7 +237,7 @@ Details::setIds (const QSet& ids) myTrackerModel->refresh (myModel, myIds); // listen to the new torrents - foreach (int id, myIds) + for (const int id: myIds) { const Torrent * tor = myModel.getTorrentFromId (id); if (tor) @@ -305,7 +305,7 @@ Details::getNewData () if (!myIds.empty ()) { QSet infos; - foreach (int id, myIds) + for (const int id: myIds) { const Torrent * tor = myModel.getTorrentFromId (id); if (tor->isMagnet ()) @@ -375,7 +375,7 @@ Details::refresh () const QString unknown = tr ("Unknown"); // build a list of torrents - foreach (int id, myIds) + for (const int id: myIds) { const Torrent * tor = myModel.getTorrentFromId (id); if (tor) @@ -397,7 +397,7 @@ Details::refresh () bool allPaused = true; bool allFinished = true; const tr_torrent_activity baseline = torrents[0]->getActivity (); - foreach (const Torrent * t, torrents) + for (const Torrent * const t: torrents) { const tr_torrent_activity activity = t->getActivity (); if (activity != baseline) @@ -435,7 +435,7 @@ Details::refresh () int64_t haveUnverified = 0; int64_t verifiedPieces = 0; - foreach (const Torrent * t, torrents) + for (const Torrent * const t: torrents) { if (t->hasMetadata ()) { @@ -506,7 +506,7 @@ Details::refresh () { uint64_t d = 0; uint64_t f = 0; - foreach (const Torrent * t, torrents) + for (const Torrent * const t: torrents) { d += t->downloadedEver (); f += t->failedEver (); @@ -529,7 +529,7 @@ Details::refresh () { uint64_t u = 0; uint64_t d = 0; - foreach (const Torrent * t, torrents) + for (const Torrent * const t: torrents) { u += t->uploadedEver (); d += t->downloadedEver (); @@ -551,7 +551,7 @@ Details::refresh () { bool allPaused = true; QDateTime baseline = torrents[0]->lastStarted (); - foreach (const Torrent * t, torrents) + for (const Torrent * const t: torrents) { if (baseline != t->lastStarted ()) baseline = QDateTime (); @@ -578,7 +578,7 @@ Details::refresh () else { int baseline = torrents[0]->getETA (); - foreach (const Torrent * t, torrents) + for (const Torrent * const t: torrents) { if (baseline != t->getETA ()) { @@ -606,7 +606,7 @@ Details::refresh () else { QDateTime latest = torrents[0]->lastActivity (); - foreach (const Torrent * t, torrents) + for (const Torrent * const t: torrents) { const QDateTime dt = t->lastActivity (); if (latest < dt) @@ -631,7 +631,7 @@ Details::refresh () else { string = torrents[0]->getError (); - foreach (const Torrent * t, torrents) + for (const Torrent * const t: torrents) { if (string != t->getError ()) { @@ -659,7 +659,7 @@ Details::refresh () int pieces = 0; uint64_t size = 0; uint32_t pieceSize = torrents[0]->pieceSize (); - foreach (const Torrent * t, torrents) + for (const Torrent * const t: torrents) { pieces += t->pieceCount (); size += t->totalSize (); @@ -684,7 +684,7 @@ Details::refresh () if (!torrents.empty ()) { string = torrents[0]->hashString (); - foreach (const Torrent * t, torrents) + for (const Torrent * const t: torrents) { if (string != t->hashString ()) { @@ -702,7 +702,7 @@ Details::refresh () bool b = torrents[0]->isPrivate (); string = b ? tr ("Private to this tracker -- DHT and PEX disabled") : tr ("Public torrent"); - foreach (const Torrent * t, torrents) + for (const Torrent * const t: torrents) { if (b != t->isPrivate ()) { @@ -719,7 +719,7 @@ Details::refresh () if (!torrents.empty ()) { string = torrents[0]->comment (); - foreach (const Torrent * t, torrents) + for (const Torrent * const t: torrents) { if (string != t->comment ()) { @@ -742,7 +742,7 @@ Details::refresh () bool mixed_creator=false, mixed_date=false; const QString creator = torrents[0]->creator (); const QString date = torrents[0]->dateCreated ().toString (); - foreach (const Torrent * t, torrents) + for (const Torrent * const t: torrents) { mixed_creator |= (creator != t->creator ()); mixed_date |= (date != t->dateCreated ().toString ()); @@ -766,7 +766,7 @@ Details::refresh () if (!torrents.empty ()) { string = torrents[0]->getPath (); - foreach (const Torrent * t, torrents) + for (const Torrent * const t: torrents) { if (string != t->getPath ()) { @@ -788,65 +788,64 @@ Details::refresh () bool uniform; bool baselineFlag; int baselineInt; - const Torrent * tor; - const Torrent * baseline = *torrents.begin (); + const Torrent& baseline = *torrents.front (); // mySessionLimitCheck uniform = true; - baselineFlag = baseline->honorsSessionLimits (); - foreach (tor, torrents) if (baselineFlag != tor->honorsSessionLimits ()) { uniform = false; break; } + baselineFlag = baseline.honorsSessionLimits (); + for (const Torrent * const tor: torrents) if (baselineFlag != tor->honorsSessionLimits ()) { uniform = false; break; } ui.sessionLimitCheck->setChecked (uniform && baselineFlag); // mySingleDownCheck uniform = true; - baselineFlag = baseline->downloadIsLimited (); - foreach (tor, torrents) if (baselineFlag != tor->downloadIsLimited ()) { uniform = false; break; } + baselineFlag = baseline.downloadIsLimited (); + for (const Torrent * const tor: torrents) if (baselineFlag != tor->downloadIsLimited ()) { uniform = false; break; } ui.singleDownCheck->setChecked (uniform && baselineFlag); // mySingleUpCheck uniform = true; - baselineFlag = baseline->uploadIsLimited (); - foreach (tor, torrents) if (baselineFlag != tor->uploadIsLimited ()) { uniform = false; break; } + baselineFlag = baseline.uploadIsLimited (); + for (const Torrent * const tor: torrents) if (baselineFlag != tor->uploadIsLimited ()) { uniform = false; break; } ui.singleUpCheck->setChecked (uniform && baselineFlag); // myBandwidthPriorityCombo uniform = true; - baselineInt = baseline->getBandwidthPriority (); - foreach (tor, torrents) if (baselineInt != tor->getBandwidthPriority ()) { uniform = false; break; } + baselineInt = baseline.getBandwidthPriority (); + for (const Torrent * const tor: torrents) if (baselineInt != tor->getBandwidthPriority ()) { uniform = false; break; } if (uniform) i = ui.bandwidthPriorityCombo->findData (baselineInt); else i = -1; setIfIdle (ui.bandwidthPriorityCombo, i); - setIfIdle (ui.singleDownSpin, int (tor->downloadLimit ().KBps ())); - setIfIdle (ui.singleUpSpin, int (tor->uploadLimit ().KBps ())); - setIfIdle (ui.peerLimitSpin, tor->peerLimit ()); + setIfIdle (ui.singleDownSpin, int (baseline.downloadLimit ().KBps ())); + setIfIdle (ui.singleUpSpin, int (baseline.uploadLimit ().KBps ())); + setIfIdle (ui.peerLimitSpin, baseline.peerLimit ()); } if (!torrents.empty ()) { - const Torrent * tor; + const Torrent& baseline = *torrents.front (); // ratio bool uniform = true; - int baselineInt = torrents[0]->seedRatioMode (); - foreach (tor, torrents) if (baselineInt != tor->seedRatioMode ()) { uniform = false; break; } + int baselineInt = baseline.seedRatioMode (); + for (const Torrent * const tor: torrents) if (baselineInt != tor->seedRatioMode ()) { uniform = false; break; } setIfIdle (ui.ratioCombo, uniform ? ui.ratioCombo->findData (baselineInt) : -1); ui.ratioSpin->setVisible (uniform && (baselineInt == TR_RATIOLIMIT_SINGLE)); - setIfIdle (ui.ratioSpin, tor->seedRatioLimit ()); + setIfIdle (ui.ratioSpin, baseline.seedRatioLimit ()); // idle uniform = true; - baselineInt = torrents[0]->seedIdleMode (); - foreach (tor, torrents) if (baselineInt != tor->seedIdleMode ()) { uniform = false; break; } + baselineInt = baseline.seedIdleMode (); + for (const Torrent * const tor: torrents) if (baselineInt != tor->seedIdleMode ()) { uniform = false; break; } setIfIdle (ui.idleCombo, uniform ? ui.idleCombo->findData (baselineInt) : -1); ui.idleSpin->setVisible (uniform && (baselineInt == TR_RATIOLIMIT_SINGLE)); - setIfIdle (ui.idleSpin, tor->seedIdleLimit ()); + setIfIdle (ui.idleSpin, baseline.seedIdleLimit ()); onIdleLimitChanged (); } @@ -862,12 +861,12 @@ Details::refresh () QMap peers2; QList newItems; - foreach (const Torrent * t, torrents) + for (const Torrent * const t: torrents) { const QString idStr (QString::number (t->id ())); PeerList peers = t->peers (); - foreach (const Peer& peer, peers) + for (const Peer& peer: peers) { const QString key = idStr + QLatin1Char (':') + peer.address; PeerItem * item = static_cast (myPeers.value (key, 0)); @@ -892,7 +891,7 @@ Details::refresh () item->refresh (peer); QString codeTip; - foreach (QChar ch, code) + for (const QChar ch: code) { QString txt; switch (ch.unicode ()) @@ -929,7 +928,7 @@ Details::refresh () } ui.peersView->addTopLevelItems (newItems); - foreach (QString key, myPeers.keys ()) + for (const QString& key: myPeers.keys ()) { if (!peers2.contains (key)) // old peer has disconnected { @@ -1078,7 +1077,7 @@ Details::onAddTrackerClicked () { QSet ids; - foreach (int id, myIds) + for (const int id: myIds) if (myTrackerModel->find (id,url) == -1) ids.insert (id); @@ -1139,14 +1138,14 @@ Details::onRemoveTrackerClicked () QItemSelectionModel * selectionModel = ui.trackersView->selectionModel (); QModelIndexList selectedRows = selectionModel->selectedRows (); QMap torrentId_to_trackerIds; - foreach (QModelIndex i, selectedRows) + for (const QModelIndex& i: selectedRows) { const TrackerInfo inf = ui.trackersView->model ()->data (i, TrackerModel::TrackerRole).value (); torrentId_to_trackerIds.insertMulti (inf.torrentId, inf.st.id); } // batch all of a tracker's torrents into one command - foreach (int id, torrentId_to_trackerIds.uniqueKeys ()) + for (const int id: torrentId_to_trackerIds.uniqueKeys ()) { QSet ids; ids << id; @@ -1315,7 +1314,7 @@ Details::onOpenRequested (const QString& path) if (!mySession.isLocal ()) return; - foreach (const int id, myIds) + for (const int id: myIds) { const Torrent * const tor = myModel.getTorrentFromId (id); if (tor == NULL) diff --git a/qt/favicon.cc b/qt/favicon.cc index ff4fbc79c..30a3771b2 100644 --- a/qt/favicon.cc +++ b/qt/favicon.cc @@ -65,7 +65,7 @@ Favicons::ensureCacheDirHasBeenScanned () cacheDir.mkpath (cacheDir.absolutePath ()); QStringList files = cacheDir.entryList (QDir::Files|QDir::Readable); - foreach (QString file, files) + for (const QString& file: files) { QPixmap pixmap; pixmap.load (cacheDir.absoluteFilePath (file)); @@ -126,7 +126,7 @@ Favicons::add (const QUrl& url) const QString path = QLatin1String ("http://") + host + QLatin1String ("/favicon."); QStringList suffixes; suffixes << QLatin1String ("ico") << QLatin1String ("png") << QLatin1String ("gif") << QLatin1String ("jpg"); - foreach (QString suffix, suffixes) + for (const QString& suffix: suffixes) myNAM->get (QNetworkRequest (path + suffix)); } } diff --git a/qt/file-tree.cc b/qt/file-tree.cc index 49d934e87..74d93ccfe 100644 --- a/qt/file-tree.cc +++ b/qt/file-tree.cc @@ -175,7 +175,7 @@ FileTreeItem::getSubtreeWantedSize (uint64_t& have, uint64_t& total) const total += myTotalSize; } - foreach(const FileTreeItem * i, myChildren) + for (const FileTreeItem * const i: myChildren) i->getSubtreeWantedSize(have, total); } @@ -302,7 +302,7 @@ FileTreeItem::priority () const } } - foreach (const FileTreeItem * child, myChildren) + for (const FileTreeItem * const child: myChildren) i |= child->priority(); return i; @@ -319,7 +319,7 @@ FileTreeItem::setSubtreePriority (int i, QSet& ids) ids.insert (myFileIndex); } - foreach (FileTreeItem * child, myChildren) + for (FileTreeItem * const child: myChildren) child->setSubtreePriority (i, ids); } @@ -345,7 +345,7 @@ FileTreeItem::isSubtreeWanted () const return myIsWanted ? Qt::Checked : Qt::Unchecked; int wanted(-1); - foreach (const FileTreeItem * child, myChildren) + for (const FileTreeItem * const child: myChildren) { const int childWanted = child->isSubtreeWanted(); @@ -373,7 +373,7 @@ FileTreeItem::setSubtreeWanted (bool b, QSet& ids) ids.insert(myFileIndex); } - foreach (FileTreeItem * child, myChildren) + for (FileTreeItem * const child: myChildren) child->setSubtreeWanted (b, ids); } @@ -985,13 +985,13 @@ FileTreeView::eventFilter (QObject * o, QEvent * event) switch (static_cast (event)->key ()) { case Qt::Key_Space: - foreach (const QModelIndex& i, selectionModel ()->selectedRows (COL_WANTED)) + for (const QModelIndex& i: selectionModel ()->selectedRows (COL_WANTED)) clicked (i); break; case Qt::Key_Enter: case Qt::Key_Return: - foreach (const QModelIndex& i, selectionModel ()->selectedRows (COL_PRIORITY)) + for (const QModelIndex& i: selectionModel ()->selectedRows (COL_PRIORITY)) clicked (i); break; } @@ -1003,11 +1003,11 @@ FileTreeView::eventFilter (QObject * o, QEvent * event) void FileTreeView::update (const FileList& files, bool updateFields) { - foreach (const TrFile file, files) + for (const TrFile& file: files) { QList added; myModel.addFile (file.index, file.filename, file.wanted, file.priority, file.size, file.have, added, updateFields); - foreach (QModelIndex i, added) + for (const QModelIndex& i: added) expand (myProxy->mapFromSource(i)); } } diff --git a/qt/filterbar.cc b/qt/filterbar.cc index 7f8139d0b..b73b25828 100644 --- a/qt/filterbar.cc +++ b/qt/filterbar.cc @@ -442,12 +442,12 @@ FilterBar::refreshTrackers () break; const Torrent * tor = index.data (TorrentModel::TorrentRole).value (); QSet torrentNames; - foreach (QString host, tor->hosts ()) + for (const QString& host: tor->hosts ()) { newHosts.insert (host); torrentNames.insert (readableHostName (host)); } - foreach (QString name, torrentNames) + for (const QString& name: torrentNames) ++torrentsPerHost[name]; } @@ -456,7 +456,7 @@ FilterBar::refreshTrackers () myTrackerModel->setData (myTrackerModel->index (0,0), getCountString (myTorrents.rowCount ()), TorrentCountStringRole); // rows to update - foreach (QString host, oldHosts & newHosts) + for (const QString& host: oldHosts & newHosts) { const QString name = readableHostName (host); QStandardItem * row = myTrackerModel->findItems (name).front (); @@ -467,7 +467,7 @@ FilterBar::refreshTrackers () } // rows to remove - foreach (QString host, oldHosts - newHosts) + for (const QString& host: oldHosts - newHosts) { const QString name = readableHostName (host); QStandardItem * item = myTrackerModel->findItems (name).front (); @@ -477,7 +477,7 @@ FilterBar::refreshTrackers () // rows to add bool anyAdded = false; - foreach (QString host, newHosts - oldHosts) + for (const QString& host: newHosts - oldHosts) { const QString name = readableHostName (host); @@ -583,7 +583,7 @@ FilterBar::FilterBar (Prefs& prefs, const TorrentModel& torrents, const TorrentF QList initKeys; initKeys << Prefs::FILTER_MODE << Prefs::FILTER_TRACKERS; - foreach (int key, initKeys) + for (const int key: initKeys) refreshPref (key); } diff --git a/qt/mainwin.cc b/qt/mainwin.cc index dff87748d..1ee503c2e 100644 --- a/qt/mainwin.cc +++ b/qt/mainwin.cc @@ -260,7 +260,7 @@ TrMainWindow::TrMainWindow (Session& session, Prefs& prefs, TorrentModel& model, << Prefs::USPEED_ENABLED << Prefs::RATIO << Prefs::RATIO_ENABLED; - foreach (int key, initKeys) + for (const int key: initKeys) refreshPref (key); connect (&mySession, SIGNAL (sourceChanged ()), this, SLOT (onSessionSourceChanged ())); @@ -381,7 +381,7 @@ TrMainWindow::createOptionsMenu () g->addAction (a); connect (a, SIGNAL (triggered (bool)), this, SLOT (onSetPrefs (bool))); sub->addSeparator (); - foreach (int i, stockSpeeds) + for (const int i: stockSpeeds) { a = sub->addAction (Formatter::speedToString (Speed::fromKBps (i))); a->setProperty (PREF_VARIANTS_KEY, QVariantList () << Prefs::DSPEED << i << Prefs::DSPEED_ENABLED << true); @@ -403,7 +403,7 @@ TrMainWindow::createOptionsMenu () g->addAction (a); connect (a, SIGNAL (triggered (bool)), this, SLOT (onSetPrefs (bool))); sub->addSeparator (); - foreach (int i, stockSpeeds) + for (const int i: stockSpeeds) { a = sub->addAction (Formatter::speedToString (Speed::fromKBps (i))); a->setProperty (PREF_VARIANTS_KEY, QVariantList () << Prefs::USPEED << i << Prefs::USPEED_ENABLED << true); @@ -426,7 +426,7 @@ TrMainWindow::createOptionsMenu () g->addAction (a); connect (a, SIGNAL (triggered (bool)), this, SLOT (onSetPrefs (bool))); sub->addSeparator (); - foreach (double i, stockRatios) + for (const double i: stockRatios) { a = sub->addAction (Formatter::ratioToString (i)); a->setProperty (PREF_VARIANTS_KEY, QVariantList () << Prefs::RATIO << i << Prefs::RATIO_ENABLED << true); @@ -811,7 +811,7 @@ TrMainWindow::getSelectedTorrents () const { QSet ids; - foreach (QModelIndex index, ui.listView->selectionModel ()->selectedRows ()) + for (const QModelIndex& index: ui.listView->selectionModel ()->selectedRows ()) { const Torrent * tor (index.data (TorrentModel::TorrentRole).value ()); ids.insert (tor->id ()); @@ -1164,7 +1164,7 @@ TrMainWindow::addTorrents (const QStringList& filenames) showOptions = b->isChecked (); } - foreach (const QString& filename, filenames) + for (const QString& filename: filenames) addTorrent (filename, showOptions); } @@ -1194,7 +1194,7 @@ TrMainWindow::removeTorrents (const bool deleteFiles) int connected = 0; int count; - foreach (QModelIndex index, ui.listView->selectionModel ()->selectedRows ()) + for (const QModelIndex& index: ui.listView->selectionModel ()->selectedRows ()) { const Torrent * tor (index.data (TorrentModel::TorrentRole).value ()); ids.insert (tor->id ()); @@ -1408,11 +1408,11 @@ TrMainWindow::dropEvent (QDropEvent * event) } else if (event->mimeData()->hasUrls()) { - foreach (QUrl url, event->mimeData()->urls()) + for (const QUrl& url: event->mimeData()->urls()) list.append(url.toLocalFile()); } - foreach (QString entry, list) + for (const QString& entry: list) { QString key = entry.trimmed(); diff --git a/qt/make-dialog.cc b/qt/make-dialog.cc index 22f766c7c..ca3765614 100644 --- a/qt/make-dialog.cc +++ b/qt/make-dialog.cc @@ -132,17 +132,17 @@ MakeDialog::makeTorrent () // get the tiers int tier = 0; QVector trackers; - foreach (QString line, ui.trackersEdit->toPlainText ().split (QLatin1Char ('\n'))) + for (const QString& line: ui.trackersEdit->toPlainText ().split (QLatin1Char ('\n'))) { - line = line.trimmed (); - if (line.isEmpty ()) + const QString announceUrl = line.trimmed (); + if (announceUrl.isEmpty ()) { ++tier; } else { tr_tracker_info tmp; - tmp.announce = tr_strdup (line.toUtf8 ().constData ()); + tmp.announce = tr_strdup (announceUrl.toUtf8 ().constData ()); tmp.tier = tier; trackers.append (tmp); } diff --git a/qt/options.cc b/qt/options.cc index 314b9a57e..619c057ab 100644 --- a/qt/options.cc +++ b/qt/options.cc @@ -214,14 +214,14 @@ OptionsDialog::reload () void OptionsDialog::onPriorityChanged (const QSet& fileIndices, int priority) { - foreach (int i, fileIndices) + for (const int i: fileIndices) myPriorities[i] = priority; } void OptionsDialog::onWantedChanged (const QSet& fileIndices, bool isWanted) { - foreach (int i, fileIndices) + for (const int i: fileIndices) myWanted[i] = isWanted; } @@ -334,8 +334,8 @@ OptionsDialog::clearVerify () myVerifyPiecePos = 0; myVerifyTimer.stop (); - for (int i = 0, n = myFiles.size (); i < n; ++i) - myFiles[i].have = 0; + for (TrFile& f: myFiles) + f.have = 0; ui.filesView->update (myFiles); } @@ -432,7 +432,7 @@ OptionsDialog::onTimeout () if (done) { uint64_t have = 0; - foreach (const TrFile& f, myFiles) + for (const TrFile& f: myFiles) have += f.have; if (!have) // everything failed diff --git a/qt/prefs-dialog.cc b/qt/prefs-dialog.cc index 9c5baee0f..2a7f3f122 100644 --- a/qt/prefs-dialog.cc +++ b/qt/prefs-dialog.cc @@ -560,14 +560,14 @@ PrefsDialog::PrefsDialog (Session& session, Prefs& prefs, QWidget * parent): << Prefs::INCOMPLETE_DIR << Prefs::INCOMPLETE_DIR_ENABLED << Prefs::SCRIPT_TORRENT_DONE_FILENAME; - foreach (int key, keys) + for (const int key: keys) refreshPref (key); // if it's a remote session, disable the preferences // that don't work in remote sessions if (!myIsServer) { - foreach (QWidget * w, myUnsupportedWhenRemote) + for (QWidget * const w: myUnsupportedWhenRemote) { w->setToolTip (tr ("Not supported by remote sessions")); w->setEnabled (false); @@ -617,11 +617,11 @@ PrefsDialog::refreshPref (int key) const bool enabled (myPrefs.getBool (Prefs::RPC_ENABLED)); const bool whitelist (myPrefs.getBool (Prefs::RPC_WHITELIST_ENABLED)); const bool auth (myPrefs.getBool (Prefs::RPC_AUTH_REQUIRED)); - foreach (QWidget * w, myWebWhitelistWidgets) + for (QWidget * const w: myWebWhitelistWidgets) w->setEnabled (enabled && whitelist); - foreach (QWidget * w, myWebAuthWidgets) + for (QWidget * const w: myWebAuthWidgets) w->setEnabled (enabled && auth); - foreach (QWidget * w, myWebWidgets) + for (QWidget * const w: myWebWidgets) w->setEnabled (enabled); break; } @@ -629,7 +629,7 @@ PrefsDialog::refreshPref (int key) case Prefs::ALT_SPEED_LIMIT_TIME_ENABLED: { const bool enabled = myPrefs.getBool (key); - foreach (QWidget * w, mySchedWidgets) + for (QWidget * const w: mySchedWidgets) w->setEnabled (enabled); break; } @@ -637,7 +637,7 @@ PrefsDialog::refreshPref (int key) case Prefs::BLOCKLIST_ENABLED: { const bool enabled = myPrefs.getBool (key); - foreach (QWidget * w, myBlockWidgets) + for (QWidget * const w: myBlockWidgets) w->setEnabled (enabled); break; } diff --git a/qt/relocate.cc b/qt/relocate.cc index fd5ab75d7..c91d8e39a 100644 --- a/qt/relocate.cc +++ b/qt/relocate.cc @@ -40,7 +40,7 @@ RelocateDialog::RelocateDialog (Session & session, ui.setupUi (this); QString path; - foreach (int id, myIds) + for (const int id: myIds) { const Torrent * tor = model.getTorrentFromId (id); diff --git a/qt/rpc-client.cc b/qt/rpc-client.cc index c28800e1a..180078843 100644 --- a/qt/rpc-client.cc +++ b/qt/rpc-client.cc @@ -137,7 +137,7 @@ RpcClient::sendRequest (const QByteArray& json) #ifdef DEBUG_HTTP std::cerr << "sending " << "POST " << qPrintable (myUrl.path ()) << std::endl; - foreach (const QByteArray& b, request.rawHeaderList ()) + for (const QByteArray& b: request.rawHeaderList ()) std::cerr << b.constData () << ": " << request.rawHeader (b).constData () @@ -182,7 +182,7 @@ RpcClient::onFinished (QNetworkReply * reply) { #ifdef DEBUG_HTTP std::cerr << "http response header: " << std::endl; - foreach (const QByteArray& b, reply->rawHeaderList ()) + for (const QByteArray& b: reply->rawHeaderList ()) std::cerr << b.constData () << ": " << reply->rawHeader (b).constData () diff --git a/qt/session-dialog.cc b/qt/session-dialog.cc index 214fe9621..308d738c7 100644 --- a/qt/session-dialog.cc +++ b/qt/session-dialog.cc @@ -34,10 +34,10 @@ SessionDialog::resensitize () const bool isRemote = ui.remoteSessionRadio->isChecked (); const bool useAuth = ui.authCheck->isChecked (); - foreach (QWidget * w, myRemoteWidgets) + for (QWidget * const w: myRemoteWidgets) w->setEnabled (isRemote); - foreach (QWidget * w, myAuthWidgets) + for (QWidget * const w: myAuthWidgets) w->setEnabled (isRemote && useAuth); } diff --git a/qt/session.cc b/qt/session.cc index 863a141f8..440c89e9e 100644 --- a/qt/session.cc +++ b/qt/session.cc @@ -66,7 +66,7 @@ namespace addList (tr_variant * list, const KeyList& keys) { tr_variantListReserve (list, keys.size ()); - foreach (tr_quark key, keys) + for (const tr_quark key: keys) tr_variantListAddQuark (list, key); } } @@ -390,7 +390,7 @@ namespace if (!ids.isEmpty ()) { tr_variant * idList (tr_variantDictAddList (args, TR_KEY_ids, ids.size ())); - foreach (int i, ids) + for (const int i: ids) tr_variantListAddInt (idList, i); } } @@ -436,7 +436,7 @@ Session::torrentSet (const QSet& ids, const tr_quark key, const QStringList tr_variantInitDict (&args, 2); addOptionalIds (&args, ids); tr_variant * list (tr_variantDictAddList (&args, key, value.size ())); - foreach (const QString& str, value) + for (const QString& str: value) tr_variantListAddStr (list, str.toUtf8 ().constData ()); exec(TR_KEY_torrent_set, &args); @@ -449,7 +449,7 @@ Session::torrentSet (const QSet& ids, const tr_quark key, const QList& tr_variantInitDict (&args, 2); addOptionalIds (&args, ids); tr_variant * list (tr_variantDictAddList (&args, key, value.size ())); - foreach (int i, value) + for (const int i: value) tr_variantListAddInt (list, i); exec (TR_KEY_torrent_set, &args); diff --git a/qt/torrent-filter.cc b/qt/torrent-filter.cc index 1d4ce8854..6d50fc74d 100644 --- a/qt/torrent-filter.cc +++ b/qt/torrent-filter.cc @@ -32,7 +32,7 @@ TorrentFilter::TorrentFilter (const Prefs& prefs): << Prefs::FILTER_MODE << Prefs::FILTER_TRACKERS << Prefs::FILTER_TEXT; - foreach (int key, initKeys) + for (const int key: initKeys) refreshPref (key); } diff --git a/qt/torrent-model.cc b/qt/torrent-model.cc index cff5be086..1f5f9a931 100644 --- a/qt/torrent-model.cc +++ b/qt/torrent-model.cc @@ -23,7 +23,7 @@ TorrentModel::clear () myIdToRow.clear (); myIdToTorrent.clear (); - foreach (Torrent * tor, myTorrents) delete tor; + qDeleteAll (myTorrents); myTorrents.clear (); endResetModel (); @@ -189,7 +189,7 @@ TorrentModel::updateTorrents (tr_variant * torrents, bool isCompleteList) beginInsertRows (QModelIndex(), oldCount, newCount - 1); - foreach (Torrent * tor, newTorrents) + for (Torrent * const tor: newTorrents) { addTorrent (tor); addIds.insert (tor->id ()); @@ -205,7 +205,7 @@ TorrentModel::updateTorrents (tr_variant * torrents, bool isCompleteList) { QSet removedIds (oldIds); removedIds -= newIds; - foreach (int id, removedIds) + for (const int id: removedIds) removeTorrent (id); } } @@ -220,7 +220,7 @@ TorrentModel::removeTorrent (int id) beginRemoveRows (QModelIndex(), row, row); // make the myIdToRow map consistent with list view/model - for (QMap::iterator i = myIdToRow.begin(); i != myIdToRow.end(); ++i) + for (auto i = myIdToRow.begin(); i != myIdToRow.end(); ++i) if (i.value() > row) --i.value(); myIdToRow.remove (id); @@ -241,7 +241,7 @@ TorrentModel::getTransferSpeed (Speed & uploadSpeed, Speed upSpeed, downSpeed; size_t upCount=0, downCount=0; - foreach (const Torrent * const tor, myTorrents) + for (const Torrent * const tor: myTorrents) { upSpeed += tor->uploadSpeed (); upCount += tor->peersWeAreUploadingTo (); @@ -262,7 +262,7 @@ TorrentModel::getIds () const QSet ids; ids.reserve (myTorrents.size()); - foreach (const Torrent * tor, myTorrents) + for (const Torrent * const tor: myTorrents) ids.insert (tor->id()); return ids; @@ -271,7 +271,7 @@ TorrentModel::getIds () const bool TorrentModel::hasTorrent (const QString& hashString) const { - foreach (const Torrent * tor, myTorrents) + for (const Torrent * const tor: myTorrents) if (tor->hashString () == hashString) return true; diff --git a/qt/torrent.cc b/qt/torrent.cc index 630f87f3f..bc3463c69 100644 --- a/qt/torrent.cc +++ b/qt/torrent.cc @@ -357,7 +357,7 @@ Torrent::getSeedRatio (double& ratio) const bool Torrent::hasFileSubstring (const QString& substr) const { - foreach (const TrFile file, myFiles) + for (const TrFile& file: myFiles) if (file.filename.contains (substr, Qt::CaseInsensitive)) return true; @@ -367,7 +367,7 @@ Torrent::hasFileSubstring (const QString& substr) const bool Torrent::hasTrackerSubstring (const QString& substr) const { - foreach (QString s, myValues[TRACKERS].toStringList()) + for (const QString& s: myValues[TRACKERS].toStringList()) if (s.contains (substr, Qt::CaseInsensitive)) return true; @@ -613,7 +613,7 @@ Torrent::update (tr_variant * d) if (myValues[TRACKERS] != list) { QStringList hosts; - foreach (QString tracker, list) + for (const QString& tracker: list) { const QString host = Favicons::getHost (QUrl (tracker)); if (!host.isEmpty()) diff --git a/qt/tracker-model.cc b/qt/tracker-model.cc index e1b8738d1..95d5b7fcd 100644 --- a/qt/tracker-model.cc +++ b/qt/tracker-model.cc @@ -81,13 +81,13 @@ TrackerModel::refresh (const TorrentModel& torrentModel, const QSet& ids) { // build a list of the TrackerInfos QVector trackers; - foreach (int id, ids) + for (const int id: ids) { const Torrent * tor = torrentModel.getTorrentFromId (id); if (tor != 0) { const TrackerStatsList trackerList = tor->trackerStats (); - foreach (const TrackerStat& st, trackerList) + for (const TrackerStat& st: trackerList) { TrackerInfo trackerInfo; trackerInfo.st = st; diff --git a/qt/utils.cc b/qt/utils.cc index 66c0b170a..99c156988 100644 --- a/qt/utils.cc +++ b/qt/utils.cc @@ -125,39 +125,39 @@ Utils::guessMimeIcon (const QString& filename) const char * doc_types[] = { "abw", "csv", "doc", "dvi", "htm", "html", "ini", "log", "odp", "ods", "odt", "pdf", "ppt", "ps", "rtf", "tex", "txt", "xml" }; - for (int i=0, n=sizeof(doc_types)/sizeof(doc_types[0]); i files; - foreach (QString str, dir.entryList (QDir::Readable|QDir::Files)) + for (const QString& str: dir.entryList (QDir::Readable|QDir::Files)) files.insert (str); // try to add any new files which end in .torrent const QSet newFiles (files - myWatchDirFiles); const QString torrentSuffix = QString::fromUtf8 (".torrent"); - foreach (QString name, newFiles) + for (const QString& name: newFiles) { if (name.endsWith (torrentSuffix, Qt::CaseInsensitive)) { @@ -147,6 +147,6 @@ WatchDir::rescanAllWatchedDirectories () if (myWatcher == nullptr) return; - foreach (const QString& path, myWatcher->directories ()) + for (const QString& path: myWatcher->directories ()) watcherActivated (path); } -- 2.40.0