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 "qscriptbreakpointdata_p.h"
41
42#include <QtCore/qdatastream.h>
43#include <QtCore/qstring.h>
44#include <QtCore/qvariant.h>
45
46QT_BEGIN_NAMESPACE
47
48/*!
49 \since 4.5
50 \class QScriptBreakpointData
51 \internal
52
53 \brief The QScriptBreakpointData class contains data associated with a breakpoint.
54*/
55
56class QScriptBreakpointDataPrivate
57{
58public:
59 QScriptBreakpointDataPrivate();
60 ~QScriptBreakpointDataPrivate();
61
62 void init(int ln);
63
64 qint64 scriptId;
65 QString fileName;
66 int lineNumber;
67 bool enabled;
68 bool singleShot;
69 int ignoreCount;
70 QString condition;
71 QVariant data;
72 int hitCount;
73};
74
75QScriptBreakpointDataPrivate::QScriptBreakpointDataPrivate()
76{
77}
78
79QScriptBreakpointDataPrivate::~QScriptBreakpointDataPrivate()
80{
81}
82
83void QScriptBreakpointDataPrivate::init(int ln)
84{
85 scriptId = -1;
86 lineNumber = ln;
87 enabled = true;
88 singleShot = false;
89 ignoreCount = 0;
90 hitCount = 0;
91}
92
93/*!
94 Constructs an empty QScriptBreakpointData.
95*/
96QScriptBreakpointData::QScriptBreakpointData()
97 : d_ptr(new QScriptBreakpointDataPrivate)
98{
99 d_ptr->init(/*lineNumber=*/ln: -1);
100}
101
102/*!
103 Constructs a QScriptBreakpointData with the given \a lineNumber.
104*/
105QScriptBreakpointData::QScriptBreakpointData(qint64 scriptId, int lineNumber)
106 : d_ptr(new QScriptBreakpointDataPrivate)
107{
108 d_ptr->init(ln: lineNumber);
109 d_ptr->scriptId = scriptId;
110}
111
112/*!
113 Constructs a QScriptBreakpointData with the given \a lineNumber.
114*/
115QScriptBreakpointData::QScriptBreakpointData(const QString &fileName, int lineNumber)
116 : d_ptr(new QScriptBreakpointDataPrivate)
117{
118 d_ptr->init(ln: lineNumber);
119 d_ptr->fileName = fileName;
120}
121
122/*!
123 Constructs a QScriptBreakpointData that is a copy of \a other.
124*/
125QScriptBreakpointData::QScriptBreakpointData(const QScriptBreakpointData &other)
126 : d_ptr(new QScriptBreakpointDataPrivate)
127{
128 Q_ASSERT(other.d_ptr != 0);
129 *d_ptr = *other.d_ptr;
130}
131
132/*!
133 Destroys this QScriptBreakpointData.
134*/
135QScriptBreakpointData::~QScriptBreakpointData()
136{
137}
138
139/*!
140 Assigns \a other to this QScriptBreakpointData.
141*/
142QScriptBreakpointData &QScriptBreakpointData::operator=(const QScriptBreakpointData &other)
143{
144 Q_ASSERT(d_ptr != 0);
145 Q_ASSERT(other.d_ptr != 0);
146 *d_ptr = *other.d_ptr;
147 return *this;
148}
149
150qint64 QScriptBreakpointData::scriptId() const
151{
152 Q_D(const QScriptBreakpointData);
153 return d->scriptId;
154}
155
156void QScriptBreakpointData::setScriptId(qint64 id)
157{
158 Q_D(QScriptBreakpointData);
159 d->scriptId = id;
160}
161
162QString QScriptBreakpointData::fileName() const
163{
164 Q_D(const QScriptBreakpointData);
165 return d->fileName;
166}
167
168void QScriptBreakpointData::setFileName(const QString &fileName)
169{
170 Q_D(QScriptBreakpointData);
171 d->fileName = fileName;
172}
173
174/*!
175 Returns the breakpoint line number.
176*/
177int QScriptBreakpointData::lineNumber() const
178{
179 Q_D(const QScriptBreakpointData);
180 return d->lineNumber;
181}
182
183/*!
184 Sets the breakpoint line number to \a lineNumber.
185*/
186void QScriptBreakpointData::setLineNumber(int lineNumber)
187{
188 Q_D(QScriptBreakpointData);
189 d->lineNumber = lineNumber;
190}
191
192/*!
193 Returns true if the breakpoint is enabled, false otherwise.
194*/
195bool QScriptBreakpointData::isEnabled() const
196{
197 Q_D(const QScriptBreakpointData);
198 return d->enabled;
199}
200
201/*!
202 Sets the \a enabled state of the breakpoint.
203*/
204void QScriptBreakpointData::setEnabled(bool enabled)
205{
206 Q_D(QScriptBreakpointData);
207 d->enabled = enabled;
208}
209
210/*!
211 Returns true if the breakpoint is single-shot, false otherwise.
212*/
213bool QScriptBreakpointData::isSingleShot() const
214{
215 Q_D(const QScriptBreakpointData);
216 return d->singleShot;
217}
218
219/*!
220 Sets the \a singleShot state of the breakpoint.
221*/
222void QScriptBreakpointData::setSingleShot(bool singleShot)
223{
224 Q_D(QScriptBreakpointData);
225 d->singleShot = singleShot;
226}
227
228/*!
229 Returns the ignore count of the breakpoint.
230*/
231int QScriptBreakpointData::ignoreCount() const
232{
233 Q_D(const QScriptBreakpointData);
234 return d->ignoreCount;
235}
236
237/*!
238 Sets the ignore \a count of the breakpoint.
239*/
240void QScriptBreakpointData::setIgnoreCount(int count)
241{
242 Q_D(QScriptBreakpointData);
243 d->ignoreCount = count;
244}
245
246/*!
247 If the ignore count is 0, this function increments the hit count and
248 returns true. Otherwise, it decrements the ignore count and returns
249 false.
250*/
251bool QScriptBreakpointData::hit()
252{
253 Q_D(QScriptBreakpointData);
254 if (d->ignoreCount == 0) {
255 ++d->hitCount;
256 return true;
257 }
258 --d->ignoreCount;
259 return false;
260}
261
262/*!
263 Returns the hit count of the breakpoint (the number of times the
264 breakpoint has been triggered).
265*/
266int QScriptBreakpointData::hitCount() const
267{
268 Q_D(const QScriptBreakpointData);
269 return d->hitCount;
270}
271
272/*!
273 Returns the condition of the breakpoint.
274*/
275QString QScriptBreakpointData::condition() const
276{
277 Q_D(const QScriptBreakpointData);
278 return d->condition;
279}
280
281/*!
282 Sets the \a condition of the breakpoint.
283*/
284void QScriptBreakpointData::setCondition(const QString &condition)
285{
286 Q_D(QScriptBreakpointData);
287 d->condition = condition;
288}
289
290/*!
291 Returns custom data associated with the breakpoint.
292*/
293QVariant QScriptBreakpointData::data() const
294{
295 Q_D(const QScriptBreakpointData);
296 return d->data;
297}
298
299/*!
300 Sets custom \a data associated with the breakpoint.
301*/
302void QScriptBreakpointData::setData(const QVariant &data)
303{
304 Q_D(QScriptBreakpointData);
305 d->data = data;
306}
307
308bool QScriptBreakpointData::isValid() const
309{
310 Q_D(const QScriptBreakpointData);
311 return (((d->scriptId != -1) || !d->fileName.isEmpty())
312 && (d->lineNumber != -1));
313}
314
315/*!
316 Returns true if this QScriptBreakpointData is equal to the \a other
317 data, otherwise returns false.
318*/
319bool QScriptBreakpointData::operator==(const QScriptBreakpointData &other) const
320{
321 Q_D(const QScriptBreakpointData);
322 const QScriptBreakpointDataPrivate *od = other.d_func();
323 if (d == od)
324 return true;
325 if (!d || !od)
326 return false;
327 return ((d->scriptId == od->scriptId)
328 && (d->fileName == od->fileName)
329 && (d->lineNumber == od->lineNumber)
330 && (d->enabled == od->enabled)
331 && (d->singleShot == od->singleShot)
332 && (d->condition == od->condition)
333 && (d->ignoreCount == od->ignoreCount)
334 && (d->data == od->data)
335 && (d->hitCount == od->hitCount));
336}
337
338/*!
339 Returns true if this QScriptBreakpointData is not equal to the \a
340 other data, otherwise returns false.
341*/
342bool QScriptBreakpointData::operator!=(const QScriptBreakpointData &other) const
343{
344 return !(*this == other);
345}
346
347/*!
348 \relates QScriptBreakpointData
349
350 Writes the given \a data to the specified \a stream.
351*/
352QDataStream &operator<<(QDataStream &out, const QScriptBreakpointData &data)
353{
354 const QScriptBreakpointDataPrivate *d = data.d_ptr.data();
355 out << d->scriptId;
356 out << d->fileName;
357 out << d->lineNumber;
358 out << d->enabled;
359 out << d->singleShot;
360 out << d->ignoreCount;
361 out << d->condition;
362 out << d->data;
363 out << d->hitCount;
364 return out;
365}
366
367/*!
368 \relates QScriptBreakpointData
369
370 Reads a QScriptBreakpointData from the specified \a stream into the
371 given \a data.
372*/
373QDataStream &operator>>(QDataStream &in, QScriptBreakpointData &data)
374{
375 QScriptBreakpointDataPrivate *d = data.d_ptr.data();
376 in >> d->scriptId;
377 in >> d->fileName;
378 in >> d->lineNumber;
379 in >> d->enabled;
380 in >> d->singleShot;
381 in >> d->ignoreCount;
382 in >> d->condition;
383 in >> d->data;
384 in >> d->hitCount;
385 return in;
386}
387
388QT_END_NAMESPACE
389

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