QbsProject: Remove some more cached current item pointers

Access on-the-fly is cheap and guaranteed to not produce outdated
data.

Change-Id: I770760f0216a61309d65ddc29b405991d95fc64b
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2017-02-24 12:33:33 +01:00
parent d6e81eb49e
commit 4275182cf9
2 changed files with 47 additions and 98 deletions

View File

@@ -183,17 +183,17 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
this, &QbsProjectManagerPlugin::updateContextActions); this, &QbsProjectManagerPlugin::updateContextActions);
connect(BuildManager::instance(), &BuildManager::buildStateChanged, connect(BuildManager::instance(), &BuildManager::buildStateChanged,
this, &QbsProjectManagerPlugin::buildStateChanged); this, &QbsProjectManagerPlugin::projectChanged);
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
this, &QbsProjectManagerPlugin::currentEditorChanged); this, &QbsProjectManagerPlugin::updateBuildActions);
connect(SessionManager::instance(), &SessionManager::projectAdded, connect(SessionManager::instance(), &SessionManager::projectAdded,
this, &QbsProjectManagerPlugin::projectWasAdded); this, &QbsProjectManagerPlugin::projectWasAdded);
connect(SessionManager::instance(), &SessionManager::projectRemoved, connect(SessionManager::instance(), &SessionManager::projectRemoved,
this, &QbsProjectManagerPlugin::projectWasRemoved); this, &QbsProjectManagerPlugin::updateBuildActions);
connect(SessionManager::instance(), &SessionManager::startupProjectChanged, connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
this, &QbsProjectManagerPlugin::currentProjectWasChanged); this, &QbsProjectManagerPlugin::updateReparseQbsAction);
// Run initial setup routines // Run initial setup routines
updateContextActions(); updateContextActions();
@@ -214,24 +214,9 @@ void QbsProjectManagerPlugin::projectWasAdded(Project *project)
return; return;
connect(qbsProject, &QbsProject::projectParsingStarted, connect(qbsProject, &QbsProject::projectParsingStarted,
this, &QbsProjectManagerPlugin::parsingStateChanged); this, &QbsProjectManagerPlugin::projectChanged);
connect(qbsProject, &QbsProject::projectParsingDone, connect(qbsProject, &QbsProject::projectParsingDone,
this, &QbsProjectManagerPlugin::parsingStateChanged); this, &QbsProjectManagerPlugin::projectChanged);
}
void QbsProjectManagerPlugin::currentProjectWasChanged(Project *project)
{
m_currentProject = qobject_cast<QbsProject *>(project);
updateReparseQbsAction();
}
void QbsProjectManagerPlugin::projectWasRemoved()
{
m_editorNode = currentEditorNode();
m_editorProject = currentEditorProject();
updateBuildActions();
} }
void QbsProjectManagerPlugin::updateContextActions() void QbsProjectManagerPlugin::updateContextActions()
@@ -243,8 +228,7 @@ void QbsProjectManagerPlugin::updateContextActions()
&& node && node->isEnabled(); && node && node->isEnabled();
bool isFile = project && node && (node->nodeType() == NodeType::File); bool isFile = project && node && (node->nodeType() == NodeType::File);
bool isProduct = project && node bool isProduct = project && node && dynamic_cast<QbsProductNode *>(node);
&& dynamic_cast<QbsProductNode *>(node);
QbsProjectNode *subproject = dynamic_cast<QbsProjectNode *>(node); QbsProjectNode *subproject = dynamic_cast<QbsProjectNode *>(node);
bool isSubproject = project && subproject && subproject != project->rootProjectNode(); bool isSubproject = project && subproject && subproject != project->rootProjectNode();
@@ -256,9 +240,10 @@ void QbsProjectManagerPlugin::updateContextActions()
void QbsProjectManagerPlugin::updateReparseQbsAction() void QbsProjectManagerPlugin::updateReparseQbsAction()
{ {
m_reparseQbs->setEnabled(m_currentProject QbsProject *project = qobject_cast<QbsProject *>(SessionManager::startupProject());
&& !BuildManager::isBuilding(m_currentProject) m_reparseQbs->setEnabled(project
&& !m_currentProject->isParsing()); && !BuildManager::isBuilding(project)
&& !project->isParsing());
} }
void QbsProjectManagerPlugin::updateBuildActions() void QbsProjectManagerPlugin::updateBuildActions()
@@ -272,23 +257,24 @@ void QbsProjectManagerPlugin::updateBuildActions()
QString productName; QString productName;
QString subprojectName; QString subprojectName;
if (m_editorNode) { if (Node *editorNode = currentEditorNode()) {
enabled = m_editorProject QbsProject *editorProject = currentEditorProject();
&& !BuildManager::isBuilding(m_editorProject) enabled = editorProject
&& !m_editorProject->isParsing(); && !BuildManager::isBuilding(editorProject)
&& !editorProject->isParsing();
fileName = m_editorNode->filePath().fileName(); fileName = editorNode->filePath().fileName();
fileVisible = m_editorProject && m_editorNode && dynamic_cast<QbsBaseProjectNode *>(m_editorNode->parentProjectNode()); fileVisible = editorProject && editorNode && dynamic_cast<QbsBaseProjectNode *>(editorNode->parentProjectNode());
QbsProductNode *productNode QbsProductNode *productNode =
= dynamic_cast<QbsProductNode *>(m_editorNode ? m_editorNode->parentProjectNode() : 0); dynamic_cast<QbsProductNode *>(editorNode ? editorNode->parentProjectNode() : 0);
if (productNode) { if (productNode) {
productVisible = true; productVisible = true;
productName = productNode->displayName(); productName = productNode->displayName();
} }
QbsProjectNode *subprojectNode QbsProjectNode *subprojectNode =
= dynamic_cast<QbsProjectNode *>(productNode ? productNode->parentFolderNode() : 0); dynamic_cast<QbsProjectNode *>(productNode ? productNode->parentFolderNode() : 0);
if (subprojectNode && m_editorProject && subprojectNode != m_editorProject->rootProjectNode()) { if (subprojectNode && editorProject && subprojectNode != editorProject->rootProjectNode()) {
subprojectVisible = true; subprojectVisible = true;
subprojectName = subprojectNode->displayName(); subprojectName = subprojectNode->displayName();
} }
@@ -307,44 +293,20 @@ void QbsProjectManagerPlugin::updateBuildActions()
m_buildSubproject->setParameter(subprojectName); m_buildSubproject->setParameter(subprojectName);
} }
void QbsProjectManagerPlugin::buildStateChanged(Project *project) void QbsProjectManagerPlugin::projectChanged()
{
if (project == m_currentProject)
updateReparseQbsAction();
if (project == ProjectTree::currentProject())
updateContextActions();
m_editorNode = currentEditorNode();
m_editorProject = currentEditorProject();
if (project == m_editorProject)
updateBuildActions();
}
void QbsProjectManagerPlugin::parsingStateChanged()
{ {
QbsProject *project = qobject_cast<QbsProject *>(sender()); QbsProject *project = qobject_cast<QbsProject *>(sender());
if (!project || project == m_currentProject) if (!project || project == SessionManager::startupProject())
updateReparseQbsAction(); updateReparseQbsAction();
if (!project || project == ProjectTree::currentProject()) if (!project || project == ProjectTree::currentProject())
updateContextActions(); updateContextActions();
m_editorNode = currentEditorNode(); if (!project || project == currentEditorProject())
m_editorProject = currentEditorProject();
if (!project || project == m_editorProject)
updateBuildActions(); updateBuildActions();
} }
void QbsProjectManagerPlugin::currentEditorChanged()
{
m_editorNode = currentEditorNode();
m_editorProject = currentEditorProject();
updateBuildActions();
}
void QbsProjectManagerPlugin::buildFileContextMenu() void QbsProjectManagerPlugin::buildFileContextMenu()
{ {
Node *node = ProjectTree::currentNode(); Node *node = ProjectTree::currentNode();
@@ -356,10 +318,12 @@ void QbsProjectManagerPlugin::buildFileContextMenu()
void QbsProjectManagerPlugin::buildFile() void QbsProjectManagerPlugin::buildFile()
{ {
if (!m_editorProject || !m_editorNode) Node *node = currentEditorNode();
QbsProject *project = currentEditorProject();
if (!project || !node)
return; return;
buildSingleFile(m_editorProject, m_editorNode->filePath().toString()); buildSingleFile(project, node->filePath().toString());
} }
void QbsProjectManagerPlugin::buildProductContextMenu() void QbsProjectManagerPlugin::buildProductContextMenu()
@@ -377,16 +341,19 @@ void QbsProjectManagerPlugin::buildProductContextMenu()
void QbsProjectManagerPlugin::buildProduct() void QbsProjectManagerPlugin::buildProduct()
{ {
if (!m_editorProject || !m_editorNode) Node *node = currentEditorNode();
if (!node)
return; return;
QbsProductNode *product = dynamic_cast<QbsProductNode *>(m_editorNode->parentProjectNode()); QbsProductNode *product = dynamic_cast<QbsProductNode *>(node->parentProjectNode());
if (!product) if (!product)
return; return;
buildProducts(m_editorProject, QbsProject *project = currentEditorProject();
QStringList(QbsProject::uniqueProductName(product->qbsProductData()))); if (!project)
return;
buildProducts(project, {QbsProject::uniqueProductName(product->qbsProductData())});
} }
void QbsProjectManagerPlugin::buildSubprojectContextMenu() void QbsProjectManagerPlugin::buildSubprojectContextMenu()
@@ -408,12 +375,14 @@ void QbsProjectManagerPlugin::buildSubprojectContextMenu()
void QbsProjectManagerPlugin::buildSubproject() void QbsProjectManagerPlugin::buildSubproject()
{ {
if (!m_editorNode || !m_editorProject) Node *editorNode = currentEditorNode();
QbsProject *editorProject = currentEditorProject();
if (!editorNode || !editorProject)
return; return;
QbsProjectNode *subproject = 0; QbsProjectNode *subproject = 0;
QbsBaseProjectNode *start = dynamic_cast<QbsBaseProjectNode *>(m_editorNode->parentProjectNode()); QbsBaseProjectNode *start = dynamic_cast<QbsBaseProjectNode *>(editorNode->parentProjectNode());
while (start && start != m_editorProject->rootProjectNode()) { while (start && start != editorProject->rootProjectNode()) {
QbsProjectNode *tmp = dynamic_cast<QbsProjectNode *>(start); QbsProjectNode *tmp = dynamic_cast<QbsProjectNode *>(start);
if (tmp) { if (tmp) {
subproject = tmp; subproject = tmp;
@@ -429,7 +398,7 @@ void QbsProjectManagerPlugin::buildSubproject()
foreach (const qbs::ProductData &data, subproject->qbsProjectData().allProducts()) foreach (const qbs::ProductData &data, subproject->qbsProjectData().allProducts())
toBuild << QbsProject::uniqueProductName(data); toBuild << QbsProject::uniqueProductName(data);
buildProducts(m_editorProject, toBuild); buildProducts(editorProject, toBuild);
} }
void QbsProjectManagerPlugin::buildFiles(QbsProject *project, const QStringList &files, void QbsProjectManagerPlugin::buildFiles(QbsProject *project, const QStringList &files,
@@ -499,7 +468,7 @@ void QbsProjectManagerPlugin::reparseSelectedProject()
void QbsProjectManagerPlugin::reparseCurrentProject() void QbsProjectManagerPlugin::reparseCurrentProject()
{ {
reparseProject(m_currentProject); reparseProject(dynamic_cast<QbsProject *>(SessionManager::startupProject()));
} }
void QbsProjectManagerPlugin::reparseProject(QbsProject *project) void QbsProjectManagerPlugin::reparseProject(QbsProject *project)

View File

@@ -28,18 +28,7 @@
#include <extensionsystem/iplugin.h> #include <extensionsystem/iplugin.h>
#include <utils/parameteraction.h> #include <utils/parameteraction.h>
#include <QObject> namespace ProjectExplorer { class Project; }
QT_BEGIN_NAMESPACE
class QAction;
QT_END_NAMESPACE
namespace ProjectExplorer {
class Project;
class ProjectExplorerPlugin;
class Node;
class Target;
} // namespace ProjectExplorer
namespace QbsProjectManager { namespace QbsProjectManager {
namespace Internal { namespace Internal {
@@ -58,11 +47,7 @@ public:
private: private:
void projectWasAdded(ProjectExplorer::Project *project); void projectWasAdded(ProjectExplorer::Project *project);
void currentProjectWasChanged(ProjectExplorer::Project *project); void projectChanged();
void projectWasRemoved();
void buildStateChanged(ProjectExplorer::Project *project);
void parsingStateChanged();
void currentEditorChanged();
void buildFileContextMenu(); void buildFileContextMenu();
void buildFile(); void buildFile();
@@ -92,11 +77,6 @@ private:
Utils::ParameterAction *m_buildFile = nullptr; Utils::ParameterAction *m_buildFile = nullptr;
Utils::ParameterAction *m_buildProduct = nullptr; Utils::ParameterAction *m_buildProduct = nullptr;
Utils::ParameterAction *m_buildSubproject = nullptr; Utils::ParameterAction *m_buildSubproject = nullptr;
Internal::QbsProject *m_currentProject = nullptr;
Internal::QbsProject *m_editorProject = nullptr;
ProjectExplorer::Node *m_editorNode = nullptr;
}; };
} // namespace Internal } // namespace Internal