Replace qAsConst with C++17 std::as_const

This commit is contained in:
Jonas Kvinge 2021-08-22 23:26:53 +02:00
parent c076933b52
commit 72d381e9ed
7 changed files with 17 additions and 13 deletions

View File

@ -24,6 +24,7 @@
#include <memory>
#include <functional>
#include <algorithm>
#include <utility>
#include <QObject>
#include <QtGlobal>
@ -586,7 +587,7 @@ void CollectionModel::SongsDeleted(const SongList &songs) {
}
// Delete empty dividers
for (const QString &divider_key : qAsConst(divider_keys)) {
for (const QString &divider_key : std::as_const(divider_keys)) {
if (!divider_nodes_.contains(divider_key)) continue;
// Look to see if there are any other items still under this divider

View File

@ -21,6 +21,7 @@
#include "config.h"
#include <utility>
#include <chrono>
#include <cassert>
@ -163,8 +164,7 @@ void CollectionWatcher::ReloadSettings() {
}
else if (monitor_ && !was_monitoring_before) {
// Add all directories to all QFileSystemWatchers again
QList<Directory> dirs = watched_dirs_.values();
for (const Directory &dir : dirs) {
for (const Directory &dir : std::as_const(watched_dirs_)) {
SubdirectoryList subdirs = backend_->SubdirsInDirectory(dir.id);
for (const Subdirectory &subdir : subdirs) {
AddWatch(dir, subdir.path);
@ -414,7 +414,7 @@ void CollectionWatcher::ScanSubdirectory(const QString &path, const Subdirectory
// Do not scan symlinked dirs that are already in collection
if (path_info.isSymLink()) {
QString real_path = path_info.symLinkTarget();
for (const Directory &dir : qAsConst(watched_dirs_)) {
for (const Directory &dir : std::as_const(watched_dirs_)) {
if (real_path.startsWith(dir.path)) {
return;
}
@ -1145,8 +1145,7 @@ void CollectionWatcher::PerformScan(const bool incremental, const bool ignore_mt
stop_requested_ = false;
QList<Directory> dirs = watched_dirs_.values();
for (const Directory &dir : dirs) {
for (const Directory &dir : std::as_const(watched_dirs_)) {
if (stop_requested_) break;
@ -1195,7 +1194,7 @@ quint64 CollectionWatcher::FilesCountForPath(ScanTransaction *t, const QString &
}
if (path_info.isSymLink()) {
QString real_path = path_info.symLinkTarget();
for (const Directory &dir : qAsConst(watched_dirs_)) {
for (const Directory &dir : std::as_const(watched_dirs_)) {
if (real_path.startsWith(dir.path)) {
continue;
}

View File

@ -22,6 +22,7 @@
#include "config.h"
#include <memory>
#include <utility>
#include <dbus/objectmanager.h>
#include <dbus/udisks2block.h>
@ -273,7 +274,7 @@ void Udisks2Lister::RemoveDevice(const QDBusObjectPath &device_path) {
QWriteLocker locker(&device_data_lock_);
QString id;
for (const auto &data : qAsConst(device_data_)) {
for (const PartitionData &data : std::as_const(device_data_)) {
if (data.dbus_path == device_path.path()) {
id = data.unique_id();
break;

View File

@ -278,7 +278,7 @@ void MoodbarItemDelegate::ImageLoaded(const QUrl &url, const QImage &image) {
const QSortFilterProxyModel *filter = playlist->proxy();
// Update all the indices with the new pixmap.
for (const QPersistentModelIndex &idx : qAsConst(data->indexes_)) {
for (const QPersistentModelIndex &idx : std::as_const(data->indexes_)) {
if (idx.isValid() && idx.sibling(idx.row(), Playlist::Column_Filename).data().toUrl() == url) {
QModelIndex source_index = idx;
if (idx.model() == filter) {

View File

@ -22,6 +22,7 @@
#include "config.h"
#include <memory>
#include <utility>
#include <QObject>
#include <QWidget>
@ -416,7 +417,7 @@ void PlaylistListContainer::Delete() {
}
// Unfavorite the playlists
for (const int id : qAsConst(ids)) {
for (const int id : std::as_const(ids)) {
app_->playlist_manager()->Favorite(id, false);
}

View File

@ -23,6 +23,7 @@
#include <memory>
#include <functional>
#include <utility>
#include <QtGlobal>
#include <QObject>
@ -496,7 +497,7 @@ void PlaylistManager::SongsDiscovered(const SongList &songs) {
// Some songs might've changed in the collection, let's update any playlist items we have that match those songs
for (const Song &song : songs) {
for (const Data &data : qAsConst(playlists_)) {
for (const Data &data : std::as_const(playlists_)) {
PlaylistItemList items = data.p->collection_items_by_id(song.id());
for (PlaylistItemPtr item : items) {
if (item->Metadata().directory_id() != song.directory_id()) continue;

View File

@ -22,6 +22,7 @@
#include "config.h"
#include <algorithm>
#include <utility>
#include <chrono>
#include <QtGlobal>
@ -477,7 +478,7 @@ void FancyTabWidget::Load(const QString &kSettingsGroup) {
QSettings s;
s.beginGroup(kSettingsGroup);
QMultiMap <int, TabData*> tabs;
for (TabData *tab : qAsConst(tabs_)) {
for (TabData *tab : std::as_const(tabs_)) {
int idx = s.value("tab_" + tab->name(), tab->index()).toInt();
while (tabs.contains(idx)) { ++idx; }
tabs.insert(idx, tab);
@ -505,7 +506,7 @@ void FancyTabWidget::SaveSettings(const QString &kSettingsGroup) {
s.setValue("tab_mode", mode_);
s.setValue("current_tab", currentIndex());
for (TabData *tab : qAsConst(tabs_)) {
for (TabData *tab : std::as_const(tabs_)) {
QString k = "tab_" + tab->name();
int idx = QTabWidget::indexOf(tab->page());
if (idx < 0) {