Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
controlstestutils_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef CONTROLSTESTUTILS_P_H
5#define CONTROLSTESTUTILS_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtTest/qtest.h>
19#include <QtGui/qpa/qplatformtheme.h>
20#include <QtQuickTestUtils/private/visualtestutils_p.h>
21
22QT_BEGIN_NAMESPACE
23
24class QQmlComponent;
25class QQmlEngine;
26class QQuickApplicationWindow;
27class QQuickAbstractButton;
28class QQuickControl;
29class QQuickMenuItem;
30class QQuickPopup;
31
33{
35 {
36 public:
37 QQuickControlsApplicationHelper(QQmlDataTest *testCase, const QString &testFilePath,
38 const QVariantMap &initialProperties = {},
39 const QStringList &qmlImportPaths = {});
40
41 QQuickApplicationWindow *appWindow = nullptr;
42 };
43
45 {
46 [[nodiscard]] bool updateStyle(const QString &style);
47
50 };
51
52 typedef std::function<void(const QString &/*styleName*/, const QString &/*typeName*/,
53 const QString &/*relativePath*/, const QUrl &/*absoluteUrl*/)> ForEachCallback;
54
55 void forEachControl(QQmlEngine *engine, const QString &qqc2ImportPath, const QString &styleName,
56 const QString &targetPath, const QStringList &skipList, ForEachCallback callback);
57 void addTestRowForEachControl(QQmlEngine *engine, const QString &qqc2ImportPath, const QString &styleName,
58 const QString &targetPath, const QStringList &skipList = QStringList());
59
60 [[nodiscard]] bool verifyButtonClickable(QQuickAbstractButton *button);
61 [[nodiscard]] bool clickButton(QQuickAbstractButton *button);
62 [[nodiscard]] bool clickMenuItem(QQuickMenuItem *menuItem);
63 [[nodiscard]] bool doubleClickButton(QQuickAbstractButton *button);
64 [[nodiscard]] QString visualFocusFailureMessage(QQuickControl *control);
65
67 {
68 Q_OBJECT
69 QML_ELEMENT
72
73 public:
75 };
76
77 class StyleInfo : public QObject
78 {
79 Q_OBJECT
80 Q_PROPERTY(QString styleName READ styleName CONSTANT FINAL)
83
84 public:
85 // Used by C++.
87 static StyleInfo *instance();
88
89 // Needed for QML integration.
90 static StyleInfo *create(QQmlEngine *, QJSEngine *);
91
92 QString styleName() const;
93
102
105
106 private:
107 StyleInfo() = default;
108
109 void warnIfNotInitialized() const;
110
111 QList<QmlFileData> m_sourceQmlFiles;
112 QList<QmlFileData> m_installedQmlFiles;
113 };
114
116 {
117 Qt::ColorScheme colorScheme() const override
118 {
119 return m_colorScheme;
120 }
121 void requestColorScheme(Qt::ColorScheme theme) override
122 {
123 m_colorScheme = theme;
124 QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>();
125 }
126
127 private:
128 Qt::ColorScheme m_colorScheme = QGuiApplication::styleHints()->colorScheme();
129 };
130
132 {
133 Q_OBJECT
134 QML_ELEMENT
136
137 public:
139 Q_INVOKABLE bool setValue(const QString &name, const QString &value);
140 };
141
143 {
144 Q_OBJECT
145 QML_ELEMENT
147
148 public:
150 Q_INVOKABLE void set(Qt::ApplicationAttribute attribute, bool on = true);
151 };
152
154 [[nodiscard]] QQuickPopup *popupParent(QQuickItem *item);
155
156 // Helper that allows us to call setFastAnimations, which requires a QCoreApplication instance.
157 class QmlTestHelper : public QObject
158 {
160
161 public slots:
166 };
167}
168
169namespace QQuickTest
170{
171namespace Private {
172// Overload of the one in quicktest.h.
173[[nodiscard]] QByteArray qActiveFocusFailureMessage(QQuickPopup *popup);
174} // namespace Private
175} // namespace QQuickTest
176
177#define VERIFY_VISUAL_FOCUS(control) do
178 {
179 QVERIFY2(control->hasVisualFocus(), qUtf8Printable(visualFocusFailureMessage(control))); \
180}while (false)
181
182#define TRY_VERIFY_POPUP_OPENED(popup) do
183 {
184 QTRY_VERIFY(popup->isOpened());
185 if (auto *popupWindow = QQuickPopupPrivate::get(popup)->popupWindow) {
186 QVERIFY(QTest::qWaitForWindowExposed(popupWindow));
187 if (QQuickTest::qIsPolishScheduled(popupWindow))
188 QQuickTest::qWaitForPolish(popupWindow);
189 } \
190}while (false)
191
192QT_END_NAMESPACE
193
194#endif // CONTROLSTESTUTILS_P_H
The QQmlComponent class encapsulates a QML component definition.
Q_INVOKABLE void set(Qt::ApplicationAttribute attribute, bool on=true)
Qt::ColorScheme colorScheme() const override
void requestColorScheme(Qt::ColorScheme theme) override
QQuickControlsApplicationHelper(QQmlDataTest *testCase, const QString &testFilePath, const QVariantMap &initialProperties={}, const QStringList &qmlImportPaths={})
QList< QmlFileData > installedQmlFiles() const
QList< QmlFileData > sourceQmlFiles() const
static StyleInfo * create(QQmlEngine *, QJSEngine *)
Q_INVOKABLE bool setValue(const QString &name, const QString &value)
bool verifyButtonClickable(QQuickAbstractButton *button)
void forEachControl(QQmlEngine *engine, const QString &qqc2ImportPath, const QString &styleName, const QString &targetPath, const QStringList &skipList, ForEachCallback callback)
void addTestRowForEachControl(QQmlEngine *engine, const QString &qqc2ImportPath, const QString &styleName, const QString &targetPath, const QStringList &skipList=QStringList())
bool clickMenuItem(QQuickMenuItem *menuItem)
std::function< void(const QString &, const QString &, const QString &, const QUrl &)> ForEachCallback
bool doubleClickButton(QQuickAbstractButton *button)
QQuickPopup * popupParent(QQuickItem *item)
QString visualFocusFailureMessage(QQuickControl *control)
bool clickButton(QQuickAbstractButton *button)
QByteArray qActiveFocusFailureMessage(QQuickPopup *popup)