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

source code of qtscript/src/scripttools/debugging/qscriptdebuggerresponse.cpp