Use float for rating
This commit is contained in:
@@ -1948,7 +1948,7 @@ void CollectionBackend::UpdatePlayCount(const QString &artist, const QString &ti
|
||||
|
||||
}
|
||||
|
||||
void CollectionBackend::UpdateSongRating(const int id, const double rating, const bool save_tags) {
|
||||
void CollectionBackend::UpdateSongRating(const int id, const float rating, const bool save_tags) {
|
||||
|
||||
if (id == -1) return;
|
||||
|
||||
@@ -1956,7 +1956,7 @@ void CollectionBackend::UpdateSongRating(const int id, const double rating, cons
|
||||
|
||||
}
|
||||
|
||||
void CollectionBackend::UpdateSongsRating(const QList<int> &id_list, const double rating, const bool save_tags) {
|
||||
void CollectionBackend::UpdateSongsRating(const QList<int> &id_list, const float rating, const bool save_tags) {
|
||||
|
||||
if (id_list.isEmpty()) return;
|
||||
|
||||
@@ -1983,12 +1983,12 @@ void CollectionBackend::UpdateSongsRating(const QList<int> &id_list, const doubl
|
||||
|
||||
}
|
||||
|
||||
void CollectionBackend::UpdateSongRatingAsync(const int id, const double rating, const bool save_tags) {
|
||||
QMetaObject::invokeMethod(this, "UpdateSongRating", Qt::QueuedConnection, Q_ARG(int, id), Q_ARG(double, rating), Q_ARG(bool, save_tags));
|
||||
void CollectionBackend::UpdateSongRatingAsync(const int id, const float rating, const bool save_tags) {
|
||||
QMetaObject::invokeMethod(this, "UpdateSongRating", Qt::QueuedConnection, Q_ARG(int, id), Q_ARG(float, rating), Q_ARG(bool, save_tags));
|
||||
}
|
||||
|
||||
void CollectionBackend::UpdateSongsRatingAsync(const QList<int> &ids, const double rating, const bool save_tags) {
|
||||
QMetaObject::invokeMethod(this, "UpdateSongsRating", Qt::QueuedConnection, Q_ARG(QList<int>, ids), Q_ARG(double, rating), Q_ARG(bool, save_tags));
|
||||
void CollectionBackend::UpdateSongsRatingAsync(const QList<int> &ids, const float rating, const bool save_tags) {
|
||||
QMetaObject::invokeMethod(this, "UpdateSongsRating", Qt::QueuedConnection, Q_ARG(QList<int>, ids), Q_ARG(float, rating), Q_ARG(bool, save_tags));
|
||||
}
|
||||
|
||||
void CollectionBackend::UpdateLastSeen(const int directory_id, const int expire_unavailable_songs_days) {
|
||||
|
||||
@@ -212,8 +212,8 @@ class CollectionBackend : public CollectionBackendInterface {
|
||||
void AddOrUpdateSongsAsync(const SongList &songs);
|
||||
void UpdateSongsBySongIDAsync(const SongMap &new_songs);
|
||||
|
||||
void UpdateSongRatingAsync(const int id, const double rating, const bool save_tags = false);
|
||||
void UpdateSongsRatingAsync(const QList<int> &ids, const double rating, const bool save_tags = false);
|
||||
void UpdateSongRatingAsync(const int id, const float rating, const bool save_tags = false);
|
||||
void UpdateSongsRatingAsync(const QList<int> &ids, const float rating, const bool save_tags = false);
|
||||
|
||||
public slots:
|
||||
void Exit();
|
||||
@@ -240,8 +240,8 @@ class CollectionBackend : public CollectionBackendInterface {
|
||||
void UpdateLastPlayed(const QString &artist, const QString &album, const QString &title, const qint64 lastplayed);
|
||||
void UpdatePlayCount(const QString &artist, const QString &title, const int playcount);
|
||||
|
||||
void UpdateSongRating(const int id, const double rating, const bool save_tags = false);
|
||||
void UpdateSongsRating(const QList<int> &id_list, const double rating, const bool save_tags = false);
|
||||
void UpdateSongRating(const int id, const float rating, const bool save_tags = false);
|
||||
void UpdateSongsRating(const QList<int> &id_list, const float rating, const bool save_tags = false);
|
||||
|
||||
void UpdateLastSeen(const int directory_id, const int expire_unavailable_songs_days);
|
||||
void ExpireSongs(const int directory_id, const int expire_unavailable_songs_days);
|
||||
|
||||
@@ -224,7 +224,7 @@ struct Song::Private : public QSharedData {
|
||||
|
||||
QString cue_path_; // If the song has a CUE, this contains it's path.
|
||||
|
||||
double rating_; // Database rating, not read from tags.
|
||||
float rating_; // Database rating, initial rating read from tag.
|
||||
|
||||
QUrl stream_url_; // Temporary stream url set by url handler.
|
||||
QImage image_; // Album Cover image set by album cover loader.
|
||||
@@ -373,7 +373,7 @@ bool Song::init_from_file() const { return d->init_from_file_; }
|
||||
const QString &Song::cue_path() const { return d->cue_path_; }
|
||||
bool Song::has_cue() const { return !d->cue_path_.isEmpty(); }
|
||||
|
||||
double Song::rating() const { return d->rating_; }
|
||||
float Song::rating() const { return d->rating_; }
|
||||
|
||||
bool Song::is_collection_song() const { return d->source_ == Source_Collection; }
|
||||
bool Song::is_metadata_good() const { return !d->url_.isEmpty() && !d->artist_.isEmpty() && !d->title_.isEmpty(); }
|
||||
@@ -478,7 +478,7 @@ void Song::set_art_automatic(const QUrl &v) { d->art_automatic_ = v; }
|
||||
void Song::set_art_manual(const QUrl &v) { d->art_manual_ = v; }
|
||||
void Song::set_cue_path(const QString &v) { d->cue_path_ = v; }
|
||||
|
||||
void Song::set_rating(double v) { d->rating_ = v; }
|
||||
void Song::set_rating(float v) { d->rating_ = v; }
|
||||
|
||||
void Song::set_stream_url(const QUrl &v) { d->stream_url_ = v; }
|
||||
void Song::set_image(const QImage &i) { d->image_ = i; }
|
||||
@@ -922,7 +922,7 @@ void Song::ToProtobuf(spb::tagreader::SongMetadata *pb) const {
|
||||
#define tostr(n) (q.value(n).isNull() ? QString() : q.value(n).toString())
|
||||
#define toint(n) (q.value(n).isNull() ? -1 : q.value(n).toInt())
|
||||
#define tolonglong(n) (q.value(n).isNull() ? -1 : q.value(n).toLongLong())
|
||||
#define todouble(n) (q.value(n).isNull() ? -1 : q.value(n).toDouble())
|
||||
#define tofloat(n) (q.value(n).isNull() ? -1 : q.value(n).toFloat())
|
||||
|
||||
void Song::InitFromQuery(const SqlRow &q, bool reliable_metadata, int col) {
|
||||
|
||||
@@ -1098,7 +1098,7 @@ void Song::InitFromQuery(const SqlRow &q, bool reliable_metadata, int col) {
|
||||
}
|
||||
|
||||
else if (Song::kColumns.value(i) == "rating") {
|
||||
d->rating_ = todouble(x);
|
||||
d->rating_ = tofloat(x);
|
||||
}
|
||||
|
||||
else {
|
||||
@@ -1114,7 +1114,7 @@ void Song::InitFromQuery(const SqlRow &q, bool reliable_metadata, int col) {
|
||||
#undef tostr
|
||||
#undef toint
|
||||
#undef tolonglong
|
||||
#undef todouble
|
||||
#undef tofloat
|
||||
|
||||
}
|
||||
|
||||
@@ -1555,7 +1555,7 @@ QString Song::SampleRateBitDepthToText() const {
|
||||
|
||||
QString Song::PrettyRating() const {
|
||||
|
||||
double rating = d->rating_;
|
||||
float rating = d->rating_;
|
||||
|
||||
if (rating == -1.0F) return "0";
|
||||
|
||||
|
||||
@@ -258,7 +258,7 @@ class Song {
|
||||
const QString &cue_path() const;
|
||||
bool has_cue() const;
|
||||
|
||||
double rating() const;
|
||||
float rating() const;
|
||||
|
||||
const QString &effective_album() const;
|
||||
int effective_originalyear() const;
|
||||
@@ -375,7 +375,7 @@ class Song {
|
||||
|
||||
void set_cue_path(const QString &v);
|
||||
|
||||
void set_rating(const double v);
|
||||
void set_rating(const float v);
|
||||
|
||||
void set_stream_url(const QUrl &v);
|
||||
void set_image(const QImage &i);
|
||||
|
||||
@@ -504,7 +504,7 @@ void EditTagDialog::Data::set_value(const QString &id, const QVariant &value) {
|
||||
else if (id == "disc") current_.set_disc(value.toInt());
|
||||
else if (id == "year") current_.set_year(value.toInt());
|
||||
else if (id == "compilation") current_.set_compilation(value.toBool());
|
||||
else if (id == "rating") { current_.set_rating(value.toDouble()); }
|
||||
else if (id == "rating") { current_.set_rating(value.toFloat()); }
|
||||
else qLog(Warning) << "Unknown ID" << id;
|
||||
|
||||
}
|
||||
|
||||
@@ -2330,7 +2330,7 @@ void Playlist::TurnOffDynamicPlaylist() {
|
||||
|
||||
}
|
||||
|
||||
void Playlist::RateSong(const QModelIndex &idx, const double rating) {
|
||||
void Playlist::RateSong(const QModelIndex &idx, const float rating) {
|
||||
|
||||
if (has_item_at(idx.row())) {
|
||||
PlaylistItemPtr item = item_at(idx.row());
|
||||
@@ -2341,7 +2341,7 @@ void Playlist::RateSong(const QModelIndex &idx, const double rating) {
|
||||
|
||||
}
|
||||
|
||||
void Playlist::RateSongs(const QModelIndexList &index_list, const double rating) {
|
||||
void Playlist::RateSongs(const QModelIndexList &index_list, const float rating) {
|
||||
|
||||
QList<int> id_list;
|
||||
for (const QModelIndex &idx : index_list) {
|
||||
|
||||
@@ -295,8 +295,8 @@ class Playlist : public QAbstractListModel {
|
||||
void ItemChanged(const int row);
|
||||
|
||||
// Changes rating of a song to the given value asynchronously
|
||||
void RateSong(const QModelIndex &idx, const double rating);
|
||||
void RateSongs(const QModelIndexList &index_list, const double rating);
|
||||
void RateSong(const QModelIndex &idx, const float rating);
|
||||
void RateSongs(const QModelIndexList &index_list, const float rating);
|
||||
|
||||
void set_auto_sort(const bool auto_sort) { auto_sort_ = auto_sort; }
|
||||
|
||||
|
||||
@@ -522,7 +522,7 @@ void RatingItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
|
||||
|
||||
const bool hover = mouse_over_index_.isValid() && (mouse_over_index_ == idx || (selected_indexes_.contains(mouse_over_index_) && selected_indexes_.contains(idx)));
|
||||
|
||||
const double rating = (hover ? RatingPainter::RatingForPos(mouse_over_pos_, option.rect) : idx.data().toDouble());
|
||||
const float rating = (hover ? RatingPainter::RatingForPos(mouse_over_pos_, option.rect) : idx.data().toFloat());
|
||||
|
||||
painter_.Paint(painter, option.rect, rating);
|
||||
|
||||
@@ -538,10 +538,10 @@ QSize RatingItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo
|
||||
|
||||
QString RatingItemDelegate::displayText(const QVariant &value, const QLocale&) const {
|
||||
|
||||
if (value.isNull() || value.toDouble() <= 0) return QString();
|
||||
if (value.isNull() || value.toFloat() <= 0) return QString();
|
||||
|
||||
// Round to the nearest 0.5
|
||||
const double rating = static_cast<double>(lround(value.toDouble() * RatingPainter::kStarCount * 2)) / 2;
|
||||
const float rating = static_cast<float>(lround(value.toFloat() * RatingPainter::kStarCount * 2)) / 2;
|
||||
|
||||
return QString::number(rating, 'f', 1);
|
||||
|
||||
|
||||
@@ -643,10 +643,10 @@ void PlaylistManager::PlaySmartPlaylist(PlaylistGeneratorPtr generator, bool as_
|
||||
|
||||
}
|
||||
|
||||
void PlaylistManager::RateCurrentSong(const double rating) {
|
||||
void PlaylistManager::RateCurrentSong(const float rating) {
|
||||
active()->RateSong(active()->current_index(), rating);
|
||||
}
|
||||
|
||||
void PlaylistManager::RateCurrentSong(const int rating) {
|
||||
RateCurrentSong(rating / 5.0);
|
||||
void PlaylistManager::RateCurrentSong2(const int rating) {
|
||||
RateCurrentSong(static_cast<float>(rating) / 5.0F);
|
||||
}
|
||||
|
||||
@@ -108,9 +108,9 @@ class PlaylistManagerInterface : public QObject {
|
||||
virtual void SetActiveStopped() = 0;
|
||||
|
||||
// Rate current song using 0.0 - 1.0 scale.
|
||||
virtual void RateCurrentSong(const double rating) = 0;
|
||||
virtual void RateCurrentSong(const float rating) = 0;
|
||||
// Rate current song using 0 - 5 scale.
|
||||
virtual void RateCurrentSong(const int rating) = 0;
|
||||
virtual void RateCurrentSong2(const int rating) = 0;
|
||||
|
||||
signals:
|
||||
void PlaylistManagerInitialized();
|
||||
@@ -218,9 +218,9 @@ class PlaylistManager : public PlaylistManagerInterface {
|
||||
void PlaySmartPlaylist(PlaylistGeneratorPtr generator, const bool as_new, const bool clear) override;
|
||||
|
||||
// Rate current song using 0.0 - 1.0 scale.
|
||||
void RateCurrentSong(const double rating) override;
|
||||
void RateCurrentSong(const float rating) override;
|
||||
// Rate current song using 0 - 5 scale.
|
||||
void RateCurrentSong(const int rating) override;
|
||||
void RateCurrentSong2(const int rating) override;
|
||||
|
||||
private slots:
|
||||
void SetActivePlaying() override;
|
||||
|
||||
@@ -859,7 +859,7 @@ void PlaylistView::mousePressEvent(QMouseEvent *event) {
|
||||
case Qt::LeftButton:{
|
||||
if (idx.data(Playlist::Role_CanSetRating).toBool() && !rating_locked_) {
|
||||
// Calculate which star was clicked
|
||||
double new_rating = RatingPainter::RatingForPos(event->pos(), visualRect(idx));
|
||||
float new_rating = RatingPainter::RatingForPos(event->pos(), visualRect(idx));
|
||||
if (selectedIndexes().contains(idx)) {
|
||||
// Update all the selected item ratings
|
||||
QModelIndexList src_index_list;
|
||||
|
||||
@@ -244,9 +244,9 @@ class RatingBox : public RatingWidget, public ExtendedEditor {
|
||||
void set_enabled(bool enabled) override { RatingWidget::setEnabled(enabled); }
|
||||
|
||||
QVariant value() const override { return RatingWidget::rating(); }
|
||||
void set_value(const QVariant &value) override { RatingWidget::set_rating(value.toDouble()); }
|
||||
void set_value(const QVariant &value) override { RatingWidget::set_rating(value.toFloat()); }
|
||||
|
||||
void set_partially() override { RatingWidget::set_rating(0.0); }
|
||||
void set_partially() override { RatingWidget::set_rating(0.0F); }
|
||||
|
||||
public slots:
|
||||
void set_focus() override { RatingWidget::setFocus(); }
|
||||
|
||||
@@ -44,7 +44,7 @@ RatingPainter::RatingPainter() {
|
||||
|
||||
// Generate the 10 states, better to do it now than on the fly
|
||||
for (int i = 0; i < kStarCount * 2 + 1; ++i) {
|
||||
const double rating = static_cast<double>(i) / static_cast<double>(2.0);
|
||||
const float rating = static_cast<float>(i) / 2.0F;
|
||||
|
||||
// Clear the pixmap
|
||||
stars_[i] = QPixmap(kStarSize * kStarCount, kStarSize);
|
||||
@@ -83,21 +83,21 @@ QRect RatingPainter::Contents(const QRect rect) {
|
||||
|
||||
}
|
||||
|
||||
double RatingPainter::RatingForPos(const QPoint pos, const QRect rect) {
|
||||
float RatingPainter::RatingForPos(const QPoint pos, const QRect rect) {
|
||||
|
||||
const QRect contents = Contents(rect);
|
||||
const double raw = static_cast<double>(pos.x() - contents.left()) / contents.width();
|
||||
const float raw = static_cast<float>(pos.x() - contents.left()) / static_cast<float>(contents.width());
|
||||
|
||||
// Check if the position was to the right or left of the rectangle.
|
||||
if (raw < 0) return 0;
|
||||
if (raw > 1) return 1;
|
||||
|
||||
// Round to the nearest 0.1
|
||||
return static_cast<double>(lround(raw * kStarCount * 2)) / (kStarCount * 2);
|
||||
return static_cast<float>(lround(raw * kStarCount * 2)) / (kStarCount * 2);
|
||||
|
||||
}
|
||||
|
||||
void RatingPainter::Paint(QPainter *painter, const QRect rect, double rating) const {
|
||||
void RatingPainter::Paint(QPainter *painter, const QRect rect, float rating) const {
|
||||
|
||||
QSize size(qMin(kStarSize * kStarCount, rect.width()), qMin(kStarSize, rect.height()));
|
||||
QPoint pos(rect.center() - QPoint(size.width() / 2, size.height() / 2));
|
||||
@@ -124,7 +124,7 @@ QSize RatingWidget::sizeHint() const {
|
||||
|
||||
}
|
||||
|
||||
void RatingWidget::set_rating(const double rating) {
|
||||
void RatingWidget::set_rating(const float rating) {
|
||||
|
||||
rating_ = rating;
|
||||
update();
|
||||
|
||||
@@ -33,9 +33,9 @@ class RatingPainter {
|
||||
static const int kStarCount = 5;
|
||||
static const int kStarSize = 16;
|
||||
static QRect Contents(const QRect rect);
|
||||
static double RatingForPos(const QPoint pos, const QRect rect);
|
||||
static float RatingForPos(const QPoint pos, const QRect rect);
|
||||
|
||||
void Paint(QPainter *painter, const QRect rect, double rating) const;
|
||||
void Paint(QPainter *painter, const QRect rect, float rating) const;
|
||||
|
||||
private:
|
||||
QPixmap stars_[kStarCount * 2 + 1];
|
||||
@@ -44,18 +44,18 @@ class RatingPainter {
|
||||
class RatingWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(double rating READ rating WRITE set_rating)
|
||||
Q_PROPERTY(float rating READ rating WRITE set_rating)
|
||||
|
||||
public:
|
||||
RatingWidget(QWidget *parent = nullptr);
|
||||
|
||||
QSize sizeHint() const override;
|
||||
|
||||
double rating() const { return rating_; }
|
||||
void set_rating(const double rating);
|
||||
float rating() const { return rating_; }
|
||||
void set_rating(const float rating);
|
||||
|
||||
signals:
|
||||
void RatingChanged(double);
|
||||
void RatingChanged(float);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
@@ -65,8 +65,8 @@ class RatingWidget : public QWidget {
|
||||
|
||||
private:
|
||||
RatingPainter painter_;
|
||||
double rating_;
|
||||
double hover_rating_;
|
||||
float rating_;
|
||||
float hover_rating_;
|
||||
};
|
||||
|
||||
#endif // RATINGWIDGET_H
|
||||
|
||||
Reference in New Issue
Block a user