More const detach fixes

This commit is contained in:
Jonas Kvinge
2024-08-23 20:30:59 +02:00
parent be09011bb7
commit 7ebcc73a49
54 changed files with 195 additions and 180 deletions

View File

@@ -620,7 +620,7 @@ int Playlist::next_row(const bool ignore_repeat_track) {
// Still off the end? Then just give up
if (next_virtual_index < 0 || next_virtual_index >= virtual_items_.count()) return -1;
return virtual_items_[next_virtual_index];
return virtual_items_.value(next_virtual_index);
}
@@ -651,7 +651,7 @@ int Playlist::previous_row(const bool ignore_repeat_track) {
// Still off the beginning? Then just give up
if (prev_virtual_index < 0) return -1;
return virtual_items_[prev_virtual_index];
return virtual_items_.value(prev_virtual_index);
}
@@ -1227,7 +1227,7 @@ void Playlist::UpdateItems(SongList songs) {
QMutableListIterator<Song> it(songs);
while (it.hasNext()) {
const Song &song = it.next();
const PlaylistItemPtr &item = items_[i];
const PlaylistItemPtr item = items_.value(i);
if (item->Metadata().url() == song.url() && (item->Metadata().filetype() == Song::FileType::Unknown || item->Metadata().filetype() == Song::FileType::Stream || item->Metadata().filetype() == Song::FileType::CDDA || !item->Metadata().init_from_file())) {
PlaylistItemPtr new_item;
if (song.url().isLocalFile()) {
@@ -2315,7 +2315,7 @@ void Playlist::InvalidateDeletedSongs() {
QList<int> invalidated_rows;
for (int row = 0; row < items_.count(); ++row) {
PlaylistItemPtr item = items_[row];
PlaylistItemPtr item = items_.value(row);
Song song = item->Metadata();
if (song.url().isLocalFile()) {
@@ -2349,7 +2349,7 @@ void Playlist::RemoveDeletedSongs() {
QList<int> rows_to_remove;
for (int row = 0; row < items_.count(); ++row) {
PlaylistItemPtr item = items_[row];
PlaylistItemPtr item = items_.value(row);
Song song = item->Metadata();
if (song.url().isLocalFile() && !QFile::exists(song.url().toLocalFile())) {
@@ -2383,7 +2383,7 @@ void Playlist::RemoveDuplicateSongs() {
std::unordered_map<Song, int, SongSimilarHash, SongSimilarEqual> unique_songs;
for (int row = 0; row < items_.count(); ++row) {
PlaylistItemPtr item = items_[row];
PlaylistItemPtr item = items_.value(row);
const Song &song = item->Metadata();
bool found_duplicate = false;
@@ -2416,7 +2416,7 @@ void Playlist::RemoveUnavailableSongs() {
QList<int> rows_to_remove;
for (int row = 0; row < items_.count(); ++row) {
PlaylistItemPtr item = items_[row];
PlaylistItemPtr item = items_.value(row);
const Song &song = item->Metadata();
// Check only local files

View File

@@ -135,7 +135,7 @@ void PlaylistListModel::RowsAboutToBeRemoved(const QModelIndex &parent, const in
const int id = idx.data(Role_PlaylistId).toInt();
QMap<int, QStandardItem*>::iterator it = playlists_by_id_.find(id);
if (it != playlists_by_id_.end() && it.value() == item) {
playlists_by_id_.erase(it); // clazy:exclude=strict-iterators
playlists_by_id_.erase(it);
}
break;
}

View File

@@ -431,7 +431,8 @@ void PlaylistManager::UpdateSummaryText() {
int selected = 0;
// Get the length of the selected tracks
for (const QItemSelectionRange &range : std::as_const(playlists_[current_id()].selection)) {
const QItemSelection ranges = playlists_.value(current_id()).selection;
for (const QItemSelectionRange &range : ranges) {
if (!range.isValid()) continue;
selected += range.bottom() - range.top() + 1;

View File

@@ -57,7 +57,7 @@ void InsertItems::undo() {
bool InsertItems::UpdateItem(const PlaylistItemPtr &updated_item) {
for (int i = 0; i < items_.size(); i++) {
PlaylistItemPtr item = items_[i];
PlaylistItemPtr item = items_.value(i);
if (item->Metadata().url() == updated_item->Metadata().url()) {
items_[i] = updated_item;
return true;

View File

@@ -177,7 +177,7 @@ void SongLoaderInserter::AsyncLoad() {
task_manager_->SetTaskProgress(async_load_id, async_progress, pending_.count());
bool first_loaded = false;
for (int i = 0; i < pending_.count(); ++i) {
SongLoader *loader = pending_[i];
SongLoader *loader = pending_.value(i);
SongLoader::Result res = loader->LoadFilenamesBlocking();
task_manager_->SetTaskProgress(async_load_id, ++async_progress);
@@ -208,7 +208,7 @@ void SongLoaderInserter::AsyncLoad() {
task_manager_->SetTaskProgress(async_load_id, async_progress, songs_.count());
SongList songs;
for (int i = 0; i < pending_.count(); ++i) {
SongLoader *loader = pending_[i];
SongLoader *loader = pending_.value(i);
if (i != 0) {
// We already did this earlier for the first song.
loader->LoadMetadataBlocking();