Qt 4.8
qscriptscriptdata.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qscriptscriptdata_p.h"
43 
44 #include <QtCore/qdatastream.h>
45 #include <QtCore/qstring.h>
46 #include <QtCore/qstringlist.h>
47 
49 
62 {
63 public:
66 
71 
73 };
74 
76 {
77  ref = 0;
78 }
79 
81 {
82 }
83 
85  : d_ptr(0)
86 {
87 }
88 
92 {
93  d_ptr->contents = contents;
94  d_ptr->fileName = fileName;
95  d_ptr->baseLineNumber = baseLineNumber;
96  if (timeStamp.isValid())
97  d_ptr->timeStamp = timeStamp;
98  else
99  d_ptr->timeStamp = QDateTime::currentDateTime();
100  d_ptr->ref.ref();
101 }
102 
104  : d_ptr(other.d_ptr.data())
105 {
106  if (d_ptr)
107  d_ptr->ref.ref();
108 }
109 
111 {
112 }
113 
115 {
116  d_ptr.assign(other.d_ptr.data());
117  return *this;
118 }
119 
121 {
122  Q_D(const QScriptScriptData);
123  if (!d)
124  return QString();
125  return d->contents;
126 }
127 
128 QStringList QScriptScriptData::lines(int startLineNumber, int count) const
129 {
130  Q_D(const QScriptScriptData);
131  if (!d)
132  return QStringList();
133  QStringList allLines = d->contents.split(QLatin1Char('\n'));
134  return allLines.mid(qMax(0, startLineNumber - d->baseLineNumber), count);
135 }
136 
138 {
139  Q_D(const QScriptScriptData);
140  if (!d)
141  return QString();
142  return d->fileName;
143 }
144 
146 {
147  Q_D(const QScriptScriptData);
148  if (!d)
149  return -1;
150  return d->baseLineNumber;
151 }
152 
154 {
155  Q_D(const QScriptScriptData);
156  if (!d)
157  return QDateTime();
158  return d->timeStamp;
159 }
160 
162 {
163  Q_D(const QScriptScriptData);
164  return (d != 0);
165 }
166 
168 {
169  Q_D(const QScriptScriptData);
170  const QScriptScriptDataPrivate *od = other.d_func();
171  if (d == od)
172  return true;
173  if (!d || !od)
174  return false;
175  return ((d->contents == od->contents)
176  && (d->fileName == od->fileName)
177  && (d->baseLineNumber == od->baseLineNumber));
178 }
179 
181 {
182  return !(*this == other);
183 }
184 
186 {
187  const QScriptScriptDataPrivate *d = data.d_ptr.data();
188  if (d) {
189  out << d->contents;
190  out << d->fileName;
191  out << qint32(d->baseLineNumber);
192  } else {
193  out << QString();
194  out << QString();
195  out << qint32(0);
196  }
197  return out;
198 }
199 
201 {
202  if (!data.d_ptr) {
204  data.d_ptr->ref.ref();
205  }
207  in >> d->contents;
208  in >> d->fileName;
209  qint32 ln;
210  in >> ln;
211  d->baseLineNumber = ln;
212  return in;
213 }
214 
double d
Definition: qnumeric_p.h:62
bool operator==(const QScriptScriptData &other) const
friend Q_AUTOTEST_EXPORT QDataStream & operator>>(QDataStream &, QScriptScriptData &)
friend Q_AUTOTEST_EXPORT QDataStream & operator<<(QDataStream &, const QScriptScriptData &)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int qint32
Definition: qglobal.h:937
T * data() const
Returns the value of the pointer referenced by this object.
QScriptScriptData & operator=(const QScriptScriptData &other)
bool isValid() const
Returns true if both the date and the time are valid; otherwise returns false.
Definition: qdatetime.cpp:2346
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QList< T > mid(int pos, int length=-1) const
Returns a list whose elements are copied from this list, starting at position pos.
Definition: qlist.h:637
The QScriptScriptData class holds data associated with a script.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QDateTime timeStamp() const
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static const char * data(const QByteArray &arr)
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
QScopedSharedPointer< QScriptScriptDataPrivate > d_ptr
bool operator!=(const QScriptScriptData &other) const
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
static QDateTime currentDateTime()
Returns the current datetime, as reported by the system clock, in the local time zone.
Definition: qdatetime.cpp:3138
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
QString contents() const
QStringList lines(int startLineNumber, int count) const
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QString fileName() const