From 87fb4e58683a2389a63c8c6d36e56f7c60799b69 Mon Sep 17 00:00:00 2001 From: Ruslan Date: Tue, 28 Jan 2025 01:08:43 +0300 Subject: [PATCH] Update categoryfiltermodel.cpp --- .../categoryfiltermodel.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/gui/transferlistfilters/categoryfiltermodel.cpp b/src/gui/transferlistfilters/categoryfiltermodel.cpp index f82ddebe7..4bc3664e3 100644 --- a/src/gui/transferlistfilters/categoryfiltermodel.cpp +++ b/src/gui/transferlistfilters/categoryfiltermodel.cpp @@ -433,17 +433,16 @@ void CategoryFilterModel::populate() m_isSubcategoriesEnabled = session->isSubcategoriesEnabled(); // All torrents - m_rootItem->addChild(CategoryModelItem::UID_ALL - , new CategoryModelItem(nullptr, tr("All"), torrents.count())); + m_rootItem->addChild(CategoryModelItem::UID_ALL, + std::make_unique(nullptr, tr("All"), torrents.count())); // Uncategorized torrents using Torrent = BitTorrent::Torrent; - const int torrentsCount = std::count_if(torrents.begin(), torrents.end() - , [](Torrent *torrent) { return torrent->category().isEmpty(); }); - m_rootItem->addChild(CategoryModelItem::UID_UNCATEGORIZED - , new CategoryModelItem(nullptr, tr("Uncategorized"), torrentsCount)); + const int torrentsCount = std::count_if(torrents.begin(), torrents.end(), + [](Torrent *torrent) { return torrent->category().isEmpty(); }); + m_rootItem->addChild(CategoryModelItem::UID_UNCATEGORIZED, + std::make_unique(nullptr, tr("Uncategorized"), torrentsCount)); - using BitTorrent::Torrent; if (m_isSubcategoriesEnabled) { for (const QString &categoryName : asConst(session->categories())) @@ -454,9 +453,9 @@ void CategoryFilterModel::populate() const QString subcatName = shortName(subcat); if (!parent->hasChild(subcatName)) { - const int torrentsCount = std::count_if(torrents.cbegin(), torrents.cend() - , [subcat](Torrent *torrent) { return torrent->category() == subcat; }); - new CategoryModelItem(parent, subcatName, torrentsCount); + const int torrentsCount = std::count_if(torrents.cbegin(), torrents.cend(), + [subcat](Torrent *torrent) { return torrent->category() == subcat; }); + parent->addChild(subcatName, std::make_unique(parent, subcatName, torrentsCount)); } parent = parent->child(subcatName); } @@ -466,13 +465,14 @@ void CategoryFilterModel::populate() { for (const QString &categoryName : asConst(session->categories())) { - const int torrentsCount = std::count_if(torrents.begin(), torrents.end() - , [categoryName](Torrent *torrent) { return torrent->belongsToCategory(categoryName); }); - new CategoryModelItem(m_rootItem, categoryName, torrentsCount); + const int torrentsCount = std::count_if(torrents.begin(), torrents.end(), + [categoryName](Torrent *torrent) { return torrent->belongsToCategory(categoryName); }); + m_rootItem->addChild(categoryName, std::make_unique(m_rootItem, categoryName, torrentsCount)); } } } + CategoryModelItem *CategoryFilterModel::findItem(const QString &fullName) const { if (fullName.isEmpty())