Merge pull request #3447 from glassez/filters

Fix label filter. Closes #3429.
This commit is contained in:
sledgehammer999 2015-07-29 23:28:47 +03:00
commit 256793aad7
4 changed files with 14 additions and 21 deletions

View file

@ -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);
}

View file

@ -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));
}
}
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);

View file

@ -832,14 +832,11 @@ 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));
if (label.isNull())
nameFilterModel->disableLabelFilter();
else
nameFilterModel->setLabelFilter(label);
}

View file

@ -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);