diff --git a/launcher/icons/IconList.cpp b/launcher/icons/IconList.cpp index 016affe29..0903131ce 100644 --- a/launcher/icons/IconList.cpp +++ b/launcher/icons/IconList.cpp @@ -157,6 +157,16 @@ QString formatName(const QDir& iconsDir, const QFileInfo& file) return relativePathWithoutExtension.replace(QDir::separator(), delimiter); } +QSet toStringSet(const QList& list) // Split into a separate function because the preprocessing impedes readability +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + QSet set(list.begin(), list.end()); +#else + auto set = list.toSet(); +#endif + return set; +} + void IconList::directoryChanged(const QString& path) { QDir new_dir(path); @@ -171,31 +181,23 @@ void IconList::directoryChanged(const QString& path) if (!FS::ensureFolderPathExists(m_dir.absolutePath())) return; m_dir.refresh(); - QStringList newFileNamesList = getIconFilePaths(); -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - QSet new_set(newFileNamesList.begin(), newFileNamesList.end()); -#else - auto new_set = new_file_names_list.toSet(); -#endif + const QStringList newFileNamesList = getIconFilePaths(); + const QSet newSet = toStringSet(newFileNamesList); QList current_list; for (auto& it : icons) { if (!it.has(IconType::FileBased)) continue; current_list.push_back(it.m_images[IconType::FileBased].filename); } -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - QSet current_set(current_list.begin(), current_list.end()); -#else - QSet current_set = current_list.toSet(); -#endif + const QSet currentSet = toStringSet(current_list); - QSet to_remove = current_set; - to_remove -= new_set; + QSet toRemove = currentSet; + toRemove -= newSet; - QSet toAdd = new_set; - toAdd -= current_set; + QSet toAdd = newSet; + toAdd -= currentSet; - for (const auto& remove : to_remove) { + for (const auto& remove : toRemove) { qDebug() << "Removing " << remove; QFileInfo removedFile(remove); QString key = m_dir.relativeFilePath(removedFile.absoluteFilePath());