Qt 4.8
qdeclarativeproxymetaobject.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/qdeclarativeproxymetaobject_p.h"
43 #include "private/qdeclarativeproperty_p.h"
44 
46 
48 : metaObjects(mList), proxies(0), parent(0), object(obj)
49 {
50  *static_cast<QMetaObject *>(this) = *metaObjects->first().metaObject;
51 
53  if (op->metaObject)
54  parent = static_cast<QAbstractDynamicMetaObject*>(op->metaObject);
55 
56  op->metaObject = this;
57 }
58 
60 {
61  if (parent)
62  delete parent;
63  parent = 0;
64 
65  if (proxies)
66  delete [] proxies;
67  proxies = 0;
68 }
69 
71 {
72  if ((c == QMetaObject::ReadProperty ||
74  id >= metaObjects->last().propertyOffset) {
75 
76  for (int ii = 0; ii < metaObjects->count(); ++ii) {
77  const ProxyData &data = metaObjects->at(ii);
78  if (id >= data.propertyOffset) {
79  if (!proxies) {
80  proxies = new QObject*[metaObjects->count()];
81  ::memset(proxies, 0,
82  sizeof(QObject *) * metaObjects->count());
83  }
84 
85  if (!proxies[ii]) {
86  QObject *proxy = data.createFunc(object);
87  const QMetaObject *metaObject = proxy->metaObject();
88  proxies[ii] = proxy;
89 
90  int localOffset = data.metaObject->methodOffset();
91  int methodOffset = metaObject->methodOffset();
92  int methods = metaObject->methodCount() - methodOffset;
93 
94  // ### - Can this be done more optimally?
95  for (int jj = 0; jj < methods; ++jj) {
97  metaObject->method(jj + methodOffset);
98  if (method.methodType() == QMetaMethod::Signal)
99  QDeclarativePropertyPrivate::connect(proxy, methodOffset + jj, object, localOffset + jj);
100  }
101  }
102 
103  int proxyOffset = proxies[ii]->metaObject()->propertyOffset();
104  int proxyId = id - data.propertyOffset + proxyOffset;
105 
106  return proxies[ii]->qt_metacall(c, proxyId, a);
107  }
108  }
109  } else if (c == QMetaObject::InvokeMetaMethod &&
110  id >= metaObjects->last().methodOffset) {
111  QMetaMethod m = object->metaObject()->method(id);
112  if (m.methodType() == QMetaMethod::Signal) {
113  QMetaObject::activate(object, id, a);
114  return -1;
115  }
116  }
117 
118  if (parent)
119  return parent->metaCall(c, id, a);
120  else
121  return object->qt_metacall(c, id, a);
122 }
123 
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static bool connect(QObject *sender, int signal_index, const QObject *receiver, int method_index, int type=0, int *types=0)
Connect sender signal_index to receiver method_index with the specified type and types.
long ASN1_INTEGER_get ASN1_INTEGER * a
QDeclarativeProxyMetaObject(QObject *, QList< ProxyData > *)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
virtual int metaCall(QMetaObject::Call, int _id, void **)
Definition: qobject_p.h:336
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
int methodOffset() const
Returns the method offset for this class; i.e.
const uint * data
Definition: qobjectdefs.h:471
MethodType methodType() const
Returns the type of this method (signal, slot, or method).
virtual int metaCall(QMetaObject::Call _c, int _id, void **_a)
static void activate(QObject *sender, int signal_index, void **argv)
Definition: qobject.cpp:3690
QAbstractDynamicMetaObject * parent
QMetaObject * metaObject
Definition: qobject.h:107
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
int propertyOffset() const
Returns the property offset for this class; i.e.
int methodCount() const
Returns the number of methods known to the meta-object system in this class, including the number of ...
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62