mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 13:04:23 +00:00
Fixed rounding bugs with floating numbers.
This commit is contained in:
parent
251d5b1921
commit
d09b0d5f72
@ -1135,9 +1135,11 @@ void MainWindow::updateGUI() {
|
||||
html += "</div>";
|
||||
#else
|
||||
// OSes such as Windows do not support html here
|
||||
QString html =tr("DL speed: %1 KiB/s", "e.g: Download speed: 10 KiB/s").arg(QString::number(QBtSession::instance()->getPayloadDownloadRate()/1024., 'f', 1));
|
||||
/* 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 */
|
||||
QString html =tr("DL speed: %1 KiB/s", "e.g: Download speed: 10 KiB/s").arg(QString::number((int)((QBtSession::instance()->getPayloadDownloadRate()/1024.)*10)/10.0, 'f', 1));
|
||||
html += "\n";
|
||||
html += tr("UP speed: %1 KiB/s", "e.g: Upload speed: 10 KiB/s").arg(QString::number(QBtSession::instance()->getPayloadUploadRate()/1024., 'f', 1));
|
||||
html += tr("UP speed: %1 KiB/s", "e.g: Upload speed: 10 KiB/s").arg(QString::number((int)((QBtSession::instance()->getPayloadUploadRate()/1024.)*10)/10.0, 'f', 1));
|
||||
#endif
|
||||
systrayIcon->setToolTip(html); // tray icon
|
||||
}
|
||||
|
@ -241,7 +241,9 @@ QString misc::friendlyUnit(qreal val, bool is_speed) {
|
||||
if (i == 0)
|
||||
ret = QString::number((long)val) + " " + QCoreApplication::translate("misc", units[0].source, units[0].comment);
|
||||
else
|
||||
ret = QString::number(val, 'f', 1) + " " + QCoreApplication::translate("misc", units[i].source, units[i].comment);
|
||||
/* 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 */
|
||||
ret = QString::number((int)(val*10)/10.0, 'f', 1) + " " + QCoreApplication::translate("misc", units[i].source, units[i].comment);
|
||||
if (is_speed)
|
||||
ret += QCoreApplication::translate("misc", "/s", "per second");
|
||||
return ret;
|
||||
|
@ -67,7 +67,9 @@ public:
|
||||
case PROGRESS:{
|
||||
QItemDelegate::drawBackground(painter, opt, index);
|
||||
qreal progress = index.data().toDouble();
|
||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::number(progress*100., 'f', 1)+"%");
|
||||
/* 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)((progress*100.0)*10)/10.0, 'f', 1)+"%");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -354,15 +354,17 @@ void PropertiesWidget::loadDynamicData() {
|
||||
std::vector<int> avail;
|
||||
h.piece_availability(avail);
|
||||
pieces_availability->setAvailability(avail);
|
||||
avail_average_lbl->setText(QString::number(h.distributed_copies(), 'f', 3));
|
||||
/* 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 */
|
||||
avail_average_lbl->setText(QString::number((int)(h.distributed_copies()*1000)/1000.0, 'f', 3));
|
||||
} else {
|
||||
showPiecesAvailability(false);
|
||||
}
|
||||
// Progress
|
||||
qreal progress = h.progress()*100.;
|
||||
if (progress > 99.94 && progress < 100.)
|
||||
progress = 99.9;
|
||||
progress_lbl->setText(QString::number(progress, 'f', 1)+"%");
|
||||
/* 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 */
|
||||
progress_lbl->setText(QString::number((int)(progress*10)/10.0, 'f', 1)+"%");
|
||||
} else {
|
||||
showPiecesAvailability(false);
|
||||
showPiecesDownloaded(false);
|
||||
|
@ -134,7 +134,9 @@ public:
|
||||
const qlonglong limit = index.data().toLongLong();
|
||||
opt.displayAlignment = Qt::AlignRight;
|
||||
if (limit > 0)
|
||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::number(limit/1024., 'f', 1) + " " + tr("KiB/s", "KiB/second (.i.e per second)"));
|
||||
/* 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("∞"));
|
||||
break;
|
||||
@ -160,7 +162,9 @@ public:
|
||||
if (ratio > QBtSession::MAX_RATIO)
|
||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8("∞"));
|
||||
else
|
||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::number(ratio, '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, QString::number((int)(ratio*100)/100.0, 'f', 2));
|
||||
break;
|
||||
}
|
||||
case TorrentModelItem::TR_PRIORITY: {
|
||||
@ -177,13 +181,11 @@ public:
|
||||
}
|
||||
case TorrentModelItem::TR_PROGRESS:{
|
||||
QStyleOptionProgressBarV2 newopt;
|
||||
qreal progress = index.data().toDouble()*100.;
|
||||
// We don't want to display 100% unless
|
||||
// the torrent is really complete
|
||||
if (progress > 99.94 && progress < 100.)
|
||||
progress = 99.9;
|
||||
qreal progress = index.data().toDouble()*100.;
|
||||
newopt.rect = opt.rect;
|
||||
newopt.text = QString::number(progress, 'f', 1)+"%";
|
||||
/* 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 */
|
||||
newopt.text = QString::number((int)(progress*10)/10.0, 'f', 1)+"%";
|
||||
newopt.progress = (int)progress;
|
||||
newopt.maximum = 100;
|
||||
newopt.minimum = 0;
|
||||
|
@ -143,7 +143,9 @@ static JsonDict toJson(const QTorrentHandle& h)
|
||||
leechs += " ("+QString::number(h.num_incomplete())+")";
|
||||
ret.add(KEY_TORRENT_LEECHS, leechs);
|
||||
const qreal ratio = QBtSession::instance()->getRealRatio(h.hash());
|
||||
ret.add(KEY_TORRENT_RATIO, (ratio > 100.) ? QString::fromUtf8("∞") : QString::number(ratio, 'f', 1));
|
||||
/* 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 */
|
||||
ret.add(KEY_TORRENT_RATIO, (ratio > 100.) ? QString::fromUtf8("∞") : QString::number((int)(ratio*10)/10.0, 'f', 1));
|
||||
QString eta;
|
||||
QString state;
|
||||
if (h.is_paused()) {
|
||||
@ -311,7 +313,9 @@ QString btjson::getPropertiesForTorrent(const QString& hash)
|
||||
data.add(KEY_PROP_TIME_ELAPSED, elapsed_txt);
|
||||
data.add(KEY_PROP_CONNECT_COUNT, QString(QString::number(h.num_connections()) + " (" + tr("%1 max", "e.g. 10 max").arg(QString::number(h.connections_limit())) + ")"));
|
||||
const qreal ratio = QBtSession::instance()->getRealRatio(h.hash());
|
||||
data.add(KEY_PROP_RATIO, ratio > 100. ? QString::fromUtf8("∞") : QString::number(ratio, 'f', 1));
|
||||
/* 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 */
|
||||
data.add(KEY_PROP_RATIO, ratio > 100. ? QString::fromUtf8("∞") : QString::number((int)(ratio*10)/10.0, 'f', 1));
|
||||
} catch(const std::exception& e) {
|
||||
qWarning() << Q_FUNC_INFO << "Invalid torrent: " << e.what();
|
||||
return QString();
|
||||
|
Loading…
x
Reference in New Issue
Block a user