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 &/*relativePath*/, const QUrl &/*absoluteUrl*/)> ForEachCallback;
52
53 void forEachControl(QQmlEngine *engine, const QString &qqc2ImportPath, const QString &sourcePath,
54 const QString &targetPath, const QStringList &skipList, ForEachCallback callback);
55 void addTestRowForEachControl(QQmlEngine *engine, const QString &qqc2ImportPath, const QString &sourcePath,
56 const QString &targetPath, const QStringList &skipList = QStringList());
57
58 [[nodiscard]] bool verifyButtonClickable(QQuickAbstractButton *button);
59 [[nodiscard]] bool clickButton(QQuickAbstractButton *button);
60 [[nodiscard]] bool clickMenuItem(QQuickMenuItem *menuItem);
61 [[nodiscard]] bool doubleClickButton(QQuickAbstractButton *button);
62 [[nodiscard]] QString visualFocusFailureMessage(QQuickControl *control);
63
65 {
66 Q_OBJECT
67 QML_ELEMENT
70
71 public:
73 };
74
75 class StyleInfo : public QObject
76 {
77 Q_OBJECT
78 Q_PROPERTY(QString styleName READ styleName CONSTANT FINAL)
81
82 public:
83 QString styleName() const;
84 };
85
87 {
88 Qt::ColorScheme colorScheme() const override
89 {
90 return m_colorScheme;
91 }
92 void requestColorScheme(Qt::ColorScheme theme) override
93 {
94 m_colorScheme = theme;
95 QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>();
96 }
97
98 private:
99 Qt::ColorScheme m_colorScheme = QGuiApplication::styleHints()->colorScheme();
100 };
101
103 {
104 Q_OBJECT
105 QML_ELEMENT
107
108 public:
110 Q_INVOKABLE bool setValue(const QString &name, const QString &value);
111 };
112
114 {
115 Q_OBJECT
116 QML_ELEMENT
118
119 public:
121 Q_INVOKABLE void set(Qt::ApplicationAttribute attribute, bool on = true);
122 };
123
125 [[nodiscard]] QQuickPopup *popupParent(QQuickItem *item);
126
127 // Helper that allows us to call setFastAnimations, which requires a QCoreApplication instance.
128 class QmlTestHelper : public QObject
129 {
131
132 public slots:
137 };
138}
139
140namespace QQuickTest
141{
142namespace Private {
143// Overload of the one in quicktest.h.
144[[nodiscard]] QByteArray qActiveFocusFailureMessage(QQuickPopup *popup);
145} // namespace Private
146} // namespace QQuickTest
147
148#define VERIFY_VISUAL_FOCUS(control) do
149 {
150 QVERIFY2(control->hasVisualFocus(), qUtf8Printable(visualFocusFailureMessage(control))); \
151}while (false)
152
153#define TRY_VERIFY_POPUP_OPENED(popup) do
154 {
155 QTRY_VERIFY(popup->isOpened());
156 if (auto *popupWindow = QQuickPopupPrivate::get(popup)->popupWindow) {
157 QVERIFY(QTest::qWaitForWindowExposed(popupWindow));
158 if (QQuickTest::qIsPolishScheduled(popupWindow))
159 QQuickTest::qWaitForPolish(popupWindow);
160 } \
161}while (false)
162
163QT_END_NAMESPACE
164
165#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={})
Q_INVOKABLE bool setValue(const QString &name, const QString &value)
bool verifyButtonClickable(QQuickAbstractButton *button)
void addTestRowForEachControl(QQmlEngine *engine, const QString &qqc2ImportPath, const QString &sourcePath, const QString &targetPath, const QStringList &skipList=QStringList())
void forEachControl(QQmlEngine *engine, const QString &qqc2ImportPath, const QString &sourcePath, const QString &targetPath, const QStringList &skipList, ForEachCallback callback)
bool clickMenuItem(QQuickMenuItem *menuItem)
bool doubleClickButton(QQuickAbstractButton *button)
QQuickPopup * popupParent(QQuickItem *item)
QString visualFocusFailureMessage(QQuickControl *control)
bool clickButton(QQuickAbstractButton *button)
std::function< void(const QString &, const QUrl &)> ForEachCallback
QByteArray qActiveFocusFailureMessage(QQuickPopup *popup)