author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 12:15:23 +0300 | |
branch | RCL_3 |
changeset 12 | cc75c76972ee |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtScript module of the Qt Toolkit. |
|
8 |
** |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9 |
** $QT_BEGIN_LICENSE:LGPL-ONLY$ |
0 | 10 |
** GNU Lesser General Public License Usage |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11 |
** This file may be used under the terms of the GNU Lesser |
0 | 12 |
** General Public License version 2.1 as published by the Free Software |
13 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
14 |
** packaging of this file. Please review the following information to |
|
15 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
16 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
17 |
** |
|
18 |
** If you have questions regarding the use of this file, please contact |
|
19 |
** Nokia at qt-info@nokia.com. |
|
20 |
** $QT_END_LICENSE$ |
|
21 |
** |
|
22 |
****************************************************************************/ |
|
23 |
||
24 |
#include "qscriptclasspropertyiterator.h" |
|
25 |
||
26 |
#include "qscriptstring.h" |
|
27 |
||
28 |
QT_BEGIN_NAMESPACE |
|
29 |
||
30 |
/*! |
|
31 |
\since 4.4 |
|
32 |
\class QScriptClassPropertyIterator |
|
33 |
||
34 |
\brief The QScriptClassPropertyIterator class provides an iterator interface for custom Qt Script objects. |
|
35 |
||
36 |
\ingroup script |
|
37 |
||
38 |
This class is only relevant if you have subclassed QScriptClass and |
|
39 |
want to provide enumeration of your custom properties (e.g. when |
|
40 |
objects of your class are used with QScriptValueIterator, or with |
|
41 |
the for-in statement in scripts). |
|
42 |
||
43 |
The object() function returns the Qt Script object the iterator is |
|
44 |
traversing. |
|
45 |
||
46 |
toFront(), hasNext() and next() provide forward iteration. |
|
47 |
||
48 |
toBack(), hasPrevious() and previous() provide backward iteration. |
|
49 |
||
50 |
name(), id() and flags() return information about the last property |
|
51 |
that was jumped over using next() or previous(). |
|
52 |
||
53 |
\sa QScriptClass::newIterator(), QScriptValueIterator |
|
54 |
*/ |
|
55 |
||
56 |
class QScriptClassPropertyIteratorPrivate |
|
57 |
{ |
|
58 |
Q_DECLARE_PUBLIC(QScriptClassPropertyIterator) |
|
59 |
public: |
|
60 |
QScriptClassPropertyIteratorPrivate() {} |
|
61 |
virtual ~QScriptClassPropertyIteratorPrivate() {} |
|
62 |
||
63 |
QScriptValue object; |
|
64 |
||
65 |
QScriptClassPropertyIterator *q_ptr; |
|
66 |
}; |
|
67 |
||
68 |
/*! |
|
69 |
Constructs an iterator for traversing \a object. |
|
70 |
||
71 |
Subclasses should ensure that the iterator is set to the front of the |
|
72 |
sequence of properties (before the first property). |
|
73 |
*/ |
|
74 |
QScriptClassPropertyIterator::QScriptClassPropertyIterator(const QScriptValue &object) |
|
75 |
: d_ptr(new QScriptClassPropertyIteratorPrivate) |
|
76 |
{ |
|
77 |
d_ptr->q_ptr = this; |
|
78 |
d_ptr->object = object; |
|
79 |
} |
|
80 |
||
81 |
/*! |
|
82 |
\internal |
|
83 |
*/ |
|
84 |
QScriptClassPropertyIterator::QScriptClassPropertyIterator(const QScriptValue &object, |
|
85 |
QScriptClassPropertyIteratorPrivate &dd) |
|
86 |
: d_ptr(&dd) |
|
87 |
{ |
|
88 |
d_ptr->q_ptr = this; |
|
89 |
d_ptr->object = object; |
|
90 |
} |
|
91 |
||
92 |
/*! |
|
93 |
Destroys the iterator. |
|
94 |
*/ |
|
95 |
QScriptClassPropertyIterator::~QScriptClassPropertyIterator() |
|
96 |
{ |
|
97 |
} |
|
98 |
||
99 |
/*! |
|
100 |
Returns the Qt Script object this iterator is traversing. |
|
101 |
*/ |
|
102 |
QScriptValue QScriptClassPropertyIterator::object() const |
|
103 |
{ |
|
104 |
Q_D(const QScriptClassPropertyIterator); |
|
105 |
return d->object; |
|
106 |
} |
|
107 |
||
108 |
/*! |
|
109 |
\fn bool QScriptClassPropertyIterator::hasNext() const |
|
110 |
||
111 |
Returns true if there is at least one item ahead of the iterator |
|
112 |
(i.e. the iterator is \e not at the back of the property sequence); |
|
113 |
otherwise returns false. |
|
114 |
||
115 |
\sa next(), hasPrevious() |
|
116 |
*/ |
|
117 |
||
118 |
/*! |
|
119 |
\fn void QScriptClassPropertyIterator::next() |
|
120 |
||
121 |
Advances the iterator by one position. |
|
122 |
||
123 |
Calling this function on an iterator located at the back of the |
|
124 |
container leads to undefined results. |
|
125 |
||
126 |
\sa hasNext(), previous(), name() |
|
127 |
*/ |
|
128 |
||
129 |
/*! |
|
130 |
\fn bool QScriptClassPropertyIterator::hasPrevious() const |
|
131 |
||
132 |
Returns true if there is at least one item behind the iterator |
|
133 |
(i.e. the iterator is \e not at the front of the property sequence); |
|
134 |
otherwise returns false. |
|
135 |
||
136 |
\sa previous(), hasNext() |
|
137 |
*/ |
|
138 |
||
139 |
/*! |
|
140 |
\fn void QScriptClassPropertyIterator::previous() |
|
141 |
||
142 |
Moves the iterator back by one position. |
|
143 |
||
144 |
Calling this function on an iterator located at the front of the |
|
145 |
container leads to undefined results. |
|
146 |
||
147 |
\sa hasPrevious(), next(), name() |
|
148 |
*/ |
|
149 |
||
150 |
/*! |
|
151 |
\fn void QScriptClassPropertyIterator::toFront() |
|
152 |
||
153 |
Moves the iterator to the front of the QScriptValue (before the |
|
154 |
first property). |
|
155 |
||
156 |
\sa toBack(), next() |
|
157 |
*/ |
|
158 |
||
159 |
/*! |
|
160 |
\fn void QScriptClassPropertyIterator::toBack() |
|
161 |
||
162 |
Moves the iterator to the back of the QScriptValue (after the |
|
163 |
last property). |
|
164 |
||
165 |
\sa toFront(), previous() |
|
166 |
*/ |
|
167 |
||
168 |
/*! |
|
169 |
\fn QScriptString QScriptClassPropertyIterator::name() const |
|
170 |
||
171 |
Returns the name of the last property that was jumped over using |
|
172 |
next() or previous(). |
|
173 |
||
174 |
\sa id() |
|
175 |
*/ |
|
176 |
||
177 |
/*! |
|
178 |
\fn uint QScriptClassPropertyIterator::id() const |
|
179 |
||
180 |
Returns the id of the last property that was jumped over using |
|
181 |
next() or previous(). |
|
182 |
||
183 |
The default implementation returns 0. |
|
184 |
||
185 |
\sa name() |
|
186 |
*/ |
|
187 |
uint QScriptClassPropertyIterator::id() const |
|
188 |
{ |
|
189 |
return 0; |
|
190 |
} |
|
191 |
||
192 |
/*! |
|
193 |
Returns the flags of the last property that was jumped over using |
|
194 |
next() or previous(). |
|
195 |
||
196 |
The default implementation calls the propertyFlags() function of |
|
197 |
object() with argument name(). |
|
198 |
*/ |
|
199 |
QScriptValue::PropertyFlags QScriptClassPropertyIterator::flags() const |
|
200 |
{ |
|
201 |
return object().propertyFlags(name()); |
|
202 |
} |
|
203 |
||
204 |
QT_END_NAMESPACE |