forked from qt-creator/qt-creator
AutoTest: Take advantage of IOptionPage::setWidgetCreator()
Less boilerplate for the implementation and user code access to IOptionPage::{apply,finish} is planned to be removed. Change-Id: I1d914d21c62a983a212d9696d14890cfd0e643c7 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -27,19 +27,18 @@
|
|||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QTreeWidget>
|
#include <QTreeWidget>
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Autotest {
|
namespace Autotest::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class TestSettingsWidget : public QWidget
|
class TestSettingsWidget : public Core::IOptionsPageWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit TestSettingsWidget(QWidget *parent = nullptr);
|
explicit TestSettingsWidget(TestSettings *settings);
|
||||||
|
|
||||||
|
void apply() final;
|
||||||
|
|
||||||
void setSettings(const TestSettings &settings);
|
|
||||||
TestSettings settings() const;
|
TestSettings settings() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -49,6 +48,7 @@ private:
|
|||||||
void testToolsSettings(TestSettings &settings) const;
|
void testToolsSettings(TestSettings &settings) const;
|
||||||
void onFrameworkItemChanged();
|
void onFrameworkItemChanged();
|
||||||
|
|
||||||
|
TestSettings *m_settings;
|
||||||
QCheckBox *m_omitInternalMsgCB;
|
QCheckBox *m_omitInternalMsgCB;
|
||||||
QCheckBox *m_omitRunConfigWarnCB;
|
QCheckBox *m_omitRunConfigWarnCB;
|
||||||
QCheckBox *m_limitResultOutputCB;
|
QCheckBox *m_limitResultOutputCB;
|
||||||
@@ -66,8 +66,8 @@ private:
|
|||||||
InfoLabel *m_frameworksWarn;
|
InfoLabel *m_frameworksWarn;
|
||||||
};
|
};
|
||||||
|
|
||||||
TestSettingsWidget::TestSettingsWidget(QWidget *parent)
|
TestSettingsWidget::TestSettingsWidget(TestSettings *settings)
|
||||||
: QWidget(parent)
|
: m_settings(settings)
|
||||||
{
|
{
|
||||||
resize(586, 469);
|
resize(586, 469);
|
||||||
|
|
||||||
@@ -203,25 +203,23 @@ TestSettingsWidget::TestSettingsWidget(QWidget *parent)
|
|||||||
m_openResultsOnFailCB, &QCheckBox::setEnabled);
|
m_openResultsOnFailCB, &QCheckBox::setEnabled);
|
||||||
connect(m_limitResultDescriptionCb, &QCheckBox::toggled,
|
connect(m_limitResultDescriptionCb, &QCheckBox::toggled,
|
||||||
m_limitResultDescriptionSpinBox, &QSpinBox::setEnabled);
|
m_limitResultDescriptionSpinBox, &QSpinBox::setEnabled);
|
||||||
}
|
|
||||||
|
|
||||||
void TestSettingsWidget::setSettings(const TestSettings &settings)
|
|
||||||
{
|
m_timeoutSpin->setValue(settings->timeout / 1000); // we store milliseconds
|
||||||
m_timeoutSpin->setValue(settings.timeout / 1000); // we store milliseconds
|
m_omitInternalMsgCB->setChecked(settings->omitInternalMssg);
|
||||||
m_omitInternalMsgCB->setChecked(settings.omitInternalMssg);
|
m_omitRunConfigWarnCB->setChecked(settings->omitRunConfigWarn);
|
||||||
m_omitRunConfigWarnCB->setChecked(settings.omitRunConfigWarn);
|
m_limitResultOutputCB->setChecked(settings->limitResultOutput);
|
||||||
m_limitResultOutputCB->setChecked(settings.limitResultOutput);
|
m_limitResultDescriptionCb->setChecked(settings->limitResultDescription);
|
||||||
m_limitResultDescriptionCb->setChecked(settings.limitResultDescription);
|
m_limitResultDescriptionSpinBox->setEnabled(settings->limitResultDescription);
|
||||||
m_limitResultDescriptionSpinBox->setEnabled(settings.limitResultDescription);
|
m_limitResultDescriptionSpinBox->setValue(settings->resultDescriptionMaxSize);
|
||||||
m_limitResultDescriptionSpinBox->setValue(settings.resultDescriptionMaxSize);
|
m_autoScrollCB->setChecked(settings->autoScroll);
|
||||||
m_autoScrollCB->setChecked(settings.autoScroll);
|
m_processArgsCB->setChecked(settings->processArgs);
|
||||||
m_processArgsCB->setChecked(settings.processArgs);
|
m_displayAppCB->setChecked(settings->displayApplication);
|
||||||
m_displayAppCB->setChecked(settings.displayApplication);
|
m_openResultsOnStartCB->setChecked(settings->popupOnStart);
|
||||||
m_openResultsOnStartCB->setChecked(settings.popupOnStart);
|
m_openResultsOnFinishCB->setChecked(settings->popupOnFinish);
|
||||||
m_openResultsOnFinishCB->setChecked(settings.popupOnFinish);
|
m_openResultsOnFailCB->setChecked(settings->popupOnFail);
|
||||||
m_openResultsOnFailCB->setChecked(settings.popupOnFail);
|
m_runAfterBuildCB->setCurrentIndex(int(settings->runAfterBuild));
|
||||||
m_runAfterBuildCB->setCurrentIndex(int(settings.runAfterBuild));
|
populateFrameworksListWidget(settings->frameworks, settings->tools);
|
||||||
populateFrameworksListWidget(settings.frameworks, settings.tools);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TestSettings TestSettingsWidget::settings() const
|
TestSettings TestSettingsWidget::settings() const
|
||||||
@@ -343,30 +341,9 @@ void TestSettingsWidget::onFrameworkItemChanged()
|
|||||||
|| (mixed == (ITestBase::Framework | ITestBase::Tool)));
|
|| (mixed == (ITestBase::Framework | ITestBase::Tool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestSettingsPage::TestSettingsPage(TestSettings *settings)
|
void TestSettingsWidget::apply()
|
||||||
: m_settings(settings)
|
|
||||||
{
|
{
|
||||||
setId(Constants::AUTOTEST_SETTINGS_ID);
|
const TestSettings newSettings = settings();
|
||||||
setDisplayName(Tr::tr("General"));
|
|
||||||
setCategory(Constants::AUTOTEST_SETTINGS_CATEGORY);
|
|
||||||
setDisplayCategory(Tr::tr("Testing"));
|
|
||||||
setCategoryIconPath(":/autotest/images/settingscategory_autotest.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget *TestSettingsPage::widget()
|
|
||||||
{
|
|
||||||
if (!m_widget) {
|
|
||||||
m_widget = new TestSettingsWidget;
|
|
||||||
m_widget->setSettings(*m_settings);
|
|
||||||
}
|
|
||||||
return m_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestSettingsPage::apply()
|
|
||||||
{
|
|
||||||
if (!m_widget) // page was not shown at all
|
|
||||||
return;
|
|
||||||
const TestSettings newSettings = m_widget->settings();
|
|
||||||
const QList<Id> changedIds = Utils::filtered(newSettings.frameworksGrouping.keys(),
|
const QList<Id> changedIds = Utils::filtered(newSettings.frameworksGrouping.keys(),
|
||||||
[newSettings, this](const Id &id) {
|
[newSettings, this](const Id &id) {
|
||||||
return newSettings.frameworksGrouping[id] != m_settings->frameworksGrouping[id];
|
return newSettings.frameworksGrouping[id] != m_settings->frameworksGrouping[id];
|
||||||
@@ -388,5 +365,16 @@ void TestSettingsPage::apply()
|
|||||||
TestTreeModel::instance()->rebuild(changedIds);
|
TestTreeModel::instance()->rebuild(changedIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
// TestSettingsPage
|
||||||
} // namespace Autotest
|
|
||||||
|
TestSettingsPage::TestSettingsPage(TestSettings *settings)
|
||||||
|
{
|
||||||
|
setId(Constants::AUTOTEST_SETTINGS_ID);
|
||||||
|
setDisplayName(Tr::tr("General"));
|
||||||
|
setCategory(Constants::AUTOTEST_SETTINGS_CATEGORY);
|
||||||
|
setDisplayCategory(Tr::tr("Testing"));
|
||||||
|
setCategoryIconPath(":/autotest/images/settingscategory_autotest.png");
|
||||||
|
setWidgetCreator([settings] { return new TestSettingsWidget(settings); });
|
||||||
|
}
|
||||||
|
|
||||||
|
} // Autotest::Internal
|
||||||
|
@@ -5,28 +5,14 @@
|
|||||||
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
#include <QPointer>
|
namespace Autotest::Internal {
|
||||||
|
|
||||||
namespace Autotest {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
struct TestSettings;
|
struct TestSettings;
|
||||||
class TestSettingsWidget;
|
|
||||||
|
|
||||||
class TestSettingsPage : public Core::IOptionsPage
|
class TestSettingsPage : public Core::IOptionsPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
explicit TestSettingsPage(TestSettings *settings);
|
explicit TestSettingsPage(TestSettings *settings);
|
||||||
|
|
||||||
QWidget *widget() override;
|
|
||||||
void apply() override;
|
|
||||||
void finish() override { }
|
|
||||||
|
|
||||||
private:
|
|
||||||
TestSettings *m_settings;
|
|
||||||
QPointer<TestSettingsWidget> m_widget;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // Autotest::Internal
|
||||||
} // namespace Autotest
|
|
||||||
|
Reference in New Issue
Block a user