Clang-Tidy and Clazy fixes

This commit is contained in:
Jonas Kvinge
2021-06-20 19:04:08 +02:00
parent 755abec636
commit 1295033fae
374 changed files with 1304 additions and 900 deletions

View File

@@ -621,6 +621,7 @@ void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const Song &song, co
SongList songs = watcher->result();
watcher->deleteLater();
QList<QUrl> urls;
urls.reserve(songs.count());
for (const Song &s : songs) urls << s.url();
if (result.is_jpeg()) {
qint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, result.image_data);
@@ -665,6 +666,7 @@ void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const Song &song, co
SongList songs = watcher->result();
watcher->deleteLater();
QList<QUrl> urls;
urls.reserve(songs.count());
for (const Song &s : songs) urls << s.url();
qint64 id = app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, cover_filename);
QMutexLocker l(&mutex_cover_save_tasks_);
@@ -678,7 +680,7 @@ void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const Song &song, co
}
void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const QList<QUrl> urls, const QImage &image) {
void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const QList<QUrl> &urls, const QImage &image) {
app_->album_cover_loader()->SaveEmbeddedCoverAsync(urls, image);

View File

@@ -145,7 +145,7 @@ class AlbumCoverChoiceController : public QWidget {
void SaveCoverEmbeddedAutomatic(const Song &song, const AlbumCoverImageResult &result);
void SaveCoverEmbeddedAutomatic(const Song &song, const QUrl &cover_url);
void SaveCoverEmbeddedAutomatic(const Song &song, const QString &cover_filename);
void SaveCoverEmbeddedAutomatic(const QList<QUrl> urls, const QImage &image);
void SaveCoverEmbeddedAutomatic(const QList<QUrl> &urls, const QImage &image);
static bool CanAcceptDrag(const QDragEnterEvent *e);

View File

@@ -43,7 +43,7 @@ void AlbumCoverExporter::SetDialogResult(const AlbumCoverExport::DialogResult &d
dialog_result_ = dialog_result;
}
void AlbumCoverExporter::AddExportRequest(Song song) {
void AlbumCoverExporter::AddExportRequest(const Song &song) {
requests_.append(new CoverExportRunnable(dialog_result_, song));
all_ = requests_.count();
}

View File

@@ -42,7 +42,7 @@ class AlbumCoverExporter : public QObject {
static const int kMaxConcurrentRequests;
void SetDialogResult(const AlbumCoverExport::DialogResult &dialog_result);
void AddExportRequest(Song song);
void AddExportRequest(const Song &song);
void StartExporting();
void Cancel();

View File

@@ -21,6 +21,8 @@
#include "config.h"
#include <chrono>
#include <QtGlobal>
#include <QObject>
#include <QTimer>
@@ -32,6 +34,8 @@
#include "albumcoverfetcher.h"
#include "albumcoverfetchersearch.h"
using namespace std::chrono_literals;
const int AlbumCoverFetcher::kMaxConcurrentRequests = 5;
AlbumCoverFetcher::AlbumCoverFetcher(CoverProviders *cover_providers, QObject *parent, NetworkAccessManager *network)
@@ -41,7 +45,7 @@ AlbumCoverFetcher::AlbumCoverFetcher(CoverProviders *cover_providers, QObject *p
next_id_(0),
request_starter_(new QTimer(this)) {
request_starter_->setInterval(1000);
request_starter_->setInterval(1s);
QObject::connect(request_starter_, &QTimer::timeout, this, &AlbumCoverFetcher::StartRequests);
}

View File

@@ -233,7 +233,7 @@ void AlbumCoverLoader::CancelTask(const quint64 id) {
QMutexLocker l(&mutex_load_image_async_);
for (QQueue<Task>::iterator it = tasks_.begin(); it != tasks_.end(); ++it) {
if (it->id == id) {
tasks_.erase(it);
tasks_.erase(it); // clazy:exclude=strict-iterators
break;
}
}
@@ -245,7 +245,7 @@ void AlbumCoverLoader::CancelTasks(const QSet<quint64> &ids) {
QMutexLocker l(&mutex_load_image_async_);
for (QQueue<Task>::iterator it = tasks_.begin(); it != tasks_.end();) {
if (ids.contains(it->id)) {
it = tasks_.erase(it);
it = tasks_.erase(it); // clazy:exclude=strict-iterators
}
else {
++it;
@@ -531,7 +531,7 @@ void AlbumCoverLoader::RemoteFetchFinished(QNetworkReply *reply, const QUrl &cov
}
qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QString song_filename, const QString &cover_filename) {
qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QString &song_filename, const QString &cover_filename) {
QMutexLocker l(&mutex_save_image_async_);
qint64 id = ++save_image_async_id_;
@@ -540,7 +540,7 @@ qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QString song_filename, con
}
qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QString song_filename, const QImage &image) {
qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QString &song_filename, const QImage &image) {
QMutexLocker l(&mutex_save_image_async_);
qint64 id = ++save_image_async_id_;
@@ -549,7 +549,7 @@ qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QString song_filename, con
}
qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QString song_filename, const QByteArray &image_data) {
qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QString &song_filename, const QByteArray &image_data) {
QMutexLocker l(&mutex_save_image_async_);
qint64 id = ++save_image_async_id_;
@@ -558,7 +558,7 @@ qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QString song_filename, con
}
qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QList<QUrl> urls, const QString &cover_filename) {
qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QList<QUrl> &urls, const QString &cover_filename) {
QMutexLocker l(&mutex_save_image_async_);
qint64 id = ++save_image_async_id_;
@@ -567,7 +567,7 @@ qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QList<QUrl> urls, const QS
}
qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QList<QUrl> urls, const QImage &image) {
qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QList<QUrl> &urls, const QImage &image) {
QMutexLocker l(&mutex_save_image_async_);
qint64 id = ++save_image_async_id_;
@@ -576,7 +576,7 @@ qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QList<QUrl> urls, const QI
}
qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QList<QUrl> urls, const QByteArray &image_data) {
qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QList<QUrl> &urls, const QByteArray &image_data) {
QMutexLocker l(&mutex_save_image_async_);
qint64 id = ++save_image_async_id_;
@@ -585,7 +585,7 @@ qint64 AlbumCoverLoader::SaveEmbeddedCoverAsync(const QList<QUrl> urls, const QB
}
void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QString song_filename, const QByteArray &image_data) {
void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QString &song_filename, const QByteArray &image_data) {
TagReaderReply *reply = TagReaderClient::Instance()->SaveEmbeddedArt(song_filename, image_data);
tagreader_save_embedded_art_requests_.insert(id, reply);
@@ -594,7 +594,7 @@ void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QString song_fil
}
void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QString song_filename, const QImage &image) {
void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QString &song_filename, const QImage &image) {
QByteArray image_data;
@@ -610,7 +610,7 @@ void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QString song_fil
}
void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QString song_filename, const QString &cover_filename) {
void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QString &song_filename, const QString &cover_filename) {
QFile file(cover_filename);
@@ -626,7 +626,7 @@ void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QString song_fil
}
void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QList<QUrl> urls, const QImage &image) {
void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QList<QUrl> &urls, const QImage &image) {
if (image.isNull()) {
for (const QUrl &url : urls) {
@@ -651,7 +651,7 @@ void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QList<QUrl> urls
}
void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QList<QUrl> urls, const QString &cover_filename) {
void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QList<QUrl> &urls, const QString &cover_filename) {
QFile file(cover_filename);
@@ -666,7 +666,7 @@ void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QList<QUrl> urls
}
void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QList<QUrl> urls, const QByteArray &image_data) {
void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QList<QUrl> &urls, const QByteArray &image_data) {
for (const QUrl &url : urls) {
SaveEmbeddedCover(id, url.toLocalFile(), image_data);

View File

@@ -81,12 +81,12 @@ class AlbumCoverLoader : public QObject {
void CancelTask(const quint64 id);
void CancelTasks(const QSet<quint64> &ids);
qint64 SaveEmbeddedCoverAsync(const QString song_filename, const QString &cover_filename);
qint64 SaveEmbeddedCoverAsync(const QString song_filename, const QImage &image);
qint64 SaveEmbeddedCoverAsync(const QString song_filename, const QByteArray &image_data);
qint64 SaveEmbeddedCoverAsync(const QList<QUrl> urls, const QString &cover_filename);
qint64 SaveEmbeddedCoverAsync(const QList<QUrl> urls, const QImage &image);
qint64 SaveEmbeddedCoverAsync(const QList<QUrl> urls, const QByteArray &image_data);
qint64 SaveEmbeddedCoverAsync(const QString &song_filename, const QString &cover_filename);
qint64 SaveEmbeddedCoverAsync(const QString &song_filename, const QImage &image);
qint64 SaveEmbeddedCoverAsync(const QString &song_filename, const QByteArray &image_data);
qint64 SaveEmbeddedCoverAsync(const QList<QUrl> &urls, const QString &cover_filename);
qint64 SaveEmbeddedCoverAsync(const QList<QUrl> &urls, const QImage &image);
qint64 SaveEmbeddedCoverAsync(const QList<QUrl> &urls, const QByteArray &image_data);
signals:
void ExitFinished();
@@ -98,12 +98,12 @@ class AlbumCoverLoader : public QObject {
void ProcessTasks();
void RemoteFetchFinished(QNetworkReply *reply, const QUrl &cover_url);
void SaveEmbeddedCover(const qint64 id, const QString song_filename, const QString &cover_filename);
void SaveEmbeddedCover(const qint64 id, const QString song_filename, const QImage &image);
void SaveEmbeddedCover(const qint64 id, const QString song_filename, const QByteArray &image_data);
void SaveEmbeddedCover(const qint64 id, const QList<QUrl> urls, const QImage &image);
void SaveEmbeddedCover(const qint64 id, const QList<QUrl> urls, const QString &cover_filename);
void SaveEmbeddedCover(const qint64 id, const QList<QUrl> urls, const QByteArray &image_data);
void SaveEmbeddedCover(const qint64 id, const QString &song_filename, const QString &cover_filename);
void SaveEmbeddedCover(const qint64 id, const QString &song_filename, const QImage &image);
void SaveEmbeddedCover(const qint64 id, const QString &song_filename, const QByteArray &image_data);
void SaveEmbeddedCover(const qint64 id, const QList<QUrl> &urls, const QImage &image);
void SaveEmbeddedCover(const qint64 id, const QList<QUrl> &urls, const QString &cover_filename);
void SaveEmbeddedCover(const qint64 id, const QList<QUrl> &urls, const QByteArray &image_data);
void SaveEmbeddedArtFinished(const qint64 id, TagReaderReply *reply, const bool cleared);

View File

@@ -594,7 +594,7 @@ bool AlbumCoverManager::eventFilter(QObject *obj, QEvent *e) {
if (obj == ui_->albums && e->type() == QEvent::ContextMenu) {
context_menu_items_ = ui_->albums->selectedItems();
if (context_menu_items_.isEmpty()) return false;
if (context_menu_items_.isEmpty()) return QMainWindow::eventFilter(obj, e);
bool some_with_covers = false;
bool some_unset = false;
@@ -624,6 +624,7 @@ bool AlbumCoverManager::eventFilter(QObject *obj, QEvent *e) {
context_menu_->popup(context_menu_event->globalPos());
return true;
}
return QMainWindow::eventFilter(obj, e);
}

View File

@@ -67,6 +67,9 @@ class AlbumItem : public QListWidgetItem {
public:
AlbumItem(const QIcon &icon, const QString &text, QListWidget *parent = nullptr, int type = Type) : QListWidgetItem(icon, text, parent, type) {};
QList<QUrl> urls;
private:
Q_DISABLE_COPY(AlbumItem)
};
class AlbumCoverManager : public QMainWindow {

View File

@@ -57,6 +57,7 @@ QMimeData *AlbumCoverManagerList::mimeData(const QList<QListWidgetItem*> items)
// Get URLs from the songs
QList<QUrl> urls;
urls.reserve(songs.count());
for (const Song &song : songs) {
urls << song.url();
}

View File

@@ -178,7 +178,7 @@ AlbumCoverImageResult AlbumCoverSearcher::Exec(const QString &artist, const QStr
return AlbumCoverImageResult();
AlbumCoverImageResult result;
result.image_data = selected.data(Role_ImageData).value<QByteArray>();
result.image_data = selected.data(Role_ImageData).toByteArray();
result.image = selected.data(Role_Image).value<QImage>();
result.mime_type = Utilities::MimeTypeFromData(result.image_data);

View File

@@ -52,6 +52,8 @@ class Application;
class Ui_AlbumCoverSearcher;
class SizeOverlayDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
static const int kMargin;
static const int kPaddingX;

View File

@@ -32,7 +32,8 @@
#include "albumcoverexport.h"
#include "coverexportrunnable.h"
CoverExportRunnable::CoverExportRunnable(const AlbumCoverExport::DialogResult &dialog_result, const Song &song) :
CoverExportRunnable::CoverExportRunnable(const AlbumCoverExport::DialogResult &dialog_result, const Song &song, QObject *parent) :
QObject(parent),
dialog_result_(dialog_result),
song_(song) {}

View File

@@ -34,7 +34,7 @@ class CoverExportRunnable : public QObject, public QRunnable {
Q_OBJECT
public:
explicit CoverExportRunnable(const AlbumCoverExport::DialogResult &dialog_result, const Song &song);
explicit CoverExportRunnable(const AlbumCoverExport::DialogResult &dialog_result, const Song &song, QObject *parent = nullptr);
void run() override;

View File

@@ -61,7 +61,7 @@ void CoverProviders::ReloadSettings() {
QSettings s;
s.beginGroup(CoversSettingsPage::kSettingsGroup);
QStringList providers_enabled = s.value("providers", QStringList() << all_providers.values()).toStringList();
QStringList providers_enabled = s.value("providers", QStringList() << all_providers.values()).toStringList(); // clazy:exclude=qt6-deprecated-api-fixes
s.endGroup();
int i = 0;
@@ -71,7 +71,7 @@ void CoverProviders::ReloadSettings() {
if (provider) {
provider->set_enabled(true);
provider->set_order(++i);
new_providers << provider;
new_providers << provider; // clazy:exclude=reserve-candidates
}
}

View File

@@ -310,7 +310,7 @@ void DeezerCoverProvider::HandleSearchReply(QNetworkReply *reply, const int id)
emit SearchFinished(id, CoverProviderSearchResults());
}
else {
CoverProviderSearchResults cover_results = results.values();
CoverProviderSearchResults cover_results = results.values(); // clazy:exclude=qt6-deprecated-api-fixes
std::stable_sort(cover_results.begin(), cover_results.end(), AlbumCoverFetcherSearch::CoverProviderSearchResultCompareNumber);
emit SearchFinished(id, cover_results);
}

View File

@@ -268,12 +268,14 @@ void DiscogsCoverProvider::HandleSearchReply(QNetworkReply *reply, const int id)
return;
}
QJsonArray array_results;
if (value_results.isArray()) {
array_results = value_results.toArray();
if (!value_results.isArray()) {
Error("Missing results array.", value_results);
EndSearch(search);
return;
}
for (const QJsonValueRef value_result : array_results) {
QJsonArray array_results = value_results.toArray();
for (QJsonValueRef value_result : array_results) {
if (!value_result.isObject()) {
Error("Invalid Json reply, results value is not a object.");
@@ -328,7 +330,7 @@ void DiscogsCoverProvider::StartReleaseRequest(std::shared_ptr<DiscogsCoverSearc
}
void DiscogsCoverProvider::SendReleaseRequest(const DiscogsCoverReleaseContext release) {
void DiscogsCoverProvider::SendReleaseRequest(const DiscogsCoverReleaseContext &release) {
QNetworkReply *reply = CreateRequest(release.url);
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, release]() { HandleReleaseReply(reply, release.search_id, release.id); } );

View File

@@ -81,7 +81,7 @@ class DiscogsCoverProvider : public JsonCoverProvider {
typedef QList<Param> ParamList;
void SendSearchRequest(std::shared_ptr<DiscogsCoverSearchContext> search);
void SendReleaseRequest(const DiscogsCoverReleaseContext release);
void SendReleaseRequest(const DiscogsCoverReleaseContext &release);
QNetworkReply *CreateRequest(QUrl url, const ParamList &params_provided = ParamList());
QByteArray GetReplyData(QNetworkReply *reply);
void StartReleaseRequest(std::shared_ptr<DiscogsCoverSearchContext> search, const quint64 release_id, const QUrl &url);

View File

@@ -205,7 +205,7 @@ void SpotifyCoverProvider::RedirectArrived() {
}
void SpotifyCoverProvider::RequestAccessToken(const QString code, const QUrl redirect_url) {
void SpotifyCoverProvider::RequestAccessToken(const QString &code, const QUrl &redirect_url) {
refresh_login_timer_.stop();
@@ -250,7 +250,7 @@ void SpotifyCoverProvider::RequestAccessToken(const QString code, const QUrl red
}
void SpotifyCoverProvider::HandleLoginSSLErrors(QList<QSslError> ssl_errors) {
void SpotifyCoverProvider::HandleLoginSSLErrors(const QList<QSslError> &ssl_errors) {
for (const QSslError &ssl_error : ssl_errors) {
login_errors_ += ssl_error.errorString();

View File

@@ -56,7 +56,7 @@ class SpotifyCoverProvider : public JsonCoverProvider {
bool IsAuthenticated() const override { return !access_token_.isEmpty(); }
private slots:
void HandleLoginSSLErrors(QList<QSslError> ssl_errors);
void HandleLoginSSLErrors(const QList<QSslError> &ssl_errors);
void RedirectArrived();
void AccessTokenRequestFinished(QNetworkReply *reply);
void HandleSearchReply(QNetworkReply *reply, const int id, const QString &extract);
@@ -66,7 +66,7 @@ class SpotifyCoverProvider : public JsonCoverProvider {
QByteArray GetReplyData(QNetworkReply *reply);
void AuthError(const QString &error = QString(), const QVariant &debug = QVariant());
void Error(const QString &error, const QVariant &debug = QVariant()) override;
void RequestAccessToken(const QString code = QString(), const QUrl redirect_url = QUrl());
void RequestAccessToken(const QString &code = QString(), const QUrl &redirect_url = QUrl());
private:
typedef QPair<QString, QString> Param;