ProjectExplorer: Fix connection lifetime in WorkingDirectory aspect

Also add some sanity checks before accessing related pointers.

Change-Id: Ic9576ad3b28333210adc1187d4a0a26d52b0538e
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
hjk
2015-05-27 09:10:16 +02:00
parent 4aa5116694
commit cf1c8a06aa
2 changed files with 30 additions and 8 deletions

View File

@@ -159,18 +159,18 @@ void WorkingDirectoryAspect::addToMainConfigurationWidget(QWidget *parent, QForm
m_chooser->setHistoryCompleter(m_key); m_chooser->setHistoryCompleter(m_key);
m_chooser->setExpectedKind(Utils::PathChooser::Directory); m_chooser->setExpectedKind(Utils::PathChooser::Directory);
m_chooser->setPromptDialogTitle(tr("Select Working Directory")); m_chooser->setPromptDialogTitle(tr("Select Working Directory"));
connect(m_chooser, &PathChooser::pathChanged, this, &WorkingDirectoryAspect::setWorkingDirectory); connect(m_chooser.data(), &PathChooser::pathChanged,
this, &WorkingDirectoryAspect::setWorkingDirectory);
auto resetButton = new QToolButton(parent); auto resetButton = new QToolButton(parent);
resetButton->setToolTip(tr("Reset to default")); resetButton->setToolTip(tr("Reset to default"));
resetButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_RESET))); resetButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_RESET)));
connect(resetButton, &QAbstractButton::clicked, this, [this] { m_chooser->setPath(QString()); }); connect(resetButton, &QAbstractButton::clicked, this, &WorkingDirectoryAspect::resetPath);
if (auto envAspect = runConfiguration()->extraAspect<EnvironmentAspect>()) { if (auto envAspect = runConfiguration()->extraAspect<EnvironmentAspect>()) {
connect(envAspect, &EnvironmentAspect::environmentChanged, this, [this, envAspect] { connect(envAspect, &EnvironmentAspect::environmentChanged,
m_chooser->setEnvironment(envAspect->environment()); this, &WorkingDirectoryAspect::updateEnvironment);
}); updateEnvironment();
m_chooser->setEnvironment(envAspect->environment());
} }
auto hbox = new QHBoxLayout; auto hbox = new QHBoxLayout;
@@ -179,6 +179,20 @@ void WorkingDirectoryAspect::addToMainConfigurationWidget(QWidget *parent, QForm
layout->addRow(tr("Working directory:"), hbox); layout->addRow(tr("Working directory:"), hbox);
} }
void WorkingDirectoryAspect::updateEnvironment()
{
auto envAspect = runConfiguration()->extraAspect<EnvironmentAspect>();
QTC_ASSERT(envAspect, return);
QTC_ASSERT(m_chooser, return);
m_chooser->setEnvironment(envAspect->environment());
}
void WorkingDirectoryAspect::resetPath()
{
QTC_ASSERT(m_chooser, return);
m_chooser->setPath(QString());
}
void WorkingDirectoryAspect::fromMap(const QVariantMap &map) void WorkingDirectoryAspect::fromMap(const QVariantMap &map)
{ {
m_workingDirectory = map.value(m_key).toBool(); m_workingDirectory = map.value(m_key).toBool();
@@ -204,6 +218,11 @@ void WorkingDirectoryAspect::setWorkingDirectory(const QString &workingDirectory
m_workingDirectory = workingDirectory; m_workingDirectory = workingDirectory;
} }
PathChooser *WorkingDirectoryAspect::pathChooser() const
{
return m_chooser;
}
/*! /*!
\class ProjectExplorer::ArgumentsAspect \class ProjectExplorer::ArgumentsAspect

View File

@@ -95,14 +95,17 @@ public:
QString workingDirectory() const; QString workingDirectory() const;
QString unexpandedWorkingDirectory() const; QString unexpandedWorkingDirectory() const;
void setWorkingDirectory(const QString &workingDirectory); void setWorkingDirectory(const QString &workingDirectory);
Utils::PathChooser *pathChooser() const { return m_chooser; } Utils::PathChooser *pathChooser() const;
private: private:
void fromMap(const QVariantMap &map) override; void fromMap(const QVariantMap &map) override;
void toMap(QVariantMap &map) const override; void toMap(QVariantMap &map) const override;
void resetPath();
void updateEnvironment();
QString m_workingDirectory; QString m_workingDirectory;
Utils::PathChooser *m_chooser; QPointer<Utils::PathChooser> m_chooser;
QString m_key; QString m_key;
}; };