PE: Fix project pointer when adding files or subprojects

It is possible to trigger the respective actions directly from
the project tree without having the respective project as
current active project.
Instead of always passing around the project which is currently
active use the one we get from the selected node if there is
any and fall back to the current active project if there is no
selected node.

Change-Id: Iccee63f1d75e88188b55f7307fcc46ba52e82a8a
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Christian Stenger
2024-06-17 12:46:12 +02:00
parent afde8fd1a7
commit 8cc58c90d3

View File

@@ -3473,7 +3473,9 @@ void ProjectExplorerPluginPrivate::addNewFile()
// to access meta data on an object that get deleted in the meantime: // to access meta data on an object that get deleted in the meantime:
map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(static_cast<void *>(currentNode))); map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(static_cast<void *>(currentNode)));
map.insert(Constants::PREFERRED_PROJECT_NODE_PATH, currentNode->filePath().toString()); map.insert(Constants::PREFERRED_PROJECT_NODE_PATH, currentNode->filePath().toString());
if (Project *p = ProjectTree::currentProject()) { Project *p = ProjectTree::projectForNode(currentNode);
QTC_ASSERT(p, p = ProjectTree::currentProject());
if (p) {
const QStringList profileIds = Utils::transform(p->targets(), [](const Target *t) { const QStringList profileIds = Utils::transform(p->targets(), [](const Target *t) {
return t->id().toString(); return t->id().toString();
}); });
@@ -3504,7 +3506,9 @@ void ProjectExplorerPluginPrivate::addNewHeaderOrSource()
QVariant::fromValue(static_cast<void *>(folderNode))); QVariant::fromValue(static_cast<void *>(folderNode)));
map.insert(Constants::PREFERRED_PROJECT_NODE_PATH, folderNode->filePath().toString()); map.insert(Constants::PREFERRED_PROJECT_NODE_PATH, folderNode->filePath().toString());
map.insert("InitialFileName", fileNode->filePath().completeBaseName()); map.insert("InitialFileName", fileNode->filePath().completeBaseName());
if (Project *p = ProjectTree::currentProject()) { Project *p = ProjectTree::projectForNode(folderNode);
QTC_ASSERT(p, p = ProjectTree::currentProject());
if (p) {
const QStringList profileIds = Utils::transform(p->targets(), [](const Target *t) { const QStringList profileIds = Utils::transform(p->targets(), [](const Target *t) {
return t->id().toString(); return t->id().toString();
}); });
@@ -3528,11 +3532,13 @@ void ProjectExplorerPluginPrivate::addNewSubproject()
if (currentNode->isProjectNodeType() if (currentNode->isProjectNodeType()
&& currentNode->supportsAction(AddSubProject, currentNode)) { && currentNode->supportsAction(AddSubProject, currentNode)) {
QVariantMap map; QVariantMap map;
map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(currentNode)); map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE),
Project *project = ProjectTree::currentProject(); QVariant::fromValue(static_cast<void *>(currentNode)));
Project *project = ProjectTree::projectForNode(currentNode);
QTC_ASSERT(project, project = ProjectTree::currentProject());
Id projectType; Id projectType;
if (project) { if (project) {
const QStringList profileIds = Utils::transform(ProjectTree::currentProject()->targets(), const QStringList profileIds = Utils::transform(project->targets(),
[](const Target *t) { [](const Target *t) {
return t->id().toString(); return t->id().toString();
}); });