source: trunk/src/scripttools/debugging/qscriptdebuggerresponse.cpp@ 573

Last change on this file since 573 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 9.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtSCriptTools 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 [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
48Q_DECLARE_METATYPE(QScriptBreakpointData)
49Q_DECLARE_METATYPE(QScriptBreakpointMap)
50Q_DECLARE_METATYPE(QScriptScriptData)
51Q_DECLARE_METATYPE(QScriptScriptMap)
52Q_DECLARE_METATYPE(QScriptDebuggerValue)
53Q_DECLARE_METATYPE(QScriptDebuggerValueList)
54Q_DECLARE_METATYPE(QScriptDebuggerValueProperty)
55Q_DECLARE_METATYPE(QScriptDebuggerValuePropertyList)
56Q_DECLARE_METATYPE(QScriptContextInfo)
57
58QT_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
70class QScriptDebuggerResponsePrivate
71{
72public:
73 QScriptDebuggerResponsePrivate();
74 ~QScriptDebuggerResponsePrivate();
75
76 QScriptDebuggerResponse::Error error;
77 QVariant result;
78 bool async;
79};
80
81QScriptDebuggerResponsePrivate::QScriptDebuggerResponsePrivate()
82{
83 error = QScriptDebuggerResponse::NoError;
84 async = false;
85}
86
87QScriptDebuggerResponsePrivate::~QScriptDebuggerResponsePrivate()
88{
89}
90
91QScriptDebuggerResponse::QScriptDebuggerResponse()
92 : d_ptr(new QScriptDebuggerResponsePrivate)
93{
94}
95
96QScriptDebuggerResponse::QScriptDebuggerResponse(const QScriptDebuggerResponse &other)
97 : d_ptr(new QScriptDebuggerResponsePrivate)
98{
99 *d_ptr = *other.d_ptr;
100}
101
102QScriptDebuggerResponse::~QScriptDebuggerResponse()
103{
104}
105
106QScriptDebuggerResponse &QScriptDebuggerResponse::operator=(const QScriptDebuggerResponse &other)
107{
108 *d_ptr = *other.d_ptr;
109 return *this;
110}
111
112/*!
113 Returns the error code of this response.
114*/
115QScriptDebuggerResponse::Error QScriptDebuggerResponse::error() const
116{
117 Q_D(const QScriptDebuggerResponse);
118 return d->error;
119}
120
121/*!
122 Sets the \a error code of this response.
123*/
124void QScriptDebuggerResponse::setError(Error error)
125{
126 Q_D(QScriptDebuggerResponse);
127 d->error = error;
128}
129
130/*!
131 Returns the result of this response. This function is provided for
132 convenience.
133*/
134QVariant QScriptDebuggerResponse::result() const
135{
136 Q_D(const QScriptDebuggerResponse);
137 return d->result;
138}
139
140/*!
141 Sets the Result attribute of this response to the given \a
142 value. This function is provided for convenience.
143*/
144void QScriptDebuggerResponse::setResult(const QVariant &value)
145{
146 Q_D(QScriptDebuggerResponse);
147 d->result = value;
148}
149
150void QScriptDebuggerResponse::setResult(int value)
151{
152 Q_D(QScriptDebuggerResponse);
153 d->result = value;
154}
155
156void QScriptDebuggerResponse::setResult(const QString &value)
157{
158 Q_D(QScriptDebuggerResponse);
159 d->result = value;
160}
161
162void QScriptDebuggerResponse::setResult(const QScriptBreakpointData &data)
163{
164 Q_D(QScriptDebuggerResponse);
165 d->result = qVariantFromValue(data);
166}
167
168void QScriptDebuggerResponse::setResult(const QScriptBreakpointMap &breakpoints)
169{
170 Q_D(QScriptDebuggerResponse);
171 d->result = qVariantFromValue(breakpoints);
172}
173
174void QScriptDebuggerResponse::setResult(const QScriptScriptMap &scripts)
175{
176 Q_D(QScriptDebuggerResponse);
177 d->result = qVariantFromValue(scripts);
178}
179
180void QScriptDebuggerResponse::setResult(const QScriptScriptData &data)
181{
182 Q_D(QScriptDebuggerResponse);
183 d->result = qVariantFromValue(data);
184}
185
186void QScriptDebuggerResponse::setResult(const QScriptDebuggerValue &value)
187{
188 Q_D(QScriptDebuggerResponse);
189 d->result = qVariantFromValue(value);
190}
191
192void QScriptDebuggerResponse::setResult(const QScriptDebuggerValueList &values)
193{
194 Q_D(QScriptDebuggerResponse);
195 d->result = qVariantFromValue(values);
196}
197
198void QScriptDebuggerResponse::setResult(const QScriptDebuggerValuePropertyList &props)
199{
200 Q_D(QScriptDebuggerResponse);
201 d->result = qVariantFromValue(props);
202}
203
204void QScriptDebuggerResponse::setResult(const QScriptContextInfo &info)
205{
206 Q_D(QScriptDebuggerResponse);
207 d->result = qVariantFromValue(info);
208}
209
210int QScriptDebuggerResponse::resultAsInt() const
211{
212 Q_D(const QScriptDebuggerResponse);
213 return d->result.toInt();
214}
215
216qint64 QScriptDebuggerResponse::resultAsLongLong() const
217{
218 Q_D(const QScriptDebuggerResponse);
219 return d->result.toLongLong();
220}
221
222QString QScriptDebuggerResponse::resultAsString() const
223{
224 Q_D(const QScriptDebuggerResponse);
225 return d->result.toString();
226}
227
228QScriptBreakpointData QScriptDebuggerResponse::resultAsBreakpointData() const
229{
230 Q_D(const QScriptDebuggerResponse);
231 return qvariant_cast<QScriptBreakpointData>(d->result);
232}
233
234QScriptBreakpointMap QScriptDebuggerResponse::resultAsBreakpoints() const
235{
236 Q_D(const QScriptDebuggerResponse);
237 return qvariant_cast<QScriptBreakpointMap>(d->result);
238}
239
240QScriptScriptMap QScriptDebuggerResponse::resultAsScripts() const
241{
242 Q_D(const QScriptDebuggerResponse);
243 return qvariant_cast<QScriptScriptMap>(d->result);
244}
245
246QScriptScriptData QScriptDebuggerResponse::resultAsScriptData() const
247{
248 Q_D(const QScriptDebuggerResponse);
249 return qvariant_cast<QScriptScriptData>(d->result);
250}
251
252QScriptDebuggerValue QScriptDebuggerResponse::resultAsScriptValue() const
253{
254 Q_D(const QScriptDebuggerResponse);
255 return qvariant_cast<QScriptDebuggerValue>(d->result);
256}
257
258QScriptDebuggerValueList QScriptDebuggerResponse::resultAsScriptValueList() const
259{
260 Q_D(const QScriptDebuggerResponse);
261 return qvariant_cast<QScriptDebuggerValueList>(d->result);
262}
263
264QScriptDebuggerValuePropertyList QScriptDebuggerResponse::resultAsScriptValuePropertyList() const
265{
266 Q_D(const QScriptDebuggerResponse);
267 return qvariant_cast<QScriptDebuggerValuePropertyList>(d->result);
268}
269
270QScriptContextInfo QScriptDebuggerResponse::resultAsContextInfo() const
271{
272 Q_D(const QScriptDebuggerResponse);
273 return qvariant_cast<QScriptContextInfo>(d->result);
274}
275
276bool QScriptDebuggerResponse::async() const
277{
278 Q_D(const QScriptDebuggerResponse);
279 return d->async;
280}
281
282void QScriptDebuggerResponse::setAsync(bool async)
283{
284 Q_D(QScriptDebuggerResponse);
285 d->async = async;
286}
287
288/*!
289 Returns true if this QScriptDebuggerResponse is equal to the \a other
290 response, otherwise returns false.
291*/
292bool QScriptDebuggerResponse::operator==(const QScriptDebuggerResponse &other) const
293{
294 Q_D(const QScriptDebuggerResponse);
295 const QScriptDebuggerResponsePrivate *od = other.d_func();
296 if (d == od)
297 return true;
298 if (!d || !od)
299 return false;
300 return ((d->error == od->error)
301 && (d->result == od->result)
302 && (d->async == od->async));
303}
304
305/*!
306 Returns true if this QScriptDebuggerResponse is not equal to the \a
307 other response, otherwise returns false.
308*/
309bool QScriptDebuggerResponse::operator!=(const QScriptDebuggerResponse &other) const
310{
311 return !(*this == other);
312}
313
314/*!
315 \fn QDataStream &operator<<(QDataStream &stream, const QScriptDebuggerResponse &response)
316 \relates QScriptDebuggerResponse
317
318 Writes the given \a response to the specified \a stream.
319*/
320QDataStream &operator<<(QDataStream &out, const QScriptDebuggerResponse &response)
321{
322 const QScriptDebuggerResponsePrivate *d = response.d_ptr.data();
323 out << (quint32)d->error;
324 out << d->result;
325 out << d->async;
326 return out;
327}
328
329/*!
330 \fn QDataStream &operator>>(QDataStream &stream, QScriptDebuggerResponse &response)
331 \relates QScriptDebuggerResponse
332
333 Reads a QScriptDebuggerResponse from the specified \a stream into the
334 given \a response.
335*/
336QDataStream &operator>>(QDataStream &in, QScriptDebuggerResponse &response)
337{
338 QScriptDebuggerResponsePrivate *d = response.d_ptr.data();
339
340 quint32 error;
341 in >> error;
342 d->error = QScriptDebuggerResponse::Error(error);
343 in >> d->result;
344 in >> d->async;
345
346 return in;
347}
348
349QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.