diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp index 07d7c73cda5..1c8f057f701 100644 --- a/src/plugins/projectexplorer/session.cpp +++ b/src/plugins/projectexplorer/session.cpp @@ -25,13 +25,12 @@ #include #include -#include +#include #include #include #include #include -#include #include #include @@ -68,14 +67,14 @@ public: void restoreDependencies(const PersistentSettingsReader &reader); void restoreStartupProject(const PersistentSettingsReader &reader); void restoreEditors(const PersistentSettingsReader &reader); - void restoreProjects(const Utils::FilePaths &fileList); + void restoreProjects(const FilePaths &fileList); void askUserAboutFailedProjects(); void sessionLoadingProgress(); - bool recursiveDependencyCheck(const QString &newDep, const QString &checkDep) const; - QStringList dependencies(const QString &proName) const; - QStringList dependenciesOrder() const; - void dependencies(const QString &proName, QStringList &result) const; + bool recursiveDependencyCheck(const FilePath &newDep, const FilePath &checkDep) const; + FilePaths dependencies(const FilePath &proName) const; + FilePaths dependenciesOrder() const; + void dependencies(const FilePath &proName, FilePaths &result) const; static QString windowTitleAddition(const FilePath &filePath); static QString sessionTitle(const FilePath &filePath); @@ -94,7 +93,7 @@ public: Project *m_startupProject = nullptr; QList m_projects; FilePaths m_failedProjects; - QMap m_depMap; + QMap m_depMap; QMap m_values; QFutureInterface m_future; PersistentSettingsWriter *m_writer = nullptr; @@ -176,13 +175,14 @@ void SessionManager::saveActiveMode(Id mode) setValue(QLatin1String("ActiveMode"), mode.toString()); } -bool SessionManagerPrivate::recursiveDependencyCheck(const QString &newDep, const QString &checkDep) const +bool SessionManagerPrivate::recursiveDependencyCheck(const FilePath &newDep, + const FilePath &checkDep) const { if (newDep == checkDep) return false; - const QStringList depList = m_depMap.value(checkDep); - for (const QString &dependency : depList) { + const FilePaths depList = m_depMap.value(checkDep); + for (const FilePath &dependency : depList) { if (!recursiveDependencyCheck(newDep, dependency)) return false; } @@ -199,13 +199,14 @@ bool SessionManagerPrivate::recursiveDependencyCheck(const QString &newDep, cons QList SessionManager::dependencies(const Project *project) { - const QString proName = project->projectFilePath().toString(); - const QStringList proDeps = d->m_depMap.value(proName); + const FilePath proName = project->projectFilePath(); + const FilePaths proDeps = d->m_depMap.value(proName); QList projects; - for (const QString &dep : proDeps) { - const Utils::FilePath fn = Utils::FilePath::fromString(dep); - Project *pro = Utils::findOrDefault(d->m_projects, [&fn](Project *p) { return p->projectFilePath() == fn; }); + for (const FilePath &dep : proDeps) { + Project *pro = Utils::findOrDefault(d->m_projects, [&dep](Project *p) { + return p->projectFilePath() == dep; + }); if (pro) projects += pro; } @@ -215,31 +216,31 @@ QList SessionManager::dependencies(const Project *project) bool SessionManager::hasDependency(const Project *project, const Project *depProject) { - const QString proName = project->projectFilePath().toString(); - const QString depName = depProject->projectFilePath().toString(); + const FilePath proName = project->projectFilePath(); + const FilePath depName = depProject->projectFilePath(); - const QStringList proDeps = d->m_depMap.value(proName); + const FilePaths proDeps = d->m_depMap.value(proName); return proDeps.contains(depName); } bool SessionManager::canAddDependency(const Project *project, const Project *depProject) { - const QString newDep = project->projectFilePath().toString(); - const QString checkDep = depProject->projectFilePath().toString(); + const FilePath newDep = project->projectFilePath(); + const FilePath checkDep = depProject->projectFilePath(); return d->recursiveDependencyCheck(newDep, checkDep); } bool SessionManager::addDependency(Project *project, Project *depProject) { - const QString proName = project->projectFilePath().toString(); - const QString depName = depProject->projectFilePath().toString(); + const FilePath proName = project->projectFilePath(); + const FilePath depName = depProject->projectFilePath(); // check if this dependency is valid if (!d->recursiveDependencyCheck(proName, depName)) return false; - QStringList proDeps = d->m_depMap.value(proName); + FilePaths proDeps = d->m_depMap.value(proName); if (!proDeps.contains(depName)) { proDeps.append(depName); d->m_depMap[proName] = proDeps; @@ -251,10 +252,10 @@ bool SessionManager::addDependency(Project *project, Project *depProject) void SessionManager::removeDependency(Project *project, Project *depProject) { - const QString proName = project->projectFilePath().toString(); - const QString depName = depProject->projectFilePath().toString(); + const FilePath proName = project->projectFilePath(); + const FilePath depName = depProject->projectFilePath(); - QStringList proDeps = d->m_depMap.value(proName); + FilePaths proDeps = d->m_depMap.value(proName); proDeps.removeAll(depName); if (proDeps.isEmpty()) d->m_depMap.remove(proName); @@ -510,11 +511,11 @@ bool SessionManager::save() QVariantMap depMap; auto i = d->m_depMap.constBegin(); while (i != d->m_depMap.constEnd()) { - QString key = i.key(); + QString key = i.key().toString(); QStringList values; - const QStringList valueList = i.value(); - for (const QString &value : valueList) - values << value; + const FilePaths valueList = i.value(); + for (const FilePath &value : valueList) + values << value.toString(); depMap.insert(key, values); ++i; } @@ -569,18 +570,18 @@ bool SessionManager::hasProject(Project *p) return d->m_projects.contains(p); } -QStringList SessionManagerPrivate::dependencies(const QString &proName) const +FilePaths SessionManagerPrivate::dependencies(const FilePath &proName) const { - QStringList result; + FilePaths result; dependencies(proName, result); return result; } -void SessionManagerPrivate::dependencies(const QString &proName, QStringList &result) const +void SessionManagerPrivate::dependencies(const FilePath &proName, FilePaths &result) const { - const QStringList depends = m_depMap.value(proName); + const FilePaths depends = m_depMap.value(proName); - for (const QString &dep : depends) + for (const FilePath &dep : depends) dependencies(dep, result); if (!result.contains(proName)) @@ -630,18 +631,18 @@ QString SessionManagerPrivate::windowTitleAddition(const FilePath &filePath) return filePath.isEmpty() ? QString() : locationInProject(filePath); } -QStringList SessionManagerPrivate::dependenciesOrder() const +FilePaths SessionManagerPrivate::dependenciesOrder() const { - QList > unordered; - QStringList ordered; + QList> unordered; + FilePaths ordered; // copy the map to a temporary list for (const Project *pro : m_projects) { - const QString proName = pro->projectFilePath().toString(); - const QStringList depList = filtered(m_depMap.value(proName), - [this](const QString &proPath) { + const FilePath proName = pro->projectFilePath(); + const FilePaths depList = filtered(m_depMap.value(proName), + [this](const FilePath &proPath) { return contains(m_projects, [proPath](const Project *p) { - return p->projectFilePath().toString() == proPath; + return p->projectFilePath() == proPath; }); }); unordered.push_back({proName, depList}); @@ -658,8 +659,8 @@ QStringList SessionManagerPrivate::dependenciesOrder() const // remove the handled projects from the dependency lists // of the remaining unordered projects for (int i = 0; i < unordered.count(); ++i) { - for (const QString &pro : std::as_const(ordered)) { - QStringList depList = unordered.at(i).second; + for (const FilePath &pro : std::as_const(ordered)) { + FilePaths depList = unordered.at(i).second; depList.removeAll(pro); unordered[i].second = depList; } @@ -673,15 +674,15 @@ QList SessionManager::projectOrder(const Project *project) { QList result; - QStringList pros; + FilePaths pros; if (project) - pros = d->dependencies(project->projectFilePath().toString()); + pros = d->dependencies(project->projectFilePath()); else pros = d->dependenciesOrder(); - for (const QString &proFile : std::as_const(pros)) { + for (const FilePath &proFile : std::as_const(pros)) { for (Project *pro : projects()) { - if (pro->projectFilePath().toString() == proFile) { + if (pro->projectFilePath() == proFile) { result << pro; break; } @@ -691,13 +692,13 @@ QList SessionManager::projectOrder(const Project *project) return result; } -Project *SessionManager::projectForFile(const Utils::FilePath &fileName) +Project *SessionManager::projectForFile(const FilePath &fileName) { return Utils::findOrDefault(SessionManager::projects(), [&fileName](const Project *p) { return p->isKnownFile(fileName); }); } -Project *SessionManager::projectWithProjectFilePath(const Utils::FilePath &filePath) +Project *SessionManager::projectWithProjectFilePath(const FilePath &filePath) { return Utils::findOrDefault(SessionManager::projects(), [&filePath](const Project *p) { return p->projectFilePath() == filePath; }); @@ -866,9 +867,9 @@ bool SessionManager::deleteSession(const QString &session) d->m_sessions.removeOne(session); d->m_lastActiveTimes.remove(session); emit instance()->sessionRemoved(session); - QFile fi(sessionNameToFileName(session).toString()); - if (fi.exists()) - return fi.remove(); + FilePath sessionFile = sessionNameToFileName(session); + if (sessionFile.exists()) + return sessionFile.removeFile(); return false; } @@ -883,9 +884,9 @@ bool SessionManager::cloneSession(const QString &original, const QString &clone) if (!d->m_sessions.contains(original)) return false; - QFile fi(sessionNameToFileName(original).toString()); + FilePath sessionFile = sessionNameToFileName(original); // If the file does not exist, we can still clone - if (!fi.exists() || fi.copy(sessionNameToFileName(clone).toString())) { + if (!sessionFile.exists() || sessionFile.copyFile(sessionNameToFileName(clone))) { d->m_sessions.insert(1, clone); d->m_sessionDateTimes.insert(clone, sessionNameToFileName(clone).lastModified()); return true; @@ -908,11 +909,11 @@ void SessionManagerPrivate::restoreDependencies(const PersistentSettingsReader & auto i = depMap.constBegin(); while (i != depMap.constEnd()) { const QString &key = i.key(); - QStringList values; + FilePaths values; const QStringList valueList = i.value().toStringList(); for (const QString &value : valueList) - values << value; - m_depMap.insert(key, values); + values << FilePath::fromString(value); + m_depMap.insert(FilePath::fromString(key), values); ++i; } } @@ -940,10 +941,10 @@ void SessionManagerPrivate::askUserAboutFailedProjects() void SessionManagerPrivate::restoreStartupProject(const PersistentSettingsReader &reader) { - const QString startupProject = reader.restoreValue(QLatin1String("StartupProject")).toString(); + const FilePath startupProject = FilePath::fromVariant(reader.restoreValue("StartupProject")); if (!startupProject.isEmpty()) { for (Project *pro : std::as_const(m_projects)) { - if (pro->projectFilePath().toString() == startupProject) { + if (pro->projectFilePath() == startupProject) { m_instance->setStartupProject(pro); break; }