Commit 161b818b authored by Tobias Hunger's avatar Tobias Hunger

Qbs: Fix crashes when switching QbsRunConfigurations

Do not use pointers to qbs::(Group|Product|Project)Data. Those are
implicitly shared classes, and now have a isValid method so that
default constructed instances can be spotted.

Change-Id: Icd49fa517f2e17bc60cc82d103f479d3a2e7097a
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 28be3fb8
......@@ -134,10 +134,10 @@ QString QbsInstallStep::installRoot() const
QString QbsInstallStep::absoluteInstallRoot() const
{
const qbs::ProjectData *data = static_cast<QbsProject *>(project())->qbsProjectData();
const qbs::ProjectData data = static_cast<QbsProject *>(project())->qbsProjectData();
QString path = installRoot();
if (data && !data->buildDirectory().isEmpty() && !path.isEmpty())
path = QDir(data->buildDirectory()).absoluteFilePath(path);
if (data.isValid() && !data.buildDirectory().isEmpty() && !path.isEmpty())
path = QDir(data.buildDirectory()).absoluteFilePath(path);
return path;
}
......@@ -306,9 +306,9 @@ void QbsInstallStepConfigWidget::updateState()
m_ui->keepGoingCheckBox->setChecked(m_step->keepGoing());
}
const qbs::ProjectData *data = static_cast<QbsProject *>(m_step->project())->qbsProjectData();
if (data)
m_ui->installRootChooser->setBaseDirectory(data->buildDirectory());
const qbs::ProjectData data = static_cast<QbsProject *>(m_step->project())->qbsProjectData();
if (data.isValid())
m_ui->installRootChooser->setBaseDirectory(data.buildDirectory());
QString command = QLatin1String("qbs install ");
if (m_step->dryRun())
......
......@@ -466,15 +466,14 @@ void QbsGroupNode::setupFolder(ProjectExplorer::FolderNode *root,
// QbsProductNode:
// --------------------------------------------------------------------
QbsProductNode::QbsProductNode(const qbs::ProductData *prd) :
QbsBaseProjectNode(prd->location().fileName()),
m_qbsProductData(0)
QbsProductNode::QbsProductNode(const qbs::ProductData &prd) :
QbsBaseProjectNode(prd.location().fileName())
{
setIcon(m_productIcon);
ProjectExplorer::FileNode *idx = new QbsFileNode(prd->location().fileName(),
ProjectExplorer::FileNode *idx = new QbsFileNode(prd.location().fileName(),
ProjectExplorer::ProjectFileType, false,
prd->location().line());
prd.location().line());
addFileNodes(QList<ProjectExplorer::FileNode *>() << idx, this);
setQbsProductData(prd);
......@@ -482,22 +481,21 @@ QbsProductNode::QbsProductNode(const qbs::ProductData *prd) :
bool QbsProductNode::isEnabled() const
{
return m_qbsProductData ? m_qbsProductData->isEnabled() : false;
return m_qbsProductData.isEnabled();
}
void QbsProductNode::setQbsProductData(const qbs::ProductData *prd)
void QbsProductNode::setQbsProductData(const qbs::ProductData prd)
{
Q_ASSERT(prd);
if (m_qbsProductData == prd)
return;
bool productWasEnabled = m_qbsProductData ? m_qbsProductData->isEnabled() : true;
bool productIsEnabled = prd->isEnabled();
bool productWasEnabled = m_qbsProductData.isEnabled();
bool productIsEnabled = prd.isEnabled();
bool updateExisting = productWasEnabled != productIsEnabled;
setDisplayName(prd->name());
setPath(prd->location().fileName());
const QString &productPath = QFileInfo(prd->location().fileName()).absolutePath();
setDisplayName(prd.name());
setPath(prd.location().fileName());
const QString &productPath = QFileInfo(prd.location().fileName()).absolutePath();
// Find the QbsFileNode we added earlier:
QbsFileNode *idx = 0;
......@@ -506,14 +504,14 @@ void QbsProductNode::setQbsProductData(const qbs::ProductData *prd)
if (idx)
break;
}
if (idx->update(prd->location()) || updateExisting)
if (idx->update(prd.location()) || updateExisting)
idx->emitNodeUpdated();
QList<ProjectExplorer::ProjectNode *> toAdd;
QList<ProjectExplorer::ProjectNode *> toRemove = subProjectNodes();
foreach (const qbs::GroupData &grp, prd->groups()) {
if (grp.name() == prd->name() && grp.location() == prd->location()) {
foreach (const qbs::GroupData &grp, prd.groups()) {
if (grp.name() == prd.name() && grp.location() == prd.location()) {
// Set implicit product group right onto this node:
QbsGroupNode::setupFiles(this, grp.allFilePaths(), productPath, updateExisting);
continue;
......@@ -541,7 +539,7 @@ 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,
if (!isEnabled() || !pn || pn->qbsProject()->targetExecutable(m_qbsProductData,
qbs::InstallOptions()).isEmpty()) {
return result;
}
......@@ -550,7 +548,7 @@ QList<ProjectExplorer::RunConfiguration *> QbsProductNode::runConfigurationsFor(
QbsRunConfiguration *qbsRc = qobject_cast<QbsRunConfiguration *>(rc);
if (!qbsRc)
continue;
if (qbsRc->qbsProduct() == qbsProductData()->name())
if (qbsRc->qbsProduct() == qbsProductData().name())
result << qbsRc;
}
......@@ -573,14 +571,14 @@ QbsGroupNode *QbsProductNode::findGroupNode(const QString &name)
QbsProjectNode::QbsProjectNode(QbsProject *project) :
QbsBaseProjectNode(project->document()->fileName()),
m_project(project), m_qbsProject(0), m_qbsProjectData(0)
m_project(project), m_qbsProject(0)
{
ctor();
}
QbsProjectNode::QbsProjectNode(const QString &path) :
QbsBaseProjectNode(path),
m_project(0), m_qbsProject(0), m_qbsProjectData(0)
m_project(0), m_qbsProject(0)
{
ctor();
}
......@@ -588,14 +586,12 @@ QbsProjectNode::QbsProjectNode(const QString &path) :
QbsProjectNode::~QbsProjectNode()
{
// do not delete m_project
delete m_qbsProjectData;
delete m_qbsProject;
}
void QbsProjectNode::update(const qbs::Project *prj)
{
if (prj)
update(prj->projectData());
update(prj ? prj->projectData() : qbs::ProjectData());
delete m_qbsProject;
m_qbsProject = prj;
......@@ -621,19 +617,19 @@ void QbsProjectNode::update(const qbs::ProjectData &prjData)
foreach (const qbs::ProductData &prd, prjData.products()) {
QbsProductNode *qn = findProductNode(prd.name());
if (!qn) {
toAdd << new QbsProductNode(&prd);
toAdd << new QbsProductNode(prd);
} else {
qn->setQbsProductData(&prd);
qn->setQbsProductData(prd);
toRemove.removeOne(qn);
}
}
delete m_qbsProjectData;
m_qbsProjectData = new qbs::ProjectData(prjData);
setDisplayName(prjData.name());
removeProjectNodes(toRemove);
addProjectNodes(toAdd);
m_qbsProjectData = prjData;
}
QbsProject *QbsProjectNode::project() const
......@@ -651,7 +647,7 @@ const qbs::Project *QbsProjectNode::qbsProject() const
return m_qbsProject;
}
const qbs::ProjectData *QbsProjectNode::qbsProjectData() const
const qbs::ProjectData QbsProjectNode::qbsProjectData() const
{
return m_qbsProjectData;
}
......@@ -667,7 +663,7 @@ QbsProductNode *QbsProjectNode::findProductNode(const QString &name)
{
foreach (ProjectExplorer::ProjectNode *n, subProjectNodes()) {
QbsProductNode *qn = qobject_cast<QbsProductNode *>(n);
if (qn && qn->qbsProductData()->name() == name)
if (qn && qn->qbsProductData().name() == name)
return qn;
}
return 0;
......@@ -677,7 +673,7 @@ QbsProjectNode *QbsProjectNode::findProjectNode(const QString &name)
{
foreach (ProjectExplorer::ProjectNode *n, subProjectNodes()) {
QbsProjectNode *qn = qobject_cast<QbsProjectNode *>(n);
if (qn && qn->qbsProjectData()->name() == name)
if (qn && qn->qbsProjectData().name() == name)
return qn;
}
return 0;
......
......@@ -148,19 +148,19 @@ class QbsProductNode : public QbsBaseProjectNode
Q_OBJECT
public:
explicit QbsProductNode(const qbs::ProductData *prd);
explicit QbsProductNode(const qbs::ProductData &prd);
bool isEnabled() const;
void setQbsProductData(const qbs::ProductData *prd);
const qbs::ProductData *qbsProductData() const { return m_qbsProductData; }
void setQbsProductData(const qbs::ProductData prd);
const qbs::ProductData qbsProductData() const { return m_qbsProductData; }
QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node);
private:
QbsGroupNode *findGroupNode(const QString &name);
const qbs::ProductData *m_qbsProductData;
qbs::ProductData m_qbsProductData;
static QIcon m_productIcon;
};
......@@ -182,7 +182,7 @@ public:
QbsProject *project() const;
const qbs::Project *qbsProject() const;
const qbs::ProjectData *qbsProjectData() const;
const qbs::ProjectData qbsProjectData() const;
private:
void ctor();
......@@ -193,7 +193,7 @@ private:
QbsProject *m_project;
const qbs::Project *m_qbsProject;
const qbs::ProjectData *m_qbsProjectData;
qbs::ProjectData m_qbsProjectData;
static QIcon m_projectIcon;
};
} // namespace Internal
......
......@@ -162,8 +162,8 @@ QStringList QbsProject::files(ProjectExplorer::Project::FilesMode fileMode) cons
{
Q_UNUSED(fileMode);
QSet<QString> result;
if (m_rootProjectNode && m_rootProjectNode->qbsProjectData()) {
foreach (const qbs::ProductData &prd, m_rootProjectNode->qbsProjectData()->allProducts()) {
if (m_rootProjectNode && m_rootProjectNode->qbsProjectData().isValid()) {
foreach (const qbs::ProductData &prd, m_rootProjectNode->qbsProjectData().allProducts()) {
foreach (const qbs::GroupData &grp, prd.groups()) {
foreach (const QString &file, grp.allFilePaths())
result.insert(file);
......@@ -171,7 +171,7 @@ QStringList QbsProject::files(ProjectExplorer::Project::FilesMode fileMode) cons
}
result.insert(prd.location().fileName());
}
result.insert(m_rootProjectNode->qbsProjectData()->location().fileName());
result.insert(m_rootProjectNode->qbsProjectData().location().fileName());
}
return result.toList();
}
......@@ -191,7 +191,7 @@ qbs::BuildJob *QbsProject::build(const qbs::BuildOptions &opts, QStringList prod
QList<qbs::ProductData> products;
foreach (const QString &productName, productNames) {
bool found = false;
foreach (const qbs::ProductData &data, qbsProjectData()->allProducts()) {
foreach (const qbs::ProductData &data, qbsProjectData().allProducts()) {
if (data.name() == productName) {
found = true;
products.append(data);
......@@ -249,10 +249,10 @@ const qbs::Project *QbsProject::qbsProject() const
return m_rootProjectNode->qbsProject();
}
const qbs::ProjectData *QbsProject::qbsProjectData() const
const qbs::ProjectData QbsProject::qbsProjectData() const
{
if (!m_rootProjectNode)
return 0;
return qbs::ProjectData();
return m_rootProjectNode->qbsProjectData();
}
......@@ -494,9 +494,9 @@ void QbsProject::updateDocuments(const QSet<QString> &files)
m_qbsDocuments.unite(toAdd);
}
void QbsProject::updateCppCodeModel(const qbs::ProjectData *prj)
void QbsProject::updateCppCodeModel(const qbs::ProjectData &prj)
{
if (!prj)
if (!prj.isValid())
return;
ProjectExplorer::Kit *k = 0;
......@@ -525,7 +525,7 @@ void QbsProject::updateCppCodeModel(const qbs::ProjectData *prj)
}
QStringList allFiles;
foreach (const qbs::ProductData &prd, prj->allProducts()) {
foreach (const qbs::ProductData &prd, prj.allProducts()) {
foreach (const qbs::GroupData &grp, prd.groups()) {
const qbs::PropertyMap &props = grp.properties();
......@@ -600,7 +600,7 @@ void QbsProject::updateCppCodeModel(const qbs::ProjectData *prj)
m_codeModelFuture = modelmanager->updateSourceFiles(allFiles);
}
void QbsProject::updateQmlJsCodeModel(const qbs::ProjectData *prj)
void QbsProject::updateQmlJsCodeModel(const qbs::ProjectData &prj)
{
Q_UNUSED(prj);
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
......
......@@ -92,7 +92,7 @@ public:
Utils::FileName defaultBuildDirectory() const;
const qbs::Project *qbsProject() const;
const qbs::ProjectData *qbsProjectData() const;
const qbs::ProjectData qbsProjectData() const;
bool needsSpecialDeployment() const;
......@@ -123,8 +123,8 @@ private:
void generateErrors(const qbs::ErrorInfo &e);
void prepareForParsing();
void updateDocuments(const QSet<QString> &files);
void updateCppCodeModel(const qbs::ProjectData *prj);
void updateQmlJsCodeModel(const qbs::ProjectData *prj);
void updateCppCodeModel(const qbs::ProjectData &prj);
void updateQmlJsCodeModel(const qbs::ProjectData &prj);
QString qbsBuildDir() const;
QbsManager *const m_manager;
......
......@@ -71,16 +71,13 @@ QString productFromId(Core::Id id)
return id.suffixAfter(QBS_RC_PREFIX);
}
const qbs::ProductData *findProduct(const qbs::ProjectData *pro, const QString &name)
const qbs::ProductData findProduct(const qbs::ProjectData &pro, const QString &name)
{
if (!pro)
return 0;
foreach (const qbs::ProductData &product, pro->allProducts()) {
foreach (const qbs::ProductData &product, pro.allProducts()) {
if (product.name() == name)
return &product;
return product;
}
return 0;
return qbs::ProductData();
}
} // namespace
......@@ -197,12 +194,12 @@ void QbsRunConfiguration::installStepChanged()
QString QbsRunConfiguration::executable() const
{
QbsProject *pro = static_cast<QbsProject *>(target()->project());
const qbs::ProductData *product = findProduct(pro->qbsProjectData(), m_qbsProduct);
const qbs::ProductData product = findProduct(pro->qbsProjectData(), m_qbsProduct);
if (!product || !pro->qbsProject())
if (product.isValid() || !pro->qbsProject())
return QString();
return pro->qbsProject()->targetExecutable(*product, installOptions());
return pro->qbsProject()->targetExecutable(product, installOptions());
}
ProjectExplorer::LocalApplicationRunConfiguration::RunMode QbsRunConfiguration::runMode() const
......@@ -521,7 +518,7 @@ bool QbsRunConfigurationFactory::canCreate(ProjectExplorer::Target *parent, cons
return false;
QbsProject *project = static_cast<QbsProject *>(parent->project());
return findProduct(project->qbsProjectData(), productFromId(id));
return !findProduct(project->qbsProjectData(), productFromId(id)).isValid();
}
ProjectExplorer::RunConfiguration *QbsRunConfigurationFactory::doCreate(ProjectExplorer::Target *parent, const Core::Id id)
......@@ -562,10 +559,10 @@ QList<Core::Id> QbsRunConfigurationFactory::availableCreationIds(ProjectExplorer
return result;
QbsProject *project = static_cast<QbsProject *>(parent->project());
if (!project || !project->qbsProjectData() || !project->qbsProject())
if (!project || !project->qbsProject())
return result;
foreach (const qbs::ProductData &product, project->qbsProjectData()->allProducts()) {
foreach (const qbs::ProductData &product, project->qbsProjectData().allProducts()) {
if (!project->qbsProject()->targetExecutable(product, qbs::InstallOptions()).isEmpty())
result << Core::Id::fromString(QString::fromLatin1(QBS_RC_PREFIX) + product.name());
}
......
Subproject commit 22a2777a898fdef6f2d5fc4f93a8c11682ecf4ea
Subproject commit 6de45d07b8382c80dd0ebab993b8e0cadaac4338
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