ProjectExplorer: Return FilePaths for SessionManager::projectsForSessionName()

Change-Id: Ie168973e872ea105c7eb46ff7f58fb34883364b1
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2023-01-03 17:31:38 +01:00
parent ac9023e851
commit 4b237c0e98
5 changed files with 17 additions and 20 deletions

View File

@@ -31,6 +31,7 @@
using namespace CppEditor;
using namespace ProjectExplorer;
using namespace Utils;
static bool processEventsUntil(const std::function<bool()> condition, int timeOutInMs = 30000)
{
@@ -51,7 +52,7 @@ static bool processEventsUntil(const std::function<bool()> condition, int timeOu
class WaitForParsedProjects : public QObject
{
public:
WaitForParsedProjects(const QStringList &projects)
WaitForParsedProjects(const FilePaths &projects)
: m_projectsToWaitFor(projects)
{
connect(SessionManager::instance(),
@@ -61,7 +62,7 @@ public:
void onProjectFinishedParsing(ProjectExplorer::Project *project)
{
m_projectsToWaitFor.removeOne(project->projectFilePath().toString());
m_projectsToWaitFor.removeOne(project->projectFilePath());
}
bool wait()
@@ -70,7 +71,7 @@ public:
}
private:
QStringList m_projectsToWaitFor;
FilePaths m_projectsToWaitFor;
};
namespace ClangTools {
@@ -86,7 +87,7 @@ void PreconfiguredSessionTests::initTestCase()
QSKIP("Session must not be already active.");
// Load session
const QStringList projects = SessionManager::projectsForSessionName(preconfiguredSessionName);
const FilePaths projects = SessionManager::projectsForSessionName(preconfiguredSessionName);
WaitForParsedProjects waitForParsedProjects(projects);
QVERIFY(SessionManager::loadSession(preconfiguredSessionName));
QVERIFY(waitForParsedProjects.wait());

View File

@@ -322,12 +322,11 @@ public:
if (expanded) {
painter->setPen(textColor);
painter->setFont(sizedFont(12, option.widget));
const QStringList projects = SessionManager::projectsForSessionName(sessionName);
const FilePaths projects = SessionManager::projectsForSessionName(sessionName);
int yy = firstBase + SESSION_LINE_HEIGHT - 3;
QFontMetrics fm(option.widget->font());
for (const QString &project : projects) {
for (const FilePath &projectPath : projects) {
// Project name.
FilePath projectPath = FilePath::fromString(project);
QString completeBase = projectPath.completeBaseName();
painter->setPen(textColor);
painter->drawText(x1, yy, fm.elidedText(completeBase, Qt::ElideMiddle, textSpace));
@@ -375,7 +374,7 @@ public:
int h = SESSION_LINE_HEIGHT;
QString sessionName = idx.data(Qt::DisplayRole).toString();
if (m_expandedSessions.contains(sessionName)) {
QStringList projects = SessionManager::projectsForSessionName(sessionName);
const FilePaths projects = SessionManager::projectsForSessionName(sessionName);
h += projects.size() * 40 + LINK_HEIGHT - 6;
}
return QSize(380, h + ItemGap);

View File

@@ -1179,17 +1179,18 @@ void SessionManagerPrivate::sessionLoadingProgress()
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
}
QStringList SessionManager::projectsForSessionName(const QString &session)
FilePaths SessionManager::projectsForSessionName(const QString &session)
{
const FilePath fileName = sessionNameToFileName(session);
PersistentSettingsReader reader;
if (fileName.exists()) {
if (!reader.load(fileName)) {
qWarning() << "Could not restore session" << fileName.toUserOutput();
return QStringList();
return {};
}
}
return reader.restoreValue(QLatin1String("ProjectList")).toStringList();
return transform(reader.restoreValue(QLatin1String("ProjectList")).toStringList(),
&FilePath::fromUserInput);
}
#ifdef WITH_TESTS

View File

@@ -99,7 +99,7 @@ public:
static Project *projectForFile(const Utils::FilePath &fileName);
static Project *projectWithProjectFilePath(const Utils::FilePath &filePath);
static QStringList projectsForSessionName(const QString &session);
static Utils::FilePaths projectsForSessionName(const QString &session);
static void reportProjectLoadingProgress();
static bool loadingSession();

View File

@@ -74,18 +74,14 @@ int SessionModel::rowCount(const QModelIndex &) const
return m_sortedSessions.count();
}
QStringList pathsToBaseNames(const QStringList &paths)
QStringList pathsToBaseNames(const FilePaths &paths)
{
return Utils::transform(paths, [](const QString &path) {
return QFileInfo(path).completeBaseName();
});
return Utils::transform(paths, &FilePath::completeBaseName);
}
QStringList pathsWithTildeHomePath(const QStringList &paths)
QStringList pathsWithTildeHomePath(const FilePaths &paths)
{
return Utils::transform(paths, [](const QString &path) {
return FilePath::fromString(path).withTildeHomePath();
});
return Utils::transform(paths, &FilePath::withTildeHomePath);
}
QVariant SessionModel::data(const QModelIndex &index, int role) const