Commit cf1c8a06 authored by hjk's avatar hjk
Browse files

ProjectExplorer: Fix connection lifetime in WorkingDirectory aspect



Also add some sanity checks before accessing related pointers.

Change-Id: Ic9576ad3b28333210adc1187d4a0a26d52b0538e
Reviewed-by: default avatarDaniel Teske <daniel.teske@theqtcompany.com>
parent 4aa51166
......@@ -159,18 +159,18 @@ void WorkingDirectoryAspect::addToMainConfigurationWidget(QWidget *parent, QForm
m_chooser->setHistoryCompleter(m_key);
m_chooser->setExpectedKind(Utils::PathChooser::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);
resetButton->setToolTip(tr("Reset to default"));
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>()) {
connect(envAspect, &EnvironmentAspect::environmentChanged, this, [this, envAspect] {
m_chooser->setEnvironment(envAspect->environment());
});
m_chooser->setEnvironment(envAspect->environment());
connect(envAspect, &EnvironmentAspect::environmentChanged,
this, &WorkingDirectoryAspect::updateEnvironment);
updateEnvironment();
}
auto hbox = new QHBoxLayout;
......@@ -179,6 +179,20 @@ void WorkingDirectoryAspect::addToMainConfigurationWidget(QWidget *parent, QForm
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)
{
m_workingDirectory = map.value(m_key).toBool();
......@@ -204,6 +218,11 @@ void WorkingDirectoryAspect::setWorkingDirectory(const QString &workingDirectory
m_workingDirectory = workingDirectory;
}
PathChooser *WorkingDirectoryAspect::pathChooser() const
{
return m_chooser;
}
/*!
\class ProjectExplorer::ArgumentsAspect
......
......@@ -95,14 +95,17 @@ public:
QString workingDirectory() const;
QString unexpandedWorkingDirectory() const;
void setWorkingDirectory(const QString &workingDirectory);
Utils::PathChooser *pathChooser() const { return m_chooser; }
Utils::PathChooser *pathChooser() const;
private:
void fromMap(const QVariantMap &map) override;
void toMap(QVariantMap &map) const override;
void resetPath();
void updateEnvironment();
QString m_workingDirectory;
Utils::PathChooser *m_chooser;
QPointer<Utils::PathChooser> m_chooser;
QString m_key;
};
......
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