2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
Add baseline test that allows comparing the rendering of widgets
Provide basic boiler plate that sets up the baseline (aka lancelot)
framework specifically for comparing the appearance of widgets, and
implement test functions for QSlider and QPushButton.
Widgets should always look the same if the QPA platform, the OS
version, and certain UI-impacting attributes are identical. Ie.
on any macOS 10.15 machine that runs in "Light" mode, widgets
look the same. On a macOS 11 machine, they might look different.
On an OpenSUSE machine using the fusion style things might look
different from a Ubuntu machine.
The helper function removes DPR differences - images are always
scaled to a DPR of 1.0, which allows us to compare the image\
content and not get distracted by them having different dimensions
(and the fuzzy comparison of images might make the system tolerate
scaling artefacts).
Note: For now, this test is meant to be run locally, either when
testing changes to style code, or when checking how QWidget based
UIs would look on newer version of an operating system. In CI the
test is run, but then skipped in CI as the baseline server is
not configured.
Change-Id: Ie33a9d979d934f0df6883757333ce2c5e2f7ef84
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-11-11 19:29:22 +00:00
|
|
|
|
|
|
|
#include <qbaselinetest.h>
|
2021-11-19 11:25:00 +00:00
|
|
|
#include <qwidgetbaselinetest.h>
|
Add baseline test that allows comparing the rendering of widgets
Provide basic boiler plate that sets up the baseline (aka lancelot)
framework specifically for comparing the appearance of widgets, and
implement test functions for QSlider and QPushButton.
Widgets should always look the same if the QPA platform, the OS
version, and certain UI-impacting attributes are identical. Ie.
on any macOS 10.15 machine that runs in "Light" mode, widgets
look the same. On a macOS 11 machine, they might look different.
On an OpenSUSE machine using the fusion style things might look
different from a Ubuntu machine.
The helper function removes DPR differences - images are always
scaled to a DPR of 1.0, which allows us to compare the image\
content and not get distracted by them having different dimensions
(and the fuzzy comparison of images might make the system tolerate
scaling artefacts).
Note: For now, this test is meant to be run locally, either when
testing changes to style code, or when checking how QWidget based
UIs would look on newer version of an operating system. In CI the
test is run, but then skipped in CI as the baseline server is
not configured.
Change-Id: Ie33a9d979d934f0df6883757333ce2c5e2f7ef84
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-11-11 19:29:22 +00:00
|
|
|
#include <QtWidgets>
|
2022-01-14 11:56:55 +00:00
|
|
|
#include <QStyleOptionSlider>
|
Add baseline test that allows comparing the rendering of widgets
Provide basic boiler plate that sets up the baseline (aka lancelot)
framework specifically for comparing the appearance of widgets, and
implement test functions for QSlider and QPushButton.
Widgets should always look the same if the QPA platform, the OS
version, and certain UI-impacting attributes are identical. Ie.
on any macOS 10.15 machine that runs in "Light" mode, widgets
look the same. On a macOS 11 machine, they might look different.
On an OpenSUSE machine using the fusion style things might look
different from a Ubuntu machine.
The helper function removes DPR differences - images are always
scaled to a DPR of 1.0, which allows us to compare the image\
content and not get distracted by them having different dimensions
(and the fuzzy comparison of images might make the system tolerate
scaling artefacts).
Note: For now, this test is meant to be run locally, either when
testing changes to style code, or when checking how QWidget based
UIs would look on newer version of an operating system. In CI the
test is run, but then skipped in CI as the baseline server is
not configured.
Change-Id: Ie33a9d979d934f0df6883757333ce2c5e2f7ef84
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-11-11 19:29:22 +00:00
|
|
|
|
2021-11-19 11:25:00 +00:00
|
|
|
class tst_Widgets : public QWidgetBaselineTest
|
Add baseline test that allows comparing the rendering of widgets
Provide basic boiler plate that sets up the baseline (aka lancelot)
framework specifically for comparing the appearance of widgets, and
implement test functions for QSlider and QPushButton.
Widgets should always look the same if the QPA platform, the OS
version, and certain UI-impacting attributes are identical. Ie.
on any macOS 10.15 machine that runs in "Light" mode, widgets
look the same. On a macOS 11 machine, they might look different.
On an OpenSUSE machine using the fusion style things might look
different from a Ubuntu machine.
The helper function removes DPR differences - images are always
scaled to a DPR of 1.0, which allows us to compare the image\
content and not get distracted by them having different dimensions
(and the fuzzy comparison of images might make the system tolerate
scaling artefacts).
Note: For now, this test is meant to be run locally, either when
testing changes to style code, or when checking how QWidget based
UIs would look on newer version of an operating system. In CI the
test is run, but then skipped in CI as the baseline server is
not configured.
Change-Id: Ie33a9d979d934f0df6883757333ce2c5e2f7ef84
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-11-11 19:29:22 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2021-11-19 11:25:00 +00:00
|
|
|
tst_Widgets() = default;
|
Add baseline test that allows comparing the rendering of widgets
Provide basic boiler plate that sets up the baseline (aka lancelot)
framework specifically for comparing the appearance of widgets, and
implement test functions for QSlider and QPushButton.
Widgets should always look the same if the QPA platform, the OS
version, and certain UI-impacting attributes are identical. Ie.
on any macOS 10.15 machine that runs in "Light" mode, widgets
look the same. On a macOS 11 machine, they might look different.
On an OpenSUSE machine using the fusion style things might look
different from a Ubuntu machine.
The helper function removes DPR differences - images are always
scaled to a DPR of 1.0, which allows us to compare the image\
content and not get distracted by them having different dimensions
(and the fuzzy comparison of images might make the system tolerate
scaling artefacts).
Note: For now, this test is meant to be run locally, either when
testing changes to style code, or when checking how QWidget based
UIs would look on newer version of an operating system. In CI the
test is run, but then skipped in CI as the baseline server is
not configured.
Change-Id: Ie33a9d979d934f0df6883757333ce2c5e2f7ef84
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-11-11 19:29:22 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void tst_QSlider_data();
|
|
|
|
void tst_QSlider();
|
|
|
|
|
|
|
|
void tst_QPushButton_data();
|
|
|
|
void tst_QPushButton();
|
2022-01-11 10:57:49 +00:00
|
|
|
|
2022-02-23 09:03:28 +00:00
|
|
|
void tst_QPushButtonSquare();
|
|
|
|
|
2022-01-11 10:57:49 +00:00
|
|
|
void tst_QProgressBar_data();
|
|
|
|
void tst_QProgressBar();
|
2022-01-07 12:55:50 +00:00
|
|
|
|
|
|
|
void tst_QSpinBox_data();
|
|
|
|
void tst_QSpinBox();
|
2022-01-12 09:59:32 +00:00
|
|
|
|
2022-02-03 12:26:59 +00:00
|
|
|
void tst_QDoubleSpinBox_data();
|
|
|
|
void tst_QDoubleSpinBox();
|
|
|
|
|
|
|
|
void tst_QDateTimeEdit_data();
|
|
|
|
void tst_QDateTimeEdit();
|
|
|
|
|
|
|
|
void tst_QTimeEdit_data();
|
|
|
|
void tst_QTimeEdit();
|
|
|
|
|
|
|
|
void tst_QDateEdit_data();
|
|
|
|
void tst_QDateEdit();
|
|
|
|
|
2022-01-12 09:59:32 +00:00
|
|
|
void tst_QDial_data();
|
|
|
|
void tst_QDial();
|
2022-01-12 13:03:13 +00:00
|
|
|
|
|
|
|
void tst_QCheckbox_data();
|
|
|
|
void tst_QCheckbox();
|
2022-01-12 13:45:28 +00:00
|
|
|
|
|
|
|
void tst_QRadioButton_data();
|
|
|
|
void tst_QRadioButton();
|
2022-01-14 11:56:55 +00:00
|
|
|
|
|
|
|
void tst_QScrollBar_data();
|
|
|
|
void tst_QScrollBar();
|
2022-01-14 12:07:36 +00:00
|
|
|
|
|
|
|
void tst_QTabBar_data();
|
|
|
|
void tst_QTabBar();
|
2022-01-31 13:18:55 +00:00
|
|
|
|
|
|
|
void tst_QTabWidget_data();
|
|
|
|
void tst_QTabWidget();
|
2022-02-03 12:26:59 +00:00
|
|
|
|
2022-02-03 12:34:09 +00:00
|
|
|
void tst_QListView_data();
|
|
|
|
void tst_QListView();
|
|
|
|
|
|
|
|
void tst_QTableView_data();
|
|
|
|
void tst_QTableView();
|
|
|
|
|
|
|
|
void tst_QTreeView_data();
|
|
|
|
void tst_QTreeView();
|
|
|
|
|
|
|
|
void tst_QLineEdit_data();
|
|
|
|
void tst_QLineEdit();
|
|
|
|
|
2022-11-29 15:57:26 +00:00
|
|
|
void tst_QMenu_data();
|
|
|
|
void tst_QMenu();
|
|
|
|
|
|
|
|
void tst_QCombobox_data();
|
|
|
|
void tst_QCombobox();
|
|
|
|
|
|
|
|
void tst_QCommandLinkButton_data();
|
|
|
|
void tst_QCommandLinkButton();
|
|
|
|
|
|
|
|
void tst_QLCDNumber_data();
|
|
|
|
void tst_QLCDNumber();
|
|
|
|
|
2022-02-03 12:26:59 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
// Abstract SpinBox test for QSpinBox, QDoubleSpinBox, QDateTimeEdit, QDateEdit, QTimeEdit
|
|
|
|
void tst_SpinBox_data();
|
|
|
|
void tst_SpinBox(QAbstractSpinBox* spinBox);
|
2022-02-03 12:34:09 +00:00
|
|
|
|
|
|
|
// 78 standard icons from 6.3
|
|
|
|
const int numberStandardIcons = 78;
|
|
|
|
|
|
|
|
// recursive methods for QTreeView population
|
|
|
|
void tst_QTreeView_populateTree(QStandardItem* node, int height, int itemsPerNode, bool hasIcon);
|
|
|
|
QStandardItem* tst_QTreeView_populateItem(int height, int number, bool hasIcon);
|
Add baseline test that allows comparing the rendering of widgets
Provide basic boiler plate that sets up the baseline (aka lancelot)
framework specifically for comparing the appearance of widgets, and
implement test functions for QSlider and QPushButton.
Widgets should always look the same if the QPA platform, the OS
version, and certain UI-impacting attributes are identical. Ie.
on any macOS 10.15 machine that runs in "Light" mode, widgets
look the same. On a macOS 11 machine, they might look different.
On an OpenSUSE machine using the fusion style things might look
different from a Ubuntu machine.
The helper function removes DPR differences - images are always
scaled to a DPR of 1.0, which allows us to compare the image\
content and not get distracted by them having different dimensions
(and the fuzzy comparison of images might make the system tolerate
scaling artefacts).
Note: For now, this test is meant to be run locally, either when
testing changes to style code, or when checking how QWidget based
UIs would look on newer version of an operating system. In CI the
test is run, but then skipped in CI as the baseline server is
not configured.
Change-Id: Ie33a9d979d934f0df6883757333ce2c5e2f7ef84
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-11-11 19:29:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QSlider_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<Qt::Orientation>("orientation");
|
|
|
|
QTest::addColumn<QSlider::TickPosition>("tickPosition");
|
|
|
|
|
|
|
|
QBaselineTest::newRow("horizontal") << Qt::Horizontal << QSlider::NoTicks;
|
|
|
|
QBaselineTest::newRow("horizontal ticks above") << Qt::Horizontal << QSlider::TicksAbove;
|
|
|
|
QBaselineTest::newRow("horizontal ticks below") << Qt::Horizontal << QSlider::TicksBelow;
|
|
|
|
QBaselineTest::newRow("horizontal ticks both") << Qt::Horizontal << QSlider::TicksBothSides;
|
|
|
|
QBaselineTest::newRow("vertical") << Qt::Vertical << QSlider::NoTicks;
|
|
|
|
QBaselineTest::newRow("vertical ticks left") << Qt::Vertical << QSlider::TicksLeft;
|
|
|
|
QBaselineTest::newRow("vertical ticks right") << Qt::Vertical << QSlider::TicksRight;
|
|
|
|
QBaselineTest::newRow("vertical ticks both") << Qt::Vertical << QSlider::TicksBothSides;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QSlider()
|
|
|
|
{
|
|
|
|
struct PublicSlider : QSlider { friend tst_Widgets; };
|
|
|
|
QFETCH(Qt::Orientation, orientation);
|
|
|
|
QFETCH(QSlider::TickPosition, tickPosition);
|
|
|
|
|
|
|
|
QBoxLayout *box = new QBoxLayout(orientation == Qt::Horizontal ? QBoxLayout::TopToBottom
|
|
|
|
: QBoxLayout::LeftToRight);
|
|
|
|
QList<QSlider*> _sliders;
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
QSlider *slider = new QSlider;
|
|
|
|
slider->setOrientation(orientation);
|
|
|
|
slider->setTickPosition(tickPosition);
|
|
|
|
_sliders << slider;
|
|
|
|
box->addWidget(slider);
|
|
|
|
}
|
|
|
|
const auto sliders = _sliders;
|
|
|
|
|
2021-11-19 11:25:00 +00:00
|
|
|
testWindow()->setLayout(box);
|
Add baseline test that allows comparing the rendering of widgets
Provide basic boiler plate that sets up the baseline (aka lancelot)
framework specifically for comparing the appearance of widgets, and
implement test functions for QSlider and QPushButton.
Widgets should always look the same if the QPA platform, the OS
version, and certain UI-impacting attributes are identical. Ie.
on any macOS 10.15 machine that runs in "Light" mode, widgets
look the same. On a macOS 11 machine, they might look different.
On an OpenSUSE machine using the fusion style things might look
different from a Ubuntu machine.
The helper function removes DPR differences - images are always
scaled to a DPR of 1.0, which allows us to compare the image\
content and not get distracted by them having different dimensions
(and the fuzzy comparison of images might make the system tolerate
scaling artefacts).
Note: For now, this test is meant to be run locally, either when
testing changes to style code, or when checking how QWidget based
UIs would look on newer version of an operating system. In CI the
test is run, but then skipped in CI as the baseline server is
not configured.
Change-Id: Ie33a9d979d934f0df6883757333ce2c5e2f7ef84
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-11-11 19:29:22 +00:00
|
|
|
|
|
|
|
// we want to see sliders with different values
|
|
|
|
int value = 0;
|
|
|
|
for (const auto &slider : sliders)
|
|
|
|
slider->setValue(value += 33);
|
|
|
|
|
|
|
|
takeStandardSnapshots();
|
|
|
|
|
|
|
|
PublicSlider *slider = static_cast<PublicSlider*>(sliders.first());
|
|
|
|
QStyleOptionSlider sliderOptions;
|
|
|
|
slider->initStyleOption(&sliderOptions);
|
|
|
|
const QRect handleRect = slider->style()->subControlRect(QStyle::CC_Slider, &sliderOptions,
|
|
|
|
QStyle::SubControl::SC_SliderHandle, slider);
|
|
|
|
QTest::mousePress(slider, Qt::LeftButton, {}, handleRect.center());
|
|
|
|
QBASELINE_CHECK(takeSnapshot(), "pressed");
|
|
|
|
QTest::mouseRelease(slider, Qt::LeftButton, {}, handleRect.center());
|
|
|
|
QBASELINE_CHECK(takeSnapshot(), "released");
|
|
|
|
|
|
|
|
slider->setSliderDown(true);
|
|
|
|
QBASELINE_CHECK(takeSnapshot(), "down");
|
|
|
|
|
|
|
|
sliders.first()->setSliderDown(false);
|
|
|
|
QBASELINE_CHECK(takeSnapshot(), "notdown");
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QPushButton_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("isFlat");
|
|
|
|
|
|
|
|
QBaselineTest::newRow("normal") << false;
|
|
|
|
QBaselineTest::newRow("flat") << true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QPushButton()
|
|
|
|
{
|
|
|
|
QFETCH(bool, isFlat);
|
|
|
|
|
|
|
|
QVBoxLayout *vbox = new QVBoxLayout;
|
|
|
|
QPushButton *testButton = new QPushButton("Ok");
|
|
|
|
testButton->setFlat(isFlat);
|
|
|
|
vbox->addWidget(testButton);
|
|
|
|
|
|
|
|
testWindow()->setLayout(vbox);
|
|
|
|
takeStandardSnapshots();
|
|
|
|
|
|
|
|
testButton->setDown(true);
|
|
|
|
QBASELINE_CHECK(takeSnapshot(), "down");
|
|
|
|
testButton->setDown(false);
|
|
|
|
QBASELINE_CHECK(takeSnapshot(), "up");
|
2021-11-23 13:13:26 +00:00
|
|
|
|
|
|
|
testButton->setDefault(true);
|
|
|
|
QBASELINE_CHECK(takeSnapshot(), "default_up");
|
|
|
|
testButton->setDown(true);
|
|
|
|
QBASELINE_CHECK(takeSnapshot(), "default_down");
|
|
|
|
testButton->setDown(false);
|
Add baseline test that allows comparing the rendering of widgets
Provide basic boiler plate that sets up the baseline (aka lancelot)
framework specifically for comparing the appearance of widgets, and
implement test functions for QSlider and QPushButton.
Widgets should always look the same if the QPA platform, the OS
version, and certain UI-impacting attributes are identical. Ie.
on any macOS 10.15 machine that runs in "Light" mode, widgets
look the same. On a macOS 11 machine, they might look different.
On an OpenSUSE machine using the fusion style things might look
different from a Ubuntu machine.
The helper function removes DPR differences - images are always
scaled to a DPR of 1.0, which allows us to compare the image\
content and not get distracted by them having different dimensions
(and the fuzzy comparison of images might make the system tolerate
scaling artefacts).
Note: For now, this test is meant to be run locally, either when
testing changes to style code, or when checking how QWidget based
UIs would look on newer version of an operating system. In CI the
test is run, but then skipped in CI as the baseline server is
not configured.
Change-Id: Ie33a9d979d934f0df6883757333ce2c5e2f7ef84
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-11-11 19:29:22 +00:00
|
|
|
}
|
|
|
|
|
2022-02-23 09:03:28 +00:00
|
|
|
void tst_Widgets::tst_QPushButtonSquare()
|
|
|
|
{
|
|
|
|
QVBoxLayout layout;
|
|
|
|
|
|
|
|
QPushButton button(testWindow());
|
|
|
|
button.setText(QLatin1String("Square"));
|
|
|
|
const auto sizeHint = button.sizeHint().width();
|
|
|
|
// Depending on the current QStyle, this may result in
|
|
|
|
// a different button look - on macOS it will look as
|
|
|
|
// a toolbutton:
|
|
|
|
button.setFixedSize(sizeHint, sizeHint);
|
|
|
|
|
|
|
|
layout.addWidget(&button);
|
|
|
|
testWindow()->setLayout(&layout);
|
|
|
|
|
|
|
|
takeStandardSnapshots();
|
|
|
|
|
|
|
|
button.setCheckable(true);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "square_unchecked");
|
|
|
|
button.setChecked(true);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "square_checked");
|
|
|
|
}
|
|
|
|
|
2022-01-11 10:57:49 +00:00
|
|
|
void tst_Widgets::tst_QProgressBar_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<Qt::Orientation>("orientation");
|
|
|
|
QTest::addColumn<bool>("invertedAppearance");
|
|
|
|
QTest::addColumn<bool>("textVisible");
|
|
|
|
|
|
|
|
QTest::newRow("vertical_normalAppearance_textVisible") << Qt::Vertical << false << true;
|
|
|
|
QTest::newRow("vertical_invertedAppearance_textVisible") << Qt::Vertical << true << true;
|
|
|
|
QTest::newRow("horizontal_normalAppearance_textVisible") << Qt::Horizontal << false << true;
|
|
|
|
QTest::newRow("horizontal_invertedAppearance_textVisible") << Qt::Horizontal << true << true;
|
|
|
|
QTest::newRow("vertical_normalAppearance_textNotVisible") << Qt::Vertical << false << false;
|
|
|
|
QTest::newRow("vertical_invertedAppearance_textNotVisible") << Qt::Vertical << true << false;
|
|
|
|
QTest::newRow("horizontal_normalAppearance_textNotVisible") << Qt::Horizontal << false << false;
|
|
|
|
QTest::newRow("horizontal_invertedAppearance_textNotVisible") << Qt::Horizontal << true << false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QProgressBar()
|
|
|
|
{
|
|
|
|
QFETCH(Qt::Orientation, orientation);
|
|
|
|
QFETCH(bool, invertedAppearance);
|
|
|
|
QFETCH(bool, textVisible);
|
|
|
|
|
|
|
|
QBoxLayout box((orientation == Qt::Vertical) ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom);
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
QProgressBar *bar = new QProgressBar(testWindow());
|
|
|
|
bar->setOrientation(orientation);
|
|
|
|
bar->setInvertedAppearance(invertedAppearance);
|
|
|
|
bar->setTextVisible(textVisible);
|
|
|
|
bar->setValue(i * 33);
|
|
|
|
box.addWidget(bar);
|
|
|
|
}
|
|
|
|
|
|
|
|
testWindow()->setLayout(&box);
|
|
|
|
takeStandardSnapshots();
|
|
|
|
}
|
Add baseline test that allows comparing the rendering of widgets
Provide basic boiler plate that sets up the baseline (aka lancelot)
framework specifically for comparing the appearance of widgets, and
implement test functions for QSlider and QPushButton.
Widgets should always look the same if the QPA platform, the OS
version, and certain UI-impacting attributes are identical. Ie.
on any macOS 10.15 machine that runs in "Light" mode, widgets
look the same. On a macOS 11 machine, they might look different.
On an OpenSUSE machine using the fusion style things might look
different from a Ubuntu machine.
The helper function removes DPR differences - images are always
scaled to a DPR of 1.0, which allows us to compare the image\
content and not get distracted by them having different dimensions
(and the fuzzy comparison of images might make the system tolerate
scaling artefacts).
Note: For now, this test is meant to be run locally, either when
testing changes to style code, or when checking how QWidget based
UIs would look on newer version of an operating system. In CI the
test is run, but then skipped in CI as the baseline server is
not configured.
Change-Id: Ie33a9d979d934f0df6883757333ce2c5e2f7ef84
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-11-11 19:29:22 +00:00
|
|
|
|
2022-02-03 12:26:59 +00:00
|
|
|
void tst_Widgets::tst_SpinBox_data()
|
2022-01-07 12:55:50 +00:00
|
|
|
{
|
|
|
|
QTest::addColumn<QAbstractSpinBox::ButtonSymbols>("buttons");
|
|
|
|
|
2022-02-03 12:26:59 +00:00
|
|
|
QTest::addRow("NoButtons") << QAbstractSpinBox::NoButtons;
|
|
|
|
QTest::addRow("UpDownArrows") << QAbstractSpinBox::UpDownArrows;
|
|
|
|
QTest::addRow("PlusMinus") << QAbstractSpinBox::PlusMinus;
|
2022-01-07 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
2022-02-03 12:26:59 +00:00
|
|
|
void tst_Widgets::tst_SpinBox(QAbstractSpinBox *spinBox)
|
2022-01-07 12:55:50 +00:00
|
|
|
{
|
2022-02-03 12:26:59 +00:00
|
|
|
QFETCH(const QAbstractSpinBox::ButtonSymbols, buttons);
|
2022-01-07 12:55:50 +00:00
|
|
|
|
|
|
|
spinBox->setButtonSymbols(buttons);
|
|
|
|
spinBox->setMinimumWidth(200);
|
|
|
|
|
2022-02-03 12:26:59 +00:00
|
|
|
QVBoxLayout layout;
|
|
|
|
layout.addWidget(spinBox);
|
|
|
|
testWindow()->setLayout(&layout);
|
2022-01-07 12:55:50 +00:00
|
|
|
|
|
|
|
takeStandardSnapshots();
|
|
|
|
|
|
|
|
spinBox->setAlignment(Qt::AlignHCenter);
|
2022-02-03 12:26:59 +00:00
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "alignCenter");
|
2022-01-07 12:55:50 +00:00
|
|
|
|
|
|
|
spinBox->setAlignment(Qt::AlignRight);
|
2022-02-03 12:26:59 +00:00
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "alignRight");
|
|
|
|
|
|
|
|
// Press / release up button
|
|
|
|
QStyleOptionSpinBox styleOption;
|
|
|
|
styleOption.initFrom(spinBox);
|
|
|
|
QPoint clickTarget = spinBox->style()->subControlRect(QStyle::CC_SpinBox,&styleOption,
|
|
|
|
QStyle::SC_SpinBoxUp,spinBox).center();
|
|
|
|
|
|
|
|
QTest::mousePress(spinBox, Qt::LeftButton, Qt::KeyboardModifiers(), clickTarget);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "upPressed");
|
|
|
|
QTest::mouseRelease(spinBox, Qt::LeftButton, Qt::KeyboardModifiers(), clickTarget);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "upReleased");
|
|
|
|
|
|
|
|
// Press / release down button
|
|
|
|
clickTarget = spinBox->style()->subControlRect(QStyle::CC_SpinBox,&styleOption,
|
|
|
|
QStyle::SC_SpinBoxDown,spinBox).center();
|
|
|
|
|
|
|
|
QTest::mousePress(spinBox, Qt::LeftButton, Qt::KeyboardModifiers(), clickTarget);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "downPressed");
|
|
|
|
QTest::mouseRelease(spinBox, Qt::LeftButton, Qt::KeyboardModifiers(), clickTarget);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "downReleased");
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QSpinBox_data()
|
|
|
|
{
|
|
|
|
tst_SpinBox_data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QSpinBox()
|
|
|
|
{
|
|
|
|
QSpinBox spinBox;
|
|
|
|
tst_SpinBox(&spinBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QDoubleSpinBox_data()
|
|
|
|
{
|
|
|
|
tst_SpinBox_data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QDoubleSpinBox()
|
|
|
|
{
|
|
|
|
QDoubleSpinBox spinBox;
|
|
|
|
tst_SpinBox(&spinBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QDateTimeEdit_data()
|
|
|
|
{
|
|
|
|
tst_SpinBox_data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QDateTimeEdit()
|
|
|
|
{
|
|
|
|
QDateTimeEdit edit;
|
|
|
|
tst_SpinBox(&edit);
|
|
|
|
|
|
|
|
// show calendar popup
|
|
|
|
QStyleOptionSpinBox styleOption;
|
|
|
|
styleOption.initFrom(&edit);
|
|
|
|
const QRect buttonUp = edit.style()->subControlRect(QStyle::CC_SpinBox,&styleOption,
|
|
|
|
QStyle::SC_SpinBoxUp,&edit);
|
|
|
|
|
|
|
|
// no rect for popup button => use bottom center of up-button
|
|
|
|
QPoint clickTarget = buttonUp.center();
|
|
|
|
clickTarget.setY(buttonUp.bottomLeft().y());
|
|
|
|
edit.setCalendarPopup(true);
|
|
|
|
QTest::mouseClick(&edit, Qt::LeftButton, Qt::KeyboardModifiers(), clickTarget);
|
|
|
|
QCalendarWidget* calendar = edit.calendarWidget();
|
|
|
|
QVERIFY(calendar);
|
|
|
|
QVBoxLayout layout;
|
|
|
|
layout.addWidget(calendar);
|
|
|
|
testWindow()->setLayout(&layout);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "showCalendar");
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QTimeEdit_data()
|
|
|
|
{
|
|
|
|
tst_SpinBox_data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QTimeEdit()
|
|
|
|
{
|
|
|
|
QTimeEdit edit;
|
|
|
|
tst_SpinBox(&edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QDateEdit_data()
|
|
|
|
{
|
|
|
|
tst_SpinBox_data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QDateEdit()
|
|
|
|
{
|
|
|
|
QDateEdit edit;
|
|
|
|
tst_SpinBox(&edit);
|
2022-01-07 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
2022-01-12 09:59:32 +00:00
|
|
|
void tst_Widgets::tst_QDial_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("minimum");
|
|
|
|
QTest::addColumn<int>("maximum");
|
|
|
|
QTest::addColumn<bool>("notchesVisible");
|
|
|
|
QTest::addColumn<qreal>("notchTarget");
|
|
|
|
|
|
|
|
QTest::newRow("0..99_notches") << 0 << 99 << true << 3.7;
|
|
|
|
QTest::newRow("0..99_noNotches") << 0 << 99 << false << 3.7;
|
|
|
|
QTest::newRow("1..100_notches") << 1 << 100 << true << 5.7;
|
|
|
|
QTest::newRow("1..100_noNotches") << 1 << 100 << false << 3.7;
|
|
|
|
QTest::newRow("1..5_notches") << 1 << 5 << true << 8.7;
|
|
|
|
QTest::newRow("1..5_noNotches") << 1 << 5 << false << 3.7;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QDial()
|
|
|
|
{
|
|
|
|
QFETCH(int, minimum);
|
|
|
|
QFETCH(int, maximum);
|
|
|
|
QFETCH(bool, notchesVisible);
|
|
|
|
QFETCH(qreal, notchTarget);
|
|
|
|
|
|
|
|
QVERIFY(maximum > minimum);
|
|
|
|
const int steps = maximum - minimum;
|
|
|
|
|
|
|
|
QDial dial(testWindow());
|
|
|
|
dial.setMinimum(minimum);
|
|
|
|
dial.setMaximum(maximum);
|
|
|
|
dial.setNotchTarget(notchTarget);
|
|
|
|
dial.setSliderPosition(minimum + (steps / 2));
|
|
|
|
dial.setNotchesVisible(notchesVisible);
|
|
|
|
|
|
|
|
QBoxLayout box(QBoxLayout::LeftToRight);
|
|
|
|
box.addWidget(&dial);
|
|
|
|
testWindow()->setLayout(&box);
|
|
|
|
takeStandardSnapshots();
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:03:13 +00:00
|
|
|
void tst_Widgets::tst_QCheckbox_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("text");
|
|
|
|
QTest::addColumn<bool>("hasIcon");
|
|
|
|
QTest::addColumn<bool>("isTriState");
|
|
|
|
|
|
|
|
QTest::newRow("SimpleCheckbox") << "" << false << false;
|
|
|
|
QTest::newRow("SimpleCheckboxWithIcon") << "" << true << false;
|
|
|
|
QTest::newRow("SimpleCheckboxWithText") << "checkBox" << false << false;
|
|
|
|
QTest::newRow("SimpleCheckboxWithTextAndIcon") << "checkBox with icon" << true << false;
|
|
|
|
QTest::newRow("SimpleTristate") << "" << false << true;
|
|
|
|
QTest::newRow("SimpleTristateWithText") << "tristateBox" << false << true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QCheckbox()
|
|
|
|
{
|
|
|
|
QFETCH(QString, text);
|
|
|
|
QFETCH(bool, hasIcon);
|
|
|
|
QFETCH(bool, isTriState);
|
|
|
|
|
2022-03-10 12:01:32 +00:00
|
|
|
class CheckBox : public QCheckBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using QCheckBox::initStyleOption;
|
|
|
|
};
|
|
|
|
|
2022-01-12 13:03:13 +00:00
|
|
|
QBoxLayout layout(QBoxLayout::TopToBottom);
|
2022-03-10 12:01:32 +00:00
|
|
|
CheckBox box;
|
2022-01-12 13:03:13 +00:00
|
|
|
box.setTristate(isTriState);
|
|
|
|
|
|
|
|
if (!text.isEmpty())
|
|
|
|
box.setText(text);
|
|
|
|
|
|
|
|
if (hasIcon)
|
|
|
|
box.setIcon(QApplication::style()->standardIcon(QStyle::SP_ComputerIcon));
|
|
|
|
|
|
|
|
layout.addWidget(&box);
|
|
|
|
testWindow()->setLayout(&layout);
|
|
|
|
takeStandardSnapshots();
|
|
|
|
|
2022-03-10 12:01:32 +00:00
|
|
|
do {
|
2022-01-12 13:03:13 +00:00
|
|
|
const Qt::CheckState checkState = box.checkState();
|
2022-03-10 12:01:32 +00:00
|
|
|
QStyleOptionButton styleOption;
|
|
|
|
box.initStyleOption(&styleOption);
|
|
|
|
const QPoint clickTarget = box.style()->subElementRect(QStyle::SE_CheckBoxClickRect, &styleOption, &box).center();
|
2022-01-12 13:03:13 +00:00
|
|
|
|
|
|
|
const std::array titles = {"unChecked", "partiallyChecked", "checked"};
|
|
|
|
const QString snapShotTitle = titles[checkState];
|
|
|
|
|
|
|
|
QTest::mousePress(&box,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QVERIFY(box.isDown());
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), (snapShotTitle + "_pressed").toLocal8Bit().constData());
|
|
|
|
|
|
|
|
QTest::mouseRelease(&box,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QVERIFY(!box.isDown());
|
|
|
|
QVERIFY(checkState != box.checkState());
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), (snapShotTitle + "_released").toLocal8Bit().constData());
|
|
|
|
|
|
|
|
} while (box.checkState() != Qt::Unchecked);
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:45:28 +00:00
|
|
|
void tst_Widgets::tst_QRadioButton_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("text");
|
|
|
|
QTest::addColumn<bool>("hasIcon");
|
|
|
|
|
|
|
|
QTest::newRow("SimpleRadioButton") << "" << false;
|
|
|
|
QTest::newRow("RadioButtonWithText") << "RadioButton" << false;
|
|
|
|
QTest::newRow("SimpleRadioButtonWithIcon") << "" << true;
|
|
|
|
QTest::newRow("RadioButtonWithTextAndIcon") << "RadioButton" << true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QRadioButton()
|
|
|
|
{
|
|
|
|
QFETCH(QString,text);
|
|
|
|
QFETCH(bool,hasIcon);
|
|
|
|
|
2022-03-10 12:01:32 +00:00
|
|
|
class RadioButton : public QRadioButton
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using QRadioButton::QRadioButton;
|
|
|
|
using QRadioButton::initStyleOption;
|
|
|
|
};
|
|
|
|
|
|
|
|
RadioButton button1(testWindow());
|
2022-01-12 13:45:28 +00:00
|
|
|
|
|
|
|
if (!text.isEmpty())
|
|
|
|
button1.setText(text);
|
|
|
|
|
|
|
|
if (hasIcon)
|
|
|
|
button1.setIcon(QApplication::style()->standardIcon(QStyle::SP_ComputerIcon));
|
|
|
|
|
|
|
|
button1.setChecked(false);
|
|
|
|
|
2022-03-10 12:01:32 +00:00
|
|
|
RadioButton button2(testWindow());
|
2022-01-12 13:45:28 +00:00
|
|
|
|
|
|
|
if (!text.isEmpty())
|
|
|
|
button2.setText(text);
|
|
|
|
|
|
|
|
if (hasIcon)
|
|
|
|
button2.setIcon(QApplication::style()->standardIcon(QStyle::SP_ComputerIcon));
|
|
|
|
|
|
|
|
// button2 has to start checked for the following tests to work
|
|
|
|
button2.setChecked(true);
|
|
|
|
|
|
|
|
QBoxLayout box(QBoxLayout::TopToBottom);
|
|
|
|
box.addWidget(&button1);
|
|
|
|
box.addWidget(&button2);
|
2022-01-21 15:26:06 +00:00
|
|
|
testWindow()->setLayout(&box);
|
2022-01-12 13:45:28 +00:00
|
|
|
takeStandardSnapshots();
|
|
|
|
|
2022-03-10 12:01:32 +00:00
|
|
|
QStyleOptionButton styleOption;
|
|
|
|
button1.initStyleOption(&styleOption);
|
|
|
|
const QPoint clickTarget = button1.style()->subElementRect(QStyle::SE_RadioButtonClickRect, &styleOption, &button1).center();
|
|
|
|
|
2022-01-12 13:45:28 +00:00
|
|
|
QTest::mousePress(&button1,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QVERIFY(button1.isDown());
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressUnchecked");
|
|
|
|
QTest::mouseRelease(&button1,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QVERIFY(!button1.isDown());
|
|
|
|
|
|
|
|
// button1 has grabbed the check from button2
|
|
|
|
QVERIFY(button1.isChecked());
|
|
|
|
QVERIFY(!button2.isChecked());
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "releaseUnchecked");
|
|
|
|
|
|
|
|
// press and release checked button1 again
|
|
|
|
QTest::mousePress(&button1,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QVERIFY(button1.isDown());
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressChecked");
|
|
|
|
QTest::mouseRelease(&button1,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QVERIFY(!button1.isDown());
|
|
|
|
|
|
|
|
// checkstate not supposed to change
|
|
|
|
QVERIFY(button1.isChecked());
|
|
|
|
QVERIFY(!button2.isChecked());
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "releaseChecked");
|
|
|
|
}
|
|
|
|
|
2022-01-14 11:56:55 +00:00
|
|
|
void tst_Widgets::tst_QScrollBar_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<Qt::Orientation>("orientation");
|
|
|
|
|
|
|
|
QTest::newRow("Horizontal") << Qt::Horizontal;
|
|
|
|
QTest::newRow("Vertical") << Qt::Vertical;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QScrollBar()
|
|
|
|
{
|
|
|
|
QFETCH(Qt::Orientation, orientation);
|
|
|
|
|
|
|
|
QBoxLayout box((orientation == Qt::Vertical) ? QBoxLayout::LeftToRight
|
|
|
|
: QBoxLayout::TopToBottom);
|
|
|
|
QList<QScrollBar*> bars;
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
|
|
|
|
QScrollBar *bar = new QScrollBar(testWindow());
|
|
|
|
(orientation == Qt::Vertical) ? bar->setFixedHeight(100)
|
|
|
|
: bar->setFixedWidth(100);
|
|
|
|
|
|
|
|
bar->setOrientation(orientation);
|
|
|
|
bar->setValue(i * 33);
|
|
|
|
box.addWidget(bar);
|
|
|
|
bars.append(bar);
|
|
|
|
}
|
|
|
|
|
|
|
|
testWindow()->setLayout(&box);
|
|
|
|
takeStandardSnapshots();
|
|
|
|
|
|
|
|
// press left/up of first bar
|
|
|
|
QScrollBar *bar = bars.at(0);
|
|
|
|
QStyleOptionSlider styleOption = qt_qscrollbarStyleOption(bar);
|
|
|
|
QPoint clickTarget = bar->style()->subControlRect(QStyle::CC_ScrollBar, &styleOption,
|
|
|
|
QStyle::SC_ScrollBarSubLine, bar).center();
|
|
|
|
QTest::mousePress(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressLeftUp");
|
|
|
|
QTest::mouseRelease(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
|
|
|
|
// press slider of first bar
|
|
|
|
styleOption = qt_qscrollbarStyleOption(bar);
|
|
|
|
clickTarget = bar->style()->subControlRect(QStyle::CC_ScrollBar, &styleOption,
|
|
|
|
QStyle::SC_ScrollBarSlider, bar).center();
|
|
|
|
QTest::mousePress(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QVERIFY(bar->isSliderDown());
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressSlider");
|
|
|
|
QTest::mouseRelease(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
|
|
|
|
// Press AddPage up on first bar
|
|
|
|
clickTarget = bar->style()->subControlRect(QStyle::CC_ScrollBar, &styleOption,
|
|
|
|
QStyle::SC_ScrollBarAddPage, bar).center();
|
|
|
|
QTest::mousePress(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressAddPage");
|
|
|
|
QTest::mouseRelease(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
|
|
|
|
// press SubPage of last bar
|
|
|
|
bar = bars.at(3);
|
|
|
|
styleOption = qt_qscrollbarStyleOption(bar);
|
|
|
|
clickTarget = bar->style()->subControlRect(QStyle::CC_ScrollBar, &styleOption,
|
|
|
|
QStyle::SC_ScrollBarAddLine, bar).center();
|
|
|
|
QTest::mousePress(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressRightDown");
|
|
|
|
QTest::mouseRelease(bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
}
|
|
|
|
|
2022-01-14 12:07:36 +00:00
|
|
|
void tst_Widgets::tst_QTabBar_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QTabBar::Shape>("shape");
|
|
|
|
QTest::addColumn<int>("numberTabs");
|
|
|
|
QTest::addColumn<int>("fixedWidth");
|
2022-01-31 10:02:52 +00:00
|
|
|
QTest::addColumn<bool>("isClosable");
|
2022-01-14 12:07:36 +00:00
|
|
|
|
|
|
|
// fixedWidth <0 will be interpreted as variable width
|
2022-01-31 10:02:52 +00:00
|
|
|
QTest::newRow("RoundedNorth_3_variableWidth") << QTabBar::RoundedNorth << 3 << -1 << false;
|
|
|
|
QTest::newRow("RoundedEast_3_variableWidth") << QTabBar::RoundedEast << 3 << -1 << false;
|
|
|
|
QTest::newRow("RoundedWest_3_variableWidth") << QTabBar::RoundedWest << 3 << -1 << false;
|
|
|
|
QTest::newRow("RoundedSouth_3_variableWidth") << QTabBar::RoundedSouth << 3 << -1 << false;
|
|
|
|
QTest::newRow("RoundedNorth_20_fixedWidth") << QTabBar::RoundedNorth << 20 << 250 << true;
|
2022-01-14 12:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QTabBar()
|
|
|
|
{
|
|
|
|
QFETCH(QTabBar::Shape, shape);
|
|
|
|
QFETCH(int, numberTabs);
|
|
|
|
QFETCH(int, fixedWidth);
|
2022-01-31 10:02:52 +00:00
|
|
|
QFETCH(bool, isClosable);
|
2022-01-14 12:07:36 +00:00
|
|
|
|
|
|
|
QTabBar bar (testWindow());
|
|
|
|
bar.setShape(shape);
|
2022-01-31 10:02:52 +00:00
|
|
|
bar.setTabsClosable(isClosable);
|
2022-01-14 12:07:36 +00:00
|
|
|
if (fixedWidth > 0)
|
|
|
|
bar.setFixedWidth(fixedWidth);
|
|
|
|
|
|
|
|
for (int i = 0; i < numberTabs; ++i) {
|
|
|
|
bar.insertTab(i,"Tab_" + QString::number(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
QBoxLayout box(QBoxLayout::LeftToRight, testWindow());
|
|
|
|
box.addWidget(&bar);
|
|
|
|
testWindow()->setLayout(&box);
|
|
|
|
|
|
|
|
takeStandardSnapshots();
|
|
|
|
|
|
|
|
// press/release first tab
|
|
|
|
bar.setCurrentIndex(0);
|
|
|
|
QPoint clickTarget = bar.tabRect(0).center();
|
|
|
|
QTest::mousePress(&bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressFirstTab");
|
|
|
|
QTest::mouseRelease(&bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QVERIFY(bar.currentIndex() == 0);
|
|
|
|
|
|
|
|
// press/release second tab if it exists
|
|
|
|
if (bar.count() > 1) {
|
|
|
|
clickTarget = bar.tabRect(1).center();
|
|
|
|
QTest::mousePress(&bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressSecondTab");
|
|
|
|
QTest::mouseRelease(&bar,Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QVERIFY(bar.currentIndex() == 1);
|
|
|
|
}
|
2022-01-31 10:02:52 +00:00
|
|
|
|
|
|
|
// test press/release on close button
|
|
|
|
if (isClosable) {
|
|
|
|
|
|
|
|
// CloseButton is either left or right
|
|
|
|
QWidget *leftButton = bar.tabButton(bar.currentIndex(),QTabBar::ButtonPosition::LeftSide);
|
|
|
|
QWidget *rightButton = bar.tabButton(bar.currentIndex(),QTabBar::ButtonPosition::RightSide);
|
|
|
|
QAbstractButton *button = qobject_cast<QAbstractButton*>(leftButton);
|
|
|
|
if (button == nullptr)
|
|
|
|
button = qobject_cast<QAbstractButton*>(rightButton);
|
|
|
|
|
|
|
|
if (button != nullptr) {
|
|
|
|
clickTarget = button->rect().center();
|
|
|
|
QTest::mousePress(button,Qt::MouseButton::LeftButton,
|
|
|
|
Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressCloseFirstTab");
|
|
|
|
QTest::mouseRelease(button,Qt::MouseButton::LeftButton,
|
|
|
|
Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "releaseCloseFirstTab");
|
|
|
|
}
|
|
|
|
}
|
2022-01-14 12:07:36 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:18:55 +00:00
|
|
|
void tst_Widgets::tst_QTabWidget_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QTabWidget::TabPosition>("tabPosition");
|
|
|
|
QTest::addColumn<int>("numberTabs");
|
|
|
|
QTest::addColumn<QString>("tabText");
|
|
|
|
QTest::addColumn<int>("fixedWidth");
|
|
|
|
QTest::addColumn<bool>("isClosable");
|
|
|
|
QTest::addColumn<bool>("isDocumentMode");
|
|
|
|
|
|
|
|
// fixedWidth <0 will be interpreted as variable width
|
|
|
|
QTest::newRow("North_3_variableWidthDocMode") << QTabWidget::North << 3 << "This is a tab text" << -1 << false << true;
|
|
|
|
QTest::newRow("East_3_variableWidth") << QTabWidget::East << 3 << "This is a tab text" << -1 << false << false;
|
|
|
|
QTest::newRow("West_3_variableWidthDocMode") << QTabWidget::West << 3 << "This is a tab text" << -1 << false << true;
|
|
|
|
QTest::newRow("South_3_variableWidth") << QTabWidget::South << 3 << "This is a tab text" << -1 << true << false;
|
|
|
|
QTest::newRow("North_20_fixedWidthDocMode") << QTabWidget::North << 20
|
|
|
|
<< "This is a very long text to actually force wrapping!" << 100 << true << true;
|
|
|
|
QTest::newRow("South_20_variableWidth") << QTabWidget::South << 20
|
|
|
|
<< "This is a very long text to actually force wrapping!" << -1 << false << false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QTabWidget()
|
|
|
|
{
|
|
|
|
QFETCH(QTabWidget::TabPosition, tabPosition);
|
|
|
|
QFETCH(int, numberTabs);
|
|
|
|
QFETCH(QString, tabText);
|
|
|
|
QFETCH(int, fixedWidth);
|
|
|
|
QFETCH(bool, isClosable);
|
|
|
|
QFETCH(bool, isDocumentMode);
|
|
|
|
|
|
|
|
QTabWidget tabWidget (testWindow());
|
|
|
|
if (fixedWidth > 0)
|
|
|
|
tabWidget.setFixedWidth(fixedWidth);
|
|
|
|
tabWidget.setTabPosition(tabPosition);
|
|
|
|
tabWidget.setTabsClosable(isClosable);
|
|
|
|
tabWidget.setDocumentMode(isDocumentMode);
|
|
|
|
|
|
|
|
for (int i = 0; i < numberTabs; ++i) {
|
|
|
|
QLabel *tabLabel = new QLabel("Tab number " + QString::number(i) + "\n" + tabText, &tabWidget);
|
|
|
|
QBoxLayout *tabBox = new QBoxLayout(QBoxLayout::TopToBottom,&tabWidget);
|
|
|
|
tabBox->addWidget(tabLabel);
|
|
|
|
tabWidget.insertTab(i,tabLabel,"Tab_" + QString::number(i));
|
|
|
|
tabWidget.setCurrentIndex(i);
|
|
|
|
tabWidget.currentWidget()->setLayout(tabBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
tabWidget.setCurrentIndex(0);
|
|
|
|
QBoxLayout box(QBoxLayout::LeftToRight, testWindow());
|
|
|
|
box.addWidget(&tabWidget);
|
|
|
|
testWindow()->setLayout(&box);
|
|
|
|
takeStandardSnapshots();
|
|
|
|
|
|
|
|
// press/release on second tab if it exists
|
|
|
|
if (numberTabs > 1) {
|
|
|
|
const QPoint clickTarget = tabWidget.tabBar()->tabRect(1).center();
|
|
|
|
QTest::mousePress(tabWidget.tabBar(),Qt::MouseButton::LeftButton,Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressSecondTab");
|
|
|
|
QTest::mouseRelease(tabWidget.tabBar(),Qt::MouseButton::LeftButton, Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QVERIFY(tabWidget.currentIndex() == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// test press/release on close button
|
|
|
|
if (isClosable) {
|
|
|
|
|
|
|
|
// CloseButton is either left or right
|
|
|
|
QWidget *leftButton = tabWidget.tabBar()->tabButton(tabWidget.currentIndex(),QTabBar::ButtonPosition::LeftSide);
|
|
|
|
QWidget *rightButton = tabWidget.tabBar()->tabButton(tabWidget.currentIndex(),QTabBar::ButtonPosition::RightSide);
|
|
|
|
QAbstractButton *button = qobject_cast<QAbstractButton*>(leftButton);
|
|
|
|
if (button == nullptr)
|
|
|
|
button = qobject_cast<QAbstractButton*>(rightButton);
|
|
|
|
|
|
|
|
if (button != nullptr) {
|
|
|
|
const QPoint clickTarget = button->rect().center();
|
|
|
|
QTest::mousePress(button,Qt::MouseButton::LeftButton,
|
|
|
|
Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "pressCloseTab");
|
|
|
|
QTest::mouseRelease(button,Qt::MouseButton::LeftButton,
|
|
|
|
Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "releaseCloseTab");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-03 12:34:09 +00:00
|
|
|
void tst_Widgets::tst_QListView_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QListView::ViewMode>("viewMode");
|
|
|
|
QTest::addColumn<bool>("isWrapping");
|
|
|
|
QTest::addColumn<bool>("hasWordWrap");
|
|
|
|
QTest::addColumn<int>("numberItems");
|
|
|
|
QTest::addColumn<QSize>("fixedSize");
|
|
|
|
|
|
|
|
|
|
|
|
// QSize() will be interpreted as variable size
|
|
|
|
QTest::newRow("ListModeWrappingNoWordWrapFixed_10") <<
|
|
|
|
QListView::ListMode << true << false << 10 << QSize(100, 500);
|
|
|
|
QTest::newRow("ListModeNoWrappingNoWordWrapVariable_20") <<
|
|
|
|
QListView::ListMode << false << true << 20 << QSize();
|
|
|
|
QTest::newRow("ListModeNoWrappingWordWrapVariable_30") <<
|
|
|
|
QListView::ListMode << false << true << 30 << QSize();
|
|
|
|
QTest::newRow("IconModeNoWrappingNoWordWrapFixed_10") <<
|
|
|
|
QListView::IconMode << false << false << 10 << QSize(100, 500);
|
|
|
|
QTest::newRow("IconModeWrappingNoWordWrapVariable_20") <<
|
|
|
|
QListView::IconMode << true << false << 20 << QSize();
|
|
|
|
QTest::newRow("IconModeWrappingWordWrapVariable_30") <<
|
|
|
|
QListView::IconMode << true << true << 30 << QSize(100, 500);
|
|
|
|
}
|
|
|
|
void tst_Widgets::tst_QListView()
|
|
|
|
{
|
|
|
|
QFETCH(QListView::ViewMode,viewMode);
|
|
|
|
QFETCH(bool,isWrapping);
|
|
|
|
QFETCH(bool,hasWordWrap);
|
|
|
|
QFETCH(int,numberItems);
|
|
|
|
QFETCH(QSize,fixedSize);
|
|
|
|
|
|
|
|
QListView listView;
|
|
|
|
listView.setViewMode(viewMode);
|
|
|
|
listView.setWrapping(isWrapping);
|
|
|
|
listView.setWordWrap(hasWordWrap);
|
|
|
|
if (fixedSize.isValid())
|
|
|
|
listView.setFixedSize(fixedSize);
|
|
|
|
|
|
|
|
QStandardItemModel model(0,1,testWindow());
|
|
|
|
|
|
|
|
// Populate model, add standard icons if required
|
|
|
|
const QString itemText = hasWordWrap ? "This is a long text for word wrapping Item_"
|
|
|
|
: "ListItem_";
|
|
|
|
int icon = 0;
|
|
|
|
for (int i = 0; i < numberItems; ++i) {
|
|
|
|
QStandardItem *item;
|
|
|
|
if (viewMode == QListView::IconMode) {
|
|
|
|
item = new QStandardItem(QApplication::style()->standardIcon
|
|
|
|
(static_cast<QStyle::StandardPixmap>(icon)), itemText + QString::number(i));
|
|
|
|
icon = (icon + 1) % numberStandardIcons;
|
|
|
|
} else {
|
|
|
|
item = new QStandardItem(itemText + QString::number(i));
|
|
|
|
}
|
|
|
|
model.appendRow(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
listView.setModel(&model);
|
|
|
|
QBoxLayout layout(QBoxLayout::LeftToRight, testWindow());
|
|
|
|
layout.addWidget(&listView);
|
|
|
|
testWindow()->setLayout(&layout);
|
|
|
|
takeStandardSnapshots();
|
|
|
|
|
|
|
|
// click on first item
|
|
|
|
QPoint clickTarget = listView.visualRect(model.index(0,0)).center();
|
|
|
|
QTest::mouseClick(listView.viewport(),Qt::MouseButton::LeftButton,
|
|
|
|
Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "clickFirstItem");
|
|
|
|
|
|
|
|
// click on scond item
|
|
|
|
if (numberItems > 1) {
|
|
|
|
clickTarget = listView.visualRect(model.index(1,0)).center();
|
|
|
|
QTest::mouseClick(listView.viewport(),Qt::MouseButton::LeftButton,
|
|
|
|
Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "clickSecondItem");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide first row
|
|
|
|
listView.setRowHidden(0,true);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "hideFirstItem");
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QTableView_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("hasHeader");
|
|
|
|
QTest::addColumn<bool>("hasRowNumbers");
|
|
|
|
QTest::addColumn<bool>("hasWordWrap");
|
|
|
|
QTest::addColumn<int>("numberRows");
|
|
|
|
QTest::addColumn<int>("numberColumns");
|
|
|
|
QTest::addColumn<int>("iconColumn");
|
|
|
|
QTest::addColumn<QSize>("fixedSize");
|
|
|
|
|
|
|
|
// QSize() => variable size; iconColumn -1 => no icon
|
|
|
|
QTest::newRow("HeaderRowNumWordWrapFixed_10") << true << true << true << 10 << 3 << -1 << QSize(500, 100);
|
|
|
|
QTest::newRow("HeaderVariable_20") << true << false << false << 20 << 4 << 1 << QSize();
|
|
|
|
QTest::newRow("HeaderFixed_20") << true << false << false << 20 << 4 << 1 << QSize(500, 700);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QTableView()
|
|
|
|
{
|
|
|
|
QFETCH(bool, hasHeader);
|
|
|
|
QFETCH(bool, hasRowNumbers);
|
|
|
|
QFETCH(bool, hasWordWrap);
|
|
|
|
QFETCH(int, numberRows);
|
|
|
|
QFETCH(int, numberColumns);
|
|
|
|
QFETCH(int, iconColumn);
|
|
|
|
QFETCH(QSize, fixedSize);
|
|
|
|
|
|
|
|
// Populate model
|
|
|
|
int icon = 0;
|
|
|
|
QStandardItemModel model(numberRows, numberColumns, testWindow());
|
|
|
|
|
|
|
|
if (hasHeader) {
|
|
|
|
for (int i = 0; i < numberColumns; ++i)
|
|
|
|
model.setHorizontalHeaderItem(i, new QStandardItem("Header_" + QString::number(i)));
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString wrap = hasWordWrap ? "\n long text to wrap words" : "" ;
|
|
|
|
for (int row = 0; row < numberRows; ++row) {
|
|
|
|
for (int column = 0; column < numberColumns; ++column) {
|
|
|
|
QStandardItem *item;
|
|
|
|
const QString itemText = QString::number(row) + "/" + QString::number(column) + wrap;
|
|
|
|
if (iconColumn == column) {
|
|
|
|
item = new QStandardItem(QApplication::style()->standardIcon
|
|
|
|
(static_cast<QStyle::StandardPixmap>(icon)),itemText);
|
|
|
|
|
|
|
|
icon = (icon + 1) % numberStandardIcons;
|
|
|
|
} else {
|
|
|
|
item = new QStandardItem(itemText);
|
|
|
|
}
|
|
|
|
model.setItem(row,column,item);
|
|
|
|
}
|
|
|
|
if (hasRowNumbers)
|
|
|
|
model.setVerticalHeaderItem(row, new QStandardItem(QString::number(row)));
|
|
|
|
}
|
|
|
|
|
|
|
|
QTableView tableView(testWindow());
|
|
|
|
tableView.setWordWrap(hasWordWrap);
|
|
|
|
if (fixedSize.isValid())
|
|
|
|
tableView.setFixedSize(fixedSize);
|
|
|
|
|
|
|
|
QBoxLayout layout(QBoxLayout::LeftToRight, testWindow());
|
|
|
|
tableView.setModel(&model);
|
|
|
|
layout.addWidget(&tableView);
|
|
|
|
|
|
|
|
takeStandardSnapshots();
|
|
|
|
|
|
|
|
// Hide grid
|
|
|
|
tableView.setShowGrid(false);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "hideGrid");
|
|
|
|
tableView.setShowGrid(true);
|
|
|
|
|
|
|
|
// click item 0,0
|
|
|
|
QPoint clickTarget = tableView.visualRect(model.index(0,0)).center();
|
|
|
|
QTest::mouseClick(tableView.viewport(),Qt::MouseButton::LeftButton,
|
|
|
|
Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "clickFirstItem");
|
|
|
|
|
|
|
|
// click item 0,1 if it exists
|
|
|
|
if (numberColumns > 1) {
|
|
|
|
clickTarget = tableView.visualRect(model.index(0,1)).center();
|
|
|
|
QTest::mouseClick(tableView.viewport(),Qt::MouseButton::LeftButton,
|
|
|
|
Qt::KeyboardModifiers(), clickTarget,0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "clickSecondItem");
|
|
|
|
}
|
|
|
|
|
|
|
|
tableView.clearSelection();
|
|
|
|
|
|
|
|
// Hide first row and column
|
|
|
|
tableView.setRowHidden(0, true);
|
|
|
|
tableView.setColumnHidden(0, true);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "hideFirstRowColumn");
|
|
|
|
tableView.setRowHidden(0, false);
|
|
|
|
tableView.setColumnHidden(0, false);
|
|
|
|
|
|
|
|
// Select first row
|
|
|
|
tableView.selectRow(0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "selectFirstRow");
|
|
|
|
|
|
|
|
// Select first column
|
|
|
|
tableView.selectColumn(0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "selectFirstColumn");
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QTreeView_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("showHeader");
|
|
|
|
QTest::addColumn<bool>("hasIcons");
|
2022-10-23 09:31:28 +00:00
|
|
|
QTest::addColumn<bool>("alternatingRowColors");
|
2022-02-03 12:34:09 +00:00
|
|
|
QTest::addColumn<QSize>("fixedSize");
|
|
|
|
QTest::addColumn<int>("treeHeight");
|
|
|
|
QTest::addColumn<int>("itemsPerNode");
|
|
|
|
|
|
|
|
// QSize() => variable size
|
2022-10-23 09:31:28 +00:00
|
|
|
QTest::newRow("HeaderIcons_4_3") << true << true << false << QSize() << 3 << 2;
|
|
|
|
QTest::newRow("NoHeaderNoIcons_4_4") << false << false << false << QSize(100, 350) << 3 << 2;
|
|
|
|
QTest::newRow("AlternatingRows") << true << true << true << QSize() << 3 << 2;
|
2022-02-03 12:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QTreeView()
|
|
|
|
{
|
|
|
|
QFETCH(bool, showHeader);
|
|
|
|
QFETCH(bool, hasIcons);
|
2022-10-23 09:31:28 +00:00
|
|
|
QFETCH(bool, alternatingRowColors);
|
2022-02-03 12:34:09 +00:00
|
|
|
QFETCH(QSize, fixedSize);
|
|
|
|
QFETCH(int, treeHeight);
|
|
|
|
QFETCH(int, itemsPerNode);
|
|
|
|
QVERIFY(treeHeight > 0 && itemsPerNode > 0);
|
|
|
|
|
|
|
|
QTreeView treeView(testWindow());
|
|
|
|
fixedSize.isValid() ? treeView.setFixedSize(fixedSize)
|
|
|
|
: treeView.setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
|
|
|
|
|
|
|
|
QStandardItemModel model(&treeView);
|
|
|
|
showHeader ? model.setHorizontalHeaderItem(0, new QStandardItem("TreeHeader"))
|
|
|
|
: treeView.setHeaderHidden(true);
|
|
|
|
|
2022-10-23 09:31:28 +00:00
|
|
|
treeView.setAlternatingRowColors(alternatingRowColors);
|
|
|
|
|
2022-02-03 12:34:09 +00:00
|
|
|
// Populate tree model
|
|
|
|
for (int i = 0; i < itemsPerNode; ++i) {
|
|
|
|
QStandardItem* root = tst_QTreeView_populateItem(treeHeight, i, hasIcons);
|
|
|
|
tst_QTreeView_populateTree(root,treeHeight - 1,itemsPerNode, hasIcons);
|
|
|
|
model.appendRow(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
treeView.setModel(&model);
|
|
|
|
QBoxLayout layout(QBoxLayout::LeftToRight, testWindow());
|
|
|
|
layout.addWidget(&treeView);
|
|
|
|
testWindow()->setLayout(&layout);
|
|
|
|
|
|
|
|
treeView.expandAll();
|
|
|
|
treeView.resizeColumnToContents(0);
|
|
|
|
takeStandardSnapshots();
|
|
|
|
|
|
|
|
// Partly expand if possible
|
|
|
|
if (treeHeight > 1) {
|
|
|
|
treeView.expandToDepth(1);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "partlyExpanded");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Click on first node
|
|
|
|
QPoint clickTarget = treeView.visualRect(model.index(0, 0)).center();
|
|
|
|
QTest::mouseClick(treeView.viewport(),Qt::MouseButton::LeftButton,
|
|
|
|
Qt::KeyboardModifiers(), clickTarget, 0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "clickFirstNode");
|
|
|
|
|
|
|
|
// Hide first row
|
|
|
|
treeView.setRowHidden(0, model.index(0, 0), true);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "hideFirstRow");
|
|
|
|
treeView.setRowHidden(0, model.index(0, 0), false);
|
|
|
|
|
|
|
|
// Click on second row if it exists
|
|
|
|
if (itemsPerNode > 1) {
|
|
|
|
clickTarget = treeView.visualRect(model.index(1, 0)).center();
|
|
|
|
QTest::mouseClick(treeView.viewport(), Qt::MouseButton::LeftButton,
|
|
|
|
Qt::KeyboardModifiers(), clickTarget, 0);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "clickSecondNode");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QTreeView_populateTree(QStandardItem* node, int height, int itemsPerNode, bool hasIcon)
|
|
|
|
{
|
|
|
|
QList<QStandardItem*> items;
|
|
|
|
for (int i = 0; i < itemsPerNode; ++i) {
|
|
|
|
if (height == 0) {
|
|
|
|
items.append(tst_QTreeView_populateItem(height, i, hasIcon));
|
|
|
|
} else {
|
|
|
|
QStandardItem* item = tst_QTreeView_populateItem(height, i, hasIcon);
|
|
|
|
tst_QTreeView_populateTree(item, height - 1, itemsPerNode, hasIcon);
|
|
|
|
items.append(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return node->appendColumn(items);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStandardItem* tst_Widgets::tst_QTreeView_populateItem(int height, int number, bool hasIcon)
|
|
|
|
{
|
|
|
|
static int icon = 0;
|
|
|
|
static int itemCount = 0;
|
|
|
|
|
|
|
|
QStandardItem* item;
|
|
|
|
const QString itemText = QString("%1/%2/%3").arg(height).arg(number).arg(itemCount);
|
|
|
|
++itemCount;
|
|
|
|
|
|
|
|
if (hasIcon) {
|
|
|
|
item = new QStandardItem(QApplication::style()->standardIcon
|
|
|
|
(static_cast<QStyle::StandardPixmap>(icon)), itemText);
|
|
|
|
|
|
|
|
icon = (icon + 1) % numberStandardIcons;
|
|
|
|
} else {
|
|
|
|
item = new QStandardItem(itemText);
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QLineEdit_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("hasFrame");
|
|
|
|
QTest::addColumn<QLineEdit::EchoMode>("echoMode");
|
|
|
|
QTest::addColumn<QString>("placeHolderText");
|
|
|
|
QTest::addColumn<QString>("text");
|
|
|
|
|
|
|
|
QTest::newRow("framePassword") << true << QLineEdit::Password << "password" << "secret";
|
|
|
|
QTest::newRow("noFrameCleartext") << false << QLineEdit::Normal << "text" << "this is a text";
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QLineEdit()
|
|
|
|
{
|
|
|
|
QFETCH(const bool, hasFrame);
|
|
|
|
QFETCH(const QLineEdit::EchoMode, echoMode);
|
|
|
|
QFETCH(const QString, placeHolderText);
|
|
|
|
QFETCH(const QString, text);
|
|
|
|
|
|
|
|
QLineEdit lineEdit(testWindow());
|
|
|
|
lineEdit.setFrame(hasFrame);
|
|
|
|
lineEdit.setEchoMode(echoMode);
|
|
|
|
lineEdit.setPlaceholderText(placeHolderText);
|
|
|
|
|
|
|
|
QHBoxLayout layout;
|
|
|
|
layout.addWidget(&lineEdit);
|
|
|
|
testWindow()->setLayout(&layout);
|
|
|
|
takeStandardSnapshots();
|
|
|
|
|
|
|
|
lineEdit.setText(text);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "setText");
|
|
|
|
|
|
|
|
lineEdit.setAlignment(Qt::AlignRight);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "alignedRight");
|
|
|
|
|
|
|
|
lineEdit.setAlignment(Qt::AlignCenter);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "alignedCenter");
|
|
|
|
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
lineEdit.setSelection(0,text.size());
|
2022-02-03 12:34:09 +00:00
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "textSelected");
|
|
|
|
}
|
|
|
|
|
2022-11-29 15:57:26 +00:00
|
|
|
void tst_Widgets::tst_QMenu_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QStringList>("actions");
|
|
|
|
|
|
|
|
const QStringList menu1 = {"Text", "", "TextAndIcon", "", "SubMenu", "", "Checked"};
|
|
|
|
QTest::newRow("showMenuPopup") << menu1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QMenu()
|
|
|
|
{
|
|
|
|
QFETCH(const QStringList, actions);
|
|
|
|
|
|
|
|
testWindow()->resize(300, 200);
|
|
|
|
|
|
|
|
QBoxLayout layout(QBoxLayout::TopToBottom);
|
|
|
|
QMenu menu1;
|
|
|
|
|
|
|
|
for (const auto& menuItem : actions) {
|
|
|
|
if (!menuItem.isEmpty()) {
|
|
|
|
if (menuItem == "Text") {
|
|
|
|
menu1.addAction(QString("MenuItem"));
|
|
|
|
menu1.addAction(QString(""));
|
|
|
|
} else if (menuItem == "TextAndIcon") {
|
|
|
|
// Using pixmap icon
|
|
|
|
QPixmap pix(10, 10);
|
|
|
|
pix.fill(Qt::green);
|
|
|
|
menu1.addAction(QIcon(pix), QString("MenuWithIcon"));
|
|
|
|
menu1.addAction(QIcon(), QString("MenuNoIcon"));
|
|
|
|
} else if (menuItem == "SubMenu") {
|
|
|
|
QMenu* submenu = menu1.addMenu(QString("&Submenu1"));
|
|
|
|
submenu->addAction("SubMenuA");
|
|
|
|
submenu->addAction("SubMenuB");
|
|
|
|
} else if (menuItem == "Checked") {
|
|
|
|
auto checked = menu1.addAction(QString("MenuChecked"));
|
|
|
|
checked->setCheckable(true);
|
|
|
|
checked->setChecked(true);
|
|
|
|
auto notChecked = menu1.addAction(QString("MenuNotChecked"));
|
|
|
|
notChecked->setCheckable(true);
|
|
|
|
notChecked->setChecked(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
menu1.addSeparator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
layout.addWidget(&menu1);
|
|
|
|
testWindow()->setLayout(&layout);
|
|
|
|
|
|
|
|
testWindow()->show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(testWindow()));
|
|
|
|
|
|
|
|
QRect testWindowRect(testWindow()->geometry());
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeScreenSnapshot(testWindowRect), "showitems");
|
|
|
|
|
|
|
|
// Normal menu item with text
|
|
|
|
QTest::keyClick(&menu1, Qt::Key_Down);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeScreenSnapshot(testWindowRect), "selectmenutext");
|
|
|
|
QTest::keyClick(&menu1, Qt::Key_Down);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeScreenSnapshot(testWindowRect), "selectmenunotext");
|
|
|
|
|
|
|
|
// Menu with icon and text
|
|
|
|
QTest::keyClick(&menu1, Qt::Key_Down);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeScreenSnapshot(testWindowRect), "selectmenuwithicon");
|
|
|
|
QTest::keyClick(&menu1, Qt::Key_Down);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeScreenSnapshot(testWindowRect), "selectmenuwithnullicon");
|
|
|
|
|
|
|
|
// Sub-menu items
|
|
|
|
QTest::keyClick(&menu1, Qt::Key_Down);
|
|
|
|
QTest::keyClick(&menu1, Qt::Key_Right);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeScreenSnapshot(testWindowRect), "selectsubmenu");
|
|
|
|
QTest::keyClick(&menu1, Qt::Key_Left);
|
|
|
|
|
|
|
|
// Checked menu
|
|
|
|
QTest::keyClick(&menu1, Qt::Key_Down);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeScreenSnapshot(testWindowRect), "selectmenuchecked");
|
|
|
|
QTest::keyClick(&menu1, Qt::Key_Down);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeScreenSnapshot(testWindowRect), "selectmenunotchecked");
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QCombobox_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("hasFrame");
|
|
|
|
QTest::addColumn<bool>("isEditable");
|
|
|
|
|
|
|
|
QTest::addRow("frameNonEditable") << true << false;
|
|
|
|
QTest::addRow("frameEditable") << true << true;
|
|
|
|
QTest::addRow("noFrameNonEditable") << false << false;
|
|
|
|
QTest::addRow("noFrameEditable") << false << true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QCombobox()
|
|
|
|
{
|
|
|
|
QFETCH(const bool, hasFrame);
|
|
|
|
QFETCH(const bool, isEditable);
|
|
|
|
|
|
|
|
testWindow()->resize(300, 300);
|
|
|
|
|
|
|
|
QScopedPointer<QComboBox> combobox(new QComboBox(testWindow()));
|
|
|
|
QStringList items;
|
|
|
|
items << tr("Item1") << tr("Item2") << tr("Item3");
|
|
|
|
QStringListModel* itemModel = new QStringListModel(items, this);
|
|
|
|
combobox->setModel(itemModel);
|
|
|
|
combobox->setFrame(hasFrame);
|
|
|
|
combobox->setEditable(isEditable);
|
|
|
|
|
|
|
|
QHBoxLayout layout;
|
|
|
|
layout.addWidget(combobox.get());
|
|
|
|
testWindow()->setLayout(&layout);
|
|
|
|
takeStandardSnapshots();
|
|
|
|
|
|
|
|
QTest::keyClick(combobox.get(), Qt::Key_Down, Qt::AltModifier);
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeScreenSnapshot(testWindow()->rect()), "combobox");
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QCommandLinkButton_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("flat");
|
|
|
|
QTest::addColumn<QString>("description");
|
|
|
|
|
|
|
|
QTest::addRow("flatDescription") << true << QString("Command button very specific to windows vista");
|
|
|
|
QTest::addRow("flatNoDescription") << true << QString("");
|
|
|
|
QTest::addRow("noFlatNoDescription") << false << QString("");
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QCommandLinkButton()
|
|
|
|
{
|
|
|
|
QFETCH(const bool, flat);
|
|
|
|
QFETCH(const QString, description);
|
|
|
|
|
|
|
|
QScopedPointer<QCommandLinkButton> commandLink(new QCommandLinkButton(QString("CommandLink"), description, testWindow()));
|
|
|
|
commandLink->setFlat(flat);
|
|
|
|
commandLink->setDescription(description);
|
|
|
|
|
|
|
|
QHBoxLayout layout;
|
|
|
|
layout.addWidget(commandLink.get());
|
|
|
|
testWindow()->setLayout(&layout);
|
|
|
|
takeStandardSnapshots();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QLCDNumber_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("segmentstyle");
|
|
|
|
|
|
|
|
QTest::addRow("outline") << 0;
|
|
|
|
QTest::addRow("filled") << 1;
|
|
|
|
QTest::addRow("flat") << 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Widgets::tst_QLCDNumber()
|
|
|
|
{
|
|
|
|
QFETCH(const int, segmentstyle);
|
|
|
|
|
|
|
|
testWindow()->resize(100, 100);
|
|
|
|
|
|
|
|
QScopedPointer<QLCDNumber> lcdNumber(new QLCDNumber(99, testWindow()));
|
|
|
|
lcdNumber->setHexMode();
|
|
|
|
lcdNumber->setSegmentStyle(static_cast<QLCDNumber::SegmentStyle>(segmentstyle));
|
|
|
|
|
|
|
|
|
|
|
|
QHBoxLayout layout;
|
|
|
|
layout.addWidget(lcdNumber.get());
|
|
|
|
testWindow()->setLayout(&layout);
|
|
|
|
|
|
|
|
QBASELINE_CHECK_DEFERRED(takeSnapshot(), "lcdnumber");
|
|
|
|
}
|
|
|
|
|
Add baseline test that allows comparing the rendering of widgets
Provide basic boiler plate that sets up the baseline (aka lancelot)
framework specifically for comparing the appearance of widgets, and
implement test functions for QSlider and QPushButton.
Widgets should always look the same if the QPA platform, the OS
version, and certain UI-impacting attributes are identical. Ie.
on any macOS 10.15 machine that runs in "Light" mode, widgets
look the same. On a macOS 11 machine, they might look different.
On an OpenSUSE machine using the fusion style things might look
different from a Ubuntu machine.
The helper function removes DPR differences - images are always
scaled to a DPR of 1.0, which allows us to compare the image\
content and not get distracted by them having different dimensions
(and the fuzzy comparison of images might make the system tolerate
scaling artefacts).
Note: For now, this test is meant to be run locally, either when
testing changes to style code, or when checking how QWidget based
UIs would look on newer version of an operating system. In CI the
test is run, but then skipped in CI as the baseline server is
not configured.
Change-Id: Ie33a9d979d934f0df6883757333ce2c5e2f7ef84
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-11-11 19:29:22 +00:00
|
|
|
#define main _realmain
|
|
|
|
QTEST_MAIN(tst_Widgets)
|
|
|
|
#undef main
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2022-08-19 09:57:32 +00:00
|
|
|
// Avoid rendering variations caused by QHash randomization
|
|
|
|
QHashSeed::setDeterministicGlobalSeed();
|
Add baseline test that allows comparing the rendering of widgets
Provide basic boiler plate that sets up the baseline (aka lancelot)
framework specifically for comparing the appearance of widgets, and
implement test functions for QSlider and QPushButton.
Widgets should always look the same if the QPA platform, the OS
version, and certain UI-impacting attributes are identical. Ie.
on any macOS 10.15 machine that runs in "Light" mode, widgets
look the same. On a macOS 11 machine, they might look different.
On an OpenSUSE machine using the fusion style things might look
different from a Ubuntu machine.
The helper function removes DPR differences - images are always
scaled to a DPR of 1.0, which allows us to compare the image\
content and not get distracted by them having different dimensions
(and the fuzzy comparison of images might make the system tolerate
scaling artefacts).
Note: For now, this test is meant to be run locally, either when
testing changes to style code, or when checking how QWidget based
UIs would look on newer version of an operating system. In CI the
test is run, but then skipped in CI as the baseline server is
not configured.
Change-Id: Ie33a9d979d934f0df6883757333ce2c5e2f7ef84
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-11-11 19:29:22 +00:00
|
|
|
|
|
|
|
QBaselineTest::handleCmdLineArgs(&argc, &argv);
|
|
|
|
return _realmain(argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "tst_baseline_widgets.moc"
|