1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtSCriptTools module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
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.
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.
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.
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.
36 ** If you have questions regarding the use of this file, please contact
37 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "qscriptdebuggerresponse_p.h"
43 #include "qscriptdebuggervalue_p.h"
45 #include <QtScript/qscriptcontextinfo.h>
46 #include <QtCore/qdatastream.h>
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
)
62 \class QScriptDebuggerResponse
65 \brief The QScriptDebuggerResponse class represents a front-end's response to a QScriptDebuggerCommand.
67 A response contains an error code and result.
70 class QScriptDebuggerResponsePrivate
73 QScriptDebuggerResponsePrivate();
74 ~QScriptDebuggerResponsePrivate();
76 QScriptDebuggerResponse::Error error
;
81 QScriptDebuggerResponsePrivate::QScriptDebuggerResponsePrivate()
83 error
= QScriptDebuggerResponse::NoError
;
87 QScriptDebuggerResponsePrivate::~QScriptDebuggerResponsePrivate()
91 QScriptDebuggerResponse::QScriptDebuggerResponse()
92 : d_ptr(new QScriptDebuggerResponsePrivate
)
96 QScriptDebuggerResponse::QScriptDebuggerResponse(const QScriptDebuggerResponse
&other
)
97 : d_ptr(new QScriptDebuggerResponsePrivate
)
99 *d_ptr
= *other
.d_ptr
;
102 QScriptDebuggerResponse::~QScriptDebuggerResponse()
107 QScriptDebuggerResponse
&QScriptDebuggerResponse::operator=(const QScriptDebuggerResponse
&other
)
109 *d_ptr
= *other
.d_ptr
;
114 Returns the error code of this response.
116 QScriptDebuggerResponse::Error
QScriptDebuggerResponse::error() const
118 Q_D(const QScriptDebuggerResponse
);
123 Sets the \a error code of this response.
125 void QScriptDebuggerResponse::setError(Error error
)
127 Q_D(QScriptDebuggerResponse
);
132 Returns the result of this response. This function is provided for
135 QVariant
QScriptDebuggerResponse::result() const
137 Q_D(const QScriptDebuggerResponse
);
142 Sets the Result attribute of this response to the given \a
143 value. This function is provided for convenience.
145 void QScriptDebuggerResponse::setResult(const QVariant
&value
)
147 Q_D(QScriptDebuggerResponse
);
151 void QScriptDebuggerResponse::setResult(int value
)
153 Q_D(QScriptDebuggerResponse
);
157 void QScriptDebuggerResponse::setResult(const QString
&value
)
159 Q_D(QScriptDebuggerResponse
);
163 void QScriptDebuggerResponse::setResult(const QScriptBreakpointData
&data
)
165 Q_D(QScriptDebuggerResponse
);
166 d
->result
= qVariantFromValue(data
);
169 void QScriptDebuggerResponse::setResult(const QScriptBreakpointMap
&breakpoints
)
171 Q_D(QScriptDebuggerResponse
);
172 d
->result
= qVariantFromValue(breakpoints
);
175 void QScriptDebuggerResponse::setResult(const QScriptScriptMap
&scripts
)
177 Q_D(QScriptDebuggerResponse
);
178 d
->result
= qVariantFromValue(scripts
);
181 void QScriptDebuggerResponse::setResult(const QScriptScriptData
&data
)
183 Q_D(QScriptDebuggerResponse
);
184 d
->result
= qVariantFromValue(data
);
187 void QScriptDebuggerResponse::setResult(const QScriptDebuggerValue
&value
)
189 Q_D(QScriptDebuggerResponse
);
190 d
->result
= qVariantFromValue(value
);
193 void QScriptDebuggerResponse::setResult(const QScriptDebuggerValueList
&values
)
195 Q_D(QScriptDebuggerResponse
);
196 d
->result
= qVariantFromValue(values
);
199 void QScriptDebuggerResponse::setResult(const QScriptDebuggerValuePropertyList
&props
)
201 Q_D(QScriptDebuggerResponse
);
202 d
->result
= qVariantFromValue(props
);
205 void QScriptDebuggerResponse::setResult(const QScriptContextInfo
&info
)
207 Q_D(QScriptDebuggerResponse
);
208 d
->result
= qVariantFromValue(info
);
211 int QScriptDebuggerResponse::resultAsInt() const
213 Q_D(const QScriptDebuggerResponse
);
214 return d
->result
.toInt();
217 qint64
QScriptDebuggerResponse::resultAsLongLong() const
219 Q_D(const QScriptDebuggerResponse
);
220 return d
->result
.toLongLong();
223 QString
QScriptDebuggerResponse::resultAsString() const
225 Q_D(const QScriptDebuggerResponse
);
226 return d
->result
.toString();
229 QScriptBreakpointData
QScriptDebuggerResponse::resultAsBreakpointData() const
231 Q_D(const QScriptDebuggerResponse
);
232 return qvariant_cast
<QScriptBreakpointData
>(d
->result
);
235 QScriptBreakpointMap
QScriptDebuggerResponse::resultAsBreakpoints() const
237 Q_D(const QScriptDebuggerResponse
);
238 return qvariant_cast
<QScriptBreakpointMap
>(d
->result
);
241 QScriptScriptMap
QScriptDebuggerResponse::resultAsScripts() const
243 Q_D(const QScriptDebuggerResponse
);
244 return qvariant_cast
<QScriptScriptMap
>(d
->result
);
247 QScriptScriptData
QScriptDebuggerResponse::resultAsScriptData() const
249 Q_D(const QScriptDebuggerResponse
);
250 return qvariant_cast
<QScriptScriptData
>(d
->result
);
253 QScriptDebuggerValue
QScriptDebuggerResponse::resultAsScriptValue() const
255 Q_D(const QScriptDebuggerResponse
);
256 return qvariant_cast
<QScriptDebuggerValue
>(d
->result
);
259 QScriptDebuggerValueList
QScriptDebuggerResponse::resultAsScriptValueList() const
261 Q_D(const QScriptDebuggerResponse
);
262 return qvariant_cast
<QScriptDebuggerValueList
>(d
->result
);
265 QScriptDebuggerValuePropertyList
QScriptDebuggerResponse::resultAsScriptValuePropertyList() const
267 Q_D(const QScriptDebuggerResponse
);
268 return qvariant_cast
<QScriptDebuggerValuePropertyList
>(d
->result
);
271 QScriptContextInfo
QScriptDebuggerResponse::resultAsContextInfo() const
273 Q_D(const QScriptDebuggerResponse
);
274 return qvariant_cast
<QScriptContextInfo
>(d
->result
);
277 bool QScriptDebuggerResponse::async() const
279 Q_D(const QScriptDebuggerResponse
);
283 void QScriptDebuggerResponse::setAsync(bool async
)
285 Q_D(QScriptDebuggerResponse
);
290 Returns true if this QScriptDebuggerResponse is equal to the \a other
291 response, otherwise returns false.
293 bool QScriptDebuggerResponse::operator==(const QScriptDebuggerResponse
&other
) const
295 Q_D(const QScriptDebuggerResponse
);
296 const QScriptDebuggerResponsePrivate
*od
= other
.d_func();
301 return ((d
->error
== od
->error
)
302 && (d
->result
== od
->result
)
303 && (d
->async
== od
->async
));
307 Returns true if this QScriptDebuggerResponse is not equal to the \a
308 other response, otherwise returns false.
310 bool QScriptDebuggerResponse::operator!=(const QScriptDebuggerResponse
&other
) const
312 return !(*this == other
);
316 \fn QDataStream &operator<<(QDataStream &stream, const QScriptDebuggerResponse &response)
317 \relates QScriptDebuggerResponse
319 Writes the given \a response to the specified \a stream.
321 QDataStream
&operator<<(QDataStream
&out
, const QScriptDebuggerResponse
&response
)
323 const QScriptDebuggerResponsePrivate
*d
= response
.d_ptr
;
324 out
<< (quint32
)d
->error
;
331 \fn QDataStream &operator>>(QDataStream &stream, QScriptDebuggerResponse &response)
332 \relates QScriptDebuggerResponse
334 Reads a QScriptDebuggerResponse from the specified \a stream into the
337 QDataStream
&operator>>(QDataStream
&in
, QScriptDebuggerResponse
&response
)
339 QScriptDebuggerResponsePrivate
*d
= response
.d_ptr
;
343 d
->error
= QScriptDebuggerResponse::Error(error
);