From 8f2cdcef0e5acd59791d7ffa7a86db84a0f42f44 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 29 Nov 2020 19:52:07 +0800 Subject: [PATCH 1/4] Fix availability value Closes #13869. Fix up 02f19bfbee1a1529a8dae5106f98c909d82c1932. --- src/gui/torrentcontentmodelitem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/torrentcontentmodelitem.cpp b/src/gui/torrentcontentmodelitem.cpp index e7f4ac247..d84c33ae1 100644 --- a/src/gui/torrentcontentmodelitem.cpp +++ b/src/gui/torrentcontentmodelitem.cpp @@ -140,11 +140,11 @@ QString TorrentContentModelItem::displayData(const int column) const return Utils::Misc::friendlyUnit(remaining()); case COL_AVAILABILITY: { - const int avail = availability(); + const qreal avail = availability(); if (avail < 0) return tr("N/A"); - const QString value = (avail >= 1.0) + const QString value = (avail >= 1) ? QString::fromLatin1("100") : Utils::String::fromDouble((avail * 100), 1); return QString {value + C_THIN_SPACE + QLatin1Char('%')}; From 4381739b6d5cb4ff2e2f53a916278cfc6ce808d0 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 29 Nov 2020 20:06:30 +0800 Subject: [PATCH 2/4] Fix coding style --- src/gui/torrentcontentmodelitem.cpp | 32 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/gui/torrentcontentmodelitem.cpp b/src/gui/torrentcontentmodelitem.cpp index d84c33ae1..71c58b8d7 100644 --- a/src/gui/torrentcontentmodelitem.cpp +++ b/src/gui/torrentcontentmodelitem.cpp @@ -112,23 +112,21 @@ QString TorrentContentModelItem::displayData(const int column) const case COL_NAME: return m_name; case COL_PRIO: - { - switch (m_priority) - { - case BitTorrent::DownloadPriority::Mixed: - return tr("Mixed", "Mixed (priorities"); - case BitTorrent::DownloadPriority::Ignored: - return tr("Not downloaded"); - case BitTorrent::DownloadPriority::High: - return tr("High", "High (priority)"); - case BitTorrent::DownloadPriority::Maximum: - return tr("Maximum", "Maximum (priority)"); - default: - return tr("Normal", "Normal (priority)"); - } + switch (m_priority) + { + case BitTorrent::DownloadPriority::Mixed: + return tr("Mixed", "Mixed (priorities"); + case BitTorrent::DownloadPriority::Ignored: + return tr("Not downloaded"); + case BitTorrent::DownloadPriority::High: + return tr("High", "High (priority)"); + case BitTorrent::DownloadPriority::Maximum: + return tr("Maximum", "Maximum (priority)"); + default: + return tr("Normal", "Normal (priority)"); } case COL_PROGRESS: - { + { const qreal progress = m_progress * 100; return (static_cast(progress) == 100) ? QString::fromLatin1("100%") @@ -139,7 +137,7 @@ QString TorrentContentModelItem::displayData(const int column) const case COL_REMAINING: return Utils::Misc::friendlyUnit(remaining()); case COL_AVAILABILITY: - { + { const qreal avail = availability(); if (avail < 0) return tr("N/A"); @@ -147,7 +145,7 @@ QString TorrentContentModelItem::displayData(const int column) const const QString value = (avail >= 1) ? QString::fromLatin1("100") : Utils::String::fromDouble((avail * 100), 1); - return QString {value + C_THIN_SPACE + QLatin1Char('%')}; + return {value + C_THIN_SPACE + QLatin1Char('%')}; } default: Q_ASSERT(false); From 75cead9266d15ed16b98e53ac4aa4ccaf72fcdb8 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 29 Nov 2020 20:16:14 +0800 Subject: [PATCH 3/4] Avoid potential rounding to integer issues --- src/gui/torrentcontentmodelitem.cpp | 9 +++------ src/gui/transferlistmodel.cpp | 7 +++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/gui/torrentcontentmodelitem.cpp b/src/gui/torrentcontentmodelitem.cpp index 71c58b8d7..34ebe498c 100644 --- a/src/gui/torrentcontentmodelitem.cpp +++ b/src/gui/torrentcontentmodelitem.cpp @@ -126,12 +126,9 @@ QString TorrentContentModelItem::displayData(const int column) const return tr("Normal", "Normal (priority)"); } case COL_PROGRESS: - { - const qreal progress = m_progress * 100; - return (static_cast(progress) == 100) - ? QString::fromLatin1("100%") - : (Utils::String::fromDouble(progress, 1) + QLatin1Char('%')); - } + return (m_progress >= 1) + ? QString::fromLatin1("100%") + : (Utils::String::fromDouble((m_progress * 100), 1) + QLatin1Char('%')); case COL_SIZE: return Utils::Misc::friendlyUnit(m_size); case COL_REMAINING: diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index f4992b8ea..5f70411d9 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -316,12 +316,11 @@ QString TransferListModel::displayValue(const BitTorrent::TorrentHandle *torrent return tagsList.join(", "); }; - const auto progressString = [](qreal progress) -> QString + const auto progressString = [](const qreal progress) -> QString { - progress *= 100; - return (static_cast(progress) == 100) + return (progress >= 1) ? QString::fromLatin1("100%") - : Utils::String::fromDouble(progress, 1) + '%'; + : Utils::String::fromDouble((progress * 100), 1) + QLatin1Char('%'); }; const auto statusString = [this](const BitTorrent::TorrentState state, const QString &errorMessage) -> QString From eaaacd71a8f1d5d46ec6f8fca5e85e2ddad958c6 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 29 Nov 2020 20:44:26 +0800 Subject: [PATCH 4/4] Simplify the calculation of speed graph scale --- src/gui/properties/speedplotview.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/gui/properties/speedplotview.cpp b/src/gui/properties/speedplotview.cpp index 7c3677743..8a3d8f255 100644 --- a/src/gui/properties/speedplotview.cpp +++ b/src/gui/properties/speedplotview.cpp @@ -28,9 +28,12 @@ #include "speedplotview.h" +#include + #include #include #include + #include "base/global.h" #include "base/unicodestrings.h" #include "base/utils/misc.h" @@ -85,20 +88,16 @@ namespace calculatedUnit = static_cast(static_cast(calculatedUnit) + 1); } - if (value > 100.0) + if (value > 100) { - int roundedValue = static_cast(value / 40) * 40; - while (roundedValue < value) - roundedValue += 40; - return {static_cast(roundedValue), calculatedUnit}; + const double roundedValue {std::ceil(value / 40) * 40}; + return {roundedValue, calculatedUnit}; } - if (value > 10.0) + if (value > 10) { - int roundedValue = static_cast(value / 4) * 4; - while (roundedValue < value) - roundedValue += 4; - return {static_cast(roundedValue), calculatedUnit}; + const double roundedValue {std::ceil(value / 4) * 4}; + return {roundedValue, calculatedUnit}; } for (const auto &roundedValue : roundingTable)