Qt 4.8
qdeclarativelistscriptclass.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "private/qdeclarativelistscriptclass_p.h"
43 
44 #include "private/qdeclarativeengine_p.h"
45 #include "private/qdeclarativeguard_p.h"
46 #include "private/qdeclarativelist_p.h"
47 
49 
54 };
55 
57 : QScriptDeclarativeClass(QDeclarativeEnginePrivate::getScriptEngine(e)), engine(e)
58 {
60  Q_UNUSED(scriptEngine);
61 
63 }
64 
66 {
67 }
68 
69 QScriptValue QDeclarativeListScriptClass::newList(QObject *object, int propId, int propType)
70 {
72 
73  if (!object || propId == -1)
74  return scriptEngine->nullValue();
75 
76  ListData *data = new ListData;
77  data->object = object;
78  data->propertyType = propType;
79  void *args[] = { &data->property, 0 };
80  QMetaObject::metacall(object, QMetaObject::ReadProperty, propId, args);
81 
82  return newObject(scriptEngine, this, data);
83 }
84 
86 {
88 
89  ListData *data = new ListData;
90  data->object = prop.object;
91  data->property = prop;
92  data->propertyType = propType;
93 
94  return newObject(scriptEngine, this, data);
95 }
96 
97 QScriptClass::QueryFlags
99  QScriptClass::QueryFlags flags)
100 {
101  Q_UNUSED(object);
102  Q_UNUSED(flags);
103  if (name == m_lengthId.identifier)
105 
106  bool ok = false;
107  quint32 idx = toArrayIndex(name, &ok);
108 
109  if (ok) {
110  lastIndex = idx;
112  } else {
113  return 0;
114  }
115 }
116 
118 {
121 
122  ListData *data = (ListData *)obj;
123  if (!data->object)
124  return Value();
125 
126  quint32 count = data->property.count?data->property.count(&data->property):0;
127 
128  if (name == m_lengthId.identifier)
129  return Value(scriptEngine, count);
130  else if (lastIndex < count && data->property.at)
131  return Value(scriptEngine, enginePriv->objectClass->newQObject(data->property.at(&data->property, lastIndex)));
132  else
133  return Value();
134 }
135 
137 {
138  ListData *data = (ListData *)obj;
139 
140  if (!data->object) {
141  if (ok) *ok = false;
142  return QVariant();
143  }
144 
146 }
147 
149 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static QScriptValue newObject(QScriptEngine *, QScriptDeclarativeClass *, Object *)
QDeclarativeListScriptClass(QDeclarativeEngine *)
static int metacall(QObject *, Call, int, void **)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static Object * object(const QScriptValue &)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
PersistentIdentifier createPersistentIdentifier(const QString &)
The QScriptDeclarativeClass::Value class acts as a container for JavaScript data types.
virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, QScriptClass::QueryFlags flags)
QDeclarativeGuard< QObject > object
QScriptValue newQObject(QObject *, int type=QMetaType::QObjectStar)
The QScriptEngine class provides an environment for evaluating Qt Script code.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static QDeclarativeListReference init(const QDeclarativeListProperty< QObject > &, int, QDeclarativeEngine *)
const char * name
QScriptEngine * engine() const
static const char * data(const QByteArray &arr)
QDeclarativeListProperty< QObject > property
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
QDeclarativeObjectScriptClass * objectClass
quint32 toArrayIndex(const Identifier &, bool *ok)
The QDeclarativeEngine class provides an environment for instantiating QML components.
unsigned int quint32
Definition: qglobal.h:938
virtual QVariant toVariant(Object *, bool *ok)
QScriptValue newList(QObject *, int, int)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QScriptValue nullValue()
Returns a QScriptValue of the primitive type Null.
virtual Value property(Object *, const Identifier &)