void ResourceTopLevelNode::update() { QList<ProjectExplorer::FolderNode *> newFolderList; QMap<QPair<QString, QString>, QList<ProjectExplorer::FileNode *> > filesToAdd; ResourceFile file(path().toString()); if (file.load() == Core::IDocument::OpenResult::Success) { QSet<QPair<QString, QString > > prefixes; int prfxcount = file.prefixCount(); for (int i = 0; i < prfxcount; ++i) { const QString &prefix = file.prefix(i); const QString &lang = file.lang(i); // ensure that we don't duplicate prefixes if (!prefixes.contains(qMakePair(prefix, lang))) { ProjectExplorer::FolderNode *fn = new ResourceFolderNode(file.prefix(i), file.lang(i), this); newFolderList << fn; prefixes.insert(qMakePair(prefix, lang)); } QSet<QString> fileNames; int filecount = file.fileCount(i); for (int j = 0; j < filecount; ++j) { const QString &fileName = file.file(i, j); QString alias = file.alias(i, j); if (alias.isEmpty()) alias = path().toFileInfo().absoluteDir().relativeFilePath(fileName); if (fileNames.contains(fileName)) { // The file name is duplicated, skip it // Note: this is wrong, but the qrceditor doesn't allow it either // only aliases need to be unique } else { QString prefixWithSlash = prefix; if (!prefixWithSlash.endsWith(QLatin1Char('/'))) prefixWithSlash.append(QLatin1Char('/')); const QString qrcPath = QDir::cleanPath(prefixWithSlash + alias); fileNames.insert(fileName); filesToAdd[qMakePair(prefix, lang)] << new ResourceFileNode(Utils::FileName::fromString(fileName), qrcPath, this); } } } } QList<ProjectExplorer::FolderNode *> oldFolderList = subFolderNodes(); QList<ProjectExplorer::FolderNode *> foldersToAdd; QList<ProjectExplorer::FolderNode *> foldersToRemove; std::sort(oldFolderList.begin(), oldFolderList.end(), sortByPrefixAndLang); std::sort(newFolderList.begin(), newFolderList.end(), sortByPrefixAndLang); ProjectExplorer::compareSortedLists(oldFolderList, newFolderList, foldersToRemove, foldersToAdd, sortByPrefixAndLang); removeFolderNodes(foldersToRemove); addFolderNodes(foldersToAdd); // delete nodes that weren't added qDeleteAll(ProjectExplorer::subtractSortedList(newFolderList, foldersToAdd, sortByPrefixAndLang)); foreach (FolderNode *fn, subFolderNodes()) { ResourceFolderNode *rn = static_cast<ResourceFolderNode *>(fn); rn->updateFiles(filesToAdd.value(qMakePair(rn->prefix(), rn->lang()))); }