mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-22 22:33:34 -07:00
refactor: simplify setTagsAction
This commit is contained in:
parent
aae6244018
commit
7b3ad2eabb
1 changed files with 3 additions and 12 deletions
|
@ -1482,23 +1482,14 @@ void TorrentsController::setTagsAction()
|
||||||
const QStringList hashes {params()[u"hashes"_s].split(u'|', Qt::SkipEmptyParts)};
|
const QStringList hashes {params()[u"hashes"_s].split(u'|', Qt::SkipEmptyParts)};
|
||||||
const QStringList tags {params()[u"tags"_s].split(u',', Qt::SkipEmptyParts)};
|
const QStringList tags {params()[u"tags"_s].split(u',', Qt::SkipEmptyParts)};
|
||||||
|
|
||||||
// Convert QStringList to TagSet
|
const TagSet newTags {tags.begin(), tags.end()};
|
||||||
TagSet newTags;
|
|
||||||
for (const QString &tagStr : tags)
|
|
||||||
newTags.insert(Tag(tagStr));
|
|
||||||
|
|
||||||
// Apply the new tags to the selected torrents
|
|
||||||
applyToTorrents(hashes, [&newTags](BitTorrent::Torrent *const torrent)
|
applyToTorrents(hashes, [&newTags](BitTorrent::Torrent *const torrent)
|
||||||
{
|
{
|
||||||
// Identify tags to add
|
|
||||||
for (const Tag &tag : newTags)
|
|
||||||
if (!torrent->hasTag(tag))
|
|
||||||
torrent->addTag(tag);
|
|
||||||
|
|
||||||
// Identify tags to remove
|
|
||||||
for (const Tag &tag : asConst(torrent->tags()))
|
for (const Tag &tag : asConst(torrent->tags()))
|
||||||
if (!newTags.contains(tag))
|
if (!newTags.contains(tag))
|
||||||
torrent->removeTag(tag);
|
torrent->removeTag(tag);
|
||||||
|
for (const Tag &tag : newTags)
|
||||||
|
torrent->addTag(tag);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue