~saviq/ubuntu/saucy/qtdeclarative-opensource-src/add-qtquick-delegate-range

« back to all changes in this revision

Viewing changes to src/qml/qml/qqmlbinding_p.h

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 14:17:19 UTC
  • Revision ID: package-import@ubuntu.com-20130205141719-qqeyml8wslpyez52
Tags: upstream-5.0.1
ImportĀ upstreamĀ versionĀ 5.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtQml 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
#ifndef QQMLBINDING_P_H
 
43
#define QQMLBINDING_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 "qqml.h"
 
57
#include "qqmlpropertyvaluesource.h"
 
58
#include "qqmlexpression.h"
 
59
#include "qqmlproperty.h"
 
60
#include "qqmlscriptstring.h"
 
61
#include "qqmlproperty_p.h"
 
62
 
 
63
#include <QtCore/QObject>
 
64
#include <QtCore/QMetaProperty>
 
65
 
 
66
#include <private/qpointervaluepair_p.h>
 
67
#include <private/qqmlabstractbinding_p.h>
 
68
#include <private/qqmlabstractexpression_p.h>
 
69
#include <private/qqmljavascriptexpression_p.h>
 
70
 
 
71
QT_BEGIN_NAMESPACE
 
72
 
 
73
class QQmlContext;
 
74
class Q_QML_PRIVATE_EXPORT QQmlBinding : public QQmlJavaScriptExpression,
 
75
                                         public QQmlAbstractExpression,
 
76
                                         public QQmlAbstractBinding
 
77
{
 
78
public:
 
79
    enum EvaluateFlag { None = 0x00, RequiresThisObject = 0x01 };
 
80
    Q_DECLARE_FLAGS(EvaluateFlags, EvaluateFlag)
 
81
 
 
82
    QQmlBinding(const QString &, QObject *, QQmlContext *);
 
83
    QQmlBinding(const QQmlScriptString &, QObject *, QQmlContext *);
 
84
    QQmlBinding(const QString &, QObject *, QQmlContextData *);
 
85
    QQmlBinding(const QString &, bool isRewritten, QObject *, QQmlContextData *, 
 
86
                const QString &url, quint16 lineNumber, quint16 columnNumber);
 
87
    QQmlBinding(void *, QObject *, QQmlContextData *,
 
88
                const QString &url, quint16 lineNumber, quint16 columnNumber);
 
89
 
 
90
    void setTarget(const QQmlProperty &);
 
91
    void setTarget(QObject *, const QQmlPropertyData &, QQmlContextData *);
 
92
    QQmlProperty property() const;
 
93
 
 
94
    void setEvaluateFlags(EvaluateFlags flags);
 
95
    EvaluateFlags evaluateFlags() const;
 
96
 
 
97
    void setNotifyOnValueChanged(bool);
 
98
 
 
99
    // Inherited from  QQmlAbstractExpression
 
100
    virtual void refresh();
 
101
 
 
102
    // "Inherited" from  QQmlAbstractBinding
 
103
    static QString expression(const QQmlAbstractBinding *);
 
104
    static int propertyIndex(const QQmlAbstractBinding *);
 
105
    static QObject *object(const QQmlAbstractBinding *);
 
106
    static void setEnabled(QQmlAbstractBinding *, bool, QQmlPropertyPrivate::WriteFlags);
 
107
    static void update(QQmlAbstractBinding *, QQmlPropertyPrivate::WriteFlags);
 
108
    static void retargetBinding(QQmlAbstractBinding *, QObject *, int);
 
109
 
 
110
    void setEnabled(bool, QQmlPropertyPrivate::WriteFlags flags);
 
111
    void update(QQmlPropertyPrivate::WriteFlags flags);
 
112
    void update() { update(QQmlPropertyPrivate::DontRemoveBinding); }
 
113
 
 
114
    QString expression() const;
 
115
    QObject *object() const;
 
116
    int propertyIndex() const;
 
117
    void retargetBinding(QObject *, int);
 
118
 
 
119
    typedef int Identifier;
 
120
    static Identifier Invalid;
 
121
 
 
122
    static QQmlBinding *createBinding(Identifier, QObject *, QQmlContext *, const QString &, quint16);
 
123
 
 
124
    QVariant evaluate();
 
125
 
 
126
    static QString expressionIdentifier(QQmlJavaScriptExpression *);
 
127
    static void expressionChanged(QQmlJavaScriptExpression *);
 
128
 
 
129
protected:
 
130
    friend class QQmlAbstractBinding;
 
131
    ~QQmlBinding();
 
132
 
 
133
private:
 
134
    v8::Persistent<v8::Function> v8function;
 
135
 
 
136
    inline bool updatingFlag() const;
 
137
    inline void setUpdatingFlag(bool);
 
138
    inline bool enabledFlag() const;
 
139
    inline void setEnabledFlag(bool);
 
140
 
 
141
    struct Retarget {
 
142
        QObject *target;
 
143
        int targetProperty;
 
144
    };
 
145
 
 
146
    QPointerValuePair<QObject, Retarget> m_coreObject;
 
147
    QQmlPropertyData m_core;
 
148
    // We store some flag bits in the following flag pointers.
 
149
    //    m_ctxt:flag1 - updatingFlag
 
150
    //    m_ctxt:flag2 - enabledFlag
 
151
    QFlagPointer<QQmlContextData> m_ctxt;
 
152
 
 
153
    // XXX It would be good if we could get rid of these in most circumstances
 
154
    QString m_url;
 
155
    quint16 m_lineNumber;
 
156
    quint16 m_columnNumber;
 
157
    QByteArray m_expression;
 
158
};
 
159
 
 
160
bool QQmlBinding::updatingFlag() const
 
161
{
 
162
    return m_ctxt.flag();
 
163
}
 
164
 
 
165
void QQmlBinding::setUpdatingFlag(bool v)
 
166
{
 
167
    m_ctxt.setFlagValue(v);
 
168
}
 
169
 
 
170
bool QQmlBinding::enabledFlag() const
 
171
{
 
172
    return m_ctxt.flag2();
 
173
}
 
174
 
 
175
void QQmlBinding::setEnabledFlag(bool v)
 
176
{
 
177
    m_ctxt.setFlag2Value(v);
 
178
}
 
179
 
 
180
Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlBinding::EvaluateFlags)
 
181
 
 
182
QT_END_NAMESPACE
 
183
 
 
184
Q_DECLARE_METATYPE(QQmlBinding*)
 
185
 
 
186
#endif // QQMLBINDING_P_H