AutoTest: Provide way to remember last chosen run configurations

In some special setups it is almost impossible to get the right
executable or run configuration. For bigger projects this can
become a pain point when trying to execute tests and always
getting asked which one to run.
So, allow remembering the choice and use it if appropriate.
The cached information is not stored permanently.

Resetting of the cached information can also be triggered by
switching or closing the current project and inside the settings.

Task-number: QTCREATORBUG-20859
Change-Id: If416ea0ae9ad3548daca2ffcf5888fd568fd2622
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2018-08-08 12:40:03 +02:00
parent 8d814facf7
commit bab836c009
6 changed files with 102 additions and 1 deletions

View File

@@ -53,6 +53,7 @@
#include <projectexplorer/buildmanager.h> #include <projectexplorer/buildmanager.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorericons.h> #include <projectexplorer/projectexplorericons.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <texteditor/texteditor.h> #include <texteditor/texteditor.h>
@@ -183,6 +184,10 @@ bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorStri
m_frameworkManager->activateFrameworksFromSettings(m_settings); m_frameworkManager->activateFrameworksFromSettings(m_settings);
TestTreeModel::instance()->syncTestFrameworks(); TestTreeModel::instance()->syncTestFrameworks();
connect(ProjectExplorer::SessionManager::instance(),
&ProjectExplorer::SessionManager::startupProjectChanged, this, [this] {
m_runconfigCache.clear();
});
return true; return true;
} }
@@ -311,6 +316,23 @@ void AutotestPlugin::updateMenuItemsEnabledState()
ActionManager::command(Constants::ACTION_RUN_DBG_UCURSOR)->action()->setEnabled(canRun); ActionManager::command(Constants::ACTION_RUN_DBG_UCURSOR)->action()->setEnabled(canRun);
} }
void AutotestPlugin::cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice)
{
if (s_instance)
s_instance->m_runconfigCache.insert(buildTargetKey, choice);
}
ChoicePair AutotestPlugin::cachedChoiceFor(const QString &buildTargetKey)
{
return s_instance ? s_instance->m_runconfigCache.value(buildTargetKey) : ChoicePair();
}
void AutotestPlugin::clearChoiceCache()
{
if (s_instance)
s_instance->m_runconfigCache.clear();
}
QList<QObject *> AutotestPlugin::createTestObjects() const QList<QObject *> AutotestPlugin::createTestObjects() const
{ {
QList<QObject *> tests; QList<QObject *> tests;
@@ -319,3 +341,9 @@ QList<QObject *> AutotestPlugin::createTestObjects() const
#endif #endif
return tests; return tests;
} }
bool ChoicePair::matches(const ProjectExplorer::RunConfiguration *rc) const
{
return rc ? (rc->displayName() == displayName && rc->runnable().executable == executable)
: false;
}

View File

@@ -29,6 +29,10 @@
#include <extensionsystem/iplugin.h> #include <extensionsystem/iplugin.h>
#include <QMap>
namespace ProjectExplorer { class RunConfiguration; }
namespace Autotest { namespace Autotest {
namespace Internal { namespace Internal {
@@ -39,6 +43,16 @@ struct TestSettings;
class TestSettingsPage; class TestSettingsPage;
enum class TestRunMode; enum class TestRunMode;
struct ChoicePair
{
explicit ChoicePair(const QString &name = QString(), const QString &exe = QString())
: displayName(name), executable(exe) {}
bool matches(const ProjectExplorer::RunConfiguration *rc) const;
QString displayName;
QString executable;
};
class AutotestPlugin : public ExtensionSystem::IPlugin class AutotestPlugin : public ExtensionSystem::IPlugin
{ {
Q_OBJECT Q_OBJECT
@@ -54,6 +68,9 @@ public:
static QSharedPointer<TestSettings> settings(); static QSharedPointer<TestSettings> settings();
static void updateMenuItemsEnabledState(); static void updateMenuItemsEnabledState();
static void cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice);
static ChoicePair cachedChoiceFor(const QString &buildTargetKey);
static void clearChoiceCache();
private: private:
bool checkLicense(); bool checkLicense();
@@ -68,6 +85,7 @@ private:
TestSettingsPage *m_testSettingPage = nullptr; TestSettingsPage *m_testSettingPage = nullptr;
TestNavigationWidgetFactory *m_navigationWidgetFactory = nullptr; TestNavigationWidgetFactory *m_navigationWidgetFactory = nullptr;
TestResultsPane *m_resultsPane = nullptr; TestResultsPane *m_resultsPane = nullptr;
QMap<QString, ChoicePair> m_runconfigCache;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -49,6 +49,7 @@
#include <utils/outputformat.h> #include <utils/outputformat.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#include <QCheckBox>
#include <QComboBox> #include <QComboBox>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QFormLayout> #include <QFormLayout>
@@ -365,6 +366,17 @@ static ProjectExplorer::RunConfiguration *getRunConfiguration(const QString &bui
= Utils::filtered(target->runConfigurations(), [] (const RunConfiguration *rc) { = Utils::filtered(target->runConfigurations(), [] (const RunConfiguration *rc) {
return !rc->runnable().executable.isEmpty(); return !rc->runnable().executable.isEmpty();
}); });
const ChoicePair oldChoice = AutotestPlugin::cachedChoiceFor(buildTargetKey);
if (!oldChoice.executable.isEmpty()) {
runConfig = Utils::findOrDefault(runConfigurations,
[&oldChoice] (const RunConfiguration *rc) {
return oldChoice.matches(rc);
});
if (runConfig)
return runConfig;
}
if (runConfigurations.size() == 1) if (runConfigurations.size() == 1)
return runConfigurations.first(); return runConfigurations.first();
@@ -380,6 +392,8 @@ static ProjectExplorer::RunConfiguration *getRunConfiguration(const QString &bui
return false; return false;
return rc->runnable().executable == exe; return rc->runnable().executable == exe;
}); });
if (runConfig && dialog.rememberChoice())
AutotestPlugin::cacheRunConfigChoice(buildTargetKey, ChoicePair(dName, exe));
} }
return runConfig; return runConfig;
} }
@@ -669,6 +683,8 @@ RunConfigurationSelectionDialog::RunConfigurationSelectionDialog(const QString &
details.append(QString(" (%1)").arg(buildTargetKey)); details.append(QString(" (%1)").arg(buildTargetKey));
m_details = new QLabel(details, this); m_details = new QLabel(details, this);
m_rcCombo = new QComboBox(this); m_rcCombo = new QComboBox(this);
m_rememberCB = new QCheckBox(tr("Remember choice. Cached choices can be reset by switching "
"projects or using the option to clear the cache."), this);
m_executable = new QLabel(this); m_executable = new QLabel(this);
m_arguments = new QLabel(this); m_arguments = new QLabel(this);
m_workingDir = new QLabel(this); m_workingDir = new QLabel(this);
@@ -680,6 +696,7 @@ RunConfigurationSelectionDialog::RunConfigurationSelectionDialog(const QString &
formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow); formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
formLayout->addRow(m_details); formLayout->addRow(m_details);
formLayout->addRow(tr("Run Configuration:"), m_rcCombo); formLayout->addRow(tr("Run Configuration:"), m_rcCombo);
formLayout->addRow(m_rememberCB);
formLayout->addRow(createLine(this)); formLayout->addRow(createLine(this));
formLayout->addRow(tr("Executable:"), m_executable); formLayout->addRow(tr("Executable:"), m_executable);
formLayout->addRow(tr("Arguments:"), m_arguments); formLayout->addRow(tr("Arguments:"), m_arguments);
@@ -709,6 +726,11 @@ QString RunConfigurationSelectionDialog::executable() const
return m_executable ? m_executable->text() : QString(); return m_executable ? m_executable->text() : QString();
} }
bool RunConfigurationSelectionDialog::rememberChoice() const
{
return m_rememberCB ? m_rememberCB->isChecked() : false;
}
void RunConfigurationSelectionDialog::populate() void RunConfigurationSelectionDialog::populate()
{ {
m_rcCombo->addItem(QString(), QStringList({QString(), QString(), QString()})); // empty default m_rcCombo->addItem(QString(), QStringList({QString(), QString(), QString()})); // empty default

View File

@@ -36,6 +36,7 @@
#include <QQueue> #include <QQueue>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QCheckBox;
class QComboBox; class QComboBox;
class QDialogButtonBox; class QDialogButtonBox;
class QLabel; class QLabel;
@@ -111,6 +112,7 @@ public:
explicit RunConfigurationSelectionDialog(const QString &buildTargetKey, QWidget *parent = nullptr); explicit RunConfigurationSelectionDialog(const QString &buildTargetKey, QWidget *parent = nullptr);
QString displayName() const; QString displayName() const;
QString executable() const; QString executable() const;
bool rememberChoice() const;
private: private:
void populate(); void populate();
void updateLabels(); void updateLabels();
@@ -119,6 +121,7 @@ private:
QLabel *m_arguments; QLabel *m_arguments;
QLabel *m_workingDir; QLabel *m_workingDir;
QComboBox *m_rcCombo; QComboBox *m_rcCombo;
QCheckBox *m_rememberCB;
QDialogButtonBox *m_buttonBox; QDialogButtonBox *m_buttonBox;
}; };

View File

@@ -29,6 +29,7 @@
#include "testsettingspage.h" #include "testsettingspage.h"
#include "testsettings.h" #include "testsettings.h"
#include "testtreemodel.h" #include "testtreemodel.h"
#include "autotestplugin.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <utils/fancylineedit.h> #include <utils/fancylineedit.h>
@@ -139,6 +140,8 @@ TestSettingsWidget::TestSettingsWidget(QWidget *parent)
m_ui.editFilter->setEnabled(enable); m_ui.editFilter->setEnabled(enable);
m_ui.removeFilter->setEnabled(enable); m_ui.removeFilter->setEnabled(enable);
}); });
connect(m_ui.resetChoicesButton, &QPushButton::clicked,
this, [] { AutotestPlugin::clearChoiceCache(); });
} }
void TestSettingsWidget::setSettings(const TestSettings &settings) void TestSettingsWidget::setSettings(const TestSettings &settings)

View File

@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>585</width> <width>585</width>
<height>373</height> <height>431</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -148,6 +148,33 @@ Warning: this is an experimental feature and might lead to failing to execute th
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QPushButton" name="resetChoicesButton">
<property name="toolTip">
<string>Clear all cached choices of run configurations for tests where the executable could not be deduced.</string>
</property>
<property name="text">
<string>Reset Cached Choices</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>