diff options
author | Christian Stenger <christian.stenger@theqtcompany.com> | 2015-06-29 09:22:58 +0200 |
---|---|---|
committer | Christian Stenger <christian.stenger@theqtcompany.com> | 2015-07-16 12:20:04 +0300 |
commit | 08ab1b6d76c604960d0dbe9da85b2308508cf012 (patch) | |
tree | 3980df58f1fb946f69b5711a6abb6bd2d4bdca87 | |
parent | c7a8a941618a5eb1bfc99c416c5adaa181b472f6 (diff) | |
download | qt-creator-08ab1b6d76c604960d0dbe9da85b2308508cf012.tar.gz |
Don't use qApp->processEvents() if not necessary
Change-Id: I2e92341530f3d79f9c0b47f2007750582db9a361
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
-rw-r--r-- | plugins/autotest/autotestplugin.cpp | 4 | ||||
-rw-r--r-- | plugins/autotest/testnavigationwidget.cpp | 2 | ||||
-rw-r--r-- | plugins/autotest/testresultspane.cpp | 4 | ||||
-rw-r--r-- | plugins/autotest/testrunner.cpp | 60 | ||||
-rw-r--r-- | plugins/autotest/testrunner.h | 7 |
5 files changed, 37 insertions, 40 deletions
diff --git a/plugins/autotest/autotestplugin.cpp b/plugins/autotest/autotestplugin.cpp index 525f21ae3e..9c32e0b75c 100644 --- a/plugins/autotest/autotestplugin.cpp +++ b/plugins/autotest/autotestplugin.cpp @@ -168,7 +168,7 @@ void AutotestPlugin::onRunAllTriggered() TestRunner *runner = TestRunner::instance(); TestTreeModel *model = TestTreeModel::instance(); runner->setSelectedTests(model->getAllTestCases()); - runner->runTests(); + runner->prepareToRunTests(); } void AutotestPlugin::onRunSelectedTriggered() @@ -176,7 +176,7 @@ void AutotestPlugin::onRunSelectedTriggered() TestRunner *runner = TestRunner::instance(); TestTreeModel *model = TestTreeModel::instance(); runner->setSelectedTests(model->getSelectedTests()); - runner->runTests(); + runner->prepareToRunTests(); } void AutotestPlugin::updateMenuItemsEnabledState() diff --git a/plugins/autotest/testnavigationwidget.cpp b/plugins/autotest/testnavigationwidget.cpp index da0de8a761..9745e1a19b 100644 --- a/plugins/autotest/testnavigationwidget.cpp +++ b/plugins/autotest/testnavigationwidget.cpp @@ -249,7 +249,7 @@ void TestNavigationWidget::onRunThisTestTriggered() if (TestConfiguration *configuration = m_model->getTestConfiguration(item)) { TestRunner *runner = TestRunner::instance(); runner->setSelectedTests( {configuration} ); - runner->runTests(); + runner->prepareToRunTests(); } } } diff --git a/plugins/autotest/testresultspane.cpp b/plugins/autotest/testresultspane.cpp index 9ebb1c09fb..db78e24cd6 100644 --- a/plugins/autotest/testresultspane.cpp +++ b/plugins/autotest/testresultspane.cpp @@ -288,14 +288,14 @@ void TestResultsPane::onRunAllTriggered() { TestRunner *runner = TestRunner::instance(); runner->setSelectedTests(TestTreeModel::instance()->getAllTestCases()); - runner->runTests(); + runner->prepareToRunTests(); } void TestResultsPane::onRunSelectedTriggered() { TestRunner *runner = TestRunner::instance(); runner->setSelectedTests(TestTreeModel::instance()->getSelectedTests()); - runner->runTests(); + runner->prepareToRunTests(); } void TestResultsPane::initializeFilterMenu() diff --git a/plugins/autotest/testrunner.cpp b/plugins/autotest/testrunner.cpp index bc246ed6aa..b556989d62 100644 --- a/plugins/autotest/testrunner.cpp +++ b/plugins/autotest/testrunner.cpp @@ -86,7 +86,6 @@ TestRunner *TestRunner::instance() TestRunner::TestRunner(QObject *parent) : QObject(parent), - m_building(false), m_executingTests(false) { } @@ -197,12 +196,9 @@ void performTestRun(QFutureInterface<void> &futureInterface, futureInterface.setProgressValue(testCaseCount); } -void TestRunner::runTests() +void TestRunner::prepareToRunTests() { - const QSharedPointer<TestSettings> settings = AutotestPlugin::instance()->settings(); - const int timeout = settings->timeout; - const QString metricsOption = TestSettings::metricsTypeToOption(settings->metrics); - const bool displayRunConfigWarnings = !settings->omitRunConfigWarn; + const bool omitRunConfigWarnings = AutotestPlugin::instance()->settings()->omitRunConfigWarn; m_executingTests = true; emit testRunStarted(); @@ -211,7 +207,7 @@ void TestRunner::runTests() TestResultsPane::instance()->clearContents(); foreach (TestConfiguration *config, m_selectedTests) { - if (displayRunConfigWarnings && config->guessedConfiguration()) { + if (!omitRunConfigWarnings && config->guessedConfiguration()) { TestResultsPane::instance()->addTestResult(FaultyTestResult(Result::MESSAGE_WARN, tr("Project's run configuration was guessed for \"%1\".\n" "This might cause trouble during execution.").arg(config->displayName()))); @@ -237,38 +233,31 @@ void TestRunner::runTests() ProjectExplorer::Internal::ProjectExplorerSettings projectExplorerSettings = ProjectExplorer::ProjectExplorerPlugin::projectExplorerSettings(); - if (projectExplorerSettings.buildBeforeDeploy) { - if (!project->hasActiveBuildSettings()) { + if (!projectExplorerSettings.buildBeforeDeploy) { + runTests(); + } else { + if (project->hasActiveBuildSettings()) { + buildProject(project); + } else { TestResultsPane::instance()->addTestResult(FaultyTestResult(Result::MESSAGE_FATAL, tr("Project is not configured. Canceling test run."))); onFinished(); return; } - - auto connection = connect(this, &TestRunner::requestStopTestRun, [&] () { - ProjectExplorer::BuildManager::instance()->cancel(); - m_building = false; - m_buildSucceeded = false; - }); - buildProject(project); - while (m_building) { - qApp->processEvents(); - } - disconnect(connection); - - if (!m_buildSucceeded) { - TestResultsPane::instance()->addTestResult(FaultyTestResult(Result::MESSAGE_FATAL, - tr("Build failed. Canceling test run."))); - onFinished(); - return; - } } +} + +void TestRunner::runTests() +{ + const QSharedPointer<TestSettings> settings = AutotestPlugin::instance()->settings(); + const QString &metricsOption = TestSettings::metricsTypeToOption(settings->metrics); connect(this, &TestRunner::testResultCreated, TestResultsPane::instance(), &TestResultsPane::addTestResult, Qt::QueuedConnection); - QFuture<void> future = QtConcurrent::run(&performTestRun, m_selectedTests, timeout, metricsOption, this); + QFuture<void> future = QtConcurrent::run(&performTestRun, m_selectedTests, settings->timeout, + metricsOption, this); Core::FutureProgress *progress = Core::ProgressManager::addTask(future, tr("Running Tests"), Autotest::Constants::TASK_INDEX); connect(progress, &Core::FutureProgress::finished, @@ -277,9 +266,9 @@ void TestRunner::runTests() void TestRunner::buildProject(ProjectExplorer::Project *project) { - m_building = true; - m_buildSucceeded = false; ProjectExplorer::BuildManager *buildManager = ProjectExplorer::BuildManager::instance(); + m_buildConnect = connect(this, &TestRunner::requestStopTestRun, + buildManager, &ProjectExplorer::BuildManager::cancel); connect(buildManager, &ProjectExplorer::BuildManager::buildQueueFinished, this, &TestRunner::buildFinished); ProjectExplorer::ProjectExplorerPlugin::buildProject(project); @@ -287,11 +276,18 @@ void TestRunner::buildProject(ProjectExplorer::Project *project) void TestRunner::buildFinished(bool success) { + disconnect(m_buildConnect); ProjectExplorer::BuildManager *buildManager = ProjectExplorer::BuildManager::instance(); disconnect(buildManager, &ProjectExplorer::BuildManager::buildQueueFinished, this, &TestRunner::buildFinished); - m_building = false; - m_buildSucceeded = success; + + if (success) { + runTests(); + } else { + TestResultsPane::instance()->addTestResult(FaultyTestResult(Result::MESSAGE_FATAL, + tr("Build failed. Canceling test run."))); + onFinished(); + } } void TestRunner::onFinished() diff --git a/plugins/autotest/testrunner.h b/plugins/autotest/testrunner.h index ddbac5e92f..92de02f67b 100644 --- a/plugins/autotest/testrunner.h +++ b/plugins/autotest/testrunner.h @@ -51,7 +51,7 @@ signals: void requestStopTestRun(); public slots: - void runTests(); + void prepareToRunTests(); private slots: void buildProject(ProjectExplorer::Project *project); @@ -59,13 +59,14 @@ private slots: void onFinished(); private: + void runTests(); explicit TestRunner(QObject *parent = 0); QList<TestConfiguration *> m_selectedTests; - bool m_building; - bool m_buildSucceeded; bool m_executingTests; + // temporarily used if building before running is necessary + QMetaObject::Connection m_buildConnect; }; } // namespace Internal |