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,7 @@
#include "config.h"
#include <utility>
#include <memory>
#include <QObject>
@@ -307,7 +308,7 @@ PlaylistItemPtr PlaylistBackend::RestoreCueData(PlaylistItemPtr item, SharedPtr<
}
}
for (const Song &from_list : song_list) {
for (const Song &from_list : std::as_const(song_list)) {
if (from_list.url().toEncoded() == song.url().toEncoded() && from_list.beginning_nanosec() == song.beginning_nanosec()) {
// We found a matching section; replace the input item with a new one containing CUE metadata
return make_shared<SongPlaylistItem>(from_list);

View File

@@ -141,7 +141,8 @@ void PlaylistListContainer::SetApplication(Application *app) {
QObject::connect(player, &Player::Stopped, this, &PlaylistListContainer::ActiveStopped);
// Get all playlists, even ones that are hidden in the UI.
for (const PlaylistBackend::Playlist &p : app->playlist_backend()->GetAllFavoritePlaylists()) {
const QList<PlaylistBackend::Playlist> playlists = app->playlist_backend()->GetAllFavoritePlaylists();
for (const PlaylistBackend::Playlist &p : playlists) {
QStandardItem *playlist_item = model_->NewPlaylist(p.name, p.id);
QStandardItem *parent_folder = model_->FolderByPath(p.ui_path);
parent_folder->appendRow(playlist_item);
@@ -407,7 +408,8 @@ void PlaylistListContainer::Delete() {
QSet<int> ids;
QList<QPersistentModelIndex> folders_to_delete;
for (const QModelIndex &proxy_index : ui_->tree->selectionModel()->selectedRows()) {
const QModelIndexList proxy_indexes = ui_->tree->selectionModel()->selectedRows();
for (const QModelIndex &proxy_index : proxy_indexes) {
const QModelIndex idx = proxy_->mapToSource(proxy_index);
// Is it a playlist?
@@ -439,7 +441,7 @@ void PlaylistListContainer::Delete() {
}
// Delete the top-level folders.
for (const QPersistentModelIndex &idx : folders_to_delete) {
for (const QPersistentModelIndex &idx : std::as_const(folders_to_delete)) {
if (idx.isValid()) {
model_->removeRow(idx.row(), idx.parent());
}

View File

@@ -20,6 +20,8 @@
#include "config.h"
#include <utility>
#include <QtGlobal>
#include <QList>
#include <QUndoStack>
@@ -92,7 +94,7 @@ bool RemoveItems::mergeWith(const QUndoCommand *other) {
ranges_.append(remove_command->ranges_);
int sum = 0;
for (const Range &range : ranges_) sum += range.count_;
for (const Range &range : std::as_const(ranges_)) sum += range.count_;
setText(tr("remove %n songs", "", sum));
return true;

View File

@@ -865,7 +865,8 @@ void PlaylistView::mousePressEvent(QMouseEvent *event) {
if (selectedIndexes().contains(idx)) {
// Update all the selected item ratings
QModelIndexList src_index_list;
for (const QModelIndex &i : selectedIndexes()) {
const QModelIndexList indexes = selectedIndexes();
for (const QModelIndex &i : indexes) {
if (i.data(Playlist::Role_CanSetRating).toBool()) {
src_index_list << playlist_->filter()->mapToSource(i);
}
@@ -1548,7 +1549,8 @@ void PlaylistView::RatingHoverIn(const QModelIndex &idx, const QPoint pos) {
update(idx);
update(old_index);
for (const QModelIndex &i : selectedIndexes()) {
const QModelIndexList indexes = selectedIndexes();
for (const QModelIndex &i : indexes) {
if (i.column() == Playlist::Column_Rating) update(i);
}
@@ -1569,7 +1571,8 @@ void PlaylistView::RatingHoverOut() {
setCursor(QCursor());
update(old_index);
for (const QModelIndex &i : selectedIndexes()) {
const QModelIndexList indexes = selectedIndexes();
for (const QModelIndex &i : indexes) {
if (i.column() == Playlist::Column_Rating) {
update(i);
}