From 666e733a4acfc083611b66a8d7c556fd51b42114 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Thu, 23 Jan 2020 11:20:38 +0300 Subject: [PATCH] Track settings changed event in TransferListModel --- src/gui/transferlistmodel.cpp | 29 ++++++++++++++++++++++++++--- src/gui/transferlistmodel.h | 10 ++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index 244fdffe5..b2a13668a 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -105,6 +105,9 @@ TransferListModel::TransferListModel(QObject *parent) {BitTorrent::TorrentState::Error, getColorByState(BitTorrent::TorrentState::Error)} } { + configure(); + connect(Preferences::instance(), &Preferences::changed, this, &TransferListModel::configure); + // Load the torrents using namespace BitTorrent; for (TorrentHandle *const torrent : asConst(Session::instance()->torrents())) @@ -205,9 +208,11 @@ QVariant TransferListModel::headerData(int section, Qt::Orientation orientation, QString TransferListModel::displayValue(const BitTorrent::TorrentHandle *torrent, const int column) const { - const bool isHideState = (Preferences::instance()->getHideZeroComboValues() == 0) - || (torrent->state() == BitTorrent::TorrentState::PausedDownloading); // paused torrents only - const bool hideValues = Preferences::instance()->getHideZeroValues() && isHideState; + bool hideValues = false; + if (m_hideZeroValuesMode == HideZeroValuesMode::Always) + hideValues = true; + else if (m_hideZeroValuesMode != HideZeroValuesMode::Never) + hideValues = (torrent->state() == BitTorrent::TorrentState::PausedDownloading); const auto availabilityString = [hideValues](const qreal value) -> QString { @@ -575,6 +580,24 @@ void TransferListModel::handleTorrentsUpdated(const QVectorgetHideZeroValues()) { + if (pref->getHideZeroComboValues() == 1) + hideZeroValuesMode = HideZeroValuesMode::Paused; + else + hideZeroValuesMode = HideZeroValuesMode::Always; + } + + if (m_hideZeroValuesMode != hideZeroValuesMode) { + m_hideZeroValuesMode = hideZeroValuesMode; + emit dataChanged(index(0, 0), index((rowCount() - 1), (columnCount() - 1))); + } +} + void TransferListModel::setStateForeground(const BitTorrent::TorrentState state, const QColor &color) { m_stateForegroundColors[state] = color; diff --git a/src/gui/transferlistmodel.h b/src/gui/transferlistmodel.h index 437139e1b..cfd84779f 100644 --- a/src/gui/transferlistmodel.h +++ b/src/gui/transferlistmodel.h @@ -111,6 +111,7 @@ private slots: void handleTorrentsUpdated(const QVector &torrents); private: + void configure(); QString displayValue(const BitTorrent::TorrentHandle *torrent, int column) const; QVariant internalValue(const BitTorrent::TorrentHandle *torrent, int column, bool alt = false) const; @@ -119,6 +120,15 @@ private: const QHash m_statusStrings; // row text colors QHash m_stateForegroundColors; + + enum class HideZeroValuesMode + { + Never, + Paused, + Always + }; + + HideZeroValuesMode m_hideZeroValuesMode = HideZeroValuesMode::Never; }; #endif // TRANSFERLISTMODEL_H