Skip to content

Commit

Permalink
make kColumnPropertiesByEnum a constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Oct 22, 2024
1 parent 31473f6 commit 80d69e5
Showing 1 changed file with 52 additions and 51 deletions.
103 changes: 52 additions & 51 deletions src/library/columncache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const QString kSortNoCaseLex = mixxx::DbConnection::collateLexicographically(
QStringLiteral("lower(%1)"));

struct ColumnProperties {
QString name;
const QString* pName;
const char* pTrTitle;
int defaultWidth;
};
Expand All @@ -36,147 +36,147 @@ constexpr int kDefaultColumnWidth = 50;
#endif
#endif

const ColumnProperties kColumnPropertiesByEnum[] = {
DI(ColumnCache::COLUMN_LIBRARYTABLE_ID){LIBRARYTABLE_ID,
constexpr ColumnProperties kColumnPropertiesByEnum[] = {
DI(ColumnCache::COLUMN_LIBRARYTABLE_ID){&LIBRARYTABLE_ID,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_ARTIST){LIBRARYTABLE_ARTIST,
DI(ColumnCache::COLUMN_LIBRARYTABLE_ARTIST){&LIBRARYTABLE_ARTIST,
QT_TRANSLATE_NOOP("ColumnProperties", "Artist"),
kDefaultColumnWidth * 4},
DI(ColumnCache::COLUMN_LIBRARYTABLE_TITLE){LIBRARYTABLE_TITLE,
DI(ColumnCache::COLUMN_LIBRARYTABLE_TITLE){&LIBRARYTABLE_TITLE,
QT_TRANSLATE_NOOP("ColumnProperties", "Title"),
kDefaultColumnWidth * 4},
DI(ColumnCache::COLUMN_LIBRARYTABLE_ALBUM){LIBRARYTABLE_ALBUM,
DI(ColumnCache::COLUMN_LIBRARYTABLE_ALBUM){&LIBRARYTABLE_ALBUM,
QT_TRANSLATE_NOOP("ColumnProperties", "Album"),
kDefaultColumnWidth * 4},
DI(ColumnCache::COLUMN_LIBRARYTABLE_ALBUMARTIST){LIBRARYTABLE_ALBUMARTIST,
DI(ColumnCache::COLUMN_LIBRARYTABLE_ALBUMARTIST){&LIBRARYTABLE_ALBUMARTIST,
QT_TRANSLATE_NOOP("ColumnProperties", "Album Artist"),
kDefaultColumnWidth * 4},
DI(ColumnCache::COLUMN_LIBRARYTABLE_YEAR){LIBRARYTABLE_YEAR,
DI(ColumnCache::COLUMN_LIBRARYTABLE_YEAR){&LIBRARYTABLE_YEAR,
QT_TRANSLATE_NOOP("ColumnProperties", "Year"),
kDefaultColumnWidth},
DI(ColumnCache::COLUMN_LIBRARYTABLE_GENRE){LIBRARYTABLE_GENRE,
DI(ColumnCache::COLUMN_LIBRARYTABLE_GENRE){&LIBRARYTABLE_GENRE,
QT_TRANSLATE_NOOP("ColumnProperties", "Genre"),
kDefaultColumnWidth * 4},
DI(ColumnCache::COLUMN_LIBRARYTABLE_COMPOSER){LIBRARYTABLE_COMPOSER,
DI(ColumnCache::COLUMN_LIBRARYTABLE_COMPOSER){&LIBRARYTABLE_COMPOSER,
QT_TRANSLATE_NOOP("ColumnProperties", "Composer"),
kDefaultColumnWidth * 4},
DI(ColumnCache::COLUMN_LIBRARYTABLE_GROUPING){LIBRARYTABLE_GROUPING,
DI(ColumnCache::COLUMN_LIBRARYTABLE_GROUPING){&LIBRARYTABLE_GROUPING,
QT_TRANSLATE_NOOP("ColumnProperties", "Grouping"),
kDefaultColumnWidth * 4},
DI(ColumnCache::COLUMN_LIBRARYTABLE_TRACKNUMBER){LIBRARYTABLE_TRACKNUMBER,
DI(ColumnCache::COLUMN_LIBRARYTABLE_TRACKNUMBER){&LIBRARYTABLE_TRACKNUMBER,
QT_TRANSLATE_NOOP("ColumnProperties", "Track #"),
kDefaultColumnWidth},
DI(ColumnCache::COLUMN_LIBRARYTABLE_FILETYPE){LIBRARYTABLE_FILETYPE,
DI(ColumnCache::COLUMN_LIBRARYTABLE_FILETYPE){&LIBRARYTABLE_FILETYPE,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_COMMENT){LIBRARYTABLE_COMMENT,
DI(ColumnCache::COLUMN_LIBRARYTABLE_COMMENT){&LIBRARYTABLE_COMMENT,
QT_TRANSLATE_NOOP("ColumnProperties", "Comment"),
kDefaultColumnWidth * 6},
DI(ColumnCache::COLUMN_LIBRARYTABLE_DURATION){LIBRARYTABLE_DURATION,
DI(ColumnCache::COLUMN_LIBRARYTABLE_DURATION){&LIBRARYTABLE_DURATION,
QT_TRANSLATE_NOOP("ColumnProperties", "Duration"),
kDefaultColumnWidth},
DI(ColumnCache::COLUMN_LIBRARYTABLE_BITRATE){LIBRARYTABLE_BITRATE,
DI(ColumnCache::COLUMN_LIBRARYTABLE_BITRATE){&LIBRARYTABLE_BITRATE,
QT_TRANSLATE_NOOP("ColumnProperties", "Bitrate"),
kDefaultColumnWidth},
DI(ColumnCache::COLUMN_LIBRARYTABLE_BPM){LIBRARYTABLE_BPM,
DI(ColumnCache::COLUMN_LIBRARYTABLE_BPM){&LIBRARYTABLE_BPM,
QT_TRANSLATE_NOOP("ColumnProperties", "BPM"),
kDefaultColumnWidth * 2},
DI(ColumnCache::COLUMN_LIBRARYTABLE_REPLAYGAIN){LIBRARYTABLE_REPLAYGAIN,
DI(ColumnCache::COLUMN_LIBRARYTABLE_REPLAYGAIN){&LIBRARYTABLE_REPLAYGAIN,
QT_TRANSLATE_NOOP("ColumnProperties", "ReplayGain"),
kDefaultColumnWidth * 2},
DI(ColumnCache::COLUMN_LIBRARYTABLE_CUEPOINT){LIBRARYTABLE_CUEPOINT,
DI(ColumnCache::COLUMN_LIBRARYTABLE_CUEPOINT){&LIBRARYTABLE_CUEPOINT,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_URL){LIBRARYTABLE_URL,
DI(ColumnCache::COLUMN_LIBRARYTABLE_URL){&LIBRARYTABLE_URL,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_SAMPLERATE){LIBRARYTABLE_SAMPLERATE,
DI(ColumnCache::COLUMN_LIBRARYTABLE_SAMPLERATE){&LIBRARYTABLE_SAMPLERATE,
QT_TRANSLATE_NOOP("ColumnProperties", "Samplerate"),
kDefaultColumnWidth},
DI(ColumnCache::COLUMN_LIBRARYTABLE_WAVESUMMARYHEX){LIBRARYTABLE_WAVESUMMARYHEX,
DI(ColumnCache::COLUMN_LIBRARYTABLE_WAVESUMMARYHEX){&LIBRARYTABLE_WAVESUMMARYHEX,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_CHANNELS){LIBRARYTABLE_CHANNELS,
DI(ColumnCache::COLUMN_LIBRARYTABLE_CHANNELS){&LIBRARYTABLE_CHANNELS,
QT_TRANSLATE_NOOP("ColumnProperties", "Channels"),
kDefaultColumnWidth / 2},
DI(ColumnCache::COLUMN_LIBRARYTABLE_MIXXXDELETED){LIBRARYTABLE_MIXXXDELETED,
DI(ColumnCache::COLUMN_LIBRARYTABLE_MIXXXDELETED){&LIBRARYTABLE_MIXXXDELETED,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_DATETIMEADDED){LIBRARYTABLE_DATETIMEADDED,
DI(ColumnCache::COLUMN_LIBRARYTABLE_DATETIMEADDED){&LIBRARYTABLE_DATETIMEADDED,
QT_TRANSLATE_NOOP("ColumnProperties", "Date Added"),
kDefaultColumnWidth * 3},
DI(ColumnCache::COLUMN_LIBRARYTABLE_HEADERPARSED){LIBRARYTABLE_HEADERPARSED,
DI(ColumnCache::COLUMN_LIBRARYTABLE_HEADERPARSED){&LIBRARYTABLE_HEADERPARSED,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_TIMESPLAYED){LIBRARYTABLE_TIMESPLAYED,
DI(ColumnCache::COLUMN_LIBRARYTABLE_TIMESPLAYED){&LIBRARYTABLE_TIMESPLAYED,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED){LIBRARYTABLE_PLAYED,
DI(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED){&LIBRARYTABLE_PLAYED,
QT_TRANSLATE_NOOP("ColumnProperties", "Played"),
kDefaultColumnWidth * 2},
DI(ColumnCache::COLUMN_LIBRARYTABLE_RATING){LIBRARYTABLE_RATING,
DI(ColumnCache::COLUMN_LIBRARYTABLE_RATING){&LIBRARYTABLE_RATING,
QT_TRANSLATE_NOOP("ColumnProperties", "Rating"),
kDefaultColumnWidth * 2},
DI(ColumnCache::COLUMN_LIBRARYTABLE_KEY){LIBRARYTABLE_KEY,
DI(ColumnCache::COLUMN_LIBRARYTABLE_KEY){&LIBRARYTABLE_KEY,
QT_TRANSLATE_NOOP("ColumnProperties", "Key"),
kDefaultColumnWidth},
DI(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID){LIBRARYTABLE_KEY_ID,
DI(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID){&LIBRARYTABLE_KEY_ID,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK){LIBRARYTABLE_BPM_LOCK,
DI(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK){&LIBRARYTABLE_BPM_LOCK,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW){LIBRARYTABLE_PREVIEW,
DI(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW){&LIBRARYTABLE_PREVIEW,
QT_TRANSLATE_NOOP("ColumnProperties", "Preview"),
kDefaultColumnWidth / 2},
DI(ColumnCache::COLUMN_LIBRARYTABLE_COLOR){LIBRARYTABLE_COLOR,
DI(ColumnCache::COLUMN_LIBRARYTABLE_COLOR){&LIBRARYTABLE_COLOR,
QT_TRANSLATE_NOOP("ColumnProperties", "Color"),
kDefaultColumnWidth / 2},
DI(ColumnCache::COLUMN_LIBRARYTABLE_COVERART){LIBRARYTABLE_COVERART,
DI(ColumnCache::COLUMN_LIBRARYTABLE_COVERART){&LIBRARYTABLE_COVERART,
QT_TRANSLATE_NOOP("ColumnProperties", "Cover Art"),
kDefaultColumnWidth / 2},
DI(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_SOURCE){LIBRARYTABLE_COVERART_SOURCE,
DI(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_SOURCE){&LIBRARYTABLE_COVERART_SOURCE,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_TYPE){LIBRARYTABLE_COVERART_TYPE,
DI(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_TYPE){&LIBRARYTABLE_COVERART_TYPE,
QT_TRANSLATE_NOOP("ColumnProperties", "Type"),
kDefaultColumnWidth},
DI(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_LOCATION){LIBRARYTABLE_COVERART_LOCATION,
DI(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_LOCATION){&LIBRARYTABLE_COVERART_LOCATION,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_COLOR){LIBRARYTABLE_COVERART_COLOR,
DI(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_COLOR){&LIBRARYTABLE_COVERART_COLOR,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_DIGEST){LIBRARYTABLE_COVERART_DIGEST,
DI(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_DIGEST){&LIBRARYTABLE_COVERART_DIGEST,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_HASH){LIBRARYTABLE_COVERART_HASH,
DI(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_HASH){&LIBRARYTABLE_COVERART_HASH,
nullptr,
0},
DI(ColumnCache::COLUMN_LIBRARYTABLE_LAST_PLAYED_AT){LIBRARYTABLE_LAST_PLAYED_AT,
DI(ColumnCache::COLUMN_LIBRARYTABLE_LAST_PLAYED_AT){&LIBRARYTABLE_LAST_PLAYED_AT,
QT_TRANSLATE_NOOP("ColumnProperties", "Last Played"),
kDefaultColumnWidth * 3},
DI(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_LOCATION){TRACKLOCATIONSTABLE_LOCATION,
DI(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_LOCATION){&TRACKLOCATIONSTABLE_LOCATION,
QT_TRANSLATE_NOOP("ColumnProperties", "Location"),
kDefaultColumnWidth * 6},
DI(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED){TRACKLOCATIONSTABLE_FSDELETED,
DI(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED){&TRACKLOCATIONSTABLE_FSDELETED,
nullptr,
0},
DI(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_TRACKID){PLAYLISTTRACKSTABLE_TRACKID,
DI(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_TRACKID){&PLAYLISTTRACKSTABLE_TRACKID,
nullptr,
0},
DI(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION){PLAYLISTTRACKSTABLE_POSITION,
DI(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION){&PLAYLISTTRACKSTABLE_POSITION,
QT_TRANSLATE_NOOP("ColumnProperties", "#"),
kDefaultColumnWidth * 30 / 50},
DI(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_PLAYLISTID){PLAYLISTTRACKSTABLE_PLAYLISTID,
DI(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_PLAYLISTID){&PLAYLISTTRACKSTABLE_PLAYLISTID,
nullptr,
0},
DI(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_DATETIMEADDED){
PLAYLISTTRACKSTABLE_DATETIMEADDED,
&PLAYLISTTRACKSTABLE_DATETIMEADDED,
QT_TRANSLATE_NOOP("ColumnProperties", "Timestamp"),
kDefaultColumnWidth * 80 / 50},
DI(ColumnCache::COLUMN_REKORDBOX_ANALYZE_PATH){REKORDBOX_ANALYZE_PATH, nullptr, 0}};
DI(ColumnCache::COLUMN_REKORDBOX_ANALYZE_PATH){&REKORDBOX_ANALYZE_PATH, nullptr, 0}};
static_assert(std::size(kColumnPropertiesByEnum) == ColumnCache::NUM_COLUMNS);

#if defined(__clang__)
Expand Down Expand Up @@ -214,7 +214,7 @@ void ColumnCache::setColumns(QStringList columns) {
static_assert(std::size(kColumnPropertiesByEnum) ==
sizeof(m_columnIndexByEnum) / sizeof(m_columnIndexByEnum[0]));
for (std::size_t i = 0; i < std::size(kColumnPropertiesByEnum); ++i) {
m_columnIndexByEnum[i] = fieldIndex(kColumnPropertiesByEnum[i].name);
m_columnIndexByEnum[i] = fieldIndex(columnName(static_cast<Column>(i)));
}

m_columnSortByIndex.clear();
Expand Down Expand Up @@ -272,7 +272,8 @@ void ColumnCache::slotSetKeySortOrder(double notationValue) {

const QString& ColumnCache::columnName(Column column) const {
DEBUG_ASSERT(static_cast<std::size_t>(column) < std::size(kColumnPropertiesByEnum));
return kColumnPropertiesByEnum[column].name;
DEBUG_ASSERT(kColumnPropertiesByEnum[column].pName);
return *kColumnPropertiesByEnum[column].pName;
}

QString ColumnCache::columnTitle(Column column) const {
Expand Down

0 comments on commit 80d69e5

Please sign in to comment.