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>";
|
html += "</div>";
|
||||||
#else
|
#else
|
||||||
// OSes such as Windows do not support html here
|
// 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 += "\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
|
#endif
|
||||||
systrayIcon->setToolTip(html); // tray icon
|
systrayIcon->setToolTip(html); // tray icon
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,9 @@ QString misc::friendlyUnit(qreal val, bool is_speed) {
|
|||||||
if (i == 0)
|
if (i == 0)
|
||||||
ret = QString::number((long)val) + " " + QCoreApplication::translate("misc", units[0].source, units[0].comment);
|
ret = QString::number((long)val) + " " + QCoreApplication::translate("misc", units[0].source, units[0].comment);
|
||||||
else
|
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)
|
if (is_speed)
|
||||||
ret += QCoreApplication::translate("misc", "/s", "per second");
|
ret += QCoreApplication::translate("misc", "/s", "per second");
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -67,7 +67,9 @@ public:
|
|||||||
case PROGRESS:{
|
case PROGRESS:{
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
QItemDelegate::drawBackground(painter, opt, index);
|
||||||
qreal progress = index.data().toDouble();
|
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;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -354,15 +354,17 @@ void PropertiesWidget::loadDynamicData() {
|
|||||||
std::vector<int> avail;
|
std::vector<int> avail;
|
||||||
h.piece_availability(avail);
|
h.piece_availability(avail);
|
||||||
pieces_availability->setAvailability(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 {
|
} else {
|
||||||
showPiecesAvailability(false);
|
showPiecesAvailability(false);
|
||||||
}
|
}
|
||||||
// Progress
|
// Progress
|
||||||
qreal progress = h.progress()*100.;
|
qreal progress = h.progress()*100.;
|
||||||
if (progress > 99.94 && progress < 100.)
|
/* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
|
||||||
progress = 99.9;
|
** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */
|
||||||
progress_lbl->setText(QString::number(progress, 'f', 1)+"%");
|
progress_lbl->setText(QString::number((int)(progress*10)/10.0, 'f', 1)+"%");
|
||||||
} else {
|
} else {
|
||||||
showPiecesAvailability(false);
|
showPiecesAvailability(false);
|
||||||
showPiecesDownloaded(false);
|
showPiecesDownloaded(false);
|
||||||
|
@ -134,7 +134,9 @@ public:
|
|||||||
const qlonglong limit = index.data().toLongLong();
|
const qlonglong limit = index.data().toLongLong();
|
||||||
opt.displayAlignment = Qt::AlignRight;
|
opt.displayAlignment = Qt::AlignRight;
|
||||||
if (limit > 0)
|
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
|
else
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8("∞"));
|
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8("∞"));
|
||||||
break;
|
break;
|
||||||
@ -160,7 +162,9 @@ public:
|
|||||||
if (ratio > QBtSession::MAX_RATIO)
|
if (ratio > QBtSession::MAX_RATIO)
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8("∞"));
|
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8("∞"));
|
||||||
else
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case TorrentModelItem::TR_PRIORITY: {
|
case TorrentModelItem::TR_PRIORITY: {
|
||||||
@ -177,13 +181,11 @@ public:
|
|||||||
}
|
}
|
||||||
case TorrentModelItem::TR_PROGRESS:{
|
case TorrentModelItem::TR_PROGRESS:{
|
||||||
QStyleOptionProgressBarV2 newopt;
|
QStyleOptionProgressBarV2 newopt;
|
||||||
qreal progress = index.data().toDouble()*100.;
|
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;
|
|
||||||
newopt.rect = opt.rect;
|
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.progress = (int)progress;
|
||||||
newopt.maximum = 100;
|
newopt.maximum = 100;
|
||||||
newopt.minimum = 0;
|
newopt.minimum = 0;
|
||||||
|
@ -143,7 +143,9 @@ static JsonDict toJson(const QTorrentHandle& h)
|
|||||||
leechs += " ("+QString::number(h.num_incomplete())+")";
|
leechs += " ("+QString::number(h.num_incomplete())+")";
|
||||||
ret.add(KEY_TORRENT_LEECHS, leechs);
|
ret.add(KEY_TORRENT_LEECHS, leechs);
|
||||||
const qreal ratio = QBtSession::instance()->getRealRatio(h.hash());
|
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 eta;
|
||||||
QString state;
|
QString state;
|
||||||
if (h.is_paused()) {
|
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_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())) + ")"));
|
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());
|
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) {
|
} catch(const std::exception& e) {
|
||||||
qWarning() << Q_FUNC_INFO << "Invalid torrent: " << e.what();
|
qWarning() << Q_FUNC_INFO << "Invalid torrent: " << e.what();
|
||||||
return QString();
|
return QString();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user