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

@@ -21,6 +21,8 @@
#include "config.h"
#include <utility>
#include <QObject>
#include <QThread>
#include <QMutex>
@@ -105,7 +107,7 @@ DeviceDatabaseBackend::DeviceList DeviceDatabaseBackend::GetAllDevices() {
}
}
for (const Device &dev : old_devices) {
for (const Device &dev : std::as_const(old_devices)) {
RemoveDevice(dev.id_);
}

View File

@@ -64,7 +64,7 @@ void DeviceInfo::InitFromDb(const DeviceDatabaseBackend::Device &dev) {
transcode_format_ = dev.transcode_format_;
icon_name_ = dev.icon_name_;
QStringList unique_ids = dev.unique_id_.split(QLatin1Char(','));
const QStringList unique_ids = dev.unique_id_.split(QLatin1Char(','));
for (const QString &id : unique_ids) {
backends_ << Backend(nullptr, id);
}

View File

@@ -22,6 +22,7 @@
#include "config.h"
#include <functional>
#include <utility>
#include <QtGlobal>
#include <QWidget>
@@ -88,14 +89,13 @@ void DeviceProperties::ShowDevice(const QModelIndex &idx) {
if (ui_->icon->count() == 0) {
// Only load the icons the first time the dialog is shown
QStringList icon_names = QStringList()
<< QStringLiteral("device")
<< QStringLiteral("device-usb-drive")
<< QStringLiteral("device-usb-flash")
<< QStringLiteral("media-optical")
<< QStringLiteral("device-ipod")
<< QStringLiteral("device-ipod-nano")
<< QStringLiteral("device-phone");
const QStringList icon_names = QStringList() << QStringLiteral("device")
<< QStringLiteral("device-usb-drive")
<< QStringLiteral("device-usb-flash")
<< QStringLiteral("media-optical")
<< QStringLiteral("device-ipod")
<< QStringLiteral("device-ipod-nano")
<< QStringLiteral("device-phone");
for (const QString &icon_name : icon_names) {
@@ -105,7 +105,8 @@ void DeviceProperties::ShowDevice(const QModelIndex &idx) {
#ifdef HAVE_GSTREAMER
// Load the transcode formats the first time the dialog is shown
for (const TranscoderPreset &preset : Transcoder::GetAllPresets()) {
const QList<TranscoderPreset> presets = Transcoder::GetAllPresets();
for (const TranscoderPreset &preset : presets) {
ui_->transcode_format->addItem(preset.name_, QVariant::fromValue(preset.filetype_));
}
ui_->transcode_format->model()->sort(0);
@@ -161,7 +162,7 @@ void DeviceProperties::UpdateHardwareInfo() {
// Remove empty items
QStringList keys = info.keys();
for (const QString &key : keys) {
for (const QString &key : std::as_const(keys)) {
if (info[key].isNull() || info[key].toString().isEmpty())
info.remove(key);
}
@@ -174,7 +175,7 @@ void DeviceProperties::UpdateHardwareInfo() {
AddHardwareInfo(row++, tr("Model"), lister->DeviceModel(id));
AddHardwareInfo(row++, tr("Manufacturer"), lister->DeviceManufacturer(id));
keys = info.keys();
for (const QString &key : keys) {
for (const QString &key : std::as_const(keys)) {
AddHardwareInfo(row++, key, info[key].toString());
}
@@ -307,7 +308,7 @@ void DeviceProperties::UpdateFormatsFinished() {
// Populate supported types list
ui_->supported_formats->clear();
for (Song::FileType type : supported_formats_) {
for (Song::FileType type : std::as_const(supported_formats_)) {
QListWidgetItem *item = new QListWidgetItem(Song::TextForFiletype(type));
ui_->supported_formats->addItem(item);
}

View File

@@ -377,7 +377,7 @@ void DeviceView::mouseDoubleClickEvent(QMouseEvent *e) {
SongList DeviceView::GetSelectedSongs() const {
QModelIndexList selected_merged_indexes = selectionModel()->selectedRows();
const QModelIndexList selected_merged_indexes = selectionModel()->selectedRows();
SongList songs;
for (const QModelIndex &merged_index : selected_merged_indexes) {
QModelIndex collection_index = MapToCollection(merged_index);

View File

@@ -22,6 +22,7 @@
#include "config.h"
#include <functional>
#include <utility>
#include <glib.h>
#include <glib-object.h>
@@ -128,7 +129,7 @@ bool GioLister::Init() {
}
GioLister::~GioLister() {
for (gulong signal : signals_) {
for (gulong signal : std::as_const(signals_)) {
g_signal_handler_disconnect(monitor_, signal);
}
}
@@ -222,7 +223,7 @@ QList<QUrl> GioLister::MakeDeviceUrls(const QString &id) {
QList<QUrl> ret;
for (QString uri : uris) {
for (QString uri : std::as_const(uris)) {
// gphoto2 gives invalid hostnames with []:, characters in
uri.replace(QRegularExpression(QStringLiteral("//\\[usb:(\\d+),(\\d+)\\]")), QStringLiteral("//usb-\\1-\\2"));
@@ -355,7 +356,7 @@ void GioLister::MountAdded(GMount *mount) {
QMutexLocker l(&mutex_);
// The volume might already exist - either mounted or unmounted.
QStringList ids = devices_.keys();
const QStringList ids = devices_.keys();
for (const QString &id : ids) {
if (devices_[id].volume_ptr == info.volume_ptr) {
old_id = id;