Skip to content

Commit

Permalink
Used const instead of std::as_const where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
JoergAtGithub committed Oct 13, 2024
1 parent 64e6a24 commit 16daaec
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/broadcast/broadcastmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ BroadcastManager::BroadcastManager(SettingsManager* pSettingsManager,
shout_init();

// Initialize connections list from the current state of BroadcastSettings
QList<BroadcastProfilePtr> profiles = m_pBroadcastSettings->profiles();
for (const BroadcastProfilePtr& profile : std::as_const(profiles)) {
const QList<BroadcastProfilePtr> profiles = m_pBroadcastSettings->profiles();
for (const BroadcastProfilePtr& profile : profiles) {
addConnection(profile);
}

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/controllermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ void ControllerManager::slotSetUpDevices() {
qDebug() << "ControllerManager: Setting up devices";

updateControllerList();
QList<Controller*> deviceList = getControllerList(false, true);
const QList<Controller*> deviceList = getControllerList(false, true);
QStringList mappingPaths(getMappingPaths(m_pConfig));

for (Controller* pController : std::as_const(deviceList)) {
for (Controller* pController : deviceList) {
QString name = pController->getName();

if (pController->isOpen()) {
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/dlgprefcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,11 @@ MappingInfo DlgPrefController::enumerateMappingsFromEnumerator(
// re-enumerate on the next open of the preferences.
if (!pMappingEnumerator.isNull()) {
// Get a list of mappings in alphabetical order
QList<MappingInfo> systemMappings =
const QList<MappingInfo> systemMappings =
pMappingEnumerator->getMappingsByExtension(
m_pController->mappingExtension());

for (const MappingInfo& mapping : std::as_const(systemMappings)) {
for (const MappingInfo& mapping : systemMappings) {
m_ui.comboBoxMapping->addItem(
icon, mapping.getName(), mapping.getPath());
if (m_pController->matchMapping(mapping)) {
Expand Down
4 changes: 2 additions & 2 deletions src/dialog/dlgreplacecuecolor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ void DlgReplaceCueColor::slotApply() {
}

// Flush cached tracks to database
QSet<TrackId> cachedTrackIds = GlobalTrackCacheLocker().getCachedTrackIds();
for (const TrackId& trackId : std::as_const(cachedTrackIds)) {
const QSet<TrackId> cachedTrackIds = GlobalTrackCacheLocker().getCachedTrackIds();
for (const TrackId& trackId : cachedTrackIds) {
TrackPointer pTrack = GlobalTrackCacheLocker().lookupTrackById(trackId);
if (pTrack) {
m_pTrackCollectionManager->saveTrack(pTrack);
Expand Down
4 changes: 2 additions & 2 deletions src/library/banshee/bansheefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ void BansheeFeature::activate() {
m_isActivated = true;

std::unique_ptr<TreeItem> pRootItem = TreeItem::newRoot(this);
QList<BansheeDbConnection::Playlist> playlists = m_connection.getPlaylists();
for (const BansheeDbConnection::Playlist& playlist : std::as_const(playlists)) {
const QList<BansheeDbConnection::Playlist> playlists = m_connection.getPlaylists();
for (const BansheeDbConnection::Playlist& playlist : playlists) {
qDebug() << playlist.name;
// append the playlist to the child model
pRootItem->appendChild(playlist.name, playlist.playlistId);
Expand Down
4 changes: 2 additions & 2 deletions src/library/dao/trackdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ void TrackDAO::finish() {
// Do housekeeping on the LibraryHashes/track_locations tables.
qDebug() << "Cleaning LibraryHashes/track_locations tables.";
SqlTransaction transaction(m_database);
QStringList deletedHashDirs = m_libraryHashDao.getDeletedDirectories();
const QStringList deletedHashDirs = m_libraryHashDao.getDeletedDirectories();

// Delete any LibraryHashes directories that have been marked as deleted.
m_libraryHashDao.removeDeletedDirectoryHashes();

// And mark the corresponding tracks in track_locations in the deleted
// directories as deleted.
// TODO(XXX) This doesn't handle sub-directories of deleted directories.
for (const auto& dir : std::as_const(deletedHashDirs)) {
for (const auto& dir : deletedHashDirs) {
markTrackLocationsAsDeleted(m_database, dir);
}
transaction.commit();
Expand Down
4 changes: 2 additions & 2 deletions src/library/trackcollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,10 @@ bool TrackCollection::purgeAllTracks(
const QDir& rootDir) {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);

QList<TrackRef> trackRefs = m_trackDao.getAllTrackRefs(rootDir);
const QList<TrackRef> trackRefs = m_trackDao.getAllTrackRefs(rootDir);
QList<TrackId> trackIds;
trackIds.reserve(trackRefs.size());
for (const auto& trackRef : std::as_const(trackRefs)) {
for (const auto& trackRef : trackRefs) {
DEBUG_ASSERT(trackRef.hasId());
trackIds.append(trackRef.getId());
}
Expand Down
4 changes: 2 additions & 2 deletions src/library/trackset/baseplaylistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,9 @@ void BasePlaylistFeature::slotAnalyzePlaylist() {
if (m_lastRightClickedIndex.isValid()) {
int playlistId = playlistIdFromIndex(m_lastRightClickedIndex);
if (playlistId >= 0) {
QList<TrackId> ids = m_playlistDao.getTrackIds(playlistId);
const QList<TrackId> ids = m_playlistDao.getTrackIds(playlistId);
QList<AnalyzerScheduledTrack> tracks;
for (auto id : std::as_const(ids)) {
for (auto id : ids) {
tracks.append(id);
}
emit analyzeTracks(tracks);
Expand Down
4 changes: 2 additions & 2 deletions src/library/trackset/crate/cratefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ void CrateFeature::slotImportPlaylistFile(const QString& playlistFile, CrateId c

void CrateFeature::slotCreateImportCrate() {
// Get file to read
QStringList playlistFiles = LibraryFeature::getPlaylistFiles();
const QStringList playlistFiles = LibraryFeature::getPlaylistFiles();
if (playlistFiles.isEmpty()) {
return;
}
Expand All @@ -707,7 +707,7 @@ void CrateFeature::slotCreateImportCrate() {
CrateId lastCrateId;

// For each selected file create a new crate
for (const QString& playlistFile : std::as_const(playlistFiles)) {
for (const QString& playlistFile : playlistFiles) {
const QFileInfo fileInfo(playlistFile);

Crate crate;
Expand Down
4 changes: 2 additions & 2 deletions src/preferences/broadcastsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void BroadcastSettings::loadProfiles() {
}

QStringList nameFilters("*.bcp.xml");
QFileInfoList files =
const QFileInfoList files =
profilesFolder.entryInfoList(nameFilters, QDir::Files, QDir::Name);

// If *.bcp.xml files exist in the profiles subfolder, those will be loaded
Expand All @@ -49,7 +49,7 @@ void BroadcastSettings::loadProfiles() {
kLogger.info() << "Found" << files.size() << "profile(s)";

// Load profiles from filesystem
for (const QFileInfo& fileInfo : std::as_const(files)) {
for (const QFileInfo& fileInfo : files) {
BroadcastProfilePtr profile =
BroadcastProfile::loadFromFile(fileInfo.absoluteFilePath());

Expand Down
4 changes: 2 additions & 2 deletions src/preferences/colorpaletteeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ void ColorPaletteEditor::slotAddColor() {
}

void ColorPaletteEditor::slotRemoveColor() {
QModelIndexList selection = m_pTableView->selectionModel()->selectedRows();
for (const auto& index : std::as_const(selection)) {
const QModelIndexList selection = m_pTableView->selectionModel()->selectedRows();
for (const auto& index : selection) {
//row selected
int row = index.row();
m_pModel->removeRow(row);
Expand Down
4 changes: 2 additions & 2 deletions src/soundio/sounddevicenetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ void SoundDeviceNetwork::writeProcess(SINT framesPerBuffer) {
m_outputFifo->aquireReadRegions(readAvailable,
&dataPtr1, &size1, &dataPtr2, &size2);

QVector<NetworkOutputStreamWorkerPtr> workers =
const QVector<NetworkOutputStreamWorkerPtr> workers =
m_pNetworkStream->outputWorkers();
for (const auto& pWorker : std::as_const(workers)) {
for (const auto& pWorker : workers) {
if (pWorker.isNull()) {
continue;
}
Expand Down
16 changes: 9 additions & 7 deletions src/soundio/soundmanagerconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ bool SoundManagerConfig::readFromDisk() {
VERIFY_OR_DEBUG_ASSERT(m_pSoundManager != nullptr) {
return false;
}
QList<SoundDevicePointer> soundDevices = m_pSoundManager->getDeviceList(m_api, true, true);
const QList<SoundDevicePointer> soundDevices =
m_pSoundManager->getDeviceList(m_api, true, true);

for (int i = 0; i < devElements.count(); ++i) {
QDomElement devElement(devElements.at(i).toElement());
Expand All @@ -109,7 +110,7 @@ bool SoundManagerConfig::readFromDisk() {
}

int devicesMatchingByName = 0;
for (const auto& soundDevice : std::as_const(soundDevices)) {
for (const auto& soundDevice : soundDevices) {
SoundDeviceId hardwareDeviceId = soundDevice->getDeviceId();
if (hardwareDeviceId.name == deviceIdFromFile.name) {
devicesMatchingByName++;
Expand All @@ -127,7 +128,7 @@ bool SoundManagerConfig::readFromDisk() {
// very reliable as persistent identifiers across restarts of Mixxx.
// Set deviceIdFromFile's alsaHwDevice and portAudioIndex to match
// the hardwareDeviceId so operator== works for SoundDeviceId.
for (const auto& soundDevice : std::as_const(soundDevices)) {
for (const auto& soundDevice : soundDevices) {
SoundDeviceId hardwareDeviceId = soundDevice->getDeviceId();
if (hardwareDeviceId.name == deviceIdFromFile.name) {
deviceIdFromFile.alsaHwDevice = hardwareDeviceId.alsaHwDevice;
Expand All @@ -146,7 +147,7 @@ bool SoundManagerConfig::readFromDisk() {
// multiple devices with the same name. This might be possible
// somehow with a udev rule matching device serial numbers, but
// I have not tested this.
for (const auto& soundDevice : std::as_const(soundDevices)) {
for (const auto& soundDevice : soundDevices) {
SoundDeviceId hardwareDeviceId = soundDevice->getDeviceId();
if (hardwareDeviceId.name == deviceIdFromFile.name
&& hardwareDeviceId.alsaHwDevice == deviceIdFromFile.alsaHwDevice) {
Expand All @@ -156,7 +157,7 @@ bool SoundManagerConfig::readFromDisk() {
}
} else {
// Check if the one of the matching devices has the configured in and output channels
for (const auto& soundDevice : std::as_const(soundDevices)) {
for (const auto& soundDevice : soundDevices) {
SoundDeviceId hardwareDeviceId = soundDevice->getDeviceId();
if (hardwareDeviceId.name == deviceIdFromFile.name &&
soundDevice->getNumOutputChannels() >=
Expand Down Expand Up @@ -513,9 +514,10 @@ void SoundManagerConfig::loadDefaults(SoundManager* soundManager, unsigned int f
if (flags & SoundManagerConfig::DEVICES) {
clearOutputs();
clearInputs();
QList<SoundDevicePointer> outputDevices = soundManager->getDeviceList(m_api, true, false);
const QList<SoundDevicePointer> outputDevices =
soundManager->getDeviceList(m_api, true, false);
if (!outputDevices.isEmpty()) {
for (const auto& pDevice : std::as_const(outputDevices)) {
for (const auto& pDevice : outputDevices) {
if (pDevice->getNumOutputChannels() < 2) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/seratobeatgridtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class SeratoBeatGridTest : public testing::Test {
dir.setFilter(QDir::Files);
dir.setNameFilters(QStringList() << "*.octet-stream");

QFileInfoList fileList = dir.entryInfoList();
const QFileInfoList fileList = dir.entryInfoList();
EXPECT_FALSE(fileList.isEmpty());
for (const QFileInfo& fileInfo : std::as_const(fileList)) {
for (const QFileInfo& fileInfo : fileList) {
qDebug() << "--- File:" << fileInfo.fileName();
QFile file(dir.filePath(fileInfo.fileName()));
bool openOk = file.open(QIODevice::ReadOnly);
Expand Down
4 changes: 2 additions & 2 deletions src/test/seratomarkers2test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ class SeratoMarkers2Test : public testing::Test {
dir.setFilter(QDir::Files);
dir.setNameFilters(QStringList() << "*.octet-stream");

QFileInfoList fileList = dir.entryInfoList();
const QFileInfoList fileList = dir.entryInfoList();
EXPECT_FALSE(fileList.isEmpty());
for (const QFileInfo& fileInfo : std::as_const(fileList)) {
for (const QFileInfo& fileInfo : fileList) {
qDebug() << "--- File:" << fileInfo.fileName();
QFile file(dir.filePath(fileInfo.fileName()));
bool openOk = file.open(QIODevice::ReadOnly);
Expand Down
4 changes: 2 additions & 2 deletions src/test/seratomarkerstest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class SeratoMarkersTest : public testing::Test {
dir.setFilter(QDir::Files);
dir.setNameFilters(QStringList() << "*.octet-stream");

QFileInfoList fileList = dir.entryInfoList();
const QFileInfoList fileList = dir.entryInfoList();
EXPECT_FALSE(fileList.isEmpty());
for (const QFileInfo& fileInfo : std::as_const(fileList)) {
for (const QFileInfo& fileInfo : fileList) {
qDebug() << "--- File:" << fileInfo.fileName();
QFile file(dir.filePath(fileInfo.fileName()));
bool openOk = file.open(QIODevice::ReadOnly);
Expand Down
10 changes: 5 additions & 5 deletions src/waveform/renderers/waveformmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ namespace {
constexpr float lineHoverPadding = 5.0;

Qt::Alignment decodeAlignmentFlags(const QString& alignString, Qt::Alignment defaultFlags) {
QStringList stringFlags = alignString.toLower()
.split('|',
const QStringList stringFlags = alignString.toLower()
.split('|',
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
Qt::SkipEmptyParts);
Qt::SkipEmptyParts);
#else
QString::SkipEmptyParts);
QString::SkipEmptyParts);
#endif

Qt::Alignment hflags;
Qt::Alignment vflags;

for (const auto& stringFlag : std::as_const(stringFlags)) {
for (const auto& stringFlag : stringFlags) {
if (stringFlag == "center") {
hflags |= Qt::AlignHCenter;
vflags |= Qt::AlignVCenter;
Expand Down
4 changes: 2 additions & 2 deletions src/waveform/renderers/waveformrendermarkbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void WaveformRenderMarkBase::updateMarksFromCues() {
}

const int dimBrightThreshold = m_waveformRenderer->getDimBrightThreshold();
QList<CuePointer> loadedCues = pTrackInfo->getCuePoints();
for (const CuePointer& pCue : std::as_const(loadedCues)) {
const QList<CuePointer> loadedCues = pTrackInfo->getCuePoints();
for (const CuePointer& pCue : loadedCues) {
const int hotCue = pCue->getHotCue();
if (hotCue == Cue::kNoHotCue) {
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/widget/woverview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ void WOverview::mousePressEvent(QMouseEvent* e) {
// WOverview in the future, another way to associate
// WaveformMarks with Cues will need to be implemented.
CuePointer pHoveredCue;
QList<CuePointer> cueList = m_pCurrentTrack->getCuePoints();
for (const auto& pCue : std::as_const(cueList)) {
const QList<CuePointer> cueList = m_pCurrentTrack->getCuePoints();
for (const auto& pCue : cueList) {
if (pCue->getHotCue() == m_pHoveredMark->getHotCue()) {
pHoveredCue = pCue;
break;
Expand Down
8 changes: 4 additions & 4 deletions src/widget/wsplitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ void WSplitter::setup(const QDomNode& node, const SkinContext& context) {

// found some value for splitsizes?
if (!sizesJoined.isEmpty()) {
QStringList sizesSplit = sizesJoined.split(",");
const QStringList sizesSplit = sizesJoined.split(",");
QList<int> sizesList;
ok = false;
for (const QString& sizeStr : std::as_const(sizesSplit)) {
for (const QString& sizeStr : sizesSplit) {
sizesList.push_back(sizeStr.toInt(&ok));
if (!ok) {
break;
Expand All @@ -75,10 +75,10 @@ void WSplitter::setup(const QDomNode& node, const SkinContext& context) {
// Which children can be collapsed?
QString collapsibleJoined;
if (context.hasNodeSelectString(node, "Collapsible", &collapsibleJoined)) {
QStringList collapsibleSplit = collapsibleJoined.split(",");
const QStringList collapsibleSplit = collapsibleJoined.split(",");
QList<bool> collapsibleList;
ok = false;
for (const QString& collapsibleStr : std::as_const(collapsibleSplit)) {
for (const QString& collapsibleStr : collapsibleSplit) {
collapsibleList.push_back(collapsibleStr.toInt(&ok)>0);
if (!ok) {
break;
Expand Down
4 changes: 2 additions & 2 deletions src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,10 +1324,10 @@ void WTrackMenu::slotPopulatePlaylistMenu() {
const PlaylistDAO& playlistDao = m_pLibrary->trackCollectionManager()
->internalCollection()
->getPlaylistDAO();
QList<QPair<int, QString>> playlists =
const QList<QPair<int, QString>> playlists =
playlistDao.getPlaylists(PlaylistDAO::PLHT_NOT_HIDDEN);

for (const auto& [id, name] : std::as_const(playlists)) {
for (const auto& [id, name] : playlists) {
// No leak because making the menu the parent means they will be
// auto-deleted
int plId = id;
Expand Down

0 comments on commit 16daaec

Please sign in to comment.