From 95b452a3e9f64c3dedca4ac4b10ef730a1ef0670 Mon Sep 17 00:00:00 2001 From: thalieht Date: Sun, 11 Oct 2020 19:06:51 +0300 Subject: [PATCH 1/2] Fix regression of not hiding zero values in the peer list Fixup 13aab6e04d6accc6768d49246967b167187a6df2 --- src/gui/properties/peerlistwidget.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index f1e40a9fc..8b10ccd72 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -425,16 +425,21 @@ void PeerListWidget::updatePeer(const BitTorrent::TorrentHandle *torrent, const } const int row = (*itemIter)->row(); + const bool hideValues = Preferences::instance()->getHideZeroValues(); setModelData(row, PeerListColumns::CONNECTION, peer.connectionType(), peer.connectionType()); setModelData(row, PeerListColumns::FLAGS, peer.flags(), peer.flags(), {}, peer.flagsDescription()); const QString client = peer.client().toHtmlEscaped(); setModelData(row, PeerListColumns::CLIENT, client, client); setModelData(row, PeerListColumns::PROGRESS, (Utils::String::fromDouble(peer.progress() * 100, 1) + '%'), peer.progress(), intDataTextAlignment); - setModelData(row, PeerListColumns::DOWN_SPEED, Utils::Misc::friendlyUnit(peer.payloadDownSpeed(), 1), peer.payloadDownSpeed(), intDataTextAlignment); - setModelData(row, PeerListColumns::UP_SPEED, Utils::Misc::friendlyUnit(peer.payloadUpSpeed(), true), peer.payloadUpSpeed(), intDataTextAlignment); - setModelData(row, PeerListColumns::TOT_DOWN, Utils::Misc::friendlyUnit(peer.totalDownload()), peer.totalDownload(), intDataTextAlignment); - setModelData(row, PeerListColumns::TOT_UP, Utils::Misc::friendlyUnit(peer.totalUpload()), peer.totalUpload(), intDataTextAlignment); + const QString downSpeed = (hideValues && (peer.payloadDownSpeed() <= 0)) ? QString {} : Utils::Misc::friendlyUnit(peer.payloadDownSpeed(), true); + setModelData(row, PeerListColumns::DOWN_SPEED, downSpeed, peer.payloadDownSpeed(), intDataTextAlignment); + const QString upSpeed = (hideValues && (peer.payloadUpSpeed() <= 0)) ? QString {} : Utils::Misc::friendlyUnit(peer.payloadUpSpeed(), true); + setModelData(row, PeerListColumns::UP_SPEED, upSpeed, peer.payloadUpSpeed(), intDataTextAlignment); + const QString totalDown = (hideValues && (peer.totalDownload() <= 0)) ? QString {} : Utils::Misc::friendlyUnit(peer.totalDownload()); + setModelData(row, PeerListColumns::TOT_DOWN, totalDown, peer.totalDownload(), intDataTextAlignment); + const QString totalUp = (hideValues && (peer.totalUpload() <= 0)) ? QString {} : Utils::Misc::friendlyUnit(peer.totalUpload()); + setModelData(row, PeerListColumns::TOT_UP, totalUp, peer.totalUpload(), intDataTextAlignment); setModelData(row, PeerListColumns::RELEVANCE, (Utils::String::fromDouble(peer.relevance() * 100, 1) + '%'), peer.relevance(), intDataTextAlignment); const QStringList downloadingFiles {torrent->info().filesForPiece(peer.downloadingPieceIndex())}; From 9d25405144dd21a8a5e829c399be03455748da55 Mon Sep 17 00:00:00 2001 From: thalieht Date: Sun, 11 Oct 2020 20:22:27 +0300 Subject: [PATCH 2/2] Check cheaper conditional first --- src/gui/transferlistmodel.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index 41eb23f1f..a5c887a67 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -239,19 +239,19 @@ QString TransferListModel::displayValue(const BitTorrent::TorrentHandle *torrent const auto availabilityString = [hideValues](const qreal value) -> QString { - return ((value <= 0) && hideValues) + return (hideValues && (value <= 0)) ? QString {} : Utils::String::fromDouble(value, 3); }; const auto unitString = [hideValues](const qint64 value, const bool isSpeedUnit = false) -> QString { - return ((value == 0) && hideValues) + return (hideValues && (value == 0)) ? QString {} : Utils::Misc::friendlyUnit(value, isSpeedUnit); }; const auto limitString = [hideValues](const qint64 value) -> QString { - if ((value == 0) && hideValues) + if (hideValues && (value == 0)) return {}; return (value > 0) @@ -261,14 +261,14 @@ QString TransferListModel::displayValue(const BitTorrent::TorrentHandle *torrent const auto amountString = [hideValues](const qint64 value, const qint64 total) -> QString { - return ((value == 0) && (total == 0) && hideValues) + return (hideValues && (value == 0) && (total == 0)) ? QString {} : QString::number(value) + " (" + QString::number(total) + ')'; }; const auto ratioString = [hideValues](const qreal value) -> QString { - if ((value <= 0) && hideValues) + if (hideValues && (value <= 0)) return {}; return ((static_cast(value) == -1) || (value > BitTorrent::TorrentHandle::MAX_RATIO))