1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of QtUiTest.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "testdeclarativeitem.h"
#include <QDeclarativeItem>
#include <QDeclarativeEngine>
#include <QDeclarativeContext>
#include <QDeclarativeListProperty>
#include <QScriptValue>
#include <QMetaObject>
#include <QMetaProperty>
#include <private/qdeclarativemetatype_p.h>
#include <QDebug>
TestDeclarativeItem::TestDeclarativeItem(QDeclarativeItem* _q)
: QtUiTest::TestGraphicsItem(_q),
q(_q),
m_childActivate(false)
{
}
const QObjectList& TestDeclarativeItem::children() const
{
m_children.clear();
foreach (QObject *child, q->children()) {
if (qobject_cast<QDeclarativeItem*>(child))
m_children << child;
}
return m_children;
}
bool TestDeclarativeItem::implements(char const* interface) const
{
if (interface == QLatin1String("ActivateWidget")) {
m_childActivate = 0;
foreach (QObject *child, children()) {
if (qtuitest_cast<QtUiTest::ActivateWidget*>(child)) {
m_childActivate = child;
return true;
}
}
return false;
}
return (interface == QLatin1String("Widget"));
}
static const uint qt_meta_data_TestDeclarativeItem[] = {
// content:
1, // revision
0, // classname
0, 0, // classinfo
0, 0, // methods
0, 0, // properties
0, 0, // enums/sets
0 // eodinherits
};
static const char qt_meta_stringdata_TestDeclarativeItem[] = {
"TestDeclarativeItem\0"
};
const QMetaObject TestDeclarativeItem::staticMetaObject = {
{ &QObject::staticMetaObject, qt_meta_stringdata_TestDeclarativeItem,
qt_meta_data_TestDeclarativeItem, 0 }
};
const QMetaObject *TestDeclarativeItem::metaObject() const
{
return &staticMetaObject;
}
void *TestDeclarativeItem::qt_metacast(const char *_clname)
{
if (!_clname) return 0;
void* ret = 0;
do {
#define DO(Type,String) \
if (!strcmp(_clname,#String) && implements(static_cast<Type*>(0)->_q_interfaceName())) { \
ret = static_cast<Type*>(this); \
break; \
}
DO(QtUiTest::Widget, QtUiTest::Widget);
DO(QtUiTest::Widget, com.nokia.qt.QtUiTest.Widget/1.0);
DO(QtUiTest::CheckWidget, QtUiTest::CheckWidget);
DO(QtUiTest::CheckWidget, com.nokia.qt.QtUiTest.CheckWidget/1.0);
DO(QtUiTest::ActivateWidget, QtUiTest::ActivateWidget);
DO(QtUiTest::ActivateWidget, com.nokia.qt.QtUiTest.ActivateWidget/1.0);
DO(QtUiTest::LabelWidget, QtUiTest::LabelWidget);
DO(QtUiTest::LabelWidget, com.nokia.qt.QtUiTest.LabelWidget/1.0);
DO(QtUiTest::TextWidget, QtUiTest::TextWidget);
DO(QtUiTest::TextWidget, com.nokia.qt.QtUiTest.TextWidget/1.0);
DO(QtUiTest::ListWidget, QtUiTest::ListWidget);
DO(QtUiTest::ListWidget, com.nokia.qt.QtUiTest.ListWidget/1.0);
DO(QtUiTest::InputWidget, QtUiTest::InputWidget);
DO(QtUiTest::InputWidget, com.nokia.qt.QtUiTest.InputWidget/1.0);
DO(QtUiTest::SelectWidget, QtUiTest::SelectWidget);
DO(QtUiTest::SelectWidget, com.nokia.qt.QtUiTest.SelectWidget/1.0);
#undef DO
} while(0);
if (!ret) ret = QObject::qt_metacast(_clname);
return ret;
}
/*************************************************************************************************/
static const QString TestDeclarativeItemSubclassError(
"Internal error: TestDeclarativeItem::%1() called. Either %2::implements() is wrong or %2 forgot to override %1."
);
#define SETERROR() \
QtUiTest::setErrorString(TestDeclarativeItemSubclassError.arg(__FUNCTION__).arg(metaObject()->className()))
bool TestDeclarativeItem::activate()
{
if (QtUiTest::ActivateWidget *aw = qtuitest_cast<QtUiTest::ActivateWidget*>(m_childActivate)) {
return aw->activate();
}
return false;
}
QString TestDeclarativeItem::labelText() const
{ SETERROR(); return QString(); }
bool TestDeclarativeItem::isTristate() const
{ SETERROR(); return false; }
Qt::CheckState TestDeclarativeItem::checkState() const
{ SETERROR(); return Qt::CheckState(0); }
bool TestDeclarativeItem::setCheckState(Qt::CheckState)
{ SETERROR(); return false; }
QString TestDeclarativeItem::selectedText() const
{ SETERROR(); return QString(); }
QString TestDeclarativeItem::text() const
{ SETERROR(); return QString(); }
QStringList TestDeclarativeItem::list() const
{ SETERROR(); return QStringList(); }
QRect TestDeclarativeItem::visualRect(const QString&) const
{ SETERROR(); return QRect(); }
bool TestDeclarativeItem::ensureVisible(const QString&)
{ SETERROR(); return false; }
bool TestDeclarativeItem::canEnter(const QVariant&) const
{ SETERROR(); return false; }
bool TestDeclarativeItem::enter(const QVariant&,bool)
{ SETERROR(); return false; }
bool TestDeclarativeItem::isMultiSelection() const
{ SETERROR(); return false; }
bool TestDeclarativeItem::canSelect(const QString&) const
{ SETERROR(); return false; }
bool TestDeclarativeItem::canSelectMulti(const QStringList&) const
{ SETERROR(); return false; }
bool TestDeclarativeItem::select(const QString&)
{ SETERROR(); return false; }
bool TestDeclarativeItem::selectMulti(const QStringList&)
{ SETERROR(); return false; }
///////
bool TestDeclarativeItem::isVisible() const
{
return q->isVisible();
}
QObject* TestDeclarativeItem::parent() const
{ return q->parentItem() ? q->parentItem() : TestGraphicsItem::parent(); }
bool TestDeclarativeItem::ensureVisibleRegion(const QRegion&)
{ return true; }
bool TestDeclarativeItem::hasFocus() const
{ return q->hasFocus(); }
QString unSlash(const QString &text)
{
int lastSlash = text.lastIndexOf(QLatin1Char('/'));
if (lastSlash != -1)
return text.mid(lastSlash+1);
else
return text;
}
QVariant TestDeclarativeItem::getProperty(const QString& name) const
{
QVariant ret;
if (name.toUpper() == "QMLTYPE") {
QString typeName;
QDeclarativeType *type = QDeclarativeMetaType::qmlType(q->metaObject());
if (type) {
typeName = QLatin1String(type->qmlTypeName());
} else {
typeName = QString::fromUtf8(q->metaObject()->className());
int marker = typeName.indexOf(QLatin1String("_QMLTYPE_"));
if (marker != -1)
typeName = typeName.left(marker);
else {
marker = typeName.indexOf(QLatin1String("_QML_"));
if (marker != -1)
typeName = typeName.left(marker);
foreach (QDeclarativeType* type, QDeclarativeMetaType::qmlTypes()) {
if (type->typeName() == typeName) {
typeName = QLatin1String(type->qmlTypeName());
break;
}
}
}
}
if (!typeName.isNull()) {
int lastSlash = typeName.lastIndexOf(QLatin1Char('/'));
if (lastSlash != -1)
typeName = typeName.mid(lastSlash+1);
return typeName;
}
} else if (name.contains('.')) {
// This is an attached property
int dot = name.indexOf('.');
QString attachTypeName = name.left(dot);
QDeclarativeType *attachType = 0;
foreach (QDeclarativeType* type, QDeclarativeMetaType::qmlTypes()) {
if (unSlash(type->qmlTypeName()) == attachTypeName) {
attachType = type;
break;
}
}
if (attachType) {
QDeclarativeAttachedPropertiesFunc func = attachType->attachedPropertiesFunction();
if (func) {
QObject *attached = func(q);
if (attached) {
ret = attached->property(name.mid(dot+1).toLatin1());
}
}
}
} else {
ret = q->property(name.toLatin1());
}
if (ret.type() == QVariant::UserType) {
bool ok;
QObject *obj = QDeclarativeMetaType::toQObject(ret, &ok);
if (ok) {
return QVariant::fromValue(obj);
}
return QVariant();
}
return ret;
}
|