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 <QtGui/qpa/qplatformtheme.h>
19#include <QtQuickTestUtils/private/visualtestutils_p.h>
20
21QT_BEGIN_NAMESPACE
22
23class QQmlComponent;
24class QQmlEngine;
25class QQuickApplicationWindow;
26class QQuickAbstractButton;
27class QQuickControl;
28class QQuickMenuItem;
29class QQuickPopup;
30
32{
34 {
35 public:
36 QQuickControlsApplicationHelper(QQmlDataTest *testCase, const QString &testFilePath,
37 const QVariantMap &initialProperties = {},
38 const QStringList &qmlImportPaths = {});
39
40 QQuickApplicationWindow *appWindow = nullptr;
41 };
42
44 {
45 [[nodiscard]] bool updateStyle(const QString &style);
46
49 };
50
51 typedef std::function<void(const QString &/*styleName*/, const QString &/*typeName*/,
52 const QString &/*relativePath*/, const QUrl &/*absoluteUrl*/)> ForEachCallback;
53
54 void forEachControl(QQmlEngine *engine, const QString &qqc2ImportPath, const QString &styleName,
55 const QString &targetPath, const QStringList &skipList, ForEachCallback callback);
56 void addTestRowForEachControl(QQmlEngine *engine, const QString &qqc2ImportPath, const QString &styleName,
57 const QString &targetPath, const QStringList &skipList = QStringList());
58
59 [[nodiscard]] bool verifyButtonClickable(QQuickAbstractButton *button);
60 [[nodiscard]] bool clickButton(QQuickAbstractButton *button);
61 [[nodiscard]] bool clickMenuItem(QQuickMenuItem *menuItem);
62 [[nodiscard]] bool doubleClickButton(QQuickAbstractButton *button);
63 [[nodiscard]] QString visualFocusFailureMessage(QQuickControl *control);
64
66 {
67 Q_OBJECT
68 QML_ELEMENT
71
72 public:
74 };
75
76 class StyleInfo : public QObject
77 {
78 Q_OBJECT
79 Q_PROPERTY(QString styleName READ styleName CONSTANT FINAL)
82
83 public:
84 // Used by C++.
86 static StyleInfo *instance();
87
88 // Needed for QML integration.
89 static StyleInfo *create(QQmlEngine *, QJSEngine *);
90
91 QString styleName() const;
92
101
104
105 private:
106 StyleInfo() = default;
107
108 void warnIfNotInitialized() const;
109
110 QList<QmlFileData> m_sourceQmlFiles;
111 QList<QmlFileData> m_installedQmlFiles;
112 };
113
115 {
116 Qt::ColorScheme colorScheme() const override
117 {
118 return m_colorScheme;
119 }
120 void requestColorScheme(Qt::ColorScheme theme) override
121 {
122 m_colorScheme = theme;
123 QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>();
124 }
125
126 private:
127 Qt::ColorScheme m_colorScheme = QGuiApplication::styleHints()->colorScheme();
128 };
129
131 {
132 Q_OBJECT
133 QML_ELEMENT
135
136 public:
138 Q_INVOKABLE bool setValue(const QString &name, const QString &value);
139 };
140
142 {
143 Q_OBJECT
144 QML_ELEMENT
146
147 public:
149 Q_INVOKABLE void set(Qt::ApplicationAttribute attribute, bool on = true);
150 };
151
153 [[nodiscard]] QQuickPopup *popupParent(QQuickItem *item);
154
155 // Helper that allows us to call setFastAnimations, which requires a QCoreApplication instance.
156 class QmlTestHelper : public QObject
157 {
159
160 public slots:
165 };
166}
167
168namespace QQuickTest
169{
170namespace Private {
171// Overload of the one in quicktest.h.
172[[nodiscard]] QByteArray qActiveFocusFailureMessage(QQuickPopup *popup);
173} // namespace Private
174} // namespace QQuickTest
175
176#define VERIFY_VISUAL_FOCUS(control) do
177 {
178 QVERIFY2(control->hasVisualFocus(), qUtf8Printable(visualFocusFailureMessage(control))); \
179}while (false)
180
181#define TRY_VERIFY_POPUP_OPENED(popup) do
182 {
183 QTRY_VERIFY(popup->isOpened());
184 if (auto *popupWindow = QQuickPopupPrivate::get(popup)->popupWindow) {
185 QVERIFY(QTest::qWaitForWindowExposed(popupWindow));
186 if (QQuickTest::qIsPolishScheduled(popupWindow))
187 QQuickTest::qWaitForPolish(popupWindow);
188 } \
189}while (false)
190
191QT_END_NAMESPACE
192
193#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)