author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtSCriptTools module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
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. |
|
23 |
** |
|
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. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
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 |
||
48 |
QT_BEGIN_NAMESPACE |
|
49 |
||
50 |
/*! |
|
51 |
\since 4.5 |
|
52 |
\class QScriptScriptData |
|
53 |
\internal |
|
54 |
||
55 |
\brief The QScriptScriptData class holds data associated with a script. |
|
56 |
*/ |
|
57 |
||
58 |
class QScriptScriptDataPrivate |
|
59 |
{ |
|
60 |
public: |
|
61 |
QScriptScriptDataPrivate(); |
|
62 |
~QScriptScriptDataPrivate(); |
|
63 |
||
64 |
QString contents; |
|
65 |
QString fileName; |
|
66 |
int baseLineNumber; |
|
67 |
QDateTime timeStamp; |
|
68 |
||
69 |
QBasicAtomicInt ref; |
|
70 |
}; |
|
71 |
||
72 |
QScriptScriptDataPrivate::QScriptScriptDataPrivate() |
|
73 |
{ |
|
74 |
ref = 0; |
|
75 |
} |
|
76 |
||
77 |
QScriptScriptDataPrivate::~QScriptScriptDataPrivate() |
|
78 |
{ |
|
79 |
} |
|
80 |
||
81 |
QScriptScriptData::QScriptScriptData() |
|
82 |
: d_ptr(0) |
|
83 |
{ |
|
84 |
} |
|
85 |
||
86 |
QScriptScriptData::QScriptScriptData(const QString &contents, const QString &fileName, |
|
87 |
int baseLineNumber, const QDateTime &timeStamp) |
|
88 |
: d_ptr(new QScriptScriptDataPrivate) |
|
89 |
{ |
|
90 |
d_ptr->contents = contents; |
|
91 |
d_ptr->fileName = fileName; |
|
92 |
d_ptr->baseLineNumber = baseLineNumber; |
|
93 |
if (timeStamp.isValid()) |
|
94 |
d_ptr->timeStamp = timeStamp; |
|
95 |
else |
|
96 |
d_ptr->timeStamp = QDateTime::currentDateTime(); |
|
97 |
d_ptr->ref.ref(); |
|
98 |
} |
|
99 |
||
100 |
QScriptScriptData::QScriptScriptData(const QScriptScriptData &other) |
|
101 |
: d_ptr(other.d_ptr.data()) |
|
102 |
{ |
|
103 |
if (d_ptr) |
|
104 |
d_ptr->ref.ref(); |
|
105 |
} |
|
106 |
||
107 |
QScriptScriptData::~QScriptScriptData() |
|
108 |
{ |
|
109 |
} |
|
110 |
||
111 |
QScriptScriptData &QScriptScriptData::operator=(const QScriptScriptData &other) |
|
112 |
{ |
|
113 |
d_ptr.assign(other.d_ptr.data()); |
|
114 |
return *this; |
|
115 |
} |
|
116 |
||
117 |
QString QScriptScriptData::contents() const |
|
118 |
{ |
|
119 |
Q_D(const QScriptScriptData); |
|
120 |
if (!d) |
|
121 |
return QString(); |
|
122 |
return d->contents; |
|
123 |
} |
|
124 |
||
125 |
QStringList QScriptScriptData::lines(int startLineNumber, int count) const |
|
126 |
{ |
|
127 |
Q_D(const QScriptScriptData); |
|
128 |
if (!d) |
|
129 |
return QStringList(); |
|
130 |
QStringList allLines = d->contents.split(QLatin1Char('\n')); |
|
131 |
return allLines.mid(qMax(0, startLineNumber - d->baseLineNumber), count); |
|
132 |
} |
|
133 |
||
134 |
QString QScriptScriptData::fileName() const |
|
135 |
{ |
|
136 |
Q_D(const QScriptScriptData); |
|
137 |
if (!d) |
|
138 |
return QString(); |
|
139 |
return d->fileName; |
|
140 |
} |
|
141 |
||
142 |
int QScriptScriptData::baseLineNumber() const |
|
143 |
{ |
|
144 |
Q_D(const QScriptScriptData); |
|
145 |
if (!d) |
|
146 |
return -1; |
|
147 |
return d->baseLineNumber; |
|
148 |
} |
|
149 |
||
150 |
QDateTime QScriptScriptData::timeStamp() const |
|
151 |
{ |
|
152 |
Q_D(const QScriptScriptData); |
|
153 |
if (!d) |
|
154 |
return QDateTime(); |
|
155 |
return d->timeStamp; |
|
156 |
} |
|
157 |
||
158 |
bool QScriptScriptData::isValid() const |
|
159 |
{ |
|
160 |
Q_D(const QScriptScriptData); |
|
161 |
return (d != 0); |
|
162 |
} |
|
163 |
||
164 |
bool QScriptScriptData::operator==(const QScriptScriptData &other) const |
|
165 |
{ |
|
166 |
Q_D(const QScriptScriptData); |
|
167 |
const QScriptScriptDataPrivate *od = other.d_func(); |
|
168 |
if (d == od) |
|
169 |
return true; |
|
170 |
if (!d || !od) |
|
171 |
return false; |
|
172 |
return ((d->contents == od->contents) |
|
173 |
&& (d->fileName == od->fileName) |
|
174 |
&& (d->baseLineNumber == od->baseLineNumber)); |
|
175 |
} |
|
176 |
||
177 |
bool QScriptScriptData::operator!=(const QScriptScriptData &other) const |
|
178 |
{ |
|
179 |
return !(*this == other); |
|
180 |
} |
|
181 |
||
182 |
QDataStream &operator<<(QDataStream &out, const QScriptScriptData &data) |
|
183 |
{ |
|
184 |
const QScriptScriptDataPrivate *d = data.d_ptr.data(); |
|
185 |
if (d) { |
|
186 |
out << d->contents; |
|
187 |
out << d->fileName; |
|
188 |
out << qint32(d->baseLineNumber); |
|
189 |
} else { |
|
190 |
out << QString(); |
|
191 |
out << QString(); |
|
192 |
out << qint32(0); |
|
193 |
} |
|
194 |
return out; |
|
195 |
} |
|
196 |
||
197 |
QDataStream &operator>>(QDataStream &in, QScriptScriptData &data) |
|
198 |
{ |
|
199 |
if (!data.d_ptr) { |
|
200 |
data.d_ptr.reset(new QScriptScriptDataPrivate()); |
|
201 |
data.d_ptr->ref.ref(); |
|
202 |
} |
|
203 |
QScriptScriptDataPrivate *d = data.d_ptr.data(); |
|
204 |
in >> d->contents; |
|
205 |
in >> d->fileName; |
|
206 |
qint32 ln; |
|
207 |
in >> ln; |
|
208 |
d->baseLineNumber = ln; |
|
209 |
return in; |
|
210 |
} |
|
211 |
||
212 |
QT_END_NAMESPACE |