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

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