forked from qt-creator/qt-creator
ProjectExplorer: Use more const
Clean up action update and use more const variables. Spread some const over other code, so that const variables can actually be used. Change-Id: Ia814900ddff294aeafedb2a223d3705990f9b7c1 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -561,26 +561,26 @@ void BuildManager::appendStep(BuildStep *step, const QString &name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
int count(const QHash<T *, int> &hash, T *key)
|
int count(const QHash<T *, int> &hash, const T *key)
|
||||||
{
|
{
|
||||||
typename QHash<T *, int>::const_iterator it = hash.find(key);
|
typename QHash<T *, int>::const_iterator it = hash.find(const_cast<T *>(key));
|
||||||
typename QHash<T *, int>::const_iterator end = hash.end();
|
typename QHash<T *, int>::const_iterator end = hash.end();
|
||||||
if (it != end)
|
if (it != end)
|
||||||
return *it;
|
return *it;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BuildManager::isBuilding(Project *pro)
|
bool BuildManager::isBuilding(const Project *pro)
|
||||||
{
|
{
|
||||||
return count(d->m_activeBuildSteps, pro) > 0;
|
return count(d->m_activeBuildSteps, pro) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BuildManager::isBuilding(Target *t)
|
bool BuildManager::isBuilding(const Target *t)
|
||||||
{
|
{
|
||||||
return count(d->m_activeBuildStepsPerTarget, t) > 0;
|
return count(d->m_activeBuildStepsPerTarget, t) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BuildManager::isBuilding(ProjectConfiguration *p)
|
bool BuildManager::isBuilding(const ProjectConfiguration *p)
|
||||||
{
|
{
|
||||||
return count(d->m_activeBuildStepsPerProjectConfiguration, p) > 0;
|
return count(d->m_activeBuildStepsPerProjectConfiguration, p) > 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,9 +54,9 @@ public:
|
|||||||
const QStringList &preambelMessage = QStringList());
|
const QStringList &preambelMessage = QStringList());
|
||||||
static bool buildList(BuildStepList *bsl, const QString &stepListName);
|
static bool buildList(BuildStepList *bsl, const QString &stepListName);
|
||||||
|
|
||||||
static bool isBuilding(Project *p);
|
static bool isBuilding(const Project *p);
|
||||||
static bool isBuilding(Target *t);
|
static bool isBuilding(const Target *t);
|
||||||
static bool isBuilding(ProjectConfiguration *p);
|
static bool isBuilding(const ProjectConfiguration *p);
|
||||||
static bool isBuilding(BuildStep *step);
|
static bool isBuilding(BuildStep *step);
|
||||||
|
|
||||||
// Append any build step to the list of build steps (currently only used to add the QMakeStep)
|
// Append any build step to the list of build steps (currently only used to add the QMakeStep)
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ public:
|
|||||||
void updateContextMenuActions();
|
void updateContextMenuActions();
|
||||||
void executeRunConfiguration(RunConfiguration *, Core::Id mode);
|
void executeRunConfiguration(RunConfiguration *, Core::Id mode);
|
||||||
QPair<bool, QString> buildSettingsEnabledForSession();
|
QPair<bool, QString> buildSettingsEnabledForSession();
|
||||||
QPair<bool, QString> buildSettingsEnabled(Project *pro);
|
QPair<bool, QString> buildSettingsEnabled(const Project *pro);
|
||||||
|
|
||||||
void addToRecentProjects(const QString &fileName, const QString &displayName);
|
void addToRecentProjects(const QString &fileName, const QString &displayName);
|
||||||
void startRunControl(RunControl *runControl, Core::Id runMode);
|
void startRunControl(RunControl *runControl, Core::Id runMode);
|
||||||
@@ -2063,15 +2063,15 @@ QString ProjectExplorerPlugin::directoryFor(Node *node)
|
|||||||
|
|
||||||
void ProjectExplorerPluginPrivate::updateActions()
|
void ProjectExplorerPluginPrivate::updateActions()
|
||||||
{
|
{
|
||||||
Project *project = SessionManager::startupProject();
|
const Project *const project = SessionManager::startupProject();
|
||||||
Project *currentProject = ProjectTree::currentProject(); // for context menu actions
|
const Project *const currentProject = ProjectTree::currentProject(); // for context menu actions
|
||||||
|
|
||||||
QPair<bool, QString> buildActionState = buildSettingsEnabled(project);
|
const QPair<bool, QString> buildActionState = buildSettingsEnabled(project);
|
||||||
QPair<bool, QString> buildActionContextState = buildSettingsEnabled(currentProject);
|
const QPair<bool, QString> buildActionContextState = buildSettingsEnabled(currentProject);
|
||||||
QPair<bool, QString> buildSessionState = buildSettingsEnabledForSession();
|
const QPair<bool, QString> buildSessionState = buildSettingsEnabledForSession();
|
||||||
|
|
||||||
QString projectName = project ? project->displayName() : QString();
|
const QString projectName = project ? project->displayName() : QString();
|
||||||
QString projectNameContextMenu = currentProject ? currentProject->displayName() : QString();
|
const QString projectNameContextMenu = currentProject ? currentProject->displayName() : QString();
|
||||||
|
|
||||||
m_unloadAction->setParameter(projectName);
|
m_unloadAction->setParameter(projectName);
|
||||||
m_unloadActionContextMenu->setParameter(projectNameContextMenu);
|
m_unloadActionContextMenu->setParameter(projectNameContextMenu);
|
||||||
@@ -2093,16 +2093,10 @@ void ProjectExplorerPluginPrivate::updateActions()
|
|||||||
m_setStartupProjectAction->setParameter(projectNameContextMenu);
|
m_setStartupProjectAction->setParameter(projectNameContextMenu);
|
||||||
m_setStartupProjectAction->setVisible(currentProject != project);
|
m_setStartupProjectAction->setVisible(currentProject != project);
|
||||||
|
|
||||||
bool hasDependencies = SessionManager::projectOrder(currentProject).size() > 1;
|
const bool hasDependencies = SessionManager::projectOrder(currentProject).size() > 1;
|
||||||
if (hasDependencies) {
|
m_buildActionContextMenu->setVisible(hasDependencies);
|
||||||
m_buildActionContextMenu->setVisible(true);
|
m_rebuildActionContextMenu->setVisible(hasDependencies);
|
||||||
m_rebuildActionContextMenu->setVisible(true);
|
m_cleanActionContextMenu->setVisible(hasDependencies);
|
||||||
m_cleanActionContextMenu->setVisible(true);
|
|
||||||
} else {
|
|
||||||
m_buildActionContextMenu->setVisible(false);
|
|
||||||
m_rebuildActionContextMenu->setVisible(false);
|
|
||||||
m_cleanActionContextMenu->setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_buildActionContextMenu->setEnabled(buildActionContextState.first);
|
m_buildActionContextMenu->setEnabled(buildActionContextState.first);
|
||||||
m_rebuildActionContextMenu->setEnabled(buildActionContextState.first);
|
m_rebuildActionContextMenu->setEnabled(buildActionContextState.first);
|
||||||
@@ -2438,16 +2432,16 @@ void ProjectExplorerPluginPrivate::runProjectContextMenu()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool hasBuildSettings(Project *pro)
|
static bool hasBuildSettings(const Project *pro)
|
||||||
{
|
{
|
||||||
return Utils::anyOf(SessionManager::projectOrder(pro), [](Project *project) {
|
return Utils::anyOf(SessionManager::projectOrder(pro), [](const Project *project) {
|
||||||
return project
|
return project
|
||||||
&& project->activeTarget()
|
&& project->activeTarget()
|
||||||
&& project->activeTarget()->activeBuildConfiguration();
|
&& project->activeTarget()->activeBuildConfiguration();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QPair<bool, QString> ProjectExplorerPluginPrivate::buildSettingsEnabled(Project *pro)
|
QPair<bool, QString> ProjectExplorerPluginPrivate::buildSettingsEnabled(const Project *pro)
|
||||||
{
|
{
|
||||||
QPair<bool, QString> result;
|
QPair<bool, QString> result;
|
||||||
result.first = true;
|
result.first = true;
|
||||||
|
|||||||
@@ -574,7 +574,7 @@ QStringList SessionManagerPrivate::dependenciesOrder() const
|
|||||||
return ordered;
|
return ordered;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Project *> SessionManager::projectOrder(Project *project)
|
QList<Project *> SessionManager::projectOrder(const Project *project)
|
||||||
{
|
{
|
||||||
QList<Project *> result;
|
QList<Project *> result;
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public:
|
|||||||
static QVariant value(const QString &name);
|
static QVariant value(const QString &name);
|
||||||
|
|
||||||
// NBS rewrite projectOrder (dependency management)
|
// NBS rewrite projectOrder (dependency management)
|
||||||
static QList<Project *> projectOrder(Project *project = 0);
|
static QList<Project *> projectOrder(const Project *project = 0);
|
||||||
|
|
||||||
static SessionNode *sessionNode();
|
static SessionNode *sessionNode();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user