Commit 3948f9d8 authored by Christian Kandeler's avatar Christian Kandeler

QbsProjectManager: Use qbs::Project as a value.

Those objects are shared data pointers that can (and should)
be used as values. This is now actually possible due to
the newly introduced public default constructor and
isValid() method.

Change-Id: I989e339bd495aa7581b01f17f00cbffe0b617b9c
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent f9aa1207
......@@ -535,8 +535,8 @@ QList<ProjectExplorer::RunConfiguration *> QbsProductNode::runConfigurationsFor(
Q_UNUSED(node);
QList<ProjectExplorer::RunConfiguration *> result;
QbsProjectNode *pn = qobject_cast<QbsProjectNode *>(projectNode());
if (!isEnabled() || !pn || pn->qbsProject()->targetExecutable(m_qbsProductData,
qbs::InstallOptions()).isEmpty()) {
if (!isEnabled() || !pn || !pn->qbsProject().isValid()
|| pn->qbsProject().targetExecutable(m_qbsProductData, qbs::InstallOptions()).isEmpty()) {
return result;
}
......@@ -567,14 +567,14 @@ QbsGroupNode *QbsProductNode::findGroupNode(const QString &name)
QbsProjectNode::QbsProjectNode(QbsProject *project) :
QbsBaseProjectNode(project->projectFilePath()),
m_project(project), m_qbsProject(0)
m_project(project)
{
ctor();
}
QbsProjectNode::QbsProjectNode(const QString &path) :
QbsBaseProjectNode(path),
m_project(0), m_qbsProject(0)
m_project(0)
{
ctor();
}
......@@ -582,14 +582,11 @@ QbsProjectNode::QbsProjectNode(const QString &path) :
QbsProjectNode::~QbsProjectNode()
{
// do not delete m_project
delete m_qbsProject;
}
void QbsProjectNode::update(const qbs::Project *prj)
void QbsProjectNode::update(const qbs::Project &prj)
{
update(prj ? prj->projectData() : qbs::ProjectData());
delete m_qbsProject;
update(prj.isValid() ? prj.projectData() : qbs::ProjectData());
m_qbsProject = prj;
}
......@@ -638,10 +635,10 @@ QbsProject *QbsProjectNode::project() const
return m_project;
}
const qbs::Project *QbsProjectNode::qbsProject() const
const qbs::Project QbsProjectNode::qbsProject() const
{
QbsProjectNode *parent = qobject_cast<QbsProjectNode *>(projectNode());
if (!m_qbsProject && parent != this)
if (!m_qbsProject.isValid() && parent != this)
return parent->qbsProject();
return m_qbsProject;
}
......
......@@ -32,7 +32,7 @@
#include <projectexplorer/projectnodes.h>
#include <api/projectdata.h>
#include <qbs.h>
#include <QIcon>
......@@ -170,11 +170,11 @@ public:
explicit QbsProjectNode(const QString &path);
~QbsProjectNode();
void update(const qbs::Project *prj);
void update(const qbs::Project &prj);
void update(const qbs::ProjectData &prjData);
QbsProject *project() const;
const qbs::Project *qbsProject() const;
const qbs::Project qbsProject() const;
const qbs::ProjectData qbsProjectData() const;
private:
......@@ -185,7 +185,7 @@ private:
QbsProject *m_project;
const qbs::Project *m_qbsProject;
qbs::Project m_qbsProject;
qbs::ProjectData m_qbsProjectData;
static QIcon m_projectIcon;
};
......
......@@ -181,10 +181,10 @@ void QbsProject::invalidate()
qbs::BuildJob *QbsProject::build(const qbs::BuildOptions &opts, QStringList productNames)
{
if (!qbsProject() || isParsing())
if (!qbsProject().isValid() || isParsing())
return 0;
if (productNames.isEmpty()) {
return qbsProject()->buildAllProducts(opts);
return qbsProject().buildAllProducts(opts);
} else {
QList<qbs::ProductData> products;
foreach (const QString &productName, productNames) {
......@@ -200,22 +200,22 @@ qbs::BuildJob *QbsProject::build(const qbs::BuildOptions &opts, QStringList prod
return 0;
}
return qbsProject()->buildSomeProducts(products, opts);
return qbsProject().buildSomeProducts(products, opts);
}
}
qbs::CleanJob *QbsProject::clean(const qbs::CleanOptions &opts)
{
if (!qbsProject())
if (!qbsProject().isValid())
return 0;
return qbsProject()->cleanAllProducts(opts);
return qbsProject().cleanAllProducts(opts);
}
qbs::InstallJob *QbsProject::install(const qbs::InstallOptions &opts)
{
if (!qbsProject())
if (!qbsProject().isValid())
return 0;
return qbsProject()->installAllProducts(opts);
return qbsProject().installAllProducts(opts);
}
QString QbsProject::profileForTarget(const Target *t) const
......@@ -230,7 +230,7 @@ bool QbsProject::isParsing() const
bool QbsProject::hasParseResult() const
{
return qbsProject();
return qbsProject().isValid();
}
FileName QbsProject::defaultBuildDirectory() const
......@@ -240,10 +240,10 @@ FileName QbsProject::defaultBuildDirectory() const
return FileName::fromString(buildDir);
}
const qbs::Project *QbsProject::qbsProject() const
qbs::Project QbsProject::qbsProject() const
{
if (!m_rootProjectNode)
return 0;
return qbs::Project();
return m_rootProjectNode->qbsProject();
}
......@@ -264,9 +264,9 @@ void QbsProject::handleQbsParsingDone(bool success)
QTC_ASSERT(m_qbsSetupProjectJob, return);
QTC_ASSERT(m_qbsUpdateFutureInterface, return);
qbs::Project *project = 0;
qbs::Project project;
if (success) {
project = new qbs::Project(m_qbsSetupProjectJob->project());
project = m_qbsSetupProjectJob->project();
} else {
generateErrors(m_qbsSetupProjectJob->error());
m_qbsUpdateFutureInterface->reportCanceled();
......@@ -280,7 +280,7 @@ void QbsProject::handleQbsParsingDone(bool success)
m_rootProjectNode->update(project);
updateDocuments(project ? project->buildSystemFiles() : QSet<QString>() << m_fileName);
updateDocuments(project.isValid() ? project.buildSystemFiles() : QSet<QString>() << m_fileName);
updateCppCodeModel(m_rootProjectNode->qbsProjectData());
updateQmlJsCodeModel(m_rootProjectNode->qbsProjectData());
......@@ -401,11 +401,11 @@ void QbsProject::parse(const QVariantMap &config, const Environment &env, const
}
// Avoid useless reparsing:
const qbs::Project *currentProject = qbsProject();
const qbs::Project &currentProject = qbsProject();
if (!m_forceParsing
&& currentProject
&& currentProject->projectConfiguration() == params.buildConfiguration()) {
QHash<QString, QString> usedEnv = currentProject->usedEnvironment();
&& currentProject.isValid()
&& currentProject.projectConfiguration() == params.buildConfiguration()) {
QHash<QString, QString> usedEnv = currentProject.usedEnvironment();
bool canSkip = true;
for (QHash<QString, QString>::const_iterator i = usedEnv.constBegin();
i != usedEnv.constEnd(); ++i) {
......@@ -583,7 +583,7 @@ void QbsProject::updateCppCodeModel(const qbs::ProjectData &prj)
foreach (const QString &file, grp.allFilePaths()) {
if (file.endsWith(QLatin1String(".ui"))) {
QStringList generated = m_rootProjectNode->qbsProject()
->generatedFiles(prd, file, QStringList(QLatin1String("hpp")));
.generatedFiles(prd, file, QStringList(QLatin1String("hpp")));
if (generated.count() == 1)
uiFiles.insert(file, generated.at(0));
}
......@@ -642,14 +642,14 @@ void QbsProject::updateApplicationTargets(const qbs::ProjectData &projectData)
activeTarget()->setApplicationTargets(applications);
}
void QbsProject::updateDeploymentInfo(const qbs::Project *project)
void QbsProject::updateDeploymentInfo(const qbs::Project &project)
{
ProjectExplorer::DeploymentData deploymentData;
if (project) {
if (project.isValid()) {
qbs::InstallOptions installOptions;
installOptions.setInstallRoot(QLatin1String("/"));
foreach (const qbs::InstallableFile &f,
project->installableFilesForProject(project->projectData(), installOptions)) {
project.installableFilesForProject(project.projectData(), installOptions)) {
deploymentData.addFile(f.sourceFilePath(), f.targetDirectory(), f.isExecutable()
? ProjectExplorer::DeployableFile::TypeExecutable
: ProjectExplorer::DeployableFile::TypeNormal);
......
......@@ -94,7 +94,7 @@ public:
Utils::FileName defaultBuildDirectory() const;
const qbs::Project *qbsProject() const;
qbs::Project qbsProject() const;
const qbs::ProjectData qbsProjectData() const;
bool needsSpecialDeployment() const;
......@@ -129,7 +129,7 @@ private:
void updateCppCodeModel(const qbs::ProjectData &prj);
void updateQmlJsCodeModel(const qbs::ProjectData &prj);
void updateApplicationTargets(const qbs::ProjectData &projectData);
void updateDeploymentInfo(const qbs::Project *project);
void updateDeploymentInfo(const qbs::Project &project);
QString qbsDirectory() const;
QbsManager *const m_manager;
......
......@@ -196,10 +196,10 @@ QString QbsRunConfiguration::executable() const
QbsProject *pro = static_cast<QbsProject *>(target()->project());
const qbs::ProductData product = findProduct(pro->qbsProjectData(), m_qbsProduct);
if (!product.isValid() || !pro->qbsProject())
if (!product.isValid() || !pro->qbsProject().isValid())
return QString();
return pro->qbsProject()->targetExecutable(product, installOptions());
return pro->qbsProject().targetExecutable(product, installOptions());
}
ProjectExplorer::LocalApplicationRunConfiguration::RunMode QbsRunConfiguration::runMode() const
......@@ -568,11 +568,11 @@ QList<Core::Id> QbsRunConfigurationFactory::availableCreationIds(ProjectExplorer
return result;
QbsProject *project = static_cast<QbsProject *>(parent->project());
if (!project || !project->qbsProject())
if (!project || !project->qbsProject().isValid())
return result;
foreach (const qbs::ProductData &product, project->qbsProjectData().allProducts()) {
if (!project->qbsProject()->targetExecutable(product, qbs::InstallOptions()).isEmpty())
if (!project->qbsProject().targetExecutable(product, qbs::InstallOptions()).isEmpty())
result << Core::Id::fromString(QString::fromLatin1(QBS_RC_PREFIX) + product.name());
}
return result;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment