AutoTest: Use LayoutBuilder for GTestSettingsPage

Change-Id: I7449732a77e1cb2635df3bb45c7ebb24955209d2
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-03-26 19:14:28 +01:00
parent 7769d881bc
commit 2a1742b289
9 changed files with 99 additions and 404 deletions

View File

@@ -35,7 +35,6 @@ add_qtc_plugin(AutoTest
gtest/gtestparser.cpp gtest/gtestparser.h gtest/gtestparser.cpp gtest/gtestparser.h
gtest/gtestresult.cpp gtest/gtestresult.h gtest/gtestresult.cpp gtest/gtestresult.h
gtest/gtestsettings.cpp gtest/gtestsettings.h gtest/gtestsettings.cpp gtest/gtestsettings.h
gtest/gtestsettingspage.cpp gtest/gtestsettingspage.h gtest/gtestsettingspage.ui
gtest/gtesttreeitem.cpp gtest/gtesttreeitem.h gtest/gtesttreeitem.cpp gtest/gtesttreeitem.h
gtest/gtestvisitors.cpp gtest/gtestvisitors.h gtest/gtestvisitors.cpp gtest/gtestvisitors.h
itemdatacache.h itemdatacache.h

View File

@@ -48,7 +48,6 @@ SOURCES += \
gtest/gtestvisitors.cpp \ gtest/gtestvisitors.cpp \
gtest/gtestframework.cpp \ gtest/gtestframework.cpp \
gtest/gtestsettings.cpp \ gtest/gtestsettings.cpp \
gtest/gtestsettingspage.cpp \
gtest/gtest_utils.cpp \ gtest/gtest_utils.cpp \
qtest/qttesttreeitem.cpp \ qtest/qttesttreeitem.cpp \
qtest/qttestvisitors.cpp \ qtest/qttestvisitors.cpp \
@@ -123,7 +122,6 @@ HEADERS += \
gtest/gtestvisitors.h \ gtest/gtestvisitors.h \
gtest/gtestframework.h \ gtest/gtestframework.h \
gtest/gtestsettings.h \ gtest/gtestsettings.h \
gtest/gtestsettingspage.h \
gtest/gtestconstants.h \ gtest/gtestconstants.h \
qtest/qttesttreeitem.h \ qtest/qttesttreeitem.h \
qtest/qttest_utils.h \ qtest/qttest_utils.h \
@@ -155,8 +153,7 @@ RESOURCES += \
autotest.qrc autotest.qrc
FORMS += \ FORMS += \
testsettingspage.ui \ testsettingspage.ui
gtest/gtestsettingspage.ui
equals(TEST, 1) { equals(TEST, 1) {
HEADERS += autotestunittests.h HEADERS += autotestunittests.h

View File

@@ -77,7 +77,7 @@ QString GTestFramework::groupingToolTip() const
GTest::Constants::GroupMode GTestFramework::groupMode() GTest::Constants::GroupMode GTestFramework::groupMode()
{ {
return GTest::Constants::GroupMode(g_settings->groupMode.value()); return GTest::Constants::GroupMode(g_settings->groupMode.itemValue().toInt());
} }
} // namespace Internal } // namespace Internal

View File

@@ -28,7 +28,6 @@
#include "../itestframework.h" #include "../itestframework.h"
#include "gtestconstants.h" #include "gtestconstants.h"
#include "gtestsettings.h" #include "gtestsettings.h"
#include "gtestsettingspage.h"
namespace Autotest { namespace Autotest {
namespace Internal { namespace Internal {

View File

@@ -24,7 +24,16 @@
****************************************************************************/ ****************************************************************************/
#include "gtestsettings.h" #include "gtestsettings.h"
#include "gtest_utils.h" #include "gtest_utils.h"
#include "gtestconstants.h"
#include "../autotestconstants.h"
#include "../testframeworkmanager.h"
#include "../testtreemodel.h"
#include <utils/layoutbuilder.h>
using namespace Utils;
namespace Autotest { namespace Autotest {
namespace Internal { namespace Internal {
@@ -37,38 +46,65 @@ GTestSettings::GTestSettings()
registerAspect(&iterations); registerAspect(&iterations);
iterations.setSettingsKey("Iterations"); iterations.setSettingsKey("Iterations");
iterations.setDefaultValue(1); iterations.setDefaultValue(1);
iterations.setEnabled(false);
iterations.setLabelText(tr("Iterations:"));
iterations.setEnabler(&repeat);
registerAspect(&seed); registerAspect(&seed);
seed.setSettingsKey("Seed"); seed.setSettingsKey("Seed");
seed.setSpecialValueText(QString());
seed.setEnabled(false);
seed.setLabelText(tr("Seed:"));
seed.setToolTip(tr("A seed of 0 generates a seed based on the current timestamp."));
seed.setEnabler(&shuffle);
registerAspect(&runDisabled); registerAspect(&runDisabled);
runDisabled.setSettingsKey("RunDisabled"); runDisabled.setSettingsKey("RunDisabled");
runDisabled.setLabelText(tr("Run disabled tests"));
runDisabled.setToolTip(tr("Executes disabled tests when performing a test run."));
registerAspect(&shuffle); registerAspect(&shuffle);
shuffle.setSettingsKey("Shuffle"); shuffle.setSettingsKey("Shuffle");
shuffle.setLabelText(tr("Shuffle tests"));
shuffle.setToolTip(tr("Shuffles tests automatically on every iteration by the given seed."));
registerAspect(&repeat); registerAspect(&repeat);
repeat.setSettingsKey("Repeat"); repeat.setSettingsKey("Repeat");
repeat.setLabelText(tr("Repeat tests"));
repeat.setToolTip(tr("Repeats a test run (you might be required to increase the timeout to avoid canceling the tests)."));
registerAspect(&throwOnFailure); registerAspect(&throwOnFailure);
throwOnFailure.setSettingsKey("ThrowOnFailure"); throwOnFailure.setSettingsKey("ThrowOnFailure");
throwOnFailure.setLabelText(tr("Throw on failure"));
throwOnFailure.setToolTip(tr("Turns assertion failures into C++ exceptions."));
registerAspect(&breakOnFailure); registerAspect(&breakOnFailure);
breakOnFailure.setSettingsKey("BreakOnFailure"); breakOnFailure.setSettingsKey("BreakOnFailure");
breakOnFailure.setDefaultValue(true); breakOnFailure.setDefaultValue(true);
breakOnFailure.setLabelText(tr("Break on failure while debugging"));
breakOnFailure.setToolTip(tr("Turns failures into debugger breakpoints."));
registerAspect(&groupMode); registerAspect(&groupMode);
groupMode.setDefaultValue(GTest::Constants::Directory);
groupMode.setSettingsKey("GroupMode"); groupMode.setSettingsKey("GroupMode");
groupMode.setFromSettingsTransformation([](const QVariant &savedValue) -> QVariant { groupMode.setDisplayStyle(SelectionAspect::DisplayStyle::ComboBox);
groupMode.setFromSettingsTransformation([this](const QVariant &savedValue) -> QVariant {
// avoid problems if user messes around with the settings file // avoid problems if user messes around with the settings file
bool ok = false; bool ok = false;
const int tmp = savedValue.toInt(&ok); const int tmp = savedValue.toInt(&ok);
return ok ? static_cast<GTest::Constants::GroupMode>(tmp) : GTest::Constants::Directory; return ok ? groupMode.indexForItemValue(tmp) : GTest::Constants::Directory;
}); });
groupMode.setToSettingsTransformation([this](const QVariant &value) {
return groupMode.itemValueForIndex(value.toInt());
});
groupMode.addOption({tr("Directory"), {}, GTest::Constants::Directory});
groupMode.addOption({tr("GTest Filter"), {}, GTest::Constants::GTestFilter});
groupMode.setDefaultValue(GTest::Constants::Directory);
groupMode.setLabelText(tr("Group mode:"));
groupMode.setToolTip(tr("Select on what grouping the tests should be based."));
registerAspect(&gtestFilter); registerAspect(&gtestFilter);
gtestFilter.setSettingsKey("GTestFilter"); gtestFilter.setSettingsKey("GTestFilter");
gtestFilter.setDisplayStyle(StringAspect::LineEditDisplay);
gtestFilter.setDefaultValue(GTest::Constants::DEFAULT_FILTER); gtestFilter.setDefaultValue(GTest::Constants::DEFAULT_FILTER);
gtestFilter.setFromSettingsTransformation([](const QVariant &savedValue) -> QVariant { gtestFilter.setFromSettingsTransformation([](const QVariant &savedValue) -> QVariant {
// avoid problems if user messes around with the settings file // avoid problems if user messes around with the settings file
@@ -77,6 +113,52 @@ GTestSettings::GTestSettings()
return tmp; return tmp;
return GTest::Constants::DEFAULT_FILTER; return GTest::Constants::DEFAULT_FILTER;
}); });
gtestFilter.setEnabled(false);
gtestFilter.setLabelText(tr("Active filter:"));
gtestFilter.setToolTip(tr("Set the GTest filter to be used for grouping.\n"
"See Google Test documentation for further information on GTest filters."));
gtestFilter.setValidationFunction([](FancyLineEdit *edit, QString * /*error*/) {
return edit && GTestUtils::isValidGTestFilter(edit->text());
});
QObject::connect(&groupMode, &SelectionAspect::volatileValueChanged,
&gtestFilter, [this](int val) {
gtestFilter.setEnabled(groupMode.itemValueForIndex(val) == GTest::Constants::GTestFilter);
});
}
GTestSettingsPage::GTestSettingsPage(GTestSettings *settings, Utils::Id settingsId)
{
setId(settingsId);
setCategory(Constants::AUTOTEST_SETTINGS_CATEGORY);
setDisplayName(QCoreApplication::translate("GTestFramework",
GTest::Constants::FRAMEWORK_SETTINGS_CATEGORY));
setSettings(settings);
QObject::connect(settings, &AspectContainer::applied, this, [] {
Id id = Id(Constants::FRAMEWORK_PREFIX).withSuffix(GTest::Constants::FRAMEWORK_NAME);
TestTreeModel::instance()->rebuild({id});
});
setLayouter([settings](QWidget *widget) {
GTestSettings &s = *settings;
using namespace Layouting;
const Break nl;
Grid grid {
s.runDisabled, nl,
s.breakOnFailure, nl,
s.repeat, s.iterations, nl,
s.shuffle, s.seed
};
Form form {
s.groupMode,
s.gtestFilter
};
Column { Row { Column { grid, form, Stretch() }, Stretch() } }.attachTo(widget);
});
} }
} // namespace Internal } // namespace Internal

View File

@@ -27,6 +27,8 @@
#include "gtestconstants.h" #include "gtestconstants.h"
#include <coreplugin/dialogs/ioptionspage.h>
#include <utils/aspects.h> #include <utils/aspects.h>
namespace Autotest { namespace Autotest {
@@ -34,6 +36,8 @@ namespace Internal {
class GTestSettings : public Utils::AspectContainer class GTestSettings : public Utils::AspectContainer
{ {
Q_DECLARE_TR_FUNCTIONS(Autotest::Internal::GTestSettings)
public: public:
GTestSettings(); GTestSettings();
@@ -48,5 +52,13 @@ public:
Utils::StringAspect gtestFilter; Utils::StringAspect gtestFilter;
}; };
class GTestSettingsPage final : public Core::IOptionsPage
{
Q_DECLARE_TR_FUNCTIONS(Autotest::Internal::GTestSettings)
public:
GTestSettingsPage(GTestSettings *settings, Utils::Id settingsId);
};
} // namespace Internal } // namespace Internal
} // namespace Autotest } // namespace Autotest

View File

@@ -1,123 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "gtestconstants.h"
#include "gtestsettingspage.h"
#include "gtestsettings.h"
#include "gtest_utils.h"
#include "../autotestconstants.h"
#include "../testframeworkmanager.h"
#include "../testtreemodel.h"
#include "ui_gtestsettingspage.h"
#include <coreplugin/icore.h>
namespace Autotest {
namespace Internal {
static bool validateFilter(Utils::FancyLineEdit *edit, QString * /*error*/)
{
return edit && GTestUtils::isValidGTestFilter(edit->text());
}
class GTestSettingsWidget final : public Core::IOptionsPageWidget
{
Q_DECLARE_TR_FUNCTIONS(Autotest::Internal::GTestSettingsWidget)
public:
explicit GTestSettingsWidget(GTestSettings *settings);
private:
void apply() final;
Ui::GTestSettingsPage m_ui;
QString m_currentGTestFilter;
GTestSettings *m_settings;
};
GTestSettingsWidget::GTestSettingsWidget(GTestSettings *settings)
: m_settings(settings)
{
m_ui.setupUi(this);
m_ui.filterLineEdit->setValidationFunction(&validateFilter);
m_ui.filterLineEdit->setEnabled(m_ui.groupModeCombo->currentIndex() == 1);
connect(m_ui.groupModeCombo, &QComboBox::currentTextChanged,
this, [this] () {
m_ui.filterLineEdit->setEnabled(m_ui.groupModeCombo->currentIndex() == 1);
});
connect(m_ui.repeatGTestsCB, &QCheckBox::toggled, m_ui.repetitionSpin, &QSpinBox::setEnabled);
connect(m_ui.shuffleGTestsCB, &QCheckBox::toggled, m_ui.seedSpin, &QSpinBox::setEnabled);
m_ui.runDisabledGTestsCB->setChecked(m_settings->runDisabled.value());
m_ui.repeatGTestsCB->setChecked(m_settings->repeat.value());
m_ui.shuffleGTestsCB->setChecked(m_settings->shuffle.value());
m_ui.repetitionSpin->setValue(m_settings->iterations.value());
m_ui.seedSpin->setValue(m_settings->seed.value());
m_ui.breakOnFailureCB->setChecked(m_settings->breakOnFailure.value());
m_ui.throwOnFailureCB->setChecked(m_settings->throwOnFailure.value());
m_ui.groupModeCombo->setCurrentIndex(m_settings->groupMode.value() - 1); // there's None for internal use
m_ui.filterLineEdit->setText(m_settings->gtestFilter.value());
m_currentGTestFilter = m_settings->gtestFilter.value(); // store it temporarily (if edit is invalid)
}
void GTestSettingsWidget::apply()
{
GTest::Constants::GroupMode oldGroupMode = GTest::Constants::GroupMode(m_settings->groupMode.value());
const QString oldFilter = m_settings->gtestFilter.value();
m_settings->runDisabled.setValue(m_ui.runDisabledGTestsCB->isChecked());
m_settings->repeat.setValue(m_ui.repeatGTestsCB->isChecked());
m_settings->shuffle.setValue(m_ui.shuffleGTestsCB->isChecked());
m_settings->iterations.setValue(m_ui.repetitionSpin->value());
m_settings->seed.setValue(m_ui.seedSpin->value());
m_settings->breakOnFailure.setValue(m_ui.breakOnFailureCB->isChecked());
m_settings->throwOnFailure.setValue(m_ui.throwOnFailureCB->isChecked());
m_settings->groupMode.setValue(static_cast<GTest::Constants::GroupMode>(
m_ui.groupModeCombo->currentIndex() + 1));
if (m_ui.filterLineEdit->isValid())
m_settings->gtestFilter.setValue(m_ui.filterLineEdit->text());
else
m_settings->gtestFilter.setValue(m_currentGTestFilter);
m_settings->writeSettings(Core::ICore::settings());
if (m_settings->groupMode.value() == oldGroupMode && oldFilter == m_settings->gtestFilter.value())
return;
auto id = Utils::Id(Constants::FRAMEWORK_PREFIX).withSuffix(GTest::Constants::FRAMEWORK_NAME);
TestTreeModel::instance()->rebuild({id});
}
GTestSettingsPage::GTestSettingsPage(GTestSettings *settings, Utils::Id settingsId)
{
setId(settingsId);
setCategory(Constants::AUTOTEST_SETTINGS_CATEGORY);
setDisplayName(QCoreApplication::translate("GTestFramework",
GTest::Constants::FRAMEWORK_SETTINGS_CATEGORY));
setWidgetCreator([settings] { return new GTestSettingsWidget(settings); });
}
} // namespace Internal
} // namespace Autotest

View File

@@ -1,42 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <coreplugin/dialogs/ioptionspage.h>
namespace Autotest {
namespace Internal {
class GTestSettings;
class GTestSettingsPage final : public Core::IOptionsPage
{
public:
GTestSettingsPage(GTestSettings *settings, Utils::Id settingsId);
};
} // namespace Internal
} // namespace Autotest

View File

@@ -1,229 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Autotest::Internal::GTestSettingsPage</class>
<widget class="QWidget" name="Autotest::Internal::GTestSettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>449</width>
<height>232</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QCheckBox" name="breakOnFailureCB">
<property name="toolTip">
<string>Turns failures into debugger breakpoints.</string>
</property>
<property name="text">
<string>Break on failure while debugging</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="runDisabledGTestsCB">
<property name="toolTip">
<string>Executes disabled tests when performing a test run.</string>
</property>
<property name="text">
<string>Run disabled tests</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="throwOnFailureCB">
<property name="toolTip">
<string>Turns assertion failures into C++ exceptions.</string>
</property>
<property name="text">
<string>Throw on failure</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Iterations:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="shuffleGTestsCB">
<property name="toolTip">
<string>Shuffles tests automatically on every iteration by the given seed.</string>
</property>
<property name="text">
<string>Shuffle tests</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="repeatGTestsCB">
<property name="toolTip">
<string>Repeats a test run (you might be required to increase the timeout to avoid canceling the tests).</string>
</property>
<property name="text">
<string>Repeat tests</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="repetitionSpin">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Seed:</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QSpinBox" name="seedSpin">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>A seed of 0 generates a seed based on the current timestamp.</string>
</property>
<property name="specialValueText">
<string/>
</property>
<property name="maximum">
<number>99999</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Group mode:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Active filter:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="groupModeCombo">
<property name="toolTip">
<string>Select on what grouping the tests should be based.</string>
</property>
<item>
<property name="text">
<string>Directory</string>
</property>
</item>
<item>
<property name="text">
<string>GTest Filter</string>
</property>
</item>
</widget>
</item>
<item row="1" column="2">
<widget class="Utils::FancyLineEdit" name="filterLineEdit">
<property name="toolTip">
<string>Set the GTest filter to be used for grouping.
See Google Test documentation for further information on GTest filters.</string>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>60</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</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>
</widget>
<customwidgets>
<customwidget>
<class>Utils::FancyLineEdit</class>
<extends>QLineEdit</extends>
<header location="global">utils/fancylineedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>