forked from qt-creator/qt-creator
AutoTest: Replace expensive function call
Depending on the underlying project manager it can be pretty expensive calling PE::canRunStartupProject(). AutoTest plugin used this to determine whether its global actions should be enabled or not and updating these actions is triggered for too many causes. Replace this function call by some simple checks that have almost no cost to avoid blocking UI. Task-number: QTCREATORBUG-20175 Change-Id: I0e3cce683f33abe82bf1354ec5276250f5e30068 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -50,6 +50,8 @@
|
|||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <projectexplorer/buildmanager.h>
|
#include <projectexplorer/buildmanager.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
|
#include <projectexplorer/session.h>
|
||||||
|
#include <projectexplorer/target.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
@@ -192,12 +194,16 @@ void AutotestPlugin::onRunSelectedTriggered()
|
|||||||
|
|
||||||
void AutotestPlugin::updateMenuItemsEnabledState()
|
void AutotestPlugin::updateMenuItemsEnabledState()
|
||||||
{
|
{
|
||||||
|
const ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
||||||
|
const ProjectExplorer::Target *target = project ? project->activeTarget() : nullptr;
|
||||||
const bool canScan = !TestRunner::instance()->isTestRunning()
|
const bool canScan = !TestRunner::instance()->isTestRunning()
|
||||||
&& TestTreeModel::instance()->parser()->state() == TestCodeParser::Idle;
|
&& TestTreeModel::instance()->parser()->state() == TestCodeParser::Idle;
|
||||||
const bool hasTests = TestTreeModel::instance()->hasTests();
|
const bool hasTests = TestTreeModel::instance()->hasTests();
|
||||||
|
// avoid expensive call to PE::canRunStartupProject() - limit to minimum necessary checks
|
||||||
const bool canRun = hasTests && canScan
|
const bool canRun = hasTests && canScan
|
||||||
&& ProjectExplorer::ProjectExplorerPlugin::canRunStartupProject(
|
&& project && !project->needsConfiguration()
|
||||||
ProjectExplorer::Constants::NORMAL_RUN_MODE);
|
&& target && target->activeRunConfiguration()
|
||||||
|
&& !ProjectExplorer::BuildManager::isBuilding();
|
||||||
|
|
||||||
ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action()->setEnabled(canRun);
|
ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action()->setEnabled(canRun);
|
||||||
ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action()->setEnabled(canRun);
|
ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action()->setEnabled(canRun);
|
||||||
|
Reference in New Issue
Block a user