Browse Source

Merge pull request #13876 from Chocobo1/fix

Fix availability value
adaptive-webui-19844
Mike Tzou 4 years ago committed by GitHub
parent
commit
7c5d0a0e00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      src/gui/properties/speedplotview.cpp
  2. 15
      src/gui/torrentcontentmodelitem.cpp
  3. 7
      src/gui/transferlistmodel.cpp

19
src/gui/properties/speedplotview.cpp

@ -28,9 +28,12 @@
#include "speedplotview.h" #include "speedplotview.h"
#include <cmath>
#include <QLocale> #include <QLocale>
#include <QPainter> #include <QPainter>
#include <QPen> #include <QPen>
#include "base/global.h" #include "base/global.h"
#include "base/unicodestrings.h" #include "base/unicodestrings.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
@ -85,20 +88,16 @@ namespace
calculatedUnit = static_cast<SizeUnit>(static_cast<int>(calculatedUnit) + 1); calculatedUnit = static_cast<SizeUnit>(static_cast<int>(calculatedUnit) + 1);
} }
if (value > 100.0) if (value > 100)
{ {
int roundedValue = static_cast<int>(value / 40) * 40; const double roundedValue {std::ceil(value / 40) * 40};
while (roundedValue < value) return {roundedValue, calculatedUnit};
roundedValue += 40;
return {static_cast<double>(roundedValue), calculatedUnit};
} }
if (value > 10.0) if (value > 10)
{ {
int roundedValue = static_cast<int>(value / 4) * 4; const double roundedValue {std::ceil(value / 4) * 4};
while (roundedValue < value) return {roundedValue, calculatedUnit};
roundedValue += 4;
return {static_cast<double>(roundedValue), calculatedUnit};
} }
for (const auto &roundedValue : roundingTable) for (const auto &roundedValue : roundingTable)

15
src/gui/torrentcontentmodelitem.cpp

@ -112,7 +112,6 @@ QString TorrentContentModelItem::displayData(const int column) const
case COL_NAME: case COL_NAME:
return m_name; return m_name;
case COL_PRIO: case COL_PRIO:
{
switch (m_priority) switch (m_priority)
{ {
case BitTorrent::DownloadPriority::Mixed: case BitTorrent::DownloadPriority::Mixed:
@ -126,28 +125,24 @@ QString TorrentContentModelItem::displayData(const int column) const
default: default:
return tr("Normal", "Normal (priority)"); return tr("Normal", "Normal (priority)");
} }
}
case COL_PROGRESS: case COL_PROGRESS:
{ return (m_progress >= 1)
const qreal progress = m_progress * 100;
return (static_cast<int>(progress) == 100)
? QString::fromLatin1("100%") ? QString::fromLatin1("100%")
: (Utils::String::fromDouble(progress, 1) + QLatin1Char('%')); : (Utils::String::fromDouble((m_progress * 100), 1) + QLatin1Char('%'));
}
case COL_SIZE: case COL_SIZE:
return Utils::Misc::friendlyUnit(m_size); return Utils::Misc::friendlyUnit(m_size);
case COL_REMAINING: case COL_REMAINING:
return Utils::Misc::friendlyUnit(remaining()); return Utils::Misc::friendlyUnit(remaining());
case COL_AVAILABILITY: case COL_AVAILABILITY:
{ {
const int avail = availability(); const qreal avail = availability();
if (avail < 0) if (avail < 0)
return tr("N/A"); return tr("N/A");
const QString value = (avail >= 1.0) const QString value = (avail >= 1)
? QString::fromLatin1("100") ? QString::fromLatin1("100")
: Utils::String::fromDouble((avail * 100), 1); : Utils::String::fromDouble((avail * 100), 1);
return QString {value + C_THIN_SPACE + QLatin1Char('%')}; return {value + C_THIN_SPACE + QLatin1Char('%')};
} }
default: default:
Q_ASSERT(false); Q_ASSERT(false);

7
src/gui/transferlistmodel.cpp

@ -316,12 +316,11 @@ QString TransferListModel::displayValue(const BitTorrent::TorrentHandle *torrent
return tagsList.join(", "); return tagsList.join(", ");
}; };
const auto progressString = [](qreal progress) -> QString const auto progressString = [](const qreal progress) -> QString
{ {
progress *= 100; return (progress >= 1)
return (static_cast<int>(progress) == 100)
? QString::fromLatin1("100%") ? 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 const auto statusString = [this](const BitTorrent::TorrentState state, const QString &errorMessage) -> QString

Loading…
Cancel
Save