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/projectexplorer.h>
#include <projectexplorer/projectexplorericons.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <texteditor/texteditor.h>
@@ -183,6 +184,10 @@ bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorStri
m_frameworkManager->activateFrameworksFromSettings(m_settings);
TestTreeModel::instance()->syncTestFrameworks();
connect(ProjectExplorer::SessionManager::instance(),
&ProjectExplorer::SessionManager::startupProjectChanged, this, [this] {
m_runconfigCache.clear();
});
return true;
}
@@ -311,6 +316,23 @@ void AutotestPlugin::updateMenuItemsEnabledState()
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 *> tests;
@@ -319,3 +341,9 @@ QList<QObject *> AutotestPlugin::createTestObjects() const
#endif
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 <QMap>
namespace ProjectExplorer { class RunConfiguration; }
namespace Autotest {
namespace Internal {
@@ -39,6 +43,16 @@ struct TestSettings;
class TestSettingsPage;
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
{
Q_OBJECT
@@ -54,6 +68,9 @@ public:
static QSharedPointer<TestSettings> settings();
static void updateMenuItemsEnabledState();
static void cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice);
static ChoicePair cachedChoiceFor(const QString &buildTargetKey);
static void clearChoiceCache();
private:
bool checkLicense();
@@ -68,6 +85,7 @@ private:
TestSettingsPage *m_testSettingPage = nullptr;
TestNavigationWidgetFactory *m_navigationWidgetFactory = nullptr;
TestResultsPane *m_resultsPane = nullptr;
QMap<QString, ChoicePair> m_runconfigCache;
};
} // namespace Internal

View File

@@ -49,6 +49,7 @@
#include <utils/outputformat.h>
#include <utils/qtcprocess.h>
#include <QCheckBox>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QFormLayout>
@@ -365,6 +366,17 @@ static ProjectExplorer::RunConfiguration *getRunConfiguration(const QString &bui
= Utils::filtered(target->runConfigurations(), [] (const RunConfiguration *rc) {
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)
return runConfigurations.first();
@@ -380,6 +392,8 @@ static ProjectExplorer::RunConfiguration *getRunConfiguration(const QString &bui
return false;
return rc->runnable().executable == exe;
});
if (runConfig && dialog.rememberChoice())
AutotestPlugin::cacheRunConfigChoice(buildTargetKey, ChoicePair(dName, exe));
}
return runConfig;
}
@@ -669,6 +683,8 @@ RunConfigurationSelectionDialog::RunConfigurationSelectionDialog(const QString &
details.append(QString(" (%1)").arg(buildTargetKey));
m_details = new QLabel(details, 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_arguments = new QLabel(this);
m_workingDir = new QLabel(this);
@@ -680,6 +696,7 @@ RunConfigurationSelectionDialog::RunConfigurationSelectionDialog(const QString &
formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
formLayout->addRow(m_details);
formLayout->addRow(tr("Run Configuration:"), m_rcCombo);
formLayout->addRow(m_rememberCB);
formLayout->addRow(createLine(this));
formLayout->addRow(tr("Executable:"), m_executable);
formLayout->addRow(tr("Arguments:"), m_arguments);
@@ -709,6 +726,11 @@ QString RunConfigurationSelectionDialog::executable() const
return m_executable ? m_executable->text() : QString();
}
bool RunConfigurationSelectionDialog::rememberChoice() const
{
return m_rememberCB ? m_rememberCB->isChecked() : false;
}
void RunConfigurationSelectionDialog::populate()
{
m_rcCombo->addItem(QString(), QStringList({QString(), QString(), QString()})); // empty default

View File

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

View File

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

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>585</width>
<height>373</height>
<height>431</height>
</rect>
</property>
<property name="windowTitle">
@@ -148,6 +148,33 @@ Warning: this is an experimental feature and might lead to failing to execute th
</item>
</layout>
</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>
</widget>
</item>