Feat: Add column that displays the percent of selected data from a torrent.

This commit is contained in:
Stiliyan Tonev (Bark) 2025-01-09 11:40:32 +02:00
commit ae74a1b914
5 changed files with 9 additions and 2 deletions

View file

@ -194,6 +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("% Selected", "Percentage of torrent selected");
default: return {};
}
}
@ -443,8 +444,9 @@ QString TransferListModel::displayValue(const BitTorrent::Torrent *torrent, cons
return reannounceString(torrent->nextAnnounce());
case TR_PRIVATE:
return privateString(torrent->isPrivate(), torrent->hasMetadata());
case TR_PERCENT_SELECTED:
return QString::number((torrent->wantedSize() * 100) / torrent->totalSize()) + u'%';
}
return {};
}
@ -526,6 +528,8 @@ QVariant TransferListModel::internalValue(const BitTorrent::Torrent *torrent, co
return torrent->nextAnnounce();
case TR_PRIVATE:
return (torrent->hasMetadata() ? torrent->isPrivate() : QVariant());
case TR_PERCENT_SELECTED:
return (torrent->wantedSize() * 100) / torrent->totalSize();
}
return {};

View file

@ -87,6 +87,7 @@ public:
TR_INFOHASH_V2,
TR_REANNOUNCE,
TR_PRIVATE,
TR_PERCENT_SELECTED,
NB_COLUMNS
};

View file

@ -208,6 +208,7 @@ int TransferListSortModel::compare(const QModelIndex &left, const QModelIndex &r
case TransferListModel::TR_RATIO:
case TransferListModel::TR_RATIO_LIMIT:
case TransferListModel::TR_POPULARITY:
case TransferListModel::TR_PERCENT_SELECTED:
return customCompare(leftValue.toReal(), rightValue.toReal());
case TransferListModel::TR_STATUS:
@ -241,7 +242,6 @@ int TransferListSortModel::compare(const QModelIndex &left, const QModelIndex &r
const auto totalR = right.data(TransferListModel::AdditionalUnderlyingDataRole).toInt();
return threeWayCompare(totalL, totalR);
}
default:
Q_ASSERT_X(false, Q_FUNC_INFO, "Missing comparison case");
break;

View file

@ -192,6 +192,7 @@ TransferListWidget::TransferListWidget(IGUIApplication *app, QWidget *parent)
setColumnHidden(TransferListModel::TR_TOTAL_SIZE, true);
setColumnHidden(TransferListModel::TR_REANNOUNCE, true);
setColumnHidden(TransferListModel::TR_PRIVATE, true);
setColumnHidden(TransferListModel::TR_PERCENT_SELECTED, true);
}
//Ensure that at least one column is visible at all times

View file

@ -1145,6 +1145,7 @@ 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(Percent Selected)QBT_TR[CONTEXT=TransferListModel]", 100, false);
this.columns["state_icon"].dataProperties[0] = "state";
this.columns["name"].dataProperties.push("state");