Merge branch 'master' of git://scm.dev.nokia.troll.no/qt/qtdeclarative
[profile/ivi/qtdeclarative.git] / src / declarative / qml / qdeclarativeproperty_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
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 QDeclarativeEnginePrivate;
67 class QDeclarativeExpression;
68 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativePropertyPrivate : public QDeclarativeRefCount
69 {
70 public:
71     enum WriteFlag { BypassInterceptor = 0x01, DontRemoveBinding = 0x02, RemoveBindingOnAliasWrite = 0x04 };
72     Q_DECLARE_FLAGS(WriteFlags, WriteFlag)
73
74     QDeclarativePropertyPrivate()
75         : context(0), engine(0), object(0), isNameCached(false) {}
76
77     QDeclarativeContextData *context;
78     QDeclarativeEngine *engine;
79     QDeclarativeGuard<QObject> object;
80
81     bool isNameCached:1;
82     QDeclarativePropertyCache::Data core;
83     QString nameCache;
84
85     // Describes the "virtual" value-type sub-property.  
86     QDeclarativePropertyCache::ValueTypeData valueType;
87
88     void initProperty(QObject *obj, const QString &name);
89     void initDefault(QObject *obj);
90
91     bool isValueType() const;
92     int propertyType() const;
93     QDeclarativeProperty::Type type() const;
94     QDeclarativeProperty::PropertyTypeCategory propertyTypeCategory() const;
95
96     QVariant readValueProperty();
97     bool writeValueProperty(const QVariant &, WriteFlags);
98
99     static const QMetaObject *rawMetaObjectForType(QDeclarativeEnginePrivate *, int);
100     static bool writeEnumProperty(const QMetaProperty &prop, int idx, QObject *object, 
101                                   const QVariant &value, int flags);
102     static bool write(QObject *, const QDeclarativePropertyCache::Data &, const QVariant &, 
103                       QDeclarativeContextData *, WriteFlags flags = 0);
104     static void findAliasTarget(QObject *, int, QObject **, int *);
105     static QDeclarativeAbstractBinding *setBinding(QObject *, int coreIndex, int valueTypeIndex /* -1 */,
106                                                    QDeclarativeAbstractBinding *,
107                                                    WriteFlags flags = DontRemoveBinding);
108     static QDeclarativeAbstractBinding *setBindingNoEnable(QObject *, int coreIndex, int valueTypeIndex /* -1 */,
109                                                            QDeclarativeAbstractBinding *);
110     static QDeclarativeAbstractBinding *binding(QObject *, int coreIndex, int valueTypeIndex /* -1 */);
111
112     static QByteArray saveValueType(const QMetaObject *, int, 
113                                     const QMetaObject *, int);
114     static QByteArray saveProperty(const QMetaObject *, int);
115
116     static QDeclarativeProperty restore(const QByteArray &, QObject *, QDeclarativeContextData *);
117     static QDeclarativeProperty restore(const QDeclarativePropertyCache::Data &,
118                                         const QDeclarativePropertyCache::ValueTypeData &,
119                                         QObject *,
120                                         QDeclarativeContextData *);
121
122     static bool equal(const QMetaObject *, const QMetaObject *);
123     static bool canConvert(const QMetaObject *from, const QMetaObject *to);
124
125     // "Public" (to QML) methods
126     static QDeclarativeAbstractBinding *binding(const QDeclarativeProperty &that);
127     static QDeclarativeAbstractBinding *setBinding(const QDeclarativeProperty &that,
128                                                    QDeclarativeAbstractBinding *,
129                                                    WriteFlags flags = DontRemoveBinding);
130     static QDeclarativeExpression *signalExpression(const QDeclarativeProperty &that);
131     static QDeclarativeExpression *setSignalExpression(const QDeclarativeProperty &that, 
132                                                        QDeclarativeExpression *) ;
133     static bool write(const QDeclarativeProperty &that, const QVariant &, WriteFlags);
134     static int valueTypeCoreIndex(const QDeclarativeProperty &that);
135     static int bindingIndex(const QDeclarativeProperty &that);
136     static QMetaMethod findSignalByName(const QMetaObject *mo, const QByteArray &);
137     static bool connect(const QObject *sender, int signal_index,
138                         const QObject *receiver, int method_index,
139                         int type = 0, int *types = 0);
140     static const QMetaObject *metaObjectForProperty(const QMetaObject *, int);
141 };
142
143 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativePropertyPrivate::WriteFlags)
144
145 QT_END_NAMESPACE
146
147 #endif // QDECLARATIVEPROPERTY_P_H