mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 13:04:23 +00:00
Correctly count the number of torrents in subcategories
PR #18261. Closes #18137.
This commit is contained in:
parent
b12fdcf018
commit
aeae065007
@ -56,7 +56,7 @@ public:
|
|||||||
clear();
|
clear();
|
||||||
if (m_parent)
|
if (m_parent)
|
||||||
{
|
{
|
||||||
m_parent->m_torrentsCount -= m_torrentsCount;
|
m_parent->decreaseTorrentsCount(m_torrentsCount);
|
||||||
const QString uid = m_parent->m_children.key(this);
|
const QString uid = m_parent->m_children.key(this);
|
||||||
m_parent->m_children.remove(uid);
|
m_parent->m_children.remove(uid);
|
||||||
m_parent->m_childUids.removeOne(uid);
|
m_parent->m_childUids.removeOne(uid);
|
||||||
@ -86,18 +86,18 @@ public:
|
|||||||
return m_torrentsCount;
|
return m_torrentsCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void increaseTorrentsCount()
|
void increaseTorrentsCount(const int delta = 1)
|
||||||
{
|
{
|
||||||
++m_torrentsCount;
|
m_torrentsCount += delta;
|
||||||
if (m_parent)
|
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)
|
if (m_parent)
|
||||||
m_parent->decreaseTorrentsCount();
|
m_parent->decreaseTorrentsCount(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pos() const
|
int pos() const
|
||||||
@ -139,7 +139,7 @@ public:
|
|||||||
item->m_parent = this;
|
item->m_parent = this;
|
||||||
m_children[uid] = item;
|
m_children[uid] = item;
|
||||||
m_childUids.append(uid);
|
m_childUids.append(uid);
|
||||||
m_torrentsCount += item->torrentsCount();
|
increaseTorrentsCount(item->torrentsCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
@ -408,9 +408,9 @@ void CategoryFilterModel::populate()
|
|||||||
m_rootItem->addChild(UID_UNCATEGORIZED, new CategoryModelItem(nullptr, tr("Uncategorized"), torrentsCount));
|
m_rootItem->addChild(UID_UNCATEGORIZED, new CategoryModelItem(nullptr, tr("Uncategorized"), torrentsCount));
|
||||||
|
|
||||||
using BitTorrent::Torrent;
|
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;
|
CategoryModelItem *parent = m_rootItem;
|
||||||
for (const QString &subcat : asConst(session->expandCategory(categoryName)))
|
for (const QString &subcat : asConst(session->expandCategory(categoryName)))
|
||||||
@ -419,16 +419,19 @@ void CategoryFilterModel::populate()
|
|||||||
if (!parent->hasChild(subcatName))
|
if (!parent->hasChild(subcatName))
|
||||||
{
|
{
|
||||||
const int torrentsCount = std::count_if(torrents.cbegin(), torrents.cend()
|
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);
|
new CategoryModelItem(parent, subcatName, torrentsCount);
|
||||||
}
|
}
|
||||||
parent = parent->child(subcatName);
|
parent = parent->child(subcatName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (const QString &categoryName : asConst(session->categories()))
|
||||||
{
|
{
|
||||||
const int torrentsCount = std::count_if(torrents.begin(), torrents.end()
|
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);
|
new CategoryModelItem(m_rootItem, categoryName, torrentsCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user