ProjectExplorer: Use more FilePath in session handling

Change-Id: Ia457bcaa1faa72a34998915d7648587595bd342d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2022-11-09 16:07:09 +01:00
parent f147ef73eb
commit e70658d9e9

View File

@@ -25,13 +25,12 @@
#include <texteditor/texteditor.h>
#include <utils/algorithm.h>
#include <utils/fileutils.h>
#include <utils/filepath.h>
#include <utils/qtcassert.h>
#include <utils/stylehelper.h>
#include <utils/qtcassert.h>
#include <QDebug>
#include <QDir>
#include <QMessageBox>
#include <QPushButton>
@@ -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<Project *> m_projects;
FilePaths m_failedProjects;
QMap<QString, QStringList> m_depMap;
QMap<FilePath, FilePaths> m_depMap;
QMap<QString, QVariant> m_values;
QFutureInterface<void> 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<Project *> 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<Project *> 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<Project *> 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<QPair<QString, QStringList> > unordered;
QStringList ordered;
QList<QPair<FilePath, FilePaths>> 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<Project *> SessionManager::projectOrder(const Project *project)
{
QList<Project *> 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<Project *> 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;
}