1edd611711521f025573079cbafd6e3d797864e3
[profile/ivi/qtdeclarative.git] / src / declarative / qml / qdeclarativeproperty_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDECLARATIVEPROPERTY_P_H
43 #define QDECLARATIVEPROPERTY_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include "qdeclarativeproperty.h"
57
58 #include <private/qobject_p.h>
59 #include <private/qdeclarativeglobal_p.h>
60 #include <private/qdeclarativepropertycache_p.h>
61 #include <private/qdeclarativeguard_p.h>
62
63 QT_BEGIN_NAMESPACE
64
65 class QDeclarativeContext;
66 class QDeclarativeExpression;
67 class QDeclarativeEnginePrivate;
68 class QDeclarativeJavaScriptExpression;
69 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativePropertyPrivate : public QDeclarativeRefCount
70 {
71 public:
72     enum WriteFlag {
73         BypassInterceptor = 0x01,
74         DontRemoveBinding = 0x02,
75         RemoveBindingOnAliasWrite = 0x04
76     };
77     Q_DECLARE_FLAGS(WriteFlags, WriteFlag)
78
79     QDeclarativeContextData *context;
80     QDeclarativeEngine *engine;
81     QDeclarativeGuard<QObject> object;
82
83     QDeclarativePropertyData core;
84
85     bool isNameCached:1;
86     QString nameCache;
87
88     QDeclarativePropertyPrivate();
89
90     inline QDeclarativeContextData *effectiveContext() const;
91
92     void initProperty(QObject *obj, const QString &name);
93     void initDefault(QObject *obj);
94
95     bool isValueType() const;
96     int propertyType() const;
97     QDeclarativeProperty::Type type() const;
98     QDeclarativeProperty::PropertyTypeCategory propertyTypeCategory() const;
99
100     QVariant readValueProperty();
101     bool writeValueProperty(const QVariant &, WriteFlags);
102
103     static const QMetaObject *rawMetaObjectForType(QDeclarativeEnginePrivate *, int);
104     static bool writeEnumProperty(const QMetaProperty &prop, int idx, QObject *object, 
105                                   const QVariant &value, int flags);
106     static bool writeValueProperty(QObject *, QDeclarativeEngine *,
107                                    const QDeclarativePropertyData &,
108                                    const QVariant &, QDeclarativeContextData *, 
109                                    WriteFlags flags = 0);
110     static bool write(QObject *, const QDeclarativePropertyData &, const QVariant &,
111                       QDeclarativeContextData *, WriteFlags flags = 0);
112     static void findAliasTarget(QObject *, int, QObject **, int *);
113     static QDeclarativeAbstractBinding *setBinding(QObject *, int coreIndex,
114                                                    int valueTypeIndex /* -1 */,
115                                                    QDeclarativeAbstractBinding *,
116                                                    WriteFlags flags = DontRemoveBinding);
117     static QDeclarativeAbstractBinding *setBindingNoEnable(QObject *, int coreIndex,
118                                                            int valueTypeIndex /* -1 */,
119                                                            QDeclarativeAbstractBinding *);
120     static QDeclarativeAbstractBinding *binding(QObject *, int coreIndex,
121                                                 int valueTypeIndex /* -1 */);
122
123     static QDeclarativePropertyData saveValueType(const QMetaObject *, int,
124                                                   const QMetaObject *, int,
125                                                   QDeclarativeEngine *);
126     static QDeclarativeProperty restore(QObject *,
127                                         const QDeclarativePropertyData &,
128                                         QDeclarativeContextData *);
129
130     static bool equal(const QMetaObject *, const QMetaObject *);
131     static bool canConvert(const QMetaObject *from, const QMetaObject *to);
132     static inline QDeclarativePropertyPrivate *get(const QDeclarativeProperty &p) {
133         return p.d;
134     }
135
136     // "Public" (to QML) methods
137     static QDeclarativeAbstractBinding *binding(const QDeclarativeProperty &that);
138     static QDeclarativeAbstractBinding *setBinding(const QDeclarativeProperty &that,
139                                                    QDeclarativeAbstractBinding *,
140                                                    WriteFlags flags = DontRemoveBinding);
141     static QDeclarativeExpression *signalExpression(const QDeclarativeProperty &that);
142     static QDeclarativeExpression *setSignalExpression(const QDeclarativeProperty &that, 
143                                                        QDeclarativeExpression *) ;
144     static bool write(const QDeclarativeProperty &that, const QVariant &, WriteFlags);
145     static bool writeBinding(const QDeclarativeProperty &that, 
146                              QDeclarativeJavaScriptExpression *expression, 
147                              v8::Handle<v8::Value> result, bool isUndefined,
148                              WriteFlags flags);
149     static bool writeBinding(QObject *, const QDeclarativePropertyData &,
150                              QDeclarativeJavaScriptExpression *expression, 
151                              v8::Handle<v8::Value> result, bool isUndefined,
152                              WriteFlags flags);
153     static int valueTypeCoreIndex(const QDeclarativeProperty &that);
154     static int bindingIndex(const QDeclarativeProperty &that);
155     static int bindingIndex(const QDeclarativePropertyData &that);
156     static QMetaMethod findSignalByName(const QMetaObject *mo, const QByteArray &);
157     static bool connect(const QObject *sender, int signal_index,
158                         const QObject *receiver, int method_index,
159                         int type = 0, int *types = 0);
160     static const QMetaObject *metaObjectForProperty(const QMetaObject *, int);
161     static void flushSignal(const QObject *sender, int signal_index);
162 };
163
164 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativePropertyPrivate::WriteFlags)
165
166 QT_END_NAMESPACE
167
168 #endif // QDECLARATIVEPROPERTY_P_H