Add const and std::as_const

This commit is contained in:
Jonas Kvinge
2024-04-23 17:15:42 +02:00
parent 24c8d06d41
commit 426de61525
67 changed files with 273 additions and 192 deletions

View File

@@ -187,7 +187,7 @@ class FancyTabBar : public QTabBar { // clazy:exclude=missing-qobject-macro
// if LargeSidebar, restore spacers
if (tabWidget->mode() == FancyTabWidget::Mode::LargeSidebar && spacers.count() > 0) {
QList<int> keys = spacers.keys();
const QList<int> keys = spacers.keys();
for (const int index : keys) {
tabWidget->insertTab(index, spacers[index], QIcon(), QString());
tabWidget->setTabEnabled(index, false);

View File

@@ -19,6 +19,7 @@
*/
#include <algorithm>
#include <utility>
#include <QWidget>
#include <QAbstractItemModel>
@@ -81,7 +82,7 @@ QList<QUrl> FileViewList::UrlListFromSelection() const {
QList<QUrl> urls;
urls.reserve(filenames.count());
for (const QString &filename : filenames) {
for (const QString &filename : std::as_const(filenames)) {
urls << QUrl::fromLocalFile(filename);
}

View File

@@ -18,6 +18,8 @@
*
*/
#include <utility>
#include <QtGlobal>
#include <QWidget>
#include <QList>
@@ -195,7 +197,7 @@ void FreeSpaceBar::DrawText(QPainter *p, const QRect r) {
labels << Label(TextForSize(free_text_, free_ - additional_), kColorBg2);
int text_width = 0;
for (const Label &label : labels) {
for (const Label &label : std::as_const(labels)) {
text_width += kLabelBoxSize + kLabelBoxPadding + kLabelSpacing + small_metrics.horizontalAdvance(label.text);
}
@@ -203,7 +205,7 @@ void FreeSpaceBar::DrawText(QPainter *p, const QRect r) {
int x = (r.width() - text_width) / 2;
p->setRenderHint(QPainter::Antialiasing, false);
for (const Label &label : labels) {
for (const Label &label : std::as_const(labels)) {
const bool light = palette().color(QPalette::Base).value() > 128;
QRect box(x, r.top() + (r.height() - kLabelBoxSize) / 2, kLabelBoxSize, kLabelBoxSize);

View File

@@ -18,6 +18,8 @@
*
*/
#include <utility>
#include <QWidget>
#include <QListView>
#include <QAbstractItemModel>
@@ -305,7 +307,7 @@ void GroupedIconView::paintEvent(QPaintEvent *e) {
}
// Draw headers
for (const Header &header : headers_) {
for (const Header &header : std::as_const(headers_)) {
const QRect header_rect = QRect(header_indent_, header.y, viewport()->width() - header_indent_ * 2, header_height());
// Is this header contained in the area we're drawing?
@@ -325,7 +327,7 @@ void GroupedIconView::paintEvent(QPaintEvent *e) {
void GroupedIconView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) {
QVector<QModelIndex> indexes(IntersectingItems(rect.translated(horizontalOffset(), verticalOffset())));
const QVector<QModelIndex> indexes(IntersectingItems(rect.translated(horizontalOffset(), verticalOffset())));
QItemSelection selection;
selection.reserve(indexes.count());
@@ -356,7 +358,8 @@ QVector<QModelIndex> GroupedIconView::IntersectingItems(const QRect rect) const
QRegion GroupedIconView::visualRegionForSelection(const QItemSelection &selection) const {
QRegion ret;
for (const QModelIndex &idx : selection.indexes()) {
const QModelIndexList indexes = selection.indexes();
for (const QModelIndex &idx : indexes) {
ret += visual_rects_[idx.row()];
}
return ret;

View File

@@ -22,6 +22,8 @@
#include "ui_loginstatewidget.h"
#include "core/iconloader.h"
#include <utility>
#include <QWidget>
#include <QLocale>
#include <QDate>
@@ -82,7 +84,7 @@ void LoginStateWidget::SetLoggedIn(const State state, const QString &account_nam
if (account_name.isEmpty()) ui_->signed_in_label->setText(QStringLiteral("<b>") + tr("You are signed in.") + QStringLiteral("</b>"));
else ui_->signed_in_label->setText(tr("You are signed in as %1.").arg(QStringLiteral("<b>") + account_name + QStringLiteral("</b>")));
for (QWidget *widget : credential_groups_) {
for (QWidget *widget : std::as_const(credential_groups_)) {
widget->setVisible(state != State::LoggedIn);
widget->setEnabled(state != State::LoginInProgress);
}

View File

@@ -66,7 +66,7 @@ void MultiLoadingIndicator::SetTaskManager(SharedPtr<TaskManager> task_manager)
void MultiLoadingIndicator::UpdateText() {
QList<TaskManager::Task> tasks = task_manager_->GetTasks();
const QList<TaskManager::Task> tasks = task_manager_->GetTasks();
QStringList strings;
strings.reserve(tasks.count());