diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index 0b8771820..60e721922 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -194,7 +194,7 @@ QVariant TransferListModel::headerData(const int section, const Qt::Orientation case TR_INFOHASH_V2: return tr("Info Hash v2", "i.e: torrent info hash v2"); case TR_REANNOUNCE: return tr("Reannounce In", "Indicates the time until next trackers reannounce"); case TR_PRIVATE: return tr("Private", "Flags private torrents"); - case TR_PERCENT_SELECTED: return tr("%", "Percentage of selected data to download."); + case TR_PERCENT_SELECTED: return tr("%", "Percentage of selected data to download"); default: return {}; } } @@ -203,7 +203,7 @@ QVariant TransferListModel::headerData(const int section, const Qt::Orientation switch (section) { case TR_POPULARITY: return tr("Ratio / Time Active (in months), indicates how popular the torrent is"); - case TR_PERCENT_SELECTED: return tr("Wanted / Total size, indicates percentage of selected data to download."); + case TR_PERCENT_SELECTED: return tr("Wanted / Total size, indicates percentage of selected data to download"); default: return {}; } } @@ -446,9 +446,7 @@ QString TransferListModel::displayValue(const BitTorrent::Torrent *torrent, cons case TR_PRIVATE: return privateString(torrent->isPrivate(), torrent->hasMetadata()); case TR_PERCENT_SELECTED: - if (!torrent->hasMetadata()) - return tr("N/A"); - return QString::number((torrent->wantedSize() * 100) / torrent->totalSize()) + u'%'; + return torrent->hasMetadata() ? QString::number((static_cast(torrent->wantedSize()) * 100) / torrent->totalSize(), 'f', 2) + u'%' : tr("N/A"); } return {}; @@ -533,9 +531,7 @@ QVariant TransferListModel::internalValue(const BitTorrent::Torrent *torrent, co case TR_PRIVATE: return (torrent->hasMetadata() ? torrent->isPrivate() : QVariant()); case TR_PERCENT_SELECTED: - if (!torrent->hasMetadata()) - return 0; - return (torrent->wantedSize() * 100) / torrent->totalSize(); + return torrent->hasMetadata() ? (static_cast(torrent->wantedSize()) * 100) / torrent->totalSize() : 0; } return {}; diff --git a/src/gui/transferlistsortmodel.cpp b/src/gui/transferlistsortmodel.cpp index 45199553d..e71e00c5c 100644 --- a/src/gui/transferlistsortmodel.cpp +++ b/src/gui/transferlistsortmodel.cpp @@ -207,6 +207,7 @@ int TransferListSortModel::compare(const QModelIndex &left, const QModelIndex &r case TransferListModel::TR_PROGRESS: case TransferListModel::TR_RATIO: case TransferListModel::TR_RATIO_LIMIT: + case TransferListModel::TR_PERCENT_SELECTED: case TransferListModel::TR_POPULARITY: return customCompare(leftValue.toReal(), rightValue.toReal()); @@ -242,9 +243,6 @@ int TransferListSortModel::compare(const QModelIndex &left, const QModelIndex &r return threeWayCompare(totalL, totalR); } - case TransferListModel::TR_PERCENT_SELECTED: - return customCompare(leftValue.toFloat(), rightValue.toFloat()); - default: Q_ASSERT_X(false, Q_FUNC_INFO, "Missing comparison case"); break; diff --git a/src/webui/api/serialize/serialize_torrent.cpp b/src/webui/api/serialize/serialize_torrent.cpp index 1515b55c7..94c83a934 100644 --- a/src/webui/api/serialize/serialize_torrent.cpp +++ b/src/webui/api/serialize/serialize_torrent.cpp @@ -178,14 +178,6 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent) {KEY_TORRENT_LAST_ACTIVITY_TIME, getLastActivityTime()}, {KEY_TORRENT_AVAILABILITY, torrent.distributedCopies()}, {KEY_TORRENT_REANNOUNCE, torrent.nextAnnounce()}, -<<<<<<< HEAD {KEY_TORRENT_COMMENT, torrent.comment()} -======= - {KEY_TORRENT_COMMENT, torrent.comment()}, - {KEY_TORRENT_PRIVATE, (torrent.hasMetadata() ? torrent.isPrivate() : QVariant())}, - {KEY_TORRENT_TOTAL_SIZE, torrent.totalSize()}, - {KEY_TORRENT_HAS_METADATA, torrent.hasMetadata()}, - {KEY_TORRENT_PERCENT_SELECTED, torrent.hasMetadata() ? (torrent.wantedSize() * 100) / torrent.totalSize() : -1}, ->>>>>>> ba7b726ce (Pass number to WebUI instead of text and use float when comparing.) }; } diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index 4d84d8ee3..7e4330228 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -1558,12 +1558,13 @@ window.qBittorrent.DynamicTable ??= (() => { // percent_selected this.columns["percent_selected"].updateTd = function(td, row) { - if (this.getRowValue(row) === -1) { + const percent = this.getRowValue(row); + if (percent === -1) { td.textContent = "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]"; td.title = "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]"; return; } - const value = `${window.qBittorrent.Misc.toFixedPointString(this.getRowValue(row), 2) }%`; + const value = `${window.qBittorrent.Misc.toFixedPointString(percent, 2) }%`; td.textContent = value; td.title = value; };