Add const and std::as_const
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include <QObject>
|
||||
@@ -87,7 +89,8 @@ Database::~Database() {
|
||||
|
||||
QMutexLocker l(&connect_mutex_);
|
||||
|
||||
for (const QString &connection_id : QSqlDatabase::connectionNames()) {
|
||||
const QStringList connection_names = QSqlDatabase::connectionNames();
|
||||
for (const QString &connection_id : connection_names) {
|
||||
qLog(Error) << "Connection" << connection_id << "is still open!";
|
||||
}
|
||||
|
||||
@@ -157,7 +160,7 @@ QSqlDatabase Database::Connect() {
|
||||
|
||||
// Attach external databases
|
||||
QStringList keys = attached_databases_.keys();
|
||||
for (const QString &key : keys) {
|
||||
for (const QString &key : std::as_const(keys)) {
|
||||
QString filename = attached_databases_[key].filename_;
|
||||
|
||||
if (!injected_database_name_.isNull()) filename = injected_database_name_;
|
||||
@@ -178,7 +181,7 @@ QSqlDatabase Database::Connect() {
|
||||
|
||||
// We might have to initialize the schema in some attached databases now, if they were deleted and don't match up with the main schema version.
|
||||
keys = attached_databases_.keys();
|
||||
for (const QString &key : keys) {
|
||||
for (const QString &key : std::as_const(keys)) {
|
||||
if (attached_databases_[key].is_temporary_ && attached_databases_[key].schema_.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
@@ -276,7 +279,8 @@ void Database::RecreateAttachedDb(const QString &database_name) {
|
||||
|
||||
// We can't just re-attach the database now because it needs to be done for each thread.
|
||||
// Close all the database connections, so each thread will re-attach it when they next connect.
|
||||
for (const QString &name : QSqlDatabase::connectionNames()) {
|
||||
const QStringList connection_names = QSqlDatabase::connectionNames();
|
||||
for (const QString &name : connection_names) {
|
||||
QSqlDatabase::removeDatabase(name);
|
||||
}
|
||||
|
||||
@@ -384,8 +388,7 @@ void Database::ExecSchemaCommandsFromFile(QSqlDatabase &db, const QString &filen
|
||||
void Database::ExecSchemaCommands(QSqlDatabase &db, const QString &schema, int schema_version, bool in_transaction) {
|
||||
|
||||
// Run each command
|
||||
QStringList commands;
|
||||
commands = schema.split(QRegularExpression(QStringLiteral("; *\n\n")));
|
||||
QStringList commands = schema.split(QRegularExpression(QStringLiteral("; *\n\n")));
|
||||
|
||||
// We don't want this list to reflect possible DB schema changes, so we initialize it before executing any statements.
|
||||
// If no outer transaction is provided the song tables need to be queried before beginning an inner transaction!
|
||||
@@ -445,12 +448,13 @@ QStringList Database::SongsTables(QSqlDatabase &db, const int schema_version) {
|
||||
QStringList ret;
|
||||
|
||||
// look for the tables in the main db
|
||||
for (const QString &table : db.tables()) {
|
||||
const QStringList &tables = db.tables();
|
||||
for (const QString &table : tables) {
|
||||
if (table == QStringLiteral("songs") || table.endsWith(QLatin1String("_songs"))) ret << table;
|
||||
}
|
||||
|
||||
// look for the tables in attached dbs
|
||||
QStringList keys = attached_databases_.keys();
|
||||
const QStringList keys = attached_databases_.keys();
|
||||
for (const QString &key : keys) {
|
||||
SqlQuery q(db);
|
||||
q.prepare(QStringLiteral("SELECT NAME FROM %1.sqlite_master WHERE type='table' AND name='songs' OR name LIKE '%songs'").arg(key));
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QList>
|
||||
@@ -80,7 +82,8 @@ QIcon IconLoader::Load(const QString &name, const bool system_icon, const int fi
|
||||
if (icon_prop.allow_system_icon) {
|
||||
ret = QIcon::fromTheme(name);
|
||||
if (ret.isNull()) {
|
||||
for (const QString &alt_name : icon_prop.names) {
|
||||
const QStringList alt_names = icon_prop.names;
|
||||
for (const QString &alt_name : alt_names) {
|
||||
ret = QIcon::fromTheme(alt_name);
|
||||
if (!ret.isNull()) break;
|
||||
}
|
||||
@@ -96,7 +99,8 @@ QIcon IconLoader::Load(const QString &name, const bool system_icon, const int fi
|
||||
else {
|
||||
int size_smallest = 0;
|
||||
int size_largest = 0;
|
||||
for (const QSize &s : ret.availableSizes()) {
|
||||
const QList<QSize> available_sizes = ret.availableSizes();
|
||||
for (const QSize &s : available_sizes) {
|
||||
if (s.width() != s.height()) {
|
||||
qLog(Warning) << "Can't use system icon for" << name << "icon is not proportional.";
|
||||
ret = QIcon();
|
||||
@@ -120,7 +124,7 @@ QIcon IconLoader::Load(const QString &name, const bool system_icon, const int fi
|
||||
|
||||
if (custom_icons_) {
|
||||
QString custom_icon_path = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + QStringLiteral("/icons/%1x%2/%3.png");
|
||||
for (int s : sizes) {
|
||||
for (int s : std::as_const(sizes)) {
|
||||
QString filename(custom_icon_path.arg(s).arg(s).arg(name));
|
||||
if (QFile::exists(filename)) ret.addFile(filename, QSize(s, s));
|
||||
}
|
||||
@@ -129,7 +133,7 @@ QIcon IconLoader::Load(const QString &name, const bool system_icon, const int fi
|
||||
}
|
||||
|
||||
const QString path(QStringLiteral(":/icons/%1x%2/%3.png"));
|
||||
for (int s : sizes) {
|
||||
for (int s : std::as_const(sizes)) {
|
||||
QString filename(path.arg(s).arg(s).arg(name));
|
||||
if (QFile::exists(filename)) ret.addFile(filename, QSize(s, s));
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ QStringList MergedProxyModel::mimeTypes() const {
|
||||
QStringList ret;
|
||||
ret << sourceModel()->mimeTypes();
|
||||
|
||||
QList<QAbstractItemModel*> models = merge_points_.keys();
|
||||
const QList<QAbstractItemModel*> models = merge_points_.keys();
|
||||
for (const QAbstractItemModel *model : models) {
|
||||
ret << model->mimeTypes();
|
||||
}
|
||||
@@ -506,7 +506,7 @@ QAbstractItemModel *MergedProxyModel::GetModel(const QModelIndex &source_index)
|
||||
// This is essentially const_cast<QAbstractItemModel*>(source_index.model()), but without the const_cast
|
||||
const QAbstractItemModel *const_model = source_index.model();
|
||||
if (const_model == sourceModel()) return sourceModel();
|
||||
QList<QAbstractItemModel*> submodels = merge_points_.keys();
|
||||
const QList<QAbstractItemModel*> submodels = merge_points_.keys();
|
||||
for (QAbstractItemModel *submodel : submodels) {
|
||||
if (submodel == const_model) return submodel;
|
||||
}
|
||||
@@ -522,7 +522,7 @@ void MergedProxyModel::DataChanged(const QModelIndex &top_left, const QModelInde
|
||||
void MergedProxyModel::LayoutAboutToBeChanged() {
|
||||
|
||||
old_merge_points_.clear();
|
||||
QList<QAbstractItemModel*> models = merge_points_.keys();
|
||||
const QList<QAbstractItemModel*> models = merge_points_.keys();
|
||||
for (QAbstractItemModel *model : models) {
|
||||
old_merge_points_[model] = merge_points_.value(model);
|
||||
}
|
||||
@@ -531,7 +531,7 @@ void MergedProxyModel::LayoutAboutToBeChanged() {
|
||||
|
||||
void MergedProxyModel::LayoutChanged() {
|
||||
|
||||
QList<QAbstractItemModel*> models = merge_points_.keys();
|
||||
const QList<QAbstractItemModel*> models = merge_points_.keys();
|
||||
for (QAbstractItemModel *model : models) {
|
||||
if (!old_merge_points_.contains(model)) continue;
|
||||
|
||||
|
||||
@@ -44,11 +44,10 @@ NetworkProxyFactory::NetworkProxyFactory()
|
||||
#ifdef Q_OS_LINUX
|
||||
// Linux uses environment variables to pass proxy configuration information, which systemProxyForQuery doesn't support for some reason.
|
||||
|
||||
QStringList urls;
|
||||
urls << QString::fromLocal8Bit(qgetenv("HTTP_PROXY"));
|
||||
urls << QString::fromLocal8Bit(qgetenv("http_proxy"));
|
||||
urls << QString::fromLocal8Bit(qgetenv("ALL_PROXY"));
|
||||
urls << QString::fromLocal8Bit(qgetenv("all_proxy"));
|
||||
const QStringList urls = QStringList() << QString::fromLocal8Bit(qgetenv("HTTP_PROXY"))
|
||||
<< QString::fromLocal8Bit(qgetenv("http_proxy"))
|
||||
<< QString::fromLocal8Bit(qgetenv("ALL_PROXY"))
|
||||
<< QString::fromLocal8Bit(qgetenv("all_proxy"));
|
||||
|
||||
qLog(Debug) << "Detected system proxy URLs:" << urls;
|
||||
|
||||
|
||||
@@ -437,7 +437,8 @@ void Player::PlayPlaylistInternal(const EngineBase::TrackChangeFlags change, con
|
||||
play_offset_nanosec_ = 0;
|
||||
|
||||
Playlist *playlist = nullptr;
|
||||
for (Playlist *p : app_->playlist_manager()->GetAllPlaylists()) {
|
||||
const QList<Playlist*> playlists = app_->playlist_manager()->GetAllPlaylists();
|
||||
for (Playlist *p : playlists) {
|
||||
if (playlist_name == app_->playlist_manager()->GetPlaylistName(p->id())) {
|
||||
playlist = p;
|
||||
break;
|
||||
|
||||
@@ -176,7 +176,8 @@ void StyleHelper::setBaseColor(const QColor &newcolor) {
|
||||
|
||||
if (color.isValid() && color != m_baseColor) {
|
||||
m_baseColor = color;
|
||||
for (QWidget *w : QApplication::topLevelWidgets()) {
|
||||
const QList<QWidget*> widgets = QApplication::topLevelWidgets();
|
||||
for (QWidget *w : widgets) {
|
||||
w->update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QTranslator>
|
||||
#include <QString>
|
||||
@@ -29,7 +31,7 @@
|
||||
Translations::Translations(QObject *parent) : QObject(parent) {}
|
||||
Translations::~Translations() {
|
||||
|
||||
for (QTranslator *t : translations_) {
|
||||
for (QTranslator *t : std::as_const(translations_)) {
|
||||
QCoreApplication::removeTranslator(t);
|
||||
delete t;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user