From ed3eca74096d106efa15cf72847cf79a13d8f051 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Tue, 11 Feb 2020 17:28:41 +0100 Subject: [PATCH] library: Get rid of special color constants and use NULL instead --- src/library/basesqltablemodel.cpp | 4 ++-- src/library/basetrackcache.cpp | 5 +---- src/library/colordelegate.cpp | 24 ++++++++---------------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/library/basesqltablemodel.cpp b/src/library/basesqltablemodel.cpp index d3f370b7745..9157f918b62 100644 --- a/src/library/basesqltablemodel.cpp +++ b/src/library/basesqltablemodel.cpp @@ -787,8 +787,8 @@ QVariant BaseSqlTableModel::data(const QModelIndex& index, int role) const { } else if (column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_REPLAYGAIN)) { value = mixxx::ReplayGain::ratioToString(value.toDouble()); } else if (column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COLOR)) { - QRgb rgb = QRgb(value.toUInt()); - value = QVariant::fromValue(QColor(rgb)); + mixxx::RgbColor::optional_t color = value.isNull() ? std::nullopt : mixxx::RgbColor::optional_t(mixxx::RgbColor(value.toUInt())); + value = toQVariant(color); } // Otherwise, just use the column value. break; diff --git a/src/library/basetrackcache.cpp b/src/library/basetrackcache.cpp index e51e34d560c..59efc01a90a 100644 --- a/src/library/basetrackcache.cpp +++ b/src/library/basetrackcache.cpp @@ -15,8 +15,6 @@ namespace { constexpr bool sDebug = false; -constexpr mixxx::RgbColor kDefaultTrackColor = mixxx::RgbColor(0x000000); // black - } // namespace BaseTrackCache::BaseTrackCache(TrackCollection* pTrackCollection, @@ -472,8 +470,7 @@ void BaseTrackCache::getTrackValueForColumn(TrackPointer pTrack, } else if (fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK) == column) { trackValue.setValue(pTrack->isBpmLocked()); } else if (fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COLOR) == column) { - trackValue.setValue(toQVariant( - pTrack->getColor().value_or(kDefaultTrackColor))); + trackValue.setValue(toQVariant(pTrack->getColor())); } else if (fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_LOCATION) == column) { trackValue.setValue(pTrack->getCoverInfo().coverLocation); } else if (fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_HASH) == column || diff --git a/src/library/colordelegate.cpp b/src/library/colordelegate.cpp index 6da5a64fbeb..61bea17aa65 100644 --- a/src/library/colordelegate.cpp +++ b/src/library/colordelegate.cpp @@ -1,37 +1,29 @@ #include "library/colordelegate.h" +#include #include #include -#include #include #include "library/trackmodel.h" - -namespace { - const QRgb hiddenTrackColor = 0xFF000000; -} +#include "util/color/rgbcolor.h" ColorDelegate::ColorDelegate(QTableView* pTableView) : TableItemDelegate(pTableView) { } void ColorDelegate::paintItem(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { - VERIFY_OR_DEBUG_ASSERT(index.data().canConvert()) { - return; - } - - QColor color = qvariant_cast(index.data()); - VERIFY_OR_DEBUG_ASSERT(color.isValid()) { - return; - } - - // Filter out track color that is hidden - if (color.rgb() == hiddenTrackColor) { + DEBUG_ASSERT(index.data().isValid()); + if (index.data().isNull()) { + // Filter out track color that is hidden if (option.state & QStyle::State_Selected) { painter->fillRect(option.rect, option.palette.highlight()); } return; } + + QColor color = mixxx::toQColor(mixxx::RgbColor(index.data().toUInt())); + qWarning() << "trackColor" << color; painter->fillRect(option.rect, color); // Paint transparent highlight if row is selected