mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
2b9ca488fd
commit
c4c8094e32
21 changed files with 62 additions and 49 deletions
|
@ -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);
|
||||
|
|
|
@ -77,8 +77,8 @@ void Printer::flowRender()
|
|||
// get all references to dontbreak divs
|
||||
int start = 0, end = 0;
|
||||
int fullPageResolution = webView->page()->mainFrame()->contentsSize().height();
|
||||
QWebElementCollection dontbreak = webView->page()->mainFrame()->findAllElements(".dontbreak");
|
||||
foreach (QWebElement dontbreakElement, dontbreak) {
|
||||
const QWebElementCollection dontbreak = webView->page()->mainFrame()->findAllElements(".dontbreak");
|
||||
for (QWebElement dontbreakElement: dontbreak) {
|
||||
if ((dontbreakElement.geometry().y() + dontbreakElement.geometry().height()) - start < pageSize.height()) {
|
||||
// One more element can be placed
|
||||
end = dontbreakElement.geometry().y() + dontbreakElement.geometry().height();
|
||||
|
|
|
@ -21,9 +21,9 @@ TabDiveStatistics::TabDiveStatistics(QWidget *parent) : TabBase(parent), ui(new
|
|||
ui->timeLimits->overrideMinToolTipText(tr("Shortest dive"));
|
||||
ui->timeLimits->overrideAvgToolTipText(tr("Average length of all selected dives"));
|
||||
|
||||
Q_FOREACH (QObject *obj, children()) {
|
||||
if (QLabel *label = qobject_cast<QLabel *>(obj))
|
||||
label->setAlignment(Qt::AlignHCenter);
|
||||
const auto l = findChildren<QLabel *>(QString(), Qt::FindDirectChildrenOnly);
|
||||
for (QLabel *label: l) {
|
||||
label->setAlignment(Qt::AlignHCenter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1271,14 +1271,13 @@ void MainTab::saveTaggedStrings(const QVector<dive *> &selectedDives)
|
|||
|
||||
int MainTab::diffTaggedStrings(QString currentString, QString displayedString, QStringList &addedList, QStringList &removedList)
|
||||
{
|
||||
QStringList displayedList, currentList;
|
||||
currentList = currentString.split(',', QString::SkipEmptyParts);
|
||||
displayedList = displayedString.split(',', QString::SkipEmptyParts);
|
||||
Q_FOREACH ( const QString tag, currentList) {
|
||||
const QStringList currentList = currentString.split(',', QString::SkipEmptyParts);
|
||||
const QStringList displayedList = displayedString.split(',', QString::SkipEmptyParts);
|
||||
for (const QString &tag: currentList) {
|
||||
if (!displayedList.contains(tag, Qt::CaseInsensitive))
|
||||
removedList << tag.trimmed();
|
||||
}
|
||||
Q_FOREACH (const QString tag, displayedList) {
|
||||
for (const QString &tag: displayedList) {
|
||||
if (!currentList.contains(tag, Qt::CaseInsensitive))
|
||||
addedList << tag.trimmed();
|
||||
}
|
||||
|
|
|
@ -70,7 +70,8 @@ void TagWidget::highlight()
|
|||
{
|
||||
removeAllBlocks();
|
||||
int lastPos = 0;
|
||||
Q_FOREACH (const QString& s, text().split(QChar(','), QString::SkipEmptyParts)) {
|
||||
const auto l = text().split(QChar(','), QString::SkipEmptyParts);
|
||||
for (const QString &s: l) {
|
||||
QString trimmed = s.trimmed();
|
||||
if (trimmed.isEmpty())
|
||||
continue;
|
||||
|
|
|
@ -19,20 +19,20 @@ int getTotalWork(print_options *printOptions)
|
|||
|
||||
void find_all_templates()
|
||||
{
|
||||
const QString ext(".html");
|
||||
const QLatin1String ext(".html");
|
||||
grantlee_templates.clear();
|
||||
grantlee_statistics_templates.clear();
|
||||
QDir dir(getPrintingTemplatePathUser());
|
||||
QStringList list = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
|
||||
foreach (const QString& filename, list) {
|
||||
const QStringList list = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
|
||||
for (const QString &filename: list) {
|
||||
if (filename.at(filename.size() - 1) != '~' && filename.endsWith(ext))
|
||||
grantlee_templates.append(filename);
|
||||
}
|
||||
|
||||
// find statistics templates
|
||||
dir.setPath(getPrintingTemplatePathUser() + QDir::separator() + "statistics");
|
||||
list = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
|
||||
foreach (const QString& filename, list) {
|
||||
const QStringList stat = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
|
||||
for (const QString &filename: stat) {
|
||||
if (filename.at(filename.size() - 1) != '~' && filename.endsWith(ext))
|
||||
grantlee_statistics_templates.append(filename);
|
||||
}
|
||||
|
@ -66,12 +66,14 @@ void copy_bundled_templates(QString src, QString dst, QStringList *templateBacku
|
|||
QDir dir(src);
|
||||
if (!dir.exists())
|
||||
return;
|
||||
foreach (QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
||||
const auto dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
for (const QString &d: dirs) {
|
||||
QString dst_path = dst + QDir::separator() + d;
|
||||
dir.mkpath(dst_path);
|
||||
copy_bundled_templates(src + QDir::separator() + d, dst_path, templateBackupList);
|
||||
}
|
||||
foreach (QString f, dir.entryList(QDir::Files)) {
|
||||
const auto files = dir.entryList(QDir::Files);
|
||||
for (const QString &f: files) {
|
||||
QFile fileSrc(src + QDir::separator() + f);
|
||||
QFile fileDest(dst + QDir::separator() + f);
|
||||
if (fileDest.exists()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue