|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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 QtSCriptTools module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qscriptdebuggerevent_p.h" |
|
43 #include "qscriptdebuggervalue_p.h" |
|
44 |
|
45 #include <QtCore/qhash.h> |
|
46 #include <QtCore/qdatastream.h> |
|
47 |
|
48 Q_DECLARE_METATYPE(QScriptDebuggerValue) |
|
49 |
|
50 QT_BEGIN_NAMESPACE |
|
51 |
|
52 class QScriptDebuggerEventPrivate |
|
53 { |
|
54 public: |
|
55 QScriptDebuggerEventPrivate(); |
|
56 ~QScriptDebuggerEventPrivate(); |
|
57 |
|
58 QScriptDebuggerEvent::Type type; |
|
59 QHash<QScriptDebuggerEvent::Attribute, QVariant> attributes; |
|
60 }; |
|
61 |
|
62 QScriptDebuggerEventPrivate::QScriptDebuggerEventPrivate() |
|
63 : type(QScriptDebuggerEvent::None) |
|
64 { |
|
65 } |
|
66 |
|
67 QScriptDebuggerEventPrivate::~QScriptDebuggerEventPrivate() |
|
68 { |
|
69 } |
|
70 |
|
71 QScriptDebuggerEvent::QScriptDebuggerEvent() |
|
72 : d_ptr(new QScriptDebuggerEventPrivate) |
|
73 { |
|
74 d_ptr->type = None; |
|
75 } |
|
76 |
|
77 QScriptDebuggerEvent::QScriptDebuggerEvent(Type type) |
|
78 : d_ptr(new QScriptDebuggerEventPrivate) |
|
79 { |
|
80 d_ptr->type = type; |
|
81 } |
|
82 |
|
83 QScriptDebuggerEvent::QScriptDebuggerEvent(Type type, qint64 scriptId, |
|
84 int lineNumber, int columnNumber) |
|
85 : d_ptr(new QScriptDebuggerEventPrivate) |
|
86 { |
|
87 d_ptr->type = type; |
|
88 d_ptr->attributes[ScriptID] = scriptId; |
|
89 d_ptr->attributes[LineNumber] = lineNumber; |
|
90 d_ptr->attributes[ColumnNumber] = columnNumber; |
|
91 } |
|
92 |
|
93 QScriptDebuggerEvent::QScriptDebuggerEvent(const QScriptDebuggerEvent &other) |
|
94 : d_ptr(new QScriptDebuggerEventPrivate) |
|
95 { |
|
96 *d_ptr = *other.d_ptr; |
|
97 } |
|
98 |
|
99 QScriptDebuggerEvent::~QScriptDebuggerEvent() |
|
100 { |
|
101 } |
|
102 |
|
103 QScriptDebuggerEvent &QScriptDebuggerEvent::operator=(const QScriptDebuggerEvent &other) |
|
104 { |
|
105 *d_ptr = *other.d_ptr; |
|
106 return *this; |
|
107 } |
|
108 |
|
109 QScriptDebuggerEvent::Type QScriptDebuggerEvent::type() const |
|
110 { |
|
111 Q_D(const QScriptDebuggerEvent); |
|
112 return d->type; |
|
113 } |
|
114 |
|
115 QVariant QScriptDebuggerEvent::attribute(Attribute attribute, |
|
116 const QVariant &defaultValue) const |
|
117 { |
|
118 Q_D(const QScriptDebuggerEvent); |
|
119 return d->attributes.value(attribute, defaultValue); |
|
120 } |
|
121 |
|
122 void QScriptDebuggerEvent::setAttribute(Attribute attribute, |
|
123 const QVariant &value) |
|
124 { |
|
125 Q_D(QScriptDebuggerEvent); |
|
126 if (!value.isValid()) |
|
127 d->attributes.remove(attribute); |
|
128 else |
|
129 d->attributes[attribute] = value; |
|
130 } |
|
131 |
|
132 QHash<QScriptDebuggerEvent::Attribute, QVariant> QScriptDebuggerEvent::attributes() const |
|
133 { |
|
134 Q_D(const QScriptDebuggerEvent); |
|
135 return d->attributes; |
|
136 } |
|
137 |
|
138 qint64 QScriptDebuggerEvent::scriptId() const |
|
139 { |
|
140 Q_D(const QScriptDebuggerEvent); |
|
141 return d->attributes.value(ScriptID, -1).toLongLong(); |
|
142 } |
|
143 |
|
144 void QScriptDebuggerEvent::setScriptId(qint64 id) |
|
145 { |
|
146 Q_D(QScriptDebuggerEvent); |
|
147 d->attributes[ScriptID] = id; |
|
148 } |
|
149 |
|
150 QString QScriptDebuggerEvent::fileName() const |
|
151 { |
|
152 Q_D(const QScriptDebuggerEvent); |
|
153 return d->attributes.value(FileName).toString(); |
|
154 } |
|
155 |
|
156 void QScriptDebuggerEvent::setFileName(const QString &fileName) |
|
157 { |
|
158 Q_D(QScriptDebuggerEvent); |
|
159 d->attributes[FileName] = fileName; |
|
160 } |
|
161 |
|
162 int QScriptDebuggerEvent::lineNumber() const |
|
163 { |
|
164 Q_D(const QScriptDebuggerEvent); |
|
165 return d->attributes.value(LineNumber, -1).toInt(); |
|
166 } |
|
167 |
|
168 void QScriptDebuggerEvent::setLineNumber(int lineNumber) |
|
169 { |
|
170 Q_D(QScriptDebuggerEvent); |
|
171 d->attributes[LineNumber] = lineNumber; |
|
172 } |
|
173 |
|
174 int QScriptDebuggerEvent::columnNumber() const |
|
175 { |
|
176 Q_D(const QScriptDebuggerEvent); |
|
177 return d->attributes.value(ColumnNumber, -1).toInt(); |
|
178 } |
|
179 |
|
180 void QScriptDebuggerEvent::setColumnNumber(int columnNumber) |
|
181 { |
|
182 Q_D(QScriptDebuggerEvent); |
|
183 d->attributes[ColumnNumber] = columnNumber; |
|
184 } |
|
185 |
|
186 int QScriptDebuggerEvent::breakpointId() const |
|
187 { |
|
188 Q_D(const QScriptDebuggerEvent); |
|
189 return d->attributes.value(BreakpointID, -1).toInt(); |
|
190 } |
|
191 |
|
192 void QScriptDebuggerEvent::setBreakpointId(int id) |
|
193 { |
|
194 Q_D(QScriptDebuggerEvent); |
|
195 d->attributes[BreakpointID] = id; |
|
196 } |
|
197 |
|
198 QString QScriptDebuggerEvent::message() const |
|
199 { |
|
200 Q_D(const QScriptDebuggerEvent); |
|
201 return d->attributes.value(Message).toString(); |
|
202 } |
|
203 |
|
204 void QScriptDebuggerEvent::setMessage(const QString &message) |
|
205 { |
|
206 Q_D(QScriptDebuggerEvent); |
|
207 d->attributes[Message] = message; |
|
208 } |
|
209 |
|
210 QScriptDebuggerValue QScriptDebuggerEvent::scriptValue() const |
|
211 { |
|
212 Q_D(const QScriptDebuggerEvent); |
|
213 return qvariant_cast<QScriptDebuggerValue>(d->attributes[Value]); |
|
214 } |
|
215 |
|
216 void QScriptDebuggerEvent::setScriptValue(const QScriptDebuggerValue &value) |
|
217 { |
|
218 Q_D(QScriptDebuggerEvent); |
|
219 d->attributes[Value] = qVariantFromValue(value); |
|
220 } |
|
221 |
|
222 void QScriptDebuggerEvent::setNestedEvaluate(bool nested) |
|
223 { |
|
224 Q_D(QScriptDebuggerEvent); |
|
225 d->attributes[IsNestedEvaluate] = nested; |
|
226 } |
|
227 |
|
228 bool QScriptDebuggerEvent::isNestedEvaluate() const |
|
229 { |
|
230 Q_D(const QScriptDebuggerEvent); |
|
231 return d->attributes.value(IsNestedEvaluate).toBool(); |
|
232 } |
|
233 |
|
234 void QScriptDebuggerEvent::setHasExceptionHandler(bool hasHandler) |
|
235 { |
|
236 Q_D(QScriptDebuggerEvent); |
|
237 d->attributes[HasExceptionHandler] = hasHandler; |
|
238 } |
|
239 |
|
240 bool QScriptDebuggerEvent::hasExceptionHandler() const |
|
241 { |
|
242 Q_D(const QScriptDebuggerEvent); |
|
243 return d->attributes.value(HasExceptionHandler).toBool(); |
|
244 } |
|
245 |
|
246 /*! |
|
247 Returns true if this QScriptDebuggerEvent is equal to the \a other |
|
248 event, otherwise returns false. |
|
249 */ |
|
250 bool QScriptDebuggerEvent::operator==(const QScriptDebuggerEvent &other) const |
|
251 { |
|
252 Q_D(const QScriptDebuggerEvent); |
|
253 const QScriptDebuggerEventPrivate *od = other.d_func(); |
|
254 if (d == od) |
|
255 return true; |
|
256 if (!d || !od) |
|
257 return false; |
|
258 return ((d->type == od->type) |
|
259 && (d->attributes == od->attributes)); |
|
260 } |
|
261 |
|
262 /*! |
|
263 Returns true if this QScriptDebuggerEvent is not equal to the \a |
|
264 other event, otherwise returns false. |
|
265 */ |
|
266 bool QScriptDebuggerEvent::operator!=(const QScriptDebuggerEvent &other) const |
|
267 { |
|
268 return !(*this == other); |
|
269 } |
|
270 |
|
271 /*! |
|
272 \fn QDataStream &operator<<(QDataStream &stream, const QScriptDebuggerEvent &event) |
|
273 \relates QScriptDebuggerEvent |
|
274 |
|
275 Writes the given \a event to the specified \a stream. |
|
276 */ |
|
277 QDataStream &operator<<(QDataStream &out, const QScriptDebuggerEvent &event) |
|
278 { |
|
279 const QScriptDebuggerEventPrivate *d = event.d_ptr.data(); |
|
280 out << (quint32)d->type; |
|
281 out << (qint32)d->attributes.size(); |
|
282 QHash<QScriptDebuggerEvent::Attribute, QVariant>::const_iterator it; |
|
283 for (it = d->attributes.constBegin(); it != d->attributes.constEnd(); ++it) { |
|
284 out << (quint32)it.key(); |
|
285 out << it.value(); |
|
286 } |
|
287 return out; |
|
288 } |
|
289 |
|
290 /*! |
|
291 \fn QDataStream &operator>>(QDataStream &stream, QScriptDebuggerEvent &event) |
|
292 \relates QScriptDebuggerEvent |
|
293 |
|
294 Reads a QScriptDebuggerEvent from the specified \a stream into the |
|
295 given \a event. |
|
296 */ |
|
297 QDataStream &operator>>(QDataStream &in, QScriptDebuggerEvent &event) |
|
298 { |
|
299 QScriptDebuggerEventPrivate *d = event.d_ptr.data(); |
|
300 |
|
301 quint32 type; |
|
302 in >> type; |
|
303 d->type = QScriptDebuggerEvent::Type(type); |
|
304 |
|
305 qint32 attribCount; |
|
306 in >> attribCount; |
|
307 QHash<QScriptDebuggerEvent::Attribute, QVariant> attribs; |
|
308 for (qint32 i = 0; i < attribCount; ++i) { |
|
309 quint32 key; |
|
310 in >> key; |
|
311 QVariant value; |
|
312 in >> value; |
|
313 attribs[QScriptDebuggerEvent::Attribute(key)] = value; |
|
314 } |
|
315 d->attributes = attribs; |
|
316 |
|
317 return in; |
|
318 } |
|
319 |
|
320 QT_END_NAMESPACE |