From d475ab38815f0af6064d7beb7bb8bf822bd39ae7 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Tue, 14 Jul 2015 16:03:51 +0300 Subject: [PATCH] Fix label filter. Closes #3429. --- src/core/torrentfilter.cpp | 8 ++++++-- src/gui/transferlistfilterswidget.cpp | 15 ++++----------- src/gui/transferlistwidget.cpp | 11 ++++------- src/gui/transferlistwidget.h | 1 - 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/core/torrentfilter.cpp b/src/core/torrentfilter.cpp index e514d15c8..01f87b6eb 100644 --- a/src/core/torrentfilter.cpp +++ b/src/core/torrentfilter.cpp @@ -107,7 +107,10 @@ bool TorrentFilter::setHashSet(const QStringSet &hashSet) bool TorrentFilter::setLabel(const QString &label) { - if (m_label != label) { + // QString::operator==() doesn't distinguish between empty and null strings. + if ((m_label != label) + || (m_label.isNull() && !label.isNull()) + || (!m_label.isNull() && label.isNull())) { m_label = label; return true; } @@ -154,6 +157,7 @@ bool TorrentFilter::matchHash(BitTorrent::TorrentHandle *const torrent) const bool TorrentFilter::matchLabel(BitTorrent::TorrentHandle *const torrent) const { - if (m_label == AnyLabel) return true; + if (m_label.isNull()) return true; + else if (m_label.isEmpty()) return torrent->label().isEmpty(); else return (torrent->label() == m_label); } diff --git a/src/gui/transferlistfilterswidget.cpp b/src/gui/transferlistfilterswidget.cpp index c25163a77..94678d5bd 100644 --- a/src/gui/transferlistfilterswidget.cpp +++ b/src/gui/transferlistfilterswidget.cpp @@ -375,16 +375,7 @@ void LabelFiltersList::showMenu(QPoint) void LabelFiltersList::applyFilter(int row) { - switch (row) { - case 0: - transferList->applyLabelFilterAll(); - break; - case 1: - transferList->applyLabelFilter(QString()); - break; - default: - transferList->applyLabelFilter(labelFromRow(row)); - } + transferList->applyLabelFilter(labelFromRow(row)); } void LabelFiltersList::handleNewTorrent(BitTorrent::TorrentHandle *const torrent) @@ -407,7 +398,9 @@ void LabelFiltersList::torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const QString LabelFiltersList::labelFromRow(int row) const { - Q_ASSERT(row > 1); + if (row == 0) return QString(); // All + if (row == 1) return QLatin1String(""); // Unlabeled + const QString &label = item(row)->text(); QStringList parts = label.split(" "); Q_ASSERT(parts.size() >= 2); diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index eaec0487f..f2b068a38 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -843,15 +843,12 @@ void TransferListWidget::currentChanged(const QModelIndex& current, const QModel emit currentTorrentChanged(torrent); } -void TransferListWidget::applyLabelFilterAll() -{ - nameFilterModel->disableLabelFilter(); -} - void TransferListWidget::applyLabelFilter(QString label) { - qDebug("Applying Label filter: %s", qPrintable(label)); - nameFilterModel->setLabelFilter(label); + if (label.isNull()) + nameFilterModel->disableLabelFilter(); + else + nameFilterModel->setLabelFilter(label); } void TransferListWidget::applyTrackerFilterAll() diff --git a/src/gui/transferlistwidget.h b/src/gui/transferlistwidget.h index 67261dd63..4d799d467 100644 --- a/src/gui/transferlistwidget.h +++ b/src/gui/transferlistwidget.h @@ -86,7 +86,6 @@ public slots: void displayDLHoSMenu(const QPoint&); void applyNameFilter(const QString& name); void applyStatusFilter(int f); - void applyLabelFilterAll(); void applyLabelFilter(QString label); void applyTrackerFilterAll(); void applyTrackerFilter(const QStringList &hashes);