Make tests explicitly use Basic where necessary
The previous commit changes the how the default style is set, and since the tests all assumed that Basic was the default, we now need to ensure it is explicitly set. If we want to, we can revert this patch (or file-by-file) later and ensure that these tests work with all styles. For now, just keep things working as they used to. Tests that use QTEST_QUICKCONTROLS_MAIN are not changed, as they already run with all built-in styles. Tests that don't use types that will cause issues, like tst_qquickcolor, do not need to be changed. tst_snippets can be run manually to produce screenshots, so we specify its style in a qtquickcontrols2.conf file to allow it to be overridden by e.g. application arguments (QQuickStyle::setStyle() takes precedence over all other approaches of setting a style). Change-Id: Ifae7e959f89a41a757c170272038fad139bba04f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
8b53448704
commit
81e8cd6719
|
@ -260,6 +260,11 @@ struct QQuickStyleSpec
|
|||
|
||||
Q_GLOBAL_STATIC(QQuickStyleSpec, styleSpec)
|
||||
|
||||
QString QQuickStylePrivate::style()
|
||||
{
|
||||
return styleSpec()->style;
|
||||
}
|
||||
|
||||
QString QQuickStylePrivate::effectiveStyleName(const QString &styleName)
|
||||
{
|
||||
return !styleName.isEmpty() ? styleName : QLatin1String("Basic");
|
||||
|
|
|
@ -58,6 +58,7 @@ class QSettings;
|
|||
class Q_QUICKCONTROLS2_EXPORT QQuickStylePrivate
|
||||
{
|
||||
public:
|
||||
static QString style();
|
||||
static QString effectiveStyleName(const QString &styleName);
|
||||
static QString fallbackStyle();
|
||||
static bool isCustomStyle();
|
||||
|
|
|
@ -63,7 +63,9 @@ void QQuickStylePlugin::registerTypes(const char *uri)
|
|||
qCDebug(lcStylePlugin).nospace() << "registerTypes called with uri " << uri << "; plugin name is " << name();
|
||||
|
||||
const QTypeRevision latestControlsRevision = QQmlMetaType::latestModuleVersion(QLatin1String("QtQuick.Controls"));
|
||||
QString styleName = QQuickStyle::name();
|
||||
// Use the private function because we don't want to cause resolve() to be called,
|
||||
// as the logic that assigns a default style if one wasn't set would interfere with compile-time style selection.
|
||||
QString styleName = QQuickStylePrivate::style();
|
||||
if (!latestControlsRevision.isValid() && styleName.isEmpty()) {
|
||||
// The user hasn't imported QtQuick.Controls, nor set a style via the runtime methods.
|
||||
qCDebug(lcStylePlugin).nospace() << uri << " imported before QtQuick.Controls; using compile-time style selection";
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include <QtQuickTemplates2/private/qquickpageindicator_p.h>
|
||||
#include <QtQuickTemplates2/private/qquickscrollbar_p.h>
|
||||
#include <QtQuickTemplates2/private/qquicktextarea_p.h>
|
||||
#include <QtQuickControls2/qquickstyle.h>
|
||||
|
||||
#if QT_CONFIG(cursor)
|
||||
# include <QtGui/qscreen.h>
|
||||
|
@ -55,6 +56,9 @@ class tst_cursor : public QQmlDataTest
|
|||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
tst_cursor();
|
||||
|
||||
private slots:
|
||||
void init();
|
||||
void controls_data();
|
||||
|
@ -64,6 +68,11 @@ private slots:
|
|||
void scrollBar();
|
||||
};
|
||||
|
||||
tst_cursor::tst_cursor()
|
||||
{
|
||||
QQuickStyle::setStyle("Basic");
|
||||
}
|
||||
|
||||
void tst_cursor::init()
|
||||
{
|
||||
#if QT_CONFIG(cursor)
|
||||
|
|
|
@ -57,6 +57,7 @@ private slots:
|
|||
|
||||
void tst_Designer::initTestCase()
|
||||
{
|
||||
QQuickStyle::setStyle("Basic");
|
||||
}
|
||||
|
||||
void doComponentCompleteRecursive(QObject *object)
|
||||
|
|
|
@ -74,6 +74,7 @@ private slots:
|
|||
|
||||
void tst_focus::initTestCase()
|
||||
{
|
||||
QQuickStyle::setStyle("Basic");
|
||||
QQmlDataTest::initTestCase();
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,9 @@ class tst_font : public QQmlDataTest
|
|||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
tst_font();
|
||||
|
||||
private slots:
|
||||
void systemFont();
|
||||
|
||||
|
@ -83,6 +86,11 @@ static QFont testFont()
|
|||
return var.value<QFont>();
|
||||
}
|
||||
|
||||
tst_font::tst_font()
|
||||
{
|
||||
QQuickStyle::setStyle("Basic");
|
||||
}
|
||||
|
||||
void tst_font::systemFont()
|
||||
{
|
||||
QSKIP("QTBUG-70063: qmlClearTypeRegistrations() call causes crash");
|
||||
|
|
|
@ -84,10 +84,10 @@ private slots:
|
|||
|
||||
void tst_palette::initTestCase()
|
||||
{
|
||||
QQmlDataTest::initTestCase();
|
||||
|
||||
QQuickStyle::setStyle("Basic");
|
||||
|
||||
QQmlDataTest::initTestCase();
|
||||
|
||||
// Import QtQuick.Controls to initialize styles and themes so that
|
||||
// QQuickControlPrivate::themePalette() returns a palette from the
|
||||
// style's theme instead of the platform's theme.
|
||||
|
|
|
@ -10,6 +10,7 @@ qt_add_test(tst_pressandhold
|
|||
PUBLIC_LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::Quick
|
||||
Qt::QuickControls2
|
||||
)
|
||||
|
||||
#### Keys ignored in scope 1:.:.:pressandhold.pro:<TRUE>:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
TEMPLATE = app
|
||||
TARGET = tst_pressandhold
|
||||
|
||||
QT += quick testlib
|
||||
QT += quick testlib quickcontrols2
|
||||
CONFIG += testcase
|
||||
macos:CONFIG -= app_bundle
|
||||
|
||||
|
|
|
@ -36,11 +36,15 @@
|
|||
|
||||
#include <QtTest>
|
||||
#include <QtQuick>
|
||||
#include <QtQuickControls2/qquickstyle.h>
|
||||
|
||||
class tst_PressAndHold : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
tst_PressAndHold();
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
|
@ -52,6 +56,11 @@ private slots:
|
|||
void keepSelection();
|
||||
};
|
||||
|
||||
tst_PressAndHold::tst_PressAndHold()
|
||||
{
|
||||
QQuickStyle::setStyle("Basic");
|
||||
}
|
||||
|
||||
void tst_PressAndHold::initTestCase()
|
||||
{
|
||||
QGuiApplication::styleHints()->setMousePressAndHoldInterval(100);
|
||||
|
|
|
@ -60,7 +60,9 @@ using namespace QQuickVisualTestUtil;
|
|||
class tst_QQuickApplicationWindow : public QQmlDataTest
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
tst_QQuickApplicationWindow();
|
||||
|
||||
private slots:
|
||||
void qmlCreation();
|
||||
|
@ -81,6 +83,11 @@ private slots:
|
|||
void opacity();
|
||||
};
|
||||
|
||||
tst_QQuickApplicationWindow::tst_QQuickApplicationWindow()
|
||||
{
|
||||
QQuickStyle::setStyle("Basic");
|
||||
}
|
||||
|
||||
void tst_QQuickApplicationWindow::qmlCreation()
|
||||
{
|
||||
QQmlEngine engine;
|
||||
|
|
|
@ -95,6 +95,7 @@ tst_qquickiconimage::tst_qquickiconimage() :
|
|||
dpr(qGuiApp->devicePixelRatio()),
|
||||
integerDpr(qCeil(dpr))
|
||||
{
|
||||
QQuickStyle::setStyle("Basic");
|
||||
}
|
||||
|
||||
void tst_qquickiconimage::initTestCase()
|
||||
|
|
|
@ -91,8 +91,6 @@ void tst_QQuickStyle::unloadControls()
|
|||
|
||||
void tst_QQuickStyle::lookup()
|
||||
{
|
||||
QCOMPARE(QQuickStyle::name(), QString());
|
||||
|
||||
QQuickStyle::setStyle("Material");
|
||||
QCOMPARE(QQuickStyle::name(), QString("Material"));
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ qt_add_test(tst_revisions
|
|||
PUBLIC_LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::Qml
|
||||
Qt::QuickControls2
|
||||
)
|
||||
|
||||
## Scopes:
|
||||
|
|
|
@ -4,4 +4,4 @@ SOURCES += tst_revisions.cpp
|
|||
|
||||
macos:CONFIG -= app_bundle
|
||||
|
||||
QT += qml testlib
|
||||
QT += qml testlib quickcontrols2
|
||||
|
|
|
@ -38,11 +38,15 @@
|
|||
#include <QtTest/qsignalspy.h>
|
||||
#include <QtQml/qqmlengine.h>
|
||||
#include <QtQml/qqmlcomponent.h>
|
||||
#include <QtQuickControls2/qquickstyle.h>
|
||||
|
||||
class tst_revisions : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
tst_revisions();
|
||||
|
||||
private slots:
|
||||
void revisions_data();
|
||||
void revisions();
|
||||
|
@ -51,6 +55,11 @@ private slots:
|
|||
void window();
|
||||
};
|
||||
|
||||
tst_revisions::tst_revisions()
|
||||
{
|
||||
QQuickStyle::setStyle("Basic");
|
||||
}
|
||||
|
||||
void tst_revisions::revisions_data()
|
||||
{
|
||||
QTest::addColumn<int>("revision");
|
||||
|
|
|
@ -23,6 +23,19 @@ qt_add_test(tst_snippets
|
|||
TESTDATA ${test_data}
|
||||
)
|
||||
|
||||
# Resources:
|
||||
set(qmake_immediate_resource_files
|
||||
"qtquickcontrols2.conf"
|
||||
)
|
||||
|
||||
qt_add_resource(tst_snippets "qmake_immediate"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
${qmake_immediate_resource_files}
|
||||
)
|
||||
|
||||
|
||||
#### Keys ignored in scope 1:.:.:snippets.pro:<TRUE>:
|
||||
# OTHER_FILES = "$$PWD/data/*.qml"
|
||||
# TEMPLATE = "app"
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
# Specify the style here so that it can be overridden by e.g. command line arguments.
|
||||
[Controls]
|
||||
Style=Basic
|
|
@ -13,5 +13,8 @@ SOURCES += \
|
|||
OTHER_FILES += \
|
||||
$$PWD/data/*.qml
|
||||
|
||||
RESOURCES += \
|
||||
qtquickcontrols2.conf
|
||||
|
||||
TESTDATA += \
|
||||
$$PWD/data/*
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include <QtQuickTemplates2/private/qquickdialog_p.h>
|
||||
#include <QtQuickTemplates2/private/qquickdialogbuttonbox_p.h>
|
||||
#include <QtQuickTemplates2/private/qquicktextfield_p.h>
|
||||
#include <QtQuickControls2/qquickstyle.h>
|
||||
|
||||
using namespace QQuickVisualTestUtil;
|
||||
|
||||
|
@ -53,12 +54,20 @@ class tst_translation : public QQmlDataTest
|
|||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
tst_translation();
|
||||
|
||||
private slots:
|
||||
void dialogButtonBox();
|
||||
void dialogButtonBoxWithCustomButtons();
|
||||
void comboBox();
|
||||
};
|
||||
|
||||
tst_translation::tst_translation()
|
||||
{
|
||||
QQuickStyle::setStyle("Basic");
|
||||
}
|
||||
|
||||
void tst_translation::dialogButtonBox()
|
||||
{
|
||||
QQuickView view(testFileUrl("dialogButtonBox.qml"));
|
||||
|
|
Loading…
Reference in New Issue