Qt 4.8
qdeclarativebind.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/qdeclarativebind_p.h"
43 
44 #include "private/qdeclarativenullablevalue_p_p.h"
45 #include "private/qdeclarativeguard_p.h"
46 
47 #include <qdeclarativeengine.h>
48 #include <qdeclarativecontext.h>
49 #include <qdeclarativeproperty.h>
50 
51 #include <QtCore/qfile.h>
52 #include <QtCore/qdebug.h>
53 #include <QtScript/qscriptvalue.h>
54 #include <QtScript/qscriptcontext.h>
55 #include <QtScript/qscriptengine.h>
56 
57 #include <private/qobject_p.h>
58 
60 
62 {
63 public:
65 
66  bool when : 1;
71 };
72 
73 
104  : QObject(*(new QDeclarativeBindPrivate), parent)
105 {
106 }
107 
109 {
110 }
111 
128 bool QDeclarativeBind::when() const
129 {
130  Q_D(const QDeclarativeBind);
131  return d->when;
132 }
133 
135 {
137  d->when = v;
138  eval();
139 }
140 
150 {
151  Q_D(const QDeclarativeBind);
152  return d->obj;
153 }
154 
156 {
158  d->obj = obj;
159  eval();
160 }
161 
171 {
172  Q_D(const QDeclarativeBind);
173  return d->prop;
174 }
175 
177 {
179  d->prop = p;
180  eval();
181 }
182 
193 {
194  Q_D(const QDeclarativeBind);
195  return d->value.value;
196 }
197 
199 {
201  d->value.value = v;
202  d->value.isNull = false;
203  eval();
204 }
205 
207 {
209  d->componentComplete = false;
210 }
211 
213 {
215  d->componentComplete = true;
216  eval();
217 }
218 
220 {
222  if (!d->obj || d->value.isNull || !d->when || !d->componentComplete)
223  return;
224 
225  QDeclarativeProperty prop(d->obj, d->prop);
226  prop.write(d->value.value);
227 }
228 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QDeclarativeBind(QObject *parent=0)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QDeclarativeParserStatus ** d
QString property() const
virtual void classBegin()
Invoked after class creation, but before any properties have been set.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDeclarativeNullableValue< QVariant > value
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
void setObject(QObject *)
virtual void componentComplete()=0
Invoked after the root component that caused this instantiation has completed construction.
bool when() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QDeclarativeGuard< QObject > obj
QVariant value() const
void setProperty(const QString &)
void setValue(const QVariant &)
virtual void componentComplete()
Invoked after the root component that caused this instantiation has completed construction.
QObject * parent
Definition: qobject.h:92
The QDeclarativeProperty class abstracts accessing properties on objects created from QML...
bool write(const QVariant &) const
Sets the property value to value and returns true.