forked from qt-creator/qt-creator
ProjectWindow: Fix crash in TargetSetupPage
Move ownership of the ProjectImporter to the Project. Task-number: QTCREATORBUG-16744 Change-Id: I7fc217ce8058287c5435b259bdc5300a926f8098 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io> Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -714,7 +714,7 @@ Utils::MacroExpander *Project::macroExpander() const
|
||||
return &d->m_macroExpander;
|
||||
}
|
||||
|
||||
ProjectImporter *Project::createProjectImporter() const
|
||||
ProjectImporter *Project::projectImporter() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public:
|
||||
virtual void configureAsExampleProject(const QSet<Core::Id> &platforms);
|
||||
|
||||
virtual bool requiresTargetPanel() const;
|
||||
virtual ProjectImporter *createProjectImporter() const;
|
||||
virtual ProjectImporter *projectImporter() const;
|
||||
|
||||
KitMatcher requiredKitMatcher() const;
|
||||
void setRequiredKitMatcher(const KitMatcher &matcher);
|
||||
|
||||
@@ -388,6 +388,7 @@ ProjectExplorerPlugin::ProjectExplorerPlugin()
|
||||
|
||||
ProjectExplorerPlugin::~ProjectExplorerPlugin()
|
||||
{
|
||||
delete dd->m_proWindow; // Needs access to the kit manager.
|
||||
JsonWizardFactory::destroyAllFactories();
|
||||
|
||||
// Force sequence of deletion:
|
||||
@@ -513,7 +514,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
JsonWizardFactory::registerGeneratorFactory(new ScannerGeneratorFactory);
|
||||
|
||||
dd->m_proWindow = new ProjectWindow;
|
||||
addAutoReleasedObject(dd->m_proWindow);
|
||||
|
||||
Context projecTreeContext(Constants::C_PROJECT_TREE);
|
||||
|
||||
|
||||
@@ -132,7 +132,6 @@ TargetSetupPageWrapper::TargetSetupPageWrapper(Project *project)
|
||||
: m_project(project)
|
||||
{
|
||||
m_targetSetupPage = new TargetSetupPage(this);
|
||||
m_targetSetupPage->setProjectImporter(project->createProjectImporter());
|
||||
m_targetSetupPage->setUseScrollArea(false);
|
||||
m_targetSetupPage->setProjectPath(project->projectFilePath().toString());
|
||||
m_targetSetupPage->setRequiredKitMatcher(project->requiredKitMatcher());
|
||||
@@ -209,7 +208,7 @@ class TargetGroupItemPrivate : public QObject
|
||||
|
||||
public:
|
||||
TargetGroupItemPrivate(TargetGroupItem *q, Project *project);
|
||||
~TargetGroupItemPrivate() { /*delete m_importer;*/ }
|
||||
~TargetGroupItemPrivate();
|
||||
|
||||
void handleRemovedKit(Kit *kit);
|
||||
void handleAddedKit(Kit *kit);
|
||||
@@ -224,8 +223,7 @@ public:
|
||||
|
||||
TargetGroupItem *q;
|
||||
QString m_displayName;
|
||||
QPointer<Project> m_project;
|
||||
ProjectImporter *m_importer;
|
||||
Project *m_project;
|
||||
|
||||
QPointer<QWidget> m_noKitLabel;
|
||||
QPointer<QWidget> m_configurePage;
|
||||
@@ -281,12 +279,13 @@ void TargetGroupItemPrivate::ensureWidget()
|
||||
|
||||
void TargetGroupItemPrivate::importTarget(const Utils::FileName &path)
|
||||
{
|
||||
if (!m_importer)
|
||||
ProjectImporter *importer = m_project->projectImporter();
|
||||
if (!importer)
|
||||
return;
|
||||
|
||||
Target *target = nullptr;
|
||||
BuildConfiguration *bc = nullptr;
|
||||
QList<BuildInfo *> toImport = m_importer->import(path, false);
|
||||
QList<BuildInfo *> toImport = importer->import(path, false);
|
||||
foreach (BuildInfo *info, toImport) {
|
||||
target = m_project->target(info->kitId);
|
||||
if (!target) {
|
||||
@@ -519,7 +518,7 @@ public:
|
||||
bool isEnabled() const { return target() != 0; }
|
||||
|
||||
public:
|
||||
Project *m_project; // Not owned.
|
||||
QPointer<Project> m_project; // Not owned.
|
||||
Id m_kitId;
|
||||
int m_currentChild = 1; // Use run page by default.
|
||||
};
|
||||
@@ -706,13 +705,10 @@ TargetGroupItem::~TargetGroupItem()
|
||||
delete d;
|
||||
}
|
||||
|
||||
TargetGroupItemPrivate::TargetGroupItemPrivate(TargetGroupItem *q,
|
||||
Project *project)
|
||||
TargetGroupItemPrivate::TargetGroupItemPrivate(TargetGroupItem *q, Project *project)
|
||||
: q(q), m_project(project)
|
||||
{
|
||||
m_importer = project->createProjectImporter();
|
||||
|
||||
if (m_importer) {
|
||||
if (project->projectImporter()) {
|
||||
auto importAction = new QAction(tr("Import existing build..."), 0);
|
||||
QObject::connect(importAction, &QAction::triggered, [this] {
|
||||
QString dir = m_project->projectDirectory().toString();
|
||||
@@ -730,6 +726,11 @@ TargetGroupItemPrivate::TargetGroupItemPrivate(TargetGroupItem *q,
|
||||
rebuildContents();
|
||||
}
|
||||
|
||||
TargetGroupItemPrivate::~TargetGroupItemPrivate()
|
||||
{
|
||||
disconnect();
|
||||
}
|
||||
|
||||
QVariant TargetGroupItem::data(int column, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
|
||||
@@ -218,9 +218,9 @@ void TargetSetupPage::setPreferredKitMatcher(const KitMatcher &matcher)
|
||||
|
||||
TargetSetupPage::~TargetSetupPage()
|
||||
{
|
||||
disconnect();
|
||||
reset();
|
||||
delete m_ui;
|
||||
delete m_importer;
|
||||
}
|
||||
|
||||
bool TargetSetupPage::isKitSelected(Core::Id id) const
|
||||
|
||||
@@ -298,6 +298,8 @@ QmakeProject::QmakeProject(QmakeManager *manager, const QString &fileName) :
|
||||
|
||||
QmakeProject::~QmakeProject()
|
||||
{
|
||||
delete m_projectImporter;
|
||||
m_projectImporter = nullptr;
|
||||
m_codeModelFuture.cancel();
|
||||
m_asyncUpdateState = ShuttingDown;
|
||||
|
||||
@@ -1613,9 +1615,11 @@ void QmakeProject::emitBuildDirectoryInitialized()
|
||||
emit buildDirectoryInitialized();
|
||||
}
|
||||
|
||||
ProjectImporter *QmakeProject::createProjectImporter() const
|
||||
ProjectImporter *QmakeProject::projectImporter() const
|
||||
{
|
||||
return new QmakeProjectImporter(projectFilePath().toString());
|
||||
if (!m_projectImporter)
|
||||
m_projectImporter = new QmakeProjectImporter(projectFilePath().toString());
|
||||
return m_projectImporter;
|
||||
}
|
||||
|
||||
QmakeProject::AsyncUpdateState QmakeProject::asyncUpdateState() const
|
||||
|
||||
@@ -129,7 +129,7 @@ public:
|
||||
void emitBuildDirectoryInitialized();
|
||||
static void proFileParseError(const QString &errorMessage);
|
||||
|
||||
ProjectExplorer::ProjectImporter *createProjectImporter() const override;
|
||||
ProjectExplorer::ProjectImporter *projectImporter() const override;
|
||||
|
||||
enum AsyncUpdateState { Base, AsyncFullUpdatePending, AsyncPartialUpdatePending, AsyncUpdateInProgress, ShuttingDown };
|
||||
AsyncUpdateState asyncUpdateState() const;
|
||||
@@ -203,6 +203,7 @@ private:
|
||||
Internal::CentralizedFolderWatcher *m_centralizedFolderWatcher = nullptr;
|
||||
|
||||
ProjectExplorer::Target *m_activeTarget = nullptr;
|
||||
mutable ProjectExplorer::ProjectImporter *m_projectImporter = nullptr;
|
||||
|
||||
friend class Internal::QmakeProjectFile;
|
||||
friend class Internal::QmakeProjectConfigWidget;
|
||||
|
||||
Reference in New Issue
Block a user