Commit e0c5ff03 authored by Tobias Hunger's avatar Tobias Hunger

Vcs: Do not crash when stopping running commands

Drop the connect once the editor gets killed. Remove the QSignalMapper
and replace it with a lambda to facilitate that change.

Task-number: QTCREATORBUG-14613
Change-Id: I1a5990bf37af88092933143ebb78dd5ceb9c1222
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent 582661a5
......@@ -596,7 +596,7 @@ static inline void msgCannotRun(const QStringList &args, const QString &workingD
const char *GitClient::stashNamePrefix = "stash@{";
GitClient::GitClient() : VcsBase::VcsBaseClientImpl(this, new GitSettings),
GitClient::GitClient() : VcsBase::VcsBaseClientImpl(new GitSettings),
m_cachedGitVersion(0),
m_disableEditor(false)
{
......
......@@ -56,6 +56,17 @@
#include <QVariant>
#include <QProcessEnvironment>
static void commandFinished(VcsBase::VcsBaseEditorWidget *editor, VcsBase::VcsCommand *cmd)
{
if (!cmd->lastExecutionSuccess()) {
editor->reportCommandFinished(false, cmd->lastExecutionExitCode(), cmd->cookie());
} else if (cmd->cookie().type() == QVariant::Int) {
const int line = cmd->cookie().toInt();
if (line >= 0)
editor->gotoLine(line);
}
}
/*!
\class VcsBase::VcsBaseClient
......@@ -80,27 +91,14 @@ namespace VcsBase {
class VcsBaseClientImplPrivate
{
public:
VcsBaseClientImplPrivate(VcsBaseClientImpl *client, VcsBaseClientSettings *settings);
VcsBaseClientImplPrivate(VcsBaseClientSettings *settings);
~VcsBaseClientImplPrivate();
void bindCommandToEditor(VcsCommand *cmd, VcsBaseEditorWidget *editor);
VcsBaseClientSettings *m_clientSettings;
QSignalMapper *m_cmdFinishedMapper;
};
void VcsBaseClientImplPrivate::bindCommandToEditor(VcsCommand *cmd, VcsBaseEditorWidget *editor)
{
editor->setCommand(cmd);
QObject::connect(cmd, &VcsCommand::finished,
m_cmdFinishedMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
m_cmdFinishedMapper->setMapping(cmd, editor);
}
VcsBaseClientImplPrivate::VcsBaseClientImplPrivate(VcsBaseClientImpl *client,
VcsBaseClientSettings *settings) :
m_clientSettings(settings),
m_cmdFinishedMapper(new QSignalMapper(client))
VcsBaseClientImplPrivate::VcsBaseClientImplPrivate(VcsBaseClientSettings *settings) :
m_clientSettings(settings)
{
m_clientSettings->readSettings(Core::ICore::settings());
}
......@@ -110,14 +108,11 @@ VcsBaseClientImplPrivate::~VcsBaseClientImplPrivate()
delete m_clientSettings;
}
VcsBaseClientImpl::VcsBaseClientImpl(VcsBaseClientImpl *client, VcsBaseClientSettings *settings) :
d(new VcsBaseClientImplPrivate(client, settings))
VcsBaseClientImpl::VcsBaseClientImpl(VcsBaseClientSettings *settings) :
d(new VcsBaseClientImplPrivate(settings))
{
connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested,
this, &VcsBaseClientImpl::saveSettings);
connect(d->m_cmdFinishedMapper, static_cast<void (QSignalMapper::*)(QWidget*)>(&QSignalMapper::mapped),
this, &VcsBaseClientImpl::commandFinishedGotoLine);
}
VcsBaseClientImpl::~VcsBaseClientImpl()
......@@ -141,8 +136,11 @@ VcsCommand *VcsBaseClientImpl::createCommand(const QString &workingDirectory,
{
auto cmd = new VcsCommand(workingDirectory, processEnvironment());
cmd->setDefaultTimeoutS(vcsTimeoutS());
if (editor)
d->bindCommandToEditor(cmd, editor);
if (editor) {
connect(editor, &QObject::destroyed, cmd, &VcsCommand::abort);
connect(cmd, &VcsCommand::finished,
editor, [editor, cmd]() { commandFinished(editor, cmd); });
}
if (mode == VcsWindowOutputBind) {
cmd->addFlags(VcsCommand::ShowStdOut);
if (editor) // assume that the commands output is the important thing
......@@ -278,22 +276,6 @@ void VcsBaseClientImpl::saveSettings()
settings().writeSettings(Core::ICore::settings());
}
void VcsBaseClientImpl::commandFinishedGotoLine(QWidget *editorObject)
{
VcsBaseEditorWidget *editor = qobject_cast<VcsBaseEditorWidget *>(editorObject);
VcsCommand *cmd = qobject_cast<VcsCommand *>(d->m_cmdFinishedMapper->mapping(editor));
if (editor && cmd) {
if (!cmd->lastExecutionSuccess()) {
editor->reportCommandFinished(false, cmd->lastExecutionExitCode(), cmd->cookie());
} else if (cmd->cookie().type() == QVariant::Int) {
const int line = cmd->cookie().toInt();
if (line >= 0)
editor->gotoLine(line);
}
d->m_cmdFinishedMapper->removeMappings(cmd);
}
}
class VcsBaseClientPrivate
{
public:
......@@ -319,7 +301,7 @@ VcsBaseClient::StatusItem::StatusItem(const QString &s, const QString &f) :
{ }
VcsBaseClient::VcsBaseClient(VcsBaseClientSettings *settings) :
VcsBaseClientImpl(this, settings),
VcsBaseClientImpl(settings),
d(new VcsBaseClientPrivate)
{
qRegisterMetaType<QVariant>();
......
......@@ -68,7 +68,7 @@ class VCSBASE_EXPORT VcsBaseClientImpl : public QObject
Q_OBJECT
public:
explicit VcsBaseClientImpl(VcsBaseClientImpl *client, VcsBaseClientSettings *settings);
explicit VcsBaseClientImpl(VcsBaseClientSettings *settings);
~VcsBaseClientImpl();
VcsBaseClientSettings &settings() const;
......@@ -130,7 +130,6 @@ protected:
private:
void saveSettings();
void commandFinishedGotoLine(QWidget*);
VcsBaseClientImplPrivate *d;
};
......
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