Qt 4.8
qdeclarativefastproperties.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/qdeclarativefastproperties_p.h"
43 
44 #include <private/qdeclarativeitem_p.h>
45 
47 
48 // Adding entries to the QDeclarativeFastProperties class allows the QML
49 // binding optimizer to bypass Qt's meta system and read and, more
50 // importantly, subscribe to properties directly. Any property that is
51 // primarily read from bindings is a candidate for inclusion as a fast
52 // property.
53 
54 static void QObject_objectName(QObject *object, void *output, QDeclarativeNotifierEndpoint *endpoint)
55 {
56  if (endpoint)
57  endpoint->connect(QDeclarativeData::get(object, true)->objectNameNotifier());
58  *((QString *)output) = object->objectName();
59 }
60 
62 {
65  add(&QObject::staticMetaObject, QObject::staticMetaObject.indexOfProperty("objectName"),
67 }
68 
69 int QDeclarativeFastProperties::accessorIndexForProperty(const QMetaObject *metaObject, int propertyIndex)
70 {
71  Q_ASSERT(metaObject);
72  Q_ASSERT(propertyIndex >= 0);
73 
74  // Find the "real" metaObject
75  while (metaObject->propertyOffset() > propertyIndex)
76  metaObject = metaObject->superClass();
77 
78  QHash<QPair<const QMetaObject *, int>, int>::Iterator iter =
79  m_index.find(qMakePair(metaObject, propertyIndex));
80  if (iter != m_index.end())
81  return *iter;
82  else
83  return -1;
84 }
85 
86 void QDeclarativeFastProperties::add(const QMetaObject *metaObject, int propertyIndex, Accessor accessor)
87 {
88  Q_ASSERT(metaObject);
89  Q_ASSERT(propertyIndex >= 0);
90 
91  // Find the "real" metaObject
92  while (metaObject->propertyOffset() > propertyIndex)
93  metaObject = metaObject->superClass();
94 
95  QPair<const QMetaObject *, int> data = qMakePair(metaObject, propertyIndex);
96  int accessorIndex = m_accessors.count();
97  m_accessors.append(accessor);
98  m_index.insert(data, accessorIndex);
99 }
100 
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
static QDeclarativeData * get(const QObject *object, bool create=false)
void add(const QMetaObject *, int, Accessor)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
static void QObject_objectName(QObject *object, void *output, QDeclarativeNotifierEndpoint *endpoint)
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
Accessor accessor(int index) const
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
void connect(QObject *source, int sourceSignal)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
int accessorIndexForProperty(const QMetaObject *, int)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
static const char * data(const QByteArray &arr)
const QMetaObject * superClass() const
Returns the meta-object of the superclass, or 0 if there is no such object.
Definition: qobjectdefs.h:494
static void parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
QHash< QPair< const QMetaObject *, int >, int > m_index
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
void(* Accessor)(QObject *object, void *output, QDeclarativeNotifierEndpoint *endpoint)
int propertyOffset() const
Returns the property offset for this class; i.e.
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865