Change some parameters to const

This commit is contained in:
Jonas Kvinge
2020-05-06 22:26:29 +02:00
parent 727a1f5ad1
commit 4e4e596a1e
2 changed files with 54 additions and 54 deletions

View File

@@ -149,7 +149,7 @@ CollectionModel::~CollectionModel() {
delete root_; delete root_;
} }
void CollectionModel::set_pretty_covers(bool use_pretty_covers) { void CollectionModel::set_pretty_covers(const bool use_pretty_covers) {
if (use_pretty_covers != use_pretty_covers_) { if (use_pretty_covers != use_pretty_covers_) {
use_pretty_covers_ = use_pretty_covers; use_pretty_covers_ = use_pretty_covers;
@@ -157,7 +157,7 @@ void CollectionModel::set_pretty_covers(bool use_pretty_covers) {
} }
} }
void CollectionModel::set_show_dividers(bool show_dividers) { void CollectionModel::set_show_dividers(const bool show_dividers) {
if (show_dividers != show_dividers_) { if (show_dividers != show_dividers_) {
show_dividers_ = show_dividers; show_dividers_ = show_dividers;
@@ -199,7 +199,7 @@ void CollectionModel::ReloadSettings() {
} }
void CollectionModel::Init(bool async) { void CollectionModel::Init(const bool async) {
if (async) { if (async) {
// Show a loading indicator in the model. // Show a loading indicator in the model.
@@ -338,7 +338,7 @@ void CollectionModel::SongsSlightlyChanged(const SongList &songs) {
} }
CollectionItem *CollectionModel::CreateCompilationArtistNode(bool signal, CollectionItem *parent) { CollectionItem *CollectionModel::CreateCompilationArtistNode(const bool signal, CollectionItem *parent) {
if (signal) beginInsertRows(ItemToIndex(parent), parent->children.count(), parent->children.count()); if (signal) beginInsertRows(ItemToIndex(parent), parent->children.count(), parent->children.count());
@@ -354,7 +354,7 @@ CollectionItem *CollectionModel::CreateCompilationArtistNode(bool signal, Collec
} }
QString CollectionModel::DividerKey(GroupBy type, CollectionItem *item) const { QString CollectionModel::DividerKey(const GroupBy type, CollectionItem *item) const {
// Items which are to be grouped under the same divider must produce the same divider key. This will only get called for top-level items. // Items which are to be grouped under the same divider must produce the same divider key. This will only get called for top-level items.
@@ -408,7 +408,7 @@ QString CollectionModel::DividerKey(GroupBy type, CollectionItem *item) const {
} }
QString CollectionModel::DividerDisplayText(GroupBy type, const QString &key) const { QString CollectionModel::DividerDisplayText(const GroupBy type, const QString &key) const {
// Pretty display text for the dividers. // Pretty display text for the dividers.
@@ -658,7 +658,7 @@ void CollectionModel::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderR
} }
QVariant CollectionModel::data(const QModelIndex &idx, int role) const { QVariant CollectionModel::data(const QModelIndex &idx, const int role) const {
const CollectionItem *item = IndexToItem(idx); const CollectionItem *item = IndexToItem(idx);
@@ -686,7 +686,7 @@ QVariant CollectionModel::data(const QModelIndex &idx, int role) const {
} }
QVariant CollectionModel::data(const CollectionItem *item, int role) const { QVariant CollectionModel::data(const CollectionItem *item, const int role) const {
GroupBy container_type = item->type == CollectionItem::Type_Container ? group_by_[item->container_level] : GroupBy_None; GroupBy container_type = item->type == CollectionItem::Type_Container ? group_by_[item->container_level] : GroupBy_None;
@@ -826,7 +826,7 @@ CollectionModel::QueryResult CollectionModel::RunQuery(CollectionItem *parent) {
} }
void CollectionModel::PostQuery(CollectionItem *parent, const CollectionModel::QueryResult &result, bool signal) { void CollectionModel::PostQuery(CollectionItem *parent, const CollectionModel::QueryResult &result, const bool signal) {
// Information about what we want the children to be // Information about what we want the children to be
int child_level = parent == root_ ? 0 : parent->container_level + 1; int child_level = parent == root_ ? 0 : parent->container_level + 1;
@@ -850,7 +850,7 @@ void CollectionModel::PostQuery(CollectionItem *parent, const CollectionModel::Q
} }
void CollectionModel::LazyPopulate(CollectionItem *parent, bool signal) { void CollectionModel::LazyPopulate(CollectionItem *parent, const bool signal) {
if (parent->lazy_loaded) return; if (parent->lazy_loaded) return;
parent->lazy_loaded = true; parent->lazy_loaded = true;
@@ -918,7 +918,7 @@ void CollectionModel::Reset() {
} }
void CollectionModel::InitQuery(GroupBy type, CollectionQuery *q) { void CollectionModel::InitQuery(const GroupBy type, CollectionQuery *q) {
// Say what type of thing we want to get back from the database. // Say what type of thing we want to get back from the database.
switch (type) { switch (type) {
@@ -986,7 +986,7 @@ void CollectionModel::InitQuery(GroupBy type, CollectionQuery *q) {
} }
void CollectionModel::FilterQuery(GroupBy type, CollectionItem *item, CollectionQuery *q) { void CollectionModel::FilterQuery(const GroupBy type, CollectionItem *item, CollectionQuery *q) {
// Say how we want the query to be filtered. This is done once for each parent going up the tree. // Say how we want the query to be filtered. This is done once for each parent going up the tree.
@@ -1079,7 +1079,7 @@ void CollectionModel::FilterQuery(GroupBy type, CollectionItem *item, Collection
} }
CollectionItem *CollectionModel::InitItem(GroupBy type, bool signal, CollectionItem *parent, int container_level) { CollectionItem *CollectionModel::InitItem(const GroupBy type, const bool signal, CollectionItem *parent, const int container_level) {
CollectionItem::Type item_type = type == GroupBy_None ? CollectionItem::Type_Song : CollectionItem::Type_Container; CollectionItem::Type item_type = type == GroupBy_None ? CollectionItem::Type_Song : CollectionItem::Type_Container;
@@ -1094,7 +1094,7 @@ CollectionItem *CollectionModel::InitItem(GroupBy type, bool signal, CollectionI
} }
CollectionItem *CollectionModel::ItemFromQuery(GroupBy type, bool signal, bool create_divider, CollectionItem *parent, const SqlRow &row, int container_level) { CollectionItem *CollectionModel::ItemFromQuery(const GroupBy type, const bool signal, const bool create_divider, CollectionItem *parent, const SqlRow &row, const int container_level) {
CollectionItem *item = InitItem(type, signal, parent, container_level); CollectionItem *item = InitItem(type, signal, parent, container_level);
@@ -1232,7 +1232,7 @@ CollectionItem *CollectionModel::ItemFromQuery(GroupBy type, bool signal, bool c
} }
CollectionItem *CollectionModel::ItemFromSong(GroupBy type, bool signal, bool create_divider, CollectionItem *parent, const Song &s, int container_level) { CollectionItem *CollectionModel::ItemFromSong(const GroupBy type, const bool signal, const bool create_divider, CollectionItem *parent, const Song &s, const int container_level) {
CollectionItem *item = InitItem(type, signal, parent, container_level); CollectionItem *item = InitItem(type, signal, parent, container_level);
@@ -1379,7 +1379,7 @@ CollectionItem *CollectionModel::ItemFromSong(GroupBy type, bool signal, bool cr
} }
void CollectionModel::FinishItem(GroupBy type, bool signal, bool create_divider, CollectionItem *parent, CollectionItem *item) { void CollectionModel::FinishItem(const GroupBy type, const bool signal, const bool create_divider, CollectionItem *parent, CollectionItem *item) {
if (type == GroupBy_None) item->lazy_loaded = true; if (type == GroupBy_None) item->lazy_loaded = true;
@@ -1471,19 +1471,19 @@ QString CollectionModel::SortTextForArtist(QString artist) {
} }
QString CollectionModel::SortTextForNumber(int number) { QString CollectionModel::SortTextForNumber(const int number) {
return QString("%1").arg(number, 4, 10, QChar('0')); return QString("%1").arg(number, 4, 10, QChar('0'));
} }
QString CollectionModel::SortTextForYear(int year) { QString CollectionModel::SortTextForYear(const int year) {
QString str = QString::number(year); QString str = QString::number(year);
return QString("0").repeated(qMax(0, 4 - str.length())) + str; return QString("0").repeated(qMax(0, 4 - str.length())) + str;
} }
QString CollectionModel::SortTextForBitrate(int bitrate) { QString CollectionModel::SortTextForBitrate(const int bitrate) {
QString str = QString::number(bitrate); QString str = QString::number(bitrate);
return QString("0").repeated(qMax(0, 3 - str.length())) + str; return QString("0").repeated(qMax(0, 3 - str.length())) + str;
@@ -1607,7 +1607,7 @@ SongList CollectionModel::GetChildSongs(const QModelIndex &idx) const {
return GetChildSongs(QModelIndexList() << idx); return GetChildSongs(QModelIndexList() << idx);
} }
void CollectionModel::SetFilterAge(int age) { void CollectionModel::SetFilterAge(const int age) {
query_options_.set_max_age(age); query_options_.set_max_age(age);
ResetAsync(); ResetAsync();
} }
@@ -1642,7 +1642,7 @@ void CollectionModel::SetGroupBy(const Grouping &g) {
} }
const CollectionModel::GroupBy &CollectionModel::Grouping::operator[](int i) const { const CollectionModel::GroupBy &CollectionModel::Grouping::operator[](const int i) const {
switch (i) { switch (i) {
case 0: return first; case 0: return first;
@@ -1654,7 +1654,7 @@ const CollectionModel::GroupBy &CollectionModel::Grouping::operator[](int i) con
} }
CollectionModel::GroupBy &CollectionModel::Grouping::operator[](int i) { CollectionModel::GroupBy &CollectionModel::Grouping::operator[](const int i) {
switch (i) { switch (i) {
case 0: return first; case 0: return first;
@@ -1668,21 +1668,21 @@ CollectionModel::GroupBy &CollectionModel::Grouping::operator[](int i) {
} }
void CollectionModel::TotalSongCountUpdatedSlot(int count) { void CollectionModel::TotalSongCountUpdatedSlot(const int count) {
total_song_count_ = count; total_song_count_ = count;
emit TotalSongCountUpdated(count); emit TotalSongCountUpdated(count);
} }
void CollectionModel::TotalArtistCountUpdatedSlot(int count) { void CollectionModel::TotalArtistCountUpdatedSlot(const int count) {
total_artist_count_ = count; total_artist_count_ = count;
emit TotalArtistCountUpdated(count); emit TotalArtistCountUpdated(count);
} }
void CollectionModel::TotalAlbumCountUpdatedSlot(int count) { void CollectionModel::TotalAlbumCountUpdatedSlot(const int count) {
total_album_count_ = count; total_album_count_ = count;
emit TotalAlbumCountUpdated(count); emit TotalAlbumCountUpdated(count);

View File

@@ -114,8 +114,8 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
GroupBy second; GroupBy second;
GroupBy third; GroupBy third;
const GroupBy &operator[](int i) const; const GroupBy &operator[](const int i) const;
GroupBy &operator[](int i); GroupBy &operator[](const int i);
bool operator==(const Grouping &other) const { bool operator==(const Grouping &other) const {
return first == other.first && second == other.second && third == other.third; return first == other.first && second == other.second && third == other.third;
} }
@@ -133,7 +133,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
CollectionDirectoryModel *directory_model() const { return dir_model_; } CollectionDirectoryModel *directory_model() const { return dir_model_; }
// Call before Init() // Call before Init()
void set_show_various_artists(bool show_various_artists) { show_various_artists_ = show_various_artists; } void set_show_various_artists(const bool show_various_artists) { show_various_artists_ = show_various_artists; }
// Get information about the collection // Get information about the collection
void GetChildSongs(CollectionItem *item, QList<QUrl> *urls, SongList *songs, QSet<int> *song_ids) const; void GetChildSongs(CollectionItem *item, QList<QUrl> *urls, SongList *songs, QSet<int> *song_ids) const;
@@ -146,18 +146,18 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
int total_album_count() const { return total_album_count_; } int total_album_count() const { return total_album_count_; }
// QAbstractItemModel // QAbstractItemModel
QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &idx, const int role = Qt::DisplayRole) const;
Qt::ItemFlags flags(const QModelIndex &idx) const; Qt::ItemFlags flags(const QModelIndex &idx) const;
QStringList mimeTypes() const; QStringList mimeTypes() const;
QMimeData *mimeData(const QModelIndexList &indexes) const; QMimeData *mimeData(const QModelIndexList &indexes) const;
bool canFetchMore(const QModelIndex &parent) const; bool canFetchMore(const QModelIndex &parent) const;
// Whether or not to use album cover art, if it exists, in the collection view // Whether or not to use album cover art, if it exists, in the collection view
void set_pretty_covers(bool use_pretty_covers); void set_pretty_covers(const bool use_pretty_covers);
bool use_pretty_covers() const { return use_pretty_covers_; } bool use_pretty_covers() const { return use_pretty_covers_; }
// Whether or not to show letters heading in the collection view // Whether or not to show letters heading in the collection view
void set_show_dividers(bool show_dividers); void set_show_dividers(const bool show_dividers);
// Save the current grouping // Save the current grouping
void SaveGrouping(QString name); void SaveGrouping(QString name);
@@ -171,43 +171,43 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
static QString PrettyAlbumDisc(const QString &album, const int disc); static QString PrettyAlbumDisc(const QString &album, const int disc);
static QString PrettyYearAlbumDisc(const int year, const QString &album, const int disc); static QString PrettyYearAlbumDisc(const int year, const QString &album, const int disc);
static QString SortText(QString text); static QString SortText(QString text);
static QString SortTextForNumber(int year); static QString SortTextForNumber(const int year);
static QString SortTextForArtist(QString artist); static QString SortTextForArtist(QString artist);
static QString SortTextForSong(const Song &song); static QString SortTextForSong(const Song &song);
static QString SortTextForYear(int year); static QString SortTextForYear(const int year);
static QString SortTextForBitrate(int bitrate); static QString SortTextForBitrate(const int bitrate);
quint64 icon_cache_disk_size() { return sIconCache->cacheSize(); } quint64 icon_cache_disk_size() { return sIconCache->cacheSize(); }
signals: signals:
void TotalSongCountUpdated(int count); void TotalSongCountUpdated(const int count);
void TotalArtistCountUpdated(int count); void TotalArtistCountUpdated(const int count);
void TotalAlbumCountUpdated(int count); void TotalAlbumCountUpdated(const int count);
void GroupingChanged(const CollectionModel::Grouping &g); void GroupingChanged(const CollectionModel::Grouping &g);
public slots: public slots:
void SetFilterAge(int age); void SetFilterAge(const int age);
void SetFilterText(const QString &text); void SetFilterText(const QString &text);
void SetFilterQueryMode(QueryOptions::QueryMode query_mode); void SetFilterQueryMode(QueryOptions::QueryMode query_mode);
void SetGroupBy(const CollectionModel::Grouping &g); void SetGroupBy(const CollectionModel::Grouping &g);
const CollectionModel::Grouping &GetGroupBy() const { return group_by_; } const CollectionModel::Grouping &GetGroupBy() const { return group_by_; }
void Init(bool async = true); void Init(const bool async = true);
void Reset(); void Reset();
void ResetAsync(); void ResetAsync();
protected: protected:
void LazyPopulate(CollectionItem *item) { LazyPopulate(item, true); } void LazyPopulate(CollectionItem *item) { LazyPopulate(item, true); }
void LazyPopulate(CollectionItem *item, bool signal); void LazyPopulate(CollectionItem *item, const bool signal);
private slots: private slots:
// From CollectionBackend // From CollectionBackend
void SongsDiscovered(const SongList &songs); void SongsDiscovered(const SongList &songs);
void SongsDeleted(const SongList &songs); void SongsDeleted(const SongList &songs);
void SongsSlightlyChanged(const SongList &songs); void SongsSlightlyChanged(const SongList &songs);
void TotalSongCountUpdatedSlot(int count); void TotalSongCountUpdatedSlot(const int count);
void TotalArtistCountUpdatedSlot(int count); void TotalArtistCountUpdatedSlot(const int count);
void TotalAlbumCountUpdatedSlot(int count); void TotalAlbumCountUpdatedSlot(const int count);
void ClearDiskCache(); void ClearDiskCache();
// Called after ResetAsync // Called after ResetAsync
@@ -219,7 +219,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
// Provides some optimisations for loading the list of items in the root. // Provides some optimisations for loading the list of items in the root.
// This gets called a lot when filtering the playlist, so it's nice to be able to do it in a background thread. // This gets called a lot when filtering the playlist, so it's nice to be able to do it in a background thread.
QueryResult RunQuery(CollectionItem *parent); QueryResult RunQuery(CollectionItem *parent);
void PostQuery(CollectionItem *parent, const QueryResult &result, bool signal); void PostQuery(CollectionItem *parent, const QueryResult &result, const bool signal);
bool HasCompilations(const CollectionQuery &query); bool HasCompilations(const CollectionQuery &query);
@@ -228,27 +228,27 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
// Functions for working with queries and creating items. // Functions for working with queries and creating items.
// When the model is reset or when a node is lazy-loaded the Collection constructs a database query to populate the items. // When the model is reset or when a node is lazy-loaded the Collection constructs a database query to populate the items.
// Filters are added for each parent item, restricting the songs returned to a particular album or artist for example. // Filters are added for each parent item, restricting the songs returned to a particular album or artist for example.
static void InitQuery(GroupBy type, CollectionQuery *q); static void InitQuery(const GroupBy type, CollectionQuery *q);
void FilterQuery(GroupBy type, CollectionItem *item, CollectionQuery *q); void FilterQuery(const GroupBy type, CollectionItem *item, CollectionQuery *q);
// Items can be created either from a query that's been run to populate a node, or by a spontaneous SongsDiscovered emission from the backend. // Items can be created either from a query that's been run to populate a node, or by a spontaneous SongsDiscovered emission from the backend.
CollectionItem *ItemFromQuery(GroupBy type, bool signal, bool create_divider, CollectionItem *parent, const SqlRow &row, int container_level); CollectionItem *ItemFromQuery(const GroupBy type, const bool signal, const bool create_divider, CollectionItem *parent, const SqlRow &row, const int container_level);
CollectionItem *ItemFromSong(GroupBy type, bool signal, bool create_divider, CollectionItem *parent, const Song &s, int container_level); CollectionItem *ItemFromSong(const GroupBy type, const bool signal, const bool create_divider, CollectionItem *parent, const Song &s, const int container_level);
// The "Various Artists" node is an annoying special case. // The "Various Artists" node is an annoying special case.
CollectionItem *CreateCompilationArtistNode(bool signal, CollectionItem *parent); CollectionItem *CreateCompilationArtistNode(const bool signal, CollectionItem *parent);
// Helpers for ItemFromQuery and ItemFromSong // Helpers for ItemFromQuery and ItemFromSong
CollectionItem *InitItem(GroupBy type, bool signal, CollectionItem *parent, int container_level); CollectionItem *InitItem(const GroupBy type, const bool signal, CollectionItem *parent, const int container_level);
void FinishItem(GroupBy type, bool signal, bool create_divider, CollectionItem *parent, CollectionItem *item); void FinishItem(const GroupBy type, const bool signal, const bool create_divider, CollectionItem *parent, CollectionItem *item);
QString DividerKey(GroupBy type, CollectionItem *item) const; QString DividerKey(const GroupBy type, CollectionItem *item) const;
QString DividerDisplayText(GroupBy type, const QString &key) const; QString DividerDisplayText(const GroupBy type, const QString &key) const;
// Helpers // Helpers
QString AlbumIconPixmapCacheKey(const QModelIndex &idx) const; QString AlbumIconPixmapCacheKey(const QModelIndex &idx) const;
QVariant AlbumIcon(const QModelIndex &idx); QVariant AlbumIcon(const QModelIndex &idx);
QVariant data(const CollectionItem *item, int role) const; QVariant data(const CollectionItem *item, const int role) const;
bool CompareItems(const CollectionItem *a, const CollectionItem *b) const; bool CompareItems(const CollectionItem *a, const CollectionItem *b) const;
int MaximumCacheSize(QSettings *s, const char *size_id, const char *size_unit_id, const int cache_size_default) const; int MaximumCacheSize(QSettings *s, const char *size_id, const char *size_unit_id, const int cache_size_default) const;
bool IsAlbumGrouping(const GroupBy group_by) const { return group_by == GroupBy_Album || group_by == GroupBy_YearAlbum || group_by == GroupBy_OriginalYearAlbum || group_by == GroupBy_AlbumDisc || group_by == GroupBy_YearAlbumDisc; } bool IsAlbumGrouping(const GroupBy group_by) const { return group_by == GroupBy_Album || group_by == GroupBy_YearAlbum || group_by == GroupBy_OriginalYearAlbum || group_by == GroupBy_AlbumDisc || group_by == GroupBy_YearAlbumDisc; }