mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-22 00:17:23 -06:00
Simplify various if-else and QString::number.
This commit is contained in:
@@ -33,12 +33,9 @@
|
||||
|
||||
#include <QItemDelegate>
|
||||
#include <QModelIndex>
|
||||
#include <QByteArray>
|
||||
#include <QStyleOptionViewItem>
|
||||
#include <QStyleOptionViewItemV2>
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include <QDateTime>
|
||||
#include "misc.h"
|
||||
#include "torrentmodel.h"
|
||||
#include "qbtsession.h"
|
||||
@@ -133,12 +130,9 @@ public:
|
||||
QItemDelegate::drawBackground(painter, opt, index);
|
||||
const qlonglong limit = index.data().toLongLong();
|
||||
opt.displayAlignment = Qt::AlignRight;
|
||||
if (limit > 0)
|
||||
/* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
|
||||
** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */
|
||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::number((int)((limit/1024.)*10)/10.0, 'f', 1) + " " + tr("KiB/s", "KiB/second (.i.e per second)"));
|
||||
else
|
||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8("∞"));
|
||||
/* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
|
||||
** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */
|
||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, limit > 0 ? QString::number((int)((limit/1024.)*10)/10.0, 'f', 1) + " " + tr("KiB/s", "KiB/second (.i.e per second)") : QString::fromUtf8("∞"));
|
||||
break;
|
||||
}
|
||||
case TorrentModelItem::TR_TIME_ELAPSED: {
|
||||
@@ -159,12 +153,9 @@ public:
|
||||
QItemDelegate::drawBackground(painter, opt, index);
|
||||
opt.displayAlignment = Qt::AlignRight;
|
||||
const qreal ratio = index.data().toDouble();
|
||||
if (ratio > QBtSession::MAX_RATIO)
|
||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8("∞"));
|
||||
else
|
||||
/* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
|
||||
** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */
|
||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::number((int)(ratio*100)/100.0, 'f', 2));
|
||||
/* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
|
||||
** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */
|
||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, ratio > QBtSession::MAX_RATIO ? QString::fromUtf8("∞") : QString::number((int)(ratio*100)/100.0, 'f', 2));
|
||||
break;
|
||||
}
|
||||
case TorrentModelItem::TR_PRIORITY: {
|
||||
|
||||
Reference in New Issue
Block a user