Browse Source

Correctly count the number of torrents in subcategories

PR #18261.
Closes #18137.
adaptive-webui-19844
Vladimir Golovnev 2 years ago committed by GitHub
parent
commit
aeae065007
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      src/gui/categoryfiltermodel.cpp

29
src/gui/categoryfiltermodel.cpp

@ -56,7 +56,7 @@ public: @@ -56,7 +56,7 @@ public:
clear();
if (m_parent)
{
m_parent->m_torrentsCount -= m_torrentsCount;
m_parent->decreaseTorrentsCount(m_torrentsCount);
const QString uid = m_parent->m_children.key(this);
m_parent->m_children.remove(uid);
m_parent->m_childUids.removeOne(uid);
@ -86,18 +86,18 @@ public: @@ -86,18 +86,18 @@ public:
return m_torrentsCount;
}
void increaseTorrentsCount()
void increaseTorrentsCount(const int delta = 1)
{
++m_torrentsCount;
m_torrentsCount += delta;
if (m_parent)
m_parent->increaseTorrentsCount();
m_parent->increaseTorrentsCount(delta);
}
void decreaseTorrentsCount()
void decreaseTorrentsCount(const int delta = 1)
{
--m_torrentsCount;
m_torrentsCount -= delta;
if (m_parent)
m_parent->decreaseTorrentsCount();
m_parent->decreaseTorrentsCount(delta);
}
int pos() const
@ -139,7 +139,7 @@ public: @@ -139,7 +139,7 @@ public:
item->m_parent = this;
m_children[uid] = item;
m_childUids.append(uid);
m_torrentsCount += item->torrentsCount();
increaseTorrentsCount(item->torrentsCount());
}
void clear()
@ -408,9 +408,9 @@ void CategoryFilterModel::populate() @@ -408,9 +408,9 @@ void CategoryFilterModel::populate()
m_rootItem->addChild(UID_UNCATEGORIZED, new CategoryModelItem(nullptr, tr("Uncategorized"), torrentsCount));
using BitTorrent::Torrent;
for (const QString &categoryName : asConst(session->categories()))
if (m_isSubcategoriesEnabled)
{
if (m_isSubcategoriesEnabled)
for (const QString &categoryName : asConst(session->categories()))
{
CategoryModelItem *parent = m_rootItem;
for (const QString &subcat : asConst(session->expandCategory(categoryName)))
@ -419,16 +419,19 @@ void CategoryFilterModel::populate() @@ -419,16 +419,19 @@ void CategoryFilterModel::populate()
if (!parent->hasChild(subcatName))
{
const int torrentsCount = std::count_if(torrents.cbegin(), torrents.cend()
, [subcat](Torrent *torrent) { return torrent->category() == subcat; });
, [subcat](Torrent *torrent) { return torrent->category() == subcat; });
new CategoryModelItem(parent, subcatName, torrentsCount);
}
parent = parent->child(subcatName);
}
}
else
}
else
{
for (const QString &categoryName : asConst(session->categories()))
{
const int torrentsCount = std::count_if(torrents.begin(), torrents.end()
, [categoryName](Torrent *torrent) { return torrent->belongsToCategory(categoryName); });
, [categoryName](Torrent *torrent) { return torrent->belongsToCategory(categoryName); });
new CategoryModelItem(m_rootItem, categoryName, torrentsCount);
}
}

Loading…
Cancel
Save