refact: Changes regarding PR.

* Rename column from `%` to `Size %`.
* Fix broken row comparison/sorting for this column.
* Reorder `dataProperties` as advised.
* Reorder `if` and variable declarations, so we don't declare variables earlier than needed.
This commit is contained in:
Stiliyan Tonev (Bark) 2025-06-03 14:06:25 +03:00
commit f20935b5c1
2 changed files with 24 additions and 6 deletions

View file

@ -193,7 +193,7 @@ QVariant TransferListModel::headerData(const int section, const Qt::Orientation
case TR_INFOHASH_V1: return tr("Info Hash v1", "i.e: torrent info hash v1");
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_PERCENT_SELECTED: return tr("%", "Percentage of selected data to download");
case TR_PERCENT_SELECTED: return tr("Size %", "Percentage of selected data to download");
case TR_PRIVATE: return tr("Private", "Flags private torrents");
default: return {};
}

View file

@ -1145,14 +1145,14 @@ window.qBittorrent.DynamicTable ??= (() => {
this.newColumn("infohash_v2", "", "QBT_TR(Info Hash v2)QBT_TR[CONTEXT=TransferListModel]", 100, false);
this.newColumn("reannounce", "", "QBT_TR(Reannounce In)QBT_TR[CONTEXT=TransferListModel]", 100, false);
this.newColumn("private", "", "QBT_TR(Private)QBT_TR[CONTEXT=TransferListModel]", 100, false);
this.newColumn("percent_selected", "", "QBT_TR(%)QBT_TR[CONTEXT=TransferListModel]", 100, false);
this.newColumn("percent_selected", "", "QBT_TR(Size %)QBT_TR[CONTEXT=TransferListModel]", 100, false);
this.columns["state_icon"].dataProperties[0] = "state";
this.columns["name"].dataProperties.push("state");
this.columns["num_seeds"].dataProperties.push("num_complete");
this.columns["num_leechs"].dataProperties.push("num_incomplete");
this.columns["time_active"].dataProperties.push("seeding_time");
this.columns["percent_selected"].dataProperties = ["size", "total_size", "has_metadata"];
this.columns["percent_selected"].dataProperties = ["has_metadata", "size", "total_size"];
this.initColumnsFunctions();
}
@ -1559,14 +1559,14 @@ window.qBittorrent.DynamicTable ??= (() => {
// percent_selected
this.columns["percent_selected"].updateTd = function(td, row) {
const size = this.getRowValue(row, 0);
const totalSize = this.getRowValue(row, 1);
const hasMetadata = this.getRowValue(row, 2);
const hasMetadata = this.getRowValue(row, 0);
if (hasMetadata === false) {
td.textContent = "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]";
td.title = "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]";
return;
}
const size = this.getRowValue(row, 1);
const totalSize = this.getRowValue(row, 2);
const percent = (size / totalSize) * 100;
if (percent === -1) {
td.textContent = "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]";
@ -1577,6 +1577,24 @@ window.qBittorrent.DynamicTable ??= (() => {
td.textContent = value;
td.title = value;
};
this.columns["percent_selected"].compareRows = function(row1, row2) {
let percent1 = 0;
let percent2 = 0;
const hasMetadata1 = this.getRowValue(row1, 0);
if (hasMetadata1 !== false) {
const size1 = this.getRowValue(row1, 1);
const totalSize1 = this.getRowValue(row1, 2);
percent1 = (size1 / totalSize1) * 100;
}
const hasMetadata2 = this.getRowValue(row2, 0);
if (hasMetadata2 !== false) {
const size2 = this.getRowValue(row2, 1);
const totalSize2 = this.getRowValue(row2, 2);
percent2 = (size2 / totalSize2) * 100;
}
return compareNumbers(percent1, percent2);
};
}
applyFilter(row, filterName, category, tag, trackerHost, filterTerms) {