1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtSCriptTools module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** 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 are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qscriptdebuggerresponse_p.h"
|
---|
43 | #include "qscriptdebuggervalue_p.h"
|
---|
44 |
|
---|
45 | #include <QtScript/qscriptcontextinfo.h>
|
---|
46 | #include <QtCore/qdatastream.h>
|
---|
47 |
|
---|
48 | Q_DECLARE_METATYPE(QScriptBreakpointData)
|
---|
49 | Q_DECLARE_METATYPE(QScriptBreakpointMap)
|
---|
50 | Q_DECLARE_METATYPE(QScriptScriptData)
|
---|
51 | Q_DECLARE_METATYPE(QScriptScriptMap)
|
---|
52 | Q_DECLARE_METATYPE(QScriptDebuggerValue)
|
---|
53 | Q_DECLARE_METATYPE(QScriptDebuggerValueList)
|
---|
54 | Q_DECLARE_METATYPE(QScriptDebuggerValueProperty)
|
---|
55 | Q_DECLARE_METATYPE(QScriptDebuggerValuePropertyList)
|
---|
56 | Q_DECLARE_METATYPE(QScriptContextInfo)
|
---|
57 |
|
---|
58 | QT_BEGIN_NAMESPACE
|
---|
59 |
|
---|
60 | /*!
|
---|
61 | \since 4.5
|
---|
62 | \class QScriptDebuggerResponse
|
---|
63 | \internal
|
---|
64 |
|
---|
65 | \brief The QScriptDebuggerResponse class represents a front-end's response to a QScriptDebuggerCommand.
|
---|
66 |
|
---|
67 | A response contains an error code and result.
|
---|
68 | */
|
---|
69 |
|
---|
70 | class QScriptDebuggerResponsePrivate
|
---|
71 | {
|
---|
72 | public:
|
---|
73 | QScriptDebuggerResponsePrivate();
|
---|
74 | ~QScriptDebuggerResponsePrivate();
|
---|
75 |
|
---|
76 | QScriptDebuggerResponse::Error error;
|
---|
77 | QVariant result;
|
---|
78 | bool async;
|
---|
79 | };
|
---|
80 |
|
---|
81 | QScriptDebuggerResponsePrivate::QScriptDebuggerResponsePrivate()
|
---|
82 | {
|
---|
83 | error = QScriptDebuggerResponse::NoError;
|
---|
84 | async = false;
|
---|
85 | }
|
---|
86 |
|
---|
87 | QScriptDebuggerResponsePrivate::~QScriptDebuggerResponsePrivate()
|
---|
88 | {
|
---|
89 | }
|
---|
90 |
|
---|
91 | QScriptDebuggerResponse::QScriptDebuggerResponse()
|
---|
92 | : d_ptr(new QScriptDebuggerResponsePrivate)
|
---|
93 | {
|
---|
94 | }
|
---|
95 |
|
---|
96 | QScriptDebuggerResponse::QScriptDebuggerResponse(const QScriptDebuggerResponse &other)
|
---|
97 | : d_ptr(new QScriptDebuggerResponsePrivate)
|
---|
98 | {
|
---|
99 | *d_ptr = *other.d_ptr;
|
---|
100 | }
|
---|
101 |
|
---|
102 | QScriptDebuggerResponse::~QScriptDebuggerResponse()
|
---|
103 | {
|
---|
104 | delete d_ptr;
|
---|
105 | }
|
---|
106 |
|
---|
107 | QScriptDebuggerResponse &QScriptDebuggerResponse::operator=(const QScriptDebuggerResponse &other)
|
---|
108 | {
|
---|
109 | *d_ptr = *other.d_ptr;
|
---|
110 | return *this;
|
---|
111 | }
|
---|
112 |
|
---|
113 | /*!
|
---|
114 | Returns the error code of this response.
|
---|
115 | */
|
---|
116 | QScriptDebuggerResponse::Error QScriptDebuggerResponse::error() const
|
---|
117 | {
|
---|
118 | Q_D(const QScriptDebuggerResponse);
|
---|
119 | return d->error;
|
---|
120 | }
|
---|
121 |
|
---|
122 | /*!
|
---|
123 | Sets the \a error code of this response.
|
---|
124 | */
|
---|
125 | void QScriptDebuggerResponse::setError(Error error)
|
---|
126 | {
|
---|
127 | Q_D(QScriptDebuggerResponse);
|
---|
128 | d->error = error;
|
---|
129 | }
|
---|
130 |
|
---|
131 | /*!
|
---|
132 | Returns the result of this response. This function is provided for
|
---|
133 | convenience.
|
---|
134 | */
|
---|
135 | QVariant QScriptDebuggerResponse::result() const
|
---|
136 | {
|
---|
137 | Q_D(const QScriptDebuggerResponse);
|
---|
138 | return d->result;
|
---|
139 | }
|
---|
140 |
|
---|
141 | /*!
|
---|
142 | Sets the Result attribute of this response to the given \a
|
---|
143 | value. This function is provided for convenience.
|
---|
144 | */
|
---|
145 | void QScriptDebuggerResponse::setResult(const QVariant &value)
|
---|
146 | {
|
---|
147 | Q_D(QScriptDebuggerResponse);
|
---|
148 | d->result = value;
|
---|
149 | }
|
---|
150 |
|
---|
151 | void QScriptDebuggerResponse::setResult(int value)
|
---|
152 | {
|
---|
153 | Q_D(QScriptDebuggerResponse);
|
---|
154 | d->result = value;
|
---|
155 | }
|
---|
156 |
|
---|
157 | void QScriptDebuggerResponse::setResult(const QString &value)
|
---|
158 | {
|
---|
159 | Q_D(QScriptDebuggerResponse);
|
---|
160 | d->result = value;
|
---|
161 | }
|
---|
162 |
|
---|
163 | void QScriptDebuggerResponse::setResult(const QScriptBreakpointData &data)
|
---|
164 | {
|
---|
165 | Q_D(QScriptDebuggerResponse);
|
---|
166 | d->result = qVariantFromValue(data);
|
---|
167 | }
|
---|
168 |
|
---|
169 | void QScriptDebuggerResponse::setResult(const QScriptBreakpointMap &breakpoints)
|
---|
170 | {
|
---|
171 | Q_D(QScriptDebuggerResponse);
|
---|
172 | d->result = qVariantFromValue(breakpoints);
|
---|
173 | }
|
---|
174 |
|
---|
175 | void QScriptDebuggerResponse::setResult(const QScriptScriptMap &scripts)
|
---|
176 | {
|
---|
177 | Q_D(QScriptDebuggerResponse);
|
---|
178 | d->result = qVariantFromValue(scripts);
|
---|
179 | }
|
---|
180 |
|
---|
181 | void QScriptDebuggerResponse::setResult(const QScriptScriptData &data)
|
---|
182 | {
|
---|
183 | Q_D(QScriptDebuggerResponse);
|
---|
184 | d->result = qVariantFromValue(data);
|
---|
185 | }
|
---|
186 |
|
---|
187 | void QScriptDebuggerResponse::setResult(const QScriptDebuggerValue &value)
|
---|
188 | {
|
---|
189 | Q_D(QScriptDebuggerResponse);
|
---|
190 | d->result = qVariantFromValue(value);
|
---|
191 | }
|
---|
192 |
|
---|
193 | void QScriptDebuggerResponse::setResult(const QScriptDebuggerValueList &values)
|
---|
194 | {
|
---|
195 | Q_D(QScriptDebuggerResponse);
|
---|
196 | d->result = qVariantFromValue(values);
|
---|
197 | }
|
---|
198 |
|
---|
199 | void QScriptDebuggerResponse::setResult(const QScriptDebuggerValuePropertyList &props)
|
---|
200 | {
|
---|
201 | Q_D(QScriptDebuggerResponse);
|
---|
202 | d->result = qVariantFromValue(props);
|
---|
203 | }
|
---|
204 |
|
---|
205 | void QScriptDebuggerResponse::setResult(const QScriptContextInfo &info)
|
---|
206 | {
|
---|
207 | Q_D(QScriptDebuggerResponse);
|
---|
208 | d->result = qVariantFromValue(info);
|
---|
209 | }
|
---|
210 |
|
---|
211 | int QScriptDebuggerResponse::resultAsInt() const
|
---|
212 | {
|
---|
213 | Q_D(const QScriptDebuggerResponse);
|
---|
214 | return d->result.toInt();
|
---|
215 | }
|
---|
216 |
|
---|
217 | qint64 QScriptDebuggerResponse::resultAsLongLong() const
|
---|
218 | {
|
---|
219 | Q_D(const QScriptDebuggerResponse);
|
---|
220 | return d->result.toLongLong();
|
---|
221 | }
|
---|
222 |
|
---|
223 | QString QScriptDebuggerResponse::resultAsString() const
|
---|
224 | {
|
---|
225 | Q_D(const QScriptDebuggerResponse);
|
---|
226 | return d->result.toString();
|
---|
227 | }
|
---|
228 |
|
---|
229 | QScriptBreakpointData QScriptDebuggerResponse::resultAsBreakpointData() const
|
---|
230 | {
|
---|
231 | Q_D(const QScriptDebuggerResponse);
|
---|
232 | return qvariant_cast<QScriptBreakpointData>(d->result);
|
---|
233 | }
|
---|
234 |
|
---|
235 | QScriptBreakpointMap QScriptDebuggerResponse::resultAsBreakpoints() const
|
---|
236 | {
|
---|
237 | Q_D(const QScriptDebuggerResponse);
|
---|
238 | return qvariant_cast<QScriptBreakpointMap>(d->result);
|
---|
239 | }
|
---|
240 |
|
---|
241 | QScriptScriptMap QScriptDebuggerResponse::resultAsScripts() const
|
---|
242 | {
|
---|
243 | Q_D(const QScriptDebuggerResponse);
|
---|
244 | return qvariant_cast<QScriptScriptMap>(d->result);
|
---|
245 | }
|
---|
246 |
|
---|
247 | QScriptScriptData QScriptDebuggerResponse::resultAsScriptData() const
|
---|
248 | {
|
---|
249 | Q_D(const QScriptDebuggerResponse);
|
---|
250 | return qvariant_cast<QScriptScriptData>(d->result);
|
---|
251 | }
|
---|
252 |
|
---|
253 | QScriptDebuggerValue QScriptDebuggerResponse::resultAsScriptValue() const
|
---|
254 | {
|
---|
255 | Q_D(const QScriptDebuggerResponse);
|
---|
256 | return qvariant_cast<QScriptDebuggerValue>(d->result);
|
---|
257 | }
|
---|
258 |
|
---|
259 | QScriptDebuggerValueList QScriptDebuggerResponse::resultAsScriptValueList() const
|
---|
260 | {
|
---|
261 | Q_D(const QScriptDebuggerResponse);
|
---|
262 | return qvariant_cast<QScriptDebuggerValueList>(d->result);
|
---|
263 | }
|
---|
264 |
|
---|
265 | QScriptDebuggerValuePropertyList QScriptDebuggerResponse::resultAsScriptValuePropertyList() const
|
---|
266 | {
|
---|
267 | Q_D(const QScriptDebuggerResponse);
|
---|
268 | return qvariant_cast<QScriptDebuggerValuePropertyList>(d->result);
|
---|
269 | }
|
---|
270 |
|
---|
271 | QScriptContextInfo QScriptDebuggerResponse::resultAsContextInfo() const
|
---|
272 | {
|
---|
273 | Q_D(const QScriptDebuggerResponse);
|
---|
274 | return qvariant_cast<QScriptContextInfo>(d->result);
|
---|
275 | }
|
---|
276 |
|
---|
277 | bool QScriptDebuggerResponse::async() const
|
---|
278 | {
|
---|
279 | Q_D(const QScriptDebuggerResponse);
|
---|
280 | return d->async;
|
---|
281 | }
|
---|
282 |
|
---|
283 | void QScriptDebuggerResponse::setAsync(bool async)
|
---|
284 | {
|
---|
285 | Q_D(QScriptDebuggerResponse);
|
---|
286 | d->async = async;
|
---|
287 | }
|
---|
288 |
|
---|
289 | /*!
|
---|
290 | Returns true if this QScriptDebuggerResponse is equal to the \a other
|
---|
291 | response, otherwise returns false.
|
---|
292 | */
|
---|
293 | bool QScriptDebuggerResponse::operator==(const QScriptDebuggerResponse &other) const
|
---|
294 | {
|
---|
295 | Q_D(const QScriptDebuggerResponse);
|
---|
296 | const QScriptDebuggerResponsePrivate *od = other.d_func();
|
---|
297 | if (d == od)
|
---|
298 | return true;
|
---|
299 | if (!d || !od)
|
---|
300 | return false;
|
---|
301 | return ((d->error == od->error)
|
---|
302 | && (d->result == od->result)
|
---|
303 | && (d->async == od->async));
|
---|
304 | }
|
---|
305 |
|
---|
306 | /*!
|
---|
307 | Returns true if this QScriptDebuggerResponse is not equal to the \a
|
---|
308 | other response, otherwise returns false.
|
---|
309 | */
|
---|
310 | bool QScriptDebuggerResponse::operator!=(const QScriptDebuggerResponse &other) const
|
---|
311 | {
|
---|
312 | return !(*this == other);
|
---|
313 | }
|
---|
314 |
|
---|
315 | /*!
|
---|
316 | \fn QDataStream &operator<<(QDataStream &stream, const QScriptDebuggerResponse &response)
|
---|
317 | \relates QScriptDebuggerResponse
|
---|
318 |
|
---|
319 | Writes the given \a response to the specified \a stream.
|
---|
320 | */
|
---|
321 | QDataStream &operator<<(QDataStream &out, const QScriptDebuggerResponse &response)
|
---|
322 | {
|
---|
323 | const QScriptDebuggerResponsePrivate *d = response.d_ptr;
|
---|
324 | out << (quint32)d->error;
|
---|
325 | out << d->result;
|
---|
326 | out << d->async;
|
---|
327 | return out;
|
---|
328 | }
|
---|
329 |
|
---|
330 | /*!
|
---|
331 | \fn QDataStream &operator>>(QDataStream &stream, QScriptDebuggerResponse &response)
|
---|
332 | \relates QScriptDebuggerResponse
|
---|
333 |
|
---|
334 | Reads a QScriptDebuggerResponse from the specified \a stream into the
|
---|
335 | given \a response.
|
---|
336 | */
|
---|
337 | QDataStream &operator>>(QDataStream &in, QScriptDebuggerResponse &response)
|
---|
338 | {
|
---|
339 | QScriptDebuggerResponsePrivate *d = response.d_ptr;
|
---|
340 |
|
---|
341 | quint32 error;
|
---|
342 | in >> error;
|
---|
343 | d->error = QScriptDebuggerResponse::Error(error);
|
---|
344 | in >> d->result;
|
---|
345 | in >> d->async;
|
---|
346 |
|
---|
347 | return in;
|
---|
348 | }
|
---|
349 |
|
---|
350 | QT_END_NAMESPACE
|
---|