Resolve PR review comments.

* Rebase and bump WEB version.
* Use variable for row value in JS.
* Prefer ternary operator instead of `if` clause.
* use `static_cast<qreal>` in order to work with real/decimal numbers.
This commit is contained in:
Stiliyan Tonev (Bark) 2025-04-22 12:49:26 +03:00
commit 631197c446
4 changed files with 8 additions and 21 deletions

View file

@ -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<qreal>(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<qreal>(torrent->wantedSize()) * 100) / torrent->totalSize() : 0;
}
return {};

View file

@ -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;

View file

@ -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.)
};
}

View file

@ -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;
};