Qt 4.8
qdeclarativebinding_p.h
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 #ifndef QDECLARATIVEBINDING_P_H
43 #define QDECLARATIVEBINDING_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 "qdeclarative.h"
58 #include "qdeclarativeexpression.h"
59 #include "qdeclarativeproperty.h"
60 #include "private/qdeclarativeproperty_p.h"
61 
62 #include <QtCore/QObject>
63 #include <QtCore/QMetaProperty>
64 
66 
68 {
69 public:
71 
73 
74  enum DestroyMode {
75  // The binding should disconnect itself upon destroy
77 
78  // The binding doesn't need to disconnect itself, but it can if it wants to.
79  //
80  // This is used in QDeclarativeData::destroyed() - at the point at which the bindings are
81  // destroyed, the notifiers are already disconnected, so no need to disconnect each
82  // binding again.
83  //
84  // Bindings can use this flag to speed up destruction, especially for compiled bindings
85  // disconnecting a single binding might be slow.
86  KeepBindingConnected
87  };
88 
89  virtual void destroy(DestroyMode mode = DisconnectBinding);
90 
91  virtual QString expression() const;
92 
94 
95  // Just this single binding is getting disconnected, other bindings remain connected and
96  // should not be changed.
98 
99  // All bindings of the same object are getting disconnected. As an optimization, it is
100  // therefore valid to disconnect all bindings in one go.
101  DisconnectAll
102  };
103 
104  // disconnectMode can be ignored, it is just a hint for potential optimization
105  virtual void disconnect(DisconnectMode disconnectMode) = 0;
106 
107  enum Type { PropertyBinding, ValueTypeProxy };
108  virtual Type bindingType() const { return PropertyBinding; }
109 
110  QObject *object() const;
111  int propertyIndex() const;
112 
114  virtual void setEnabled(bool, QDeclarativePropertyPrivate::WriteFlags) = 0;
115 
117  virtual void update(QDeclarativePropertyPrivate::WriteFlags) = 0;
118 
119  void addToObject(QObject *, int);
120  void removeFromObject();
121 
122  static Pointer getPointer(QDeclarativeAbstractBinding *p) { return p ? p->weakPointer() : Pointer(); }
123 
124 protected:
125  virtual ~QDeclarativeAbstractBinding();
126  void clear();
127 
128 private:
129  Pointer weakPointer();
130 
131  friend class QDeclarativeData;
135  friend class QDeclarativeVME;
136  friend class QtSharedPointer::ExternalRefCount<QDeclarativeAbstractBinding>;
137 
144 };
145 
147 {
148 public:
149  QDeclarativeValueTypeProxyBinding(QObject *o, int coreIndex);
150 
151  virtual Type bindingType() const { return ValueTypeProxy; }
152 
153  virtual void setEnabled(bool, QDeclarativePropertyPrivate::WriteFlags);
154  virtual void update(QDeclarativePropertyPrivate::WriteFlags);
155  virtual void disconnect(DisconnectMode disconnectMode);
156 
157  QDeclarativeAbstractBinding *binding(int propertyIndex);
158 
159  void removeBindings(quint32 mask);
160 
161 protected:
163 
164 private:
165  void recursiveEnable(QDeclarativeAbstractBinding *, QDeclarativePropertyPrivate::WriteFlags);
166  void recursiveDisable(QDeclarativeAbstractBinding *);
167 
170  int m_index;
172 };
173 
174 class QDeclarativeContext;
177 {
178 Q_OBJECT
179 public:
180  enum EvaluateFlag { RequiresThisObject = 0x01 };
181  Q_DECLARE_FLAGS(EvaluateFlags, EvaluateFlag)
182 
186  const QString &, int, QObject *parent);
188 
189  void setTarget(const QDeclarativeProperty &);
191 
192  void setEvaluateFlags(EvaluateFlags flags);
193  EvaluateFlags evaluateFlags() const;
194 
195  bool enabled() const;
196 
197  // Inherited from QDeclarativeAbstractBinding
198  virtual void setEnabled(bool, QDeclarativePropertyPrivate::WriteFlags flags);
199  virtual void update(QDeclarativePropertyPrivate::WriteFlags flags);
200  virtual QString expression() const;
201  virtual void disconnect(DisconnectMode disconnectMode);
202 
203  typedef int Identifier;
204  static Identifier Invalid;
205  static QDeclarativeBinding *createBinding(Identifier, QObject *, QDeclarativeContext *, const QString &, int, QObject *parent=0);
206 
207 public Q_SLOTS:
209 
210 protected:
212  void emitValueChanged();
213 
214 private:
216 };
217 
218 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeBinding::EvaluateFlags)
219 
221 
223 
224 #endif // QDECLARATIVEBINDING_P_H
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
static Pointer getPointer(QDeclarativeAbstractBinding *p)
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static Identifier Invalid
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
QDeclarativeAbstractBinding * m_nextBinding
#define Q_DECLARATIVE_PRIVATE_EXPORT
#define Q_OBJECT
Definition: qobjectdefs.h:157
#define Q_DECLARE_METATYPE(TYPE)
This macro makes the type Type known to QMetaType as long as it provides a public default constructor...
Definition: qmetatype.h:265
QDeclarativeAbstractBinding * m_bindings
unsigned int quint32
Definition: qglobal.h:938
const char * property
Definition: qwizard.cpp:138
The QDeclarativeContext class defines a context within a QML engine.
The QDeclarativeProperty class abstracts accessing properties on objects created from QML...
QSharedPointer< QDeclarativeAbstractBinding > m_selfPointer
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
The QDeclarativeExpression class evaluates JavaScript in a QML context.
QDeclarativeAbstractBinding ** m_prevBinding
QWeakPointer< QDeclarativeAbstractBinding > Pointer
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define enabled
QDeclarativeAbstractBinding ** m_mePtr