Qt 4.8
qdeclarativelist.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 "qdeclarativelist.h"
43 #include "private/qdeclarativelist_p.h"
44 #include "private/qdeclarativeengine_p.h"
45 #include "private/qdeclarativeproperty_p.h"
46 
48 
50 : propertyType(-1), refCount(1)
51 {
52 }
53 
55 {
57 
58  if (!prop.object) return rv;
59 
61 
62  int listType = p?p->listType(propType):QDeclarativeMetaType::listType(propType);
63  if (listType == -1) return rv;
64 
66  rv.d->object = prop.object;
68  rv.d->property = prop;
69  rv.d->propertyType = propType;
70 
71  return rv;
72 }
73 
75 {
76  Q_ASSERT(refCount > 0);
77  ++refCount;
78 }
79 
81 {
82  Q_ASSERT(refCount > 0);
83  --refCount;
84  if (!refCount)
85  delete this;
86 }
87 
123 : d(0)
124 {
125 }
126 
137 : d(0)
138 {
139  if (!object || !property) return;
140 
143  QDeclarativePropertyCache::property(engine, object, QLatin1String(property), local);
144 
145  if (!data || !(data->flags & QDeclarativePropertyCache::Data::IsQList)) return;
146 
148 
149  int listType = p?p->listType(data->propType):QDeclarativeMetaType::listType(data->propType);
150  if (listType == -1) return;
151 
153  d->object = object;
155  d->propertyType = data->propType;
156 
157  void *args[] = { &d->property, 0 };
159 }
160 
163 : d(o.d)
164 {
165  if (d) d->addref();
166 }
167 
170 {
171  if (o.d) o.d->addref();
172  if (d) d->release();
173  d = o.d;
174  return *this;
175 }
176 
179 {
180  if (d) d->release();
181 }
182 
187 {
188  return d && d->object;
189 }
190 
195 {
196  if (isValid()) return d->object;
197  else return 0;
198 }
199 
208 {
209  if (isValid()) return d->elementType;
210  else return 0;
211 }
212 
220 {
221  return (isValid() && d->property.append);
222 }
223 
231 {
232  return (isValid() && d->property.at);
233 }
234 
242 {
243  return (isValid() && d->property.clear);
244 }
245 
253 {
254  return (isValid() && d->property.count);
255 }
256 
263 {
264  if (!canAppend()) return false;
265 
267  return false;
268 
269  d->property.append(&d->property, object);
270 
271  return true;
272 }
273 
280 {
281  if (!canAt()) return 0;
282 
283  return d->property.at(&d->property, index);
284 }
285 
292 {
293  if (!canClear()) return false;
294 
295  d->property.clear(&d->property);
296 
297  return true;
298 }
299 
304 {
305  if (!canCount()) return 0;
306 
307  return d->property.count(&d->property);
308 }
309 
double d
Definition: qnumeric_p.h:62
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QObject * object() const
Returns the list property's object.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
friend class QDeclarativeListReferencePrivate
The QDeclarativeListReference class allows the manipulation of QDeclarativeListProperty properties...
static int metacall(QObject *, Call, int, void **)
bool append(QObject *) const
Appends object to the list.
static QDeclarativeType * qmlType(const QByteArray &, int, int)
Returns the type (if any) of URI-qualified named name in version specified by version_major and versi...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
const QMetaObject * baseMetaObject() const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
bool canClear() const
Returns true if the list property can be cleared, otherwise false.
QDeclarativeListReference & operator=(const QDeclarativeListReference &)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static QDeclarativeListReference init(const QDeclarativeListProperty< QObject > &, int, QDeclarativeEngine *)
int count() const
Returns the number of objects in the list, or 0 if the operation failed.
Data * property(const QScriptDeclarativeClass::Identifier &id) const
static const char * data(const QByteArray &arr)
const QMetaObject * listElementType() const
Returns the QMetaObject for the elements stored in the list property.
QDeclarativeListReference()
Constructs an invalid instance.
bool clear() const
Clears the list.
QDeclarativeListProperty< QObject > property
bool canAppend() const
Returns true if the list property can be appended to, otherwise false.
bool isValid() const
Returns true if the instance refers to a valid list property, otherwise false.
The QDeclarativeEngine class provides an environment for instantiating QML components.
const char * property
Definition: qwizard.cpp:138
quint16 index
static bool canConvert(const QMetaObject *from, const QMetaObject *to)
Returns true if from inherits to.
QDeclarativeListReferencePrivate * d
bool canCount() const
Returns true if the list property can be queried for its element count, otherwise false...
QDeclarativeGuard< QObject > object
QObject * at(int) const
Returns the list element at index, or 0 if the operation failed.
const QMetaObject * rawMetaObjectForType(int) const
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
bool canAt() const
Returns true if the list property can queried by index, otherwise false.