Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
quicktestutil.cpp
Go to the documentation of this file.
1
// Copyright (C) 2019 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"quicktestutil_p.h"
6
7
#
include
<
QtQuickTest
/
private
/
qtestoptions_p
.
h
>
8
#
include
<
QtQml
/
private
/
qqmltype_p
.
h
>
9
#
include
<
QtQml
/
private
/
qqmlmetatype_p
.
h
>
10
#
include
<
QtQml
/
private
/
qv4engine_p
.
h
>
11
#
include
<
QtQml
/
private
/
qv4scopedvalue_p
.
h
>
12
#
include
<
QtQml
/
private
/
qjsvalue_p
.
h
>
13
14
#
include
<
QtGui
/
qguiapplication
.
h
>
15
#
include
<
QtGui
/
qclipboard
.
h
>
16
#
include
<
QtGui
/
qstylehints
.
h
>
17
#
include
<
QtQml
/
qqmlengine
.
h
>
18
19
QT_BEGIN_NAMESPACE
20
21
using
namespace
Qt::StringLiterals;
22
23
bool
QuickTestUtil::printAvailableFunctions()
const
24
{
25
return
QTest::printAvailableFunctions;
26
}
27
28
int
QuickTestUtil::dragThreshold()
const
29
{
30
return
QGuiApplication::styleHints()->startDragDistance();
31
}
32
33
void
QuickTestUtil::populateClipboardText(
int
lineCount)
34
{
35
#
if
QT_CONFIG
(
clipboard
)
36
QString fmt(u"%1 bottles of beer on the wall, %1 bottles of beer; "
37
"take one down, pass it around, %2 bottles of beer on the wall."_s
);
38
QStringList lines;
39
for
(
int
i = lineCount; i > 0; --i)
40
lines << fmt.arg(i).arg(i - 1);
41
QGuiApplication::clipboard()->setText(lines.join(u'\n'));
42
#
else
43
Q_UNUSED(lineCount)
44
#
endif
45
}
46
47
QJSValue QuickTestUtil::typeName(
const
QVariant &v)
const
48
{
49
QString name = QString::fromUtf8(v.typeName());
50
if
(v.canConvert<QObject*>()) {
51
QQmlType type;
52
const
QMetaObject *mo = v.value<QObject*>()->metaObject();
53
while
(!type.isValid() && mo) {
54
type = QQmlMetaType::qmlType(mo);
55
mo = mo->superClass();
56
}
57
if
(type.isValid()) {
58
name = type.qmlTypeName();
59
}
60
}
61
62
QQmlEngine *engine = qmlEngine(
this
);
63
QV4::ExecutionEngine *v4 = engine->handle();
64
return
QJSValuePrivate::fromReturnedValue(v4->newString(name)->asReturnedValue());
65
}
66
67
bool
QuickTestUtil::compare(
const
QVariant &act,
const
QVariant &exp)
const
{
68
return
act == exp;
69
}
70
71
QJSValue QuickTestUtil::callerFile(
int
frameIndex)
const
72
{
73
QQmlEngine *engine = qmlEngine(
this
);
74
QV4::ExecutionEngine *v4 = engine->handle();
75
QV4::Scope scope(v4);
76
77
QList<QV4::StackFrame> stack = v4->stackTrace(frameIndex + 2);
78
return
(stack.size() > frameIndex + 1)
79
? QJSValuePrivate::fromReturnedValue(
80
v4->newString(stack.at(frameIndex + 1).source)->asReturnedValue())
81
: QJSValue();
82
}
83
84
int
QuickTestUtil::callerLine(
int
frameIndex)
const
85
{
86
QQmlEngine *engine = qmlEngine(
this
);
87
QV4::ExecutionEngine *v4 = engine->handle();
88
89
QList<QV4::StackFrame> stack = v4->stackTrace(frameIndex + 2);
90
if
(stack.size() > frameIndex + 1)
91
return
qAbs(stack.at(frameIndex + 1).line);
92
return
-1;
93
}
94
95
QT_END_NAMESPACE
96
97
#
include
"moc_quicktestutil_p.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
qmltest
quicktestutil.cpp
Generated on
for Qt by
1.18.0