From 70fdd5b0b3a2c29060aa0342e3c4c8b3fbf2c46e Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sun, 28 Jul 2024 01:24:56 +0200 Subject: [PATCH] Use anonymous namespace instead of static for constants --- src/covermanager/albumcoverexporter.cpp | 4 +++- src/covermanager/albumcoverexporter.h | 2 -- src/covermanager/albumcoverfetcher.cpp | 4 +++- src/covermanager/albumcoverfetcher.h | 2 -- src/covermanager/albumcoverfetchersearch.cpp | 10 ++++++---- src/covermanager/albumcoverfetchersearch.h | 5 ----- src/covermanager/albumcovermanager.cpp | 6 ++++-- src/covermanager/albumcovermanager.h | 3 --- src/covermanager/albumcoversearcher.cpp | 16 +++++++++------- src/covermanager/albumcoversearcher.h | 8 -------- 10 files changed, 25 insertions(+), 35 deletions(-) diff --git a/src/covermanager/albumcoverexporter.cpp b/src/covermanager/albumcoverexporter.cpp index bb7859fe..f16e07e4 100644 --- a/src/covermanager/albumcoverexporter.cpp +++ b/src/covermanager/albumcoverexporter.cpp @@ -29,7 +29,9 @@ #include "albumcoverexporter.h" #include "coverexportrunnable.h" -const int AlbumCoverExporter::kMaxConcurrentRequests = 3; +namespace { +constexpr int kMaxConcurrentRequests = 3; +} AlbumCoverExporter::AlbumCoverExporter(QObject *parent) : QObject(parent), diff --git a/src/covermanager/albumcoverexporter.h b/src/covermanager/albumcoverexporter.h index e762d653..5082856e 100644 --- a/src/covermanager/albumcoverexporter.h +++ b/src/covermanager/albumcoverexporter.h @@ -40,8 +40,6 @@ class AlbumCoverExporter : public QObject { public: explicit AlbumCoverExporter(QObject *parent = nullptr); - static const int kMaxConcurrentRequests; - void SetDialogResult(const AlbumCoverExport::DialogResult &dialog_result); void SetCoverTypes(const AlbumCoverLoaderOptions::Types &cover_types); void AddExportRequest(const Song &song); diff --git a/src/covermanager/albumcoverfetcher.cpp b/src/covermanager/albumcoverfetcher.cpp index 9497515d..59f78059 100644 --- a/src/covermanager/albumcoverfetcher.cpp +++ b/src/covermanager/albumcoverfetcher.cpp @@ -36,7 +36,9 @@ using namespace std::chrono_literals; -const int AlbumCoverFetcher::kMaxConcurrentRequests = 5; +namespace { +constexpr int kMaxConcurrentRequests = 5; +} AlbumCoverFetcher::AlbumCoverFetcher(SharedPtr cover_providers, SharedPtr network, QObject *parent) : QObject(parent), diff --git a/src/covermanager/albumcoverfetcher.h b/src/covermanager/albumcoverfetcher.h index f9714731..57fca1c8 100644 --- a/src/covermanager/albumcoverfetcher.h +++ b/src/covermanager/albumcoverfetcher.h @@ -112,8 +112,6 @@ class AlbumCoverFetcher : public QObject { explicit AlbumCoverFetcher(SharedPtr cover_providers, SharedPtr network, QObject *parent = nullptr); ~AlbumCoverFetcher() override; - static const int kMaxConcurrentRequests; - quint64 SearchForCovers(const QString &artist, const QString &album, const QString &title = QString()); quint64 FetchAlbumCover(const QString &artist, const QString &album, const QString &title, const bool batch); diff --git a/src/covermanager/albumcoverfetchersearch.cpp b/src/covermanager/albumcoverfetchersearch.cpp index d5e149f7..408a6a9c 100644 --- a/src/covermanager/albumcoverfetchersearch.cpp +++ b/src/covermanager/albumcoverfetchersearch.cpp @@ -47,10 +47,12 @@ #include "coverproviders.h" #include "albumcoverimageresult.h" -const int AlbumCoverFetcherSearch::kSearchTimeoutMs = 20000; -const int AlbumCoverFetcherSearch::kImageLoadTimeoutMs = 6000; -const int AlbumCoverFetcherSearch::kTargetSize = 500; -const float AlbumCoverFetcherSearch::kGoodScore = 4.0; +namespace { +constexpr int kSearchTimeoutMs = 20000; +constexpr int kImageLoadTimeoutMs = 6000; +constexpr int kTargetSize = 500; +constexpr float kGoodScore = 4.0; +} // namespace AlbumCoverFetcherSearch::AlbumCoverFetcherSearch(const CoverSearchRequest &request, SharedPtr network, QObject *parent) : QObject(parent), diff --git a/src/covermanager/albumcoverfetchersearch.h b/src/covermanager/albumcoverfetchersearch.h index 4c4907d1..de98f075 100644 --- a/src/covermanager/albumcoverfetchersearch.h +++ b/src/covermanager/albumcoverfetchersearch.h @@ -90,11 +90,6 @@ class AlbumCoverFetcherSearch : public QObject { static bool CoverProviderSearchResultCompareScore(const CoverProviderSearchResult &a, const CoverProviderSearchResult &b); private: - static const int kSearchTimeoutMs; - static const int kImageLoadTimeoutMs; - static const int kTargetSize; - static const float kGoodScore; - CoverSearchStatistics statistics_; // Search request encapsulated by this AlbumCoverFetcherSearch. diff --git a/src/covermanager/albumcovermanager.cpp b/src/covermanager/albumcovermanager.cpp index 30b4e5f5..f2924d31 100644 --- a/src/covermanager/albumcovermanager.cpp +++ b/src/covermanager/albumcovermanager.cpp @@ -95,8 +95,10 @@ #include "ui_albumcovermanager.h" -const char *AlbumCoverManager::kSettingsGroup = "CoverManager"; -constexpr int AlbumCoverManager::kThumbnailSize = 120; +namespace { +constexpr char kSettingsGroup[] = "CoverManager"; +constexpr int kThumbnailSize = 120; +} AlbumCoverManager::AlbumCoverManager(Application *app, SharedPtr collection_backend, QMainWindow *mainwindow, QWidget *parent) : QMainWindow(parent), diff --git a/src/covermanager/albumcovermanager.h b/src/covermanager/albumcovermanager.h index 1742dcd3..c8d21c15 100644 --- a/src/covermanager/albumcovermanager.h +++ b/src/covermanager/albumcovermanager.h @@ -185,9 +185,6 @@ class AlbumCoverManager : public QMainWindow { void SaveEmbeddedCoverFinished(TagReaderReply *reply, AlbumItem *album_item, const QUrl &url, const bool art_embedded); private: - static const char *kSettingsGroup; - static const int kThumbnailSize; - Ui_CoverManager *ui_; QMainWindow *mainwindow_; Application *app_; diff --git a/src/covermanager/albumcoversearcher.cpp b/src/covermanager/albumcoversearcher.cpp index 2855683f..71c8fbd2 100644 --- a/src/covermanager/albumcoversearcher.cpp +++ b/src/covermanager/albumcoversearcher.cpp @@ -62,13 +62,15 @@ #include "albumcoverimageresult.h" #include "ui_albumcoversearcher.h" -const int SizeOverlayDelegate::kMargin = 4; -const int SizeOverlayDelegate::kPaddingX = 3; -const int SizeOverlayDelegate::kPaddingY = 1; -const qreal SizeOverlayDelegate::kBorder = 5.0; -const qreal SizeOverlayDelegate::kFontPointSize = 7.5; -const int SizeOverlayDelegate::kBorderAlpha = 200; -const int SizeOverlayDelegate::kBackgroundAlpha = 175; +namespace { +constexpr int kMargin = 4; +constexpr int kPaddingX = 3; +constexpr int kPaddingY = 1; +constexpr qreal kBorder = 5.0; +constexpr qreal kFontPointSize = 7.5; +constexpr int kBorderAlpha = 200; +constexpr int kBackgroundAlpha = 175; +} // namespace SizeOverlayDelegate::SizeOverlayDelegate(QObject *parent) : QStyledItemDelegate(parent) {} diff --git a/src/covermanager/albumcoversearcher.h b/src/covermanager/albumcoversearcher.h index 73505d83..30d26b81 100644 --- a/src/covermanager/albumcoversearcher.h +++ b/src/covermanager/albumcoversearcher.h @@ -55,14 +55,6 @@ class SizeOverlayDelegate : public QStyledItemDelegate { Q_OBJECT public: - static const int kMargin; - static const int kPaddingX; - static const int kPaddingY; - static const qreal kBorder; - static const qreal kFontPointSize; - static const int kBorderAlpha; - static const int kBackgroundAlpha; - explicit SizeOverlayDelegate(QObject *parent = nullptr); void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &idx) const override;