mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-25 18:56:34 +03:00
Correctly count the number of torrents in subcategories
PR #18261. Closes #18137.
This commit is contained in:
parent
b12fdcf018
commit
aeae065007
1 changed files with 16 additions and 13 deletions
|
@ -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:
|
|||
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:
|
|||
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()
|
|||
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()
|
|||
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…
Reference in a new issue