get rid of some foreach and Q_FOREACH constructs

See https://www.kdab.com/goodbye-q_foreach/

This is reduced to the places where the container is const or can be made const
without the need to always introduce an extra variable. Sadly qAsConst (Qt 5.7)
and std::as_const (C++17) are not available in all supported setups.

Also do some minor cleanups along the way.

Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
This commit is contained in:
Rolf Eike Beer 2019-04-01 22:15:19 +02:00 committed by Dirk Hohndel
parent 2b9ca488fd
commit c4c8094e32
21 changed files with 62 additions and 49 deletions

View file

@ -75,11 +75,11 @@ void LocationInformationWidget::mergeSelectedDiveSites()
QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Ok)
return;
QModelIndexList selection = ui.diveSiteListView->selectionModel()->selectedIndexes();
const QModelIndexList selection = ui.diveSiteListView->selectionModel()->selectedIndexes();
// std::vector guarantees contiguous storage and can therefore be passed to C-code
std::vector<struct dive_site *> selected_dive_sites;
selected_dive_sites.reserve(selection.count());
Q_FOREACH (const QModelIndex &idx, selection) {
for (const QModelIndex &idx: selection) {
dive_site *ds = idx.data(LocationInformationModel::DIVESITE_ROLE).value<dive_site *>();
if (ds)
selected_dive_sites.push_back(ds);