|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Linguist 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 "proitems.h" |
|
43 #include "abstractproitemvisitor.h" |
|
44 |
|
45 #include <QtCore/QFileInfo> |
|
46 |
|
47 QT_BEGIN_NAMESPACE |
|
48 |
|
49 // --------------- ProItem ------------ |
|
50 void ProItem::setComment(const QString &comment) |
|
51 { |
|
52 m_comment = comment; |
|
53 } |
|
54 |
|
55 QString ProItem::comment() const |
|
56 { |
|
57 return m_comment; |
|
58 } |
|
59 |
|
60 // --------------- ProBlock ---------------- |
|
61 |
|
62 ProBlock::ProBlock(ProBlock *parent) |
|
63 { |
|
64 m_blockKind = 0; |
|
65 m_parent = parent; |
|
66 m_refCount = 1; |
|
67 } |
|
68 |
|
69 ProBlock::~ProBlock() |
|
70 { |
|
71 foreach (ProItem *itm, m_proitems) |
|
72 if (itm->kind() == BlockKind) |
|
73 static_cast<ProBlock *>(itm)->deref(); |
|
74 else |
|
75 delete itm; |
|
76 } |
|
77 |
|
78 void ProBlock::appendItem(ProItem *proitem) |
|
79 { |
|
80 m_proitems << proitem; |
|
81 } |
|
82 |
|
83 void ProBlock::setItems(const QList<ProItem *> &proitems) |
|
84 { |
|
85 m_proitems = proitems; |
|
86 } |
|
87 |
|
88 QList<ProItem *> ProBlock::items() const |
|
89 { |
|
90 return m_proitems; |
|
91 } |
|
92 |
|
93 void ProBlock::setBlockKind(int blockKind) |
|
94 { |
|
95 m_blockKind = blockKind; |
|
96 } |
|
97 |
|
98 int ProBlock::blockKind() const |
|
99 { |
|
100 return m_blockKind; |
|
101 } |
|
102 |
|
103 void ProBlock::setParent(ProBlock *parent) |
|
104 { |
|
105 m_parent = parent; |
|
106 } |
|
107 |
|
108 ProBlock *ProBlock::parent() const |
|
109 { |
|
110 return m_parent; |
|
111 } |
|
112 |
|
113 ProItem::ProItemKind ProBlock::kind() const |
|
114 { |
|
115 return ProItem::BlockKind; |
|
116 } |
|
117 |
|
118 ProItem::ProItemReturn ProBlock::Accept(AbstractProItemVisitor *visitor) |
|
119 { |
|
120 if (visitor->visitBeginProBlock(this) == ReturnSkip) |
|
121 return ReturnTrue; |
|
122 ProItemReturn rt = ReturnTrue; |
|
123 for (int i = 0; i < m_proitems.count(); ++i) { |
|
124 rt = m_proitems.at(i)->Accept(visitor); |
|
125 if (rt != ReturnTrue && rt != ReturnFalse) { |
|
126 if (rt == ReturnLoop) { |
|
127 rt = ReturnTrue; |
|
128 while (visitor->visitProLoopIteration()) |
|
129 for (int j = i; ++j < m_proitems.count(); ) { |
|
130 rt = m_proitems.at(j)->Accept(visitor); |
|
131 if (rt != ReturnTrue && rt != ReturnFalse) { |
|
132 if (rt == ReturnNext) { |
|
133 rt = ReturnTrue; |
|
134 break; |
|
135 } |
|
136 if (rt == ReturnBreak) |
|
137 rt = ReturnTrue; |
|
138 goto do_break; |
|
139 } |
|
140 } |
|
141 do_break: |
|
142 visitor->visitProLoopCleanup(); |
|
143 } |
|
144 break; |
|
145 } |
|
146 } |
|
147 visitor->visitEndProBlock(this); |
|
148 return rt; |
|
149 } |
|
150 |
|
151 // --------------- ProVariable ---------------- |
|
152 ProVariable::ProVariable(const QString &name, ProBlock *parent) |
|
153 : ProBlock(parent) |
|
154 { |
|
155 setBlockKind(ProBlock::VariableKind); |
|
156 m_variable = name; |
|
157 m_variableKind = SetOperator; |
|
158 } |
|
159 |
|
160 void ProVariable::setVariableOperator(VariableOperator variableKind) |
|
161 { |
|
162 m_variableKind = variableKind; |
|
163 } |
|
164 |
|
165 ProVariable::VariableOperator ProVariable::variableOperator() const |
|
166 { |
|
167 return m_variableKind; |
|
168 } |
|
169 |
|
170 void ProVariable::setVariable(const QString &name) |
|
171 { |
|
172 m_variable = name; |
|
173 } |
|
174 |
|
175 QString ProVariable::variable() const |
|
176 { |
|
177 return m_variable; |
|
178 } |
|
179 |
|
180 ProItem::ProItemReturn ProVariable::Accept(AbstractProItemVisitor *visitor) |
|
181 { |
|
182 visitor->visitBeginProVariable(this); |
|
183 foreach (ProItem *item, m_proitems) |
|
184 item->Accept(visitor); // cannot fail |
|
185 visitor->visitEndProVariable(this); |
|
186 return ReturnTrue; |
|
187 } |
|
188 |
|
189 // --------------- ProValue ---------------- |
|
190 ProValue::ProValue(const QString &value, ProVariable *variable) |
|
191 { |
|
192 m_variable = variable; |
|
193 m_value = value; |
|
194 } |
|
195 |
|
196 void ProValue::setValue(const QString &value) |
|
197 { |
|
198 m_value = value; |
|
199 } |
|
200 |
|
201 QString ProValue::value() const |
|
202 { |
|
203 return m_value; |
|
204 } |
|
205 |
|
206 void ProValue::setVariable(ProVariable *variable) |
|
207 { |
|
208 m_variable = variable; |
|
209 } |
|
210 |
|
211 ProVariable *ProValue::variable() const |
|
212 { |
|
213 return m_variable; |
|
214 } |
|
215 |
|
216 ProItem::ProItemKind ProValue::kind() const |
|
217 { |
|
218 return ProItem::ValueKind; |
|
219 } |
|
220 |
|
221 ProItem::ProItemReturn ProValue::Accept(AbstractProItemVisitor *visitor) |
|
222 { |
|
223 visitor->visitProValue(this); |
|
224 return ReturnTrue; |
|
225 } |
|
226 |
|
227 // --------------- ProFunction ---------------- |
|
228 ProFunction::ProFunction(const QString &text) |
|
229 { |
|
230 m_text = text; |
|
231 } |
|
232 |
|
233 void ProFunction::setText(const QString &text) |
|
234 { |
|
235 m_text = text; |
|
236 } |
|
237 |
|
238 QString ProFunction::text() const |
|
239 { |
|
240 return m_text; |
|
241 } |
|
242 |
|
243 ProItem::ProItemKind ProFunction::kind() const |
|
244 { |
|
245 return ProItem::FunctionKind; |
|
246 } |
|
247 |
|
248 ProItem::ProItemReturn ProFunction::Accept(AbstractProItemVisitor *visitor) |
|
249 { |
|
250 return visitor->visitProFunction(this); |
|
251 } |
|
252 |
|
253 // --------------- ProCondition ---------------- |
|
254 ProCondition::ProCondition(const QString &text) |
|
255 { |
|
256 m_text = text; |
|
257 } |
|
258 |
|
259 void ProCondition::setText(const QString &text) |
|
260 { |
|
261 m_text = text; |
|
262 } |
|
263 |
|
264 QString ProCondition::text() const |
|
265 { |
|
266 return m_text; |
|
267 } |
|
268 |
|
269 ProItem::ProItemKind ProCondition::kind() const |
|
270 { |
|
271 return ProItem::ConditionKind; |
|
272 } |
|
273 |
|
274 ProItem::ProItemReturn ProCondition::Accept(AbstractProItemVisitor *visitor) |
|
275 { |
|
276 visitor->visitProCondition(this); |
|
277 return ReturnTrue; |
|
278 } |
|
279 |
|
280 // --------------- ProOperator ---------------- |
|
281 ProOperator::ProOperator(OperatorKind operatorKind) |
|
282 { |
|
283 m_operatorKind = operatorKind; |
|
284 } |
|
285 |
|
286 void ProOperator::setOperatorKind(OperatorKind operatorKind) |
|
287 { |
|
288 m_operatorKind = operatorKind; |
|
289 } |
|
290 |
|
291 ProOperator::OperatorKind ProOperator::operatorKind() const |
|
292 { |
|
293 return m_operatorKind; |
|
294 } |
|
295 |
|
296 ProItem::ProItemKind ProOperator::kind() const |
|
297 { |
|
298 return ProItem::OperatorKind; |
|
299 } |
|
300 |
|
301 ProItem::ProItemReturn ProOperator::Accept(AbstractProItemVisitor *visitor) |
|
302 { |
|
303 visitor->visitProOperator(this); |
|
304 return ReturnTrue; |
|
305 } |
|
306 |
|
307 // --------------- ProFile ---------------- |
|
308 ProFile::ProFile(const QString &fileName) |
|
309 : ProBlock(0) |
|
310 { |
|
311 m_modified = false; |
|
312 setBlockKind(ProBlock::ProFileKind); |
|
313 m_fileName = fileName; |
|
314 |
|
315 QFileInfo fi(fileName); |
|
316 m_displayFileName = fi.fileName(); |
|
317 m_directoryName = fi.absolutePath(); |
|
318 } |
|
319 |
|
320 ProFile::~ProFile() |
|
321 { |
|
322 } |
|
323 |
|
324 QString ProFile::displayFileName() const |
|
325 { |
|
326 return m_displayFileName; |
|
327 } |
|
328 |
|
329 QString ProFile::fileName() const |
|
330 { |
|
331 return m_fileName; |
|
332 } |
|
333 |
|
334 QString ProFile::directoryName() const |
|
335 { |
|
336 return m_directoryName; |
|
337 } |
|
338 |
|
339 void ProFile::setModified(bool modified) |
|
340 { |
|
341 m_modified = modified; |
|
342 } |
|
343 |
|
344 bool ProFile::isModified() const |
|
345 { |
|
346 return m_modified; |
|
347 } |
|
348 |
|
349 ProItem::ProItemReturn ProFile::Accept(AbstractProItemVisitor *visitor) |
|
350 { |
|
351 ProItemReturn rt; |
|
352 if ((rt = visitor->visitBeginProFile(this)) != ReturnTrue) |
|
353 return rt; |
|
354 ProBlock::Accept(visitor); // cannot fail |
|
355 return visitor->visitEndProFile(this); |
|
356 } |
|
357 |
|
358 QT_END_NAMESPACE |