source: trunk/src/declarative/qml/qdeclarativescriptstring.cpp@ 1147

Last change on this file since 1147 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 4.4 KB
Line 
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** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qdeclarativescriptstring.h"
43
44QT_BEGIN_NAMESPACE
45
46class QDeclarativeScriptStringPrivate : public QSharedData
47{
48public:
49 QDeclarativeScriptStringPrivate() : context(0), scope(0) {}
50
51 QDeclarativeContext *context;
52 QObject *scope;
53 QString script;
54};
55
56/*!
57\class QDeclarativeScriptString
58\since 4.7
59\brief The QDeclarativeScriptString class encapsulates a script and its context.
60
61QDeclarativeScriptString is used to create QObject properties that accept a script "assignment" from QML.
62
63Normally, the following QML would result in a binding being established for the \c script
64property; i.e. \c script would be assigned the value obtained from running \c {myObj.value = Math.max(myValue, 100)}
65
66\qml
67MyType {
68 script: myObj.value = Math.max(myValue, 100)
69}
70\endqml
71
72If instead the property had a type of QDeclarativeScriptString,
73the script itself -- \e {myObj.value = Math.max(myValue, 100)} -- would be passed to the \c script property
74and the class could choose how to handle it. Typically, the class will evaluate
75the script at some later time using a QDeclarativeExpression.
76
77\code
78QDeclarativeExpression expr(scriptString.context(), scriptString.script(), scriptStr.scopeObject());
79expr.value();
80\endcode
81
82\sa QDeclarativeExpression
83*/
84
85/*!
86Constructs an empty instance.
87*/
88QDeclarativeScriptString::QDeclarativeScriptString()
89: d(new QDeclarativeScriptStringPrivate)
90{
91}
92
93/*!
94Copies \a other.
95*/
96QDeclarativeScriptString::QDeclarativeScriptString(const QDeclarativeScriptString &other)
97: d(other.d)
98{
99}
100
101/*!
102\internal
103*/
104QDeclarativeScriptString::~QDeclarativeScriptString()
105{
106}
107
108/*!
109Assigns \a other to this.
110*/
111QDeclarativeScriptString &QDeclarativeScriptString::operator=(const QDeclarativeScriptString &other)
112{
113 d = other.d;
114 return *this;
115}
116
117/*!
118Returns the context for the script.
119*/
120QDeclarativeContext *QDeclarativeScriptString::context() const
121{
122 return d->context;
123}
124
125/*!
126Sets the \a context for the script.
127*/
128void QDeclarativeScriptString::setContext(QDeclarativeContext *context)
129{
130 d->context = context;
131}
132
133/*!
134Returns the scope object for the script.
135*/
136QObject *QDeclarativeScriptString::scopeObject() const
137{
138 return d->scope;
139}
140
141/*!
142Sets the scope \a object for the script.
143*/
144void QDeclarativeScriptString::setScopeObject(QObject *object)
145{
146 d->scope = object;
147}
148
149/*!
150Returns the script text.
151*/
152QString QDeclarativeScriptString::script() const
153{
154 return d->script;
155}
156
157/*!
158Sets the \a script text.
159*/
160void QDeclarativeScriptString::setScript(const QString &script)
161{
162 d->script = script;
163}
164
165QT_END_NAMESPACE
166
Note: See TracBrowser for help on using the repository browser.