forked from qt-creator/qt-creator
Gerrit: Support cancel in query context
Task-number: QTCREATORBUG-9743 Change-Id: I106fefaee19e7ce39c1a501342d11fdf8d6b0acd Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
f93e53f369
commit
c6ccb096d6
@@ -52,6 +52,7 @@
|
||||
#include <QScopedPointer>
|
||||
#include <QTimer>
|
||||
#include <QApplication>
|
||||
#include <QFutureWatcher>
|
||||
|
||||
enum { debug = 0 };
|
||||
|
||||
@@ -242,6 +243,7 @@ private slots:
|
||||
private:
|
||||
void startQuery(const QString &query);
|
||||
void errorTermination(const QString &msg);
|
||||
void terminate();
|
||||
|
||||
const QSharedPointer<GerritParameters> m_parameters;
|
||||
const QStringList m_queries;
|
||||
@@ -251,6 +253,7 @@ private:
|
||||
QByteArray m_output;
|
||||
int m_currentQuery;
|
||||
QFutureInterface<void> m_progress;
|
||||
QFutureWatcher<void> m_watcher;
|
||||
QStringList m_baseArguments;
|
||||
};
|
||||
|
||||
@@ -273,6 +276,9 @@ QueryContext::QueryContext(const QStringList &queries,
|
||||
this, SLOT(processFinished(int,QProcess::ExitStatus)));
|
||||
connect(&m_process, SIGNAL(error(QProcess::ProcessError)),
|
||||
this, SLOT(processError(QProcess::ProcessError)));
|
||||
connect(&m_watcher, &QFutureWatcherBase::canceled,
|
||||
this, &QueryContext::terminate);
|
||||
m_watcher.setFuture(m_progress.future());
|
||||
m_process.setProcessEnvironment(Git::Internal::GitPlugin::instance()->
|
||||
gitClient()->processEnvironment());
|
||||
m_progress.setProgressRange(0, m_queries.size());
|
||||
@@ -296,7 +302,7 @@ QueryContext::~QueryContext()
|
||||
if (m_timer.isActive())
|
||||
m_timer.stop();
|
||||
m_process.disconnect(this);
|
||||
Utils::SynchronousProcess::stopProcess(m_process);
|
||||
terminate();
|
||||
}
|
||||
|
||||
void QueryContext::start()
|
||||
@@ -321,12 +327,18 @@ void QueryContext::startQuery(const QString &query)
|
||||
|
||||
void QueryContext::errorTermination(const QString &msg)
|
||||
{
|
||||
if (!m_progress.isCanceled())
|
||||
VcsOutputWindow::appendError(msg);
|
||||
m_progress.reportCanceled();
|
||||
m_progress.reportFinished();
|
||||
VcsOutputWindow::appendError(msg);
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void QueryContext::terminate()
|
||||
{
|
||||
Utils::SynchronousProcess::stopProcess(m_process);
|
||||
}
|
||||
|
||||
void QueryContext::processError(QProcess::ProcessError e)
|
||||
{
|
||||
const QString msg = tr("Error running %1: %2").arg(m_binary, m_process.errorString());
|
||||
@@ -389,7 +401,7 @@ void QueryContext::timeout()
|
||||
if (m_process.state() != QProcess::Running)
|
||||
return;
|
||||
if (box.clickedButton() == terminateButton)
|
||||
Utils::SynchronousProcess::stopProcess(m_process);
|
||||
terminate();
|
||||
else
|
||||
m_timer.start();
|
||||
}
|
||||
|
Reference in New Issue
Block a user