source: trunk/tools/linguist/shared/proitems.cpp@ 651

Last change on this file since 651 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 8.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the Qt Linguist of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "proitems.h"
43#include "abstractproitemvisitor.h"
44
45#include <QtCore/QFileInfo>
46
47QT_BEGIN_NAMESPACE
48
49// --------------- ProItem ------------
50void ProItem::setComment(const QString &comment)
51{
52 m_comment = comment;
53}
54
55QString ProItem::comment() const
56{
57 return m_comment;
58}
59
60// --------------- ProBlock ----------------
61
62ProBlock::ProBlock(ProBlock *parent)
63{
64 m_blockKind = 0;
65 m_parent = parent;
66 m_refCount = 1;
67}
68
69ProBlock::~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
78void ProBlock::appendItem(ProItem *proitem)
79{
80 m_proitems << proitem;
81}
82
83void ProBlock::setItems(const QList<ProItem *> &proitems)
84{
85 m_proitems = proitems;
86}
87
88QList<ProItem *> ProBlock::items() const
89{
90 return m_proitems;
91}
92
93void ProBlock::setBlockKind(int blockKind)
94{
95 m_blockKind = blockKind;
96}
97
98int ProBlock::blockKind() const
99{
100 return m_blockKind;
101}
102
103void ProBlock::setParent(ProBlock *parent)
104{
105 m_parent = parent;
106}
107
108ProBlock *ProBlock::parent() const
109{
110 return m_parent;
111}
112
113ProItem::ProItemKind ProBlock::kind() const
114{
115 return ProItem::BlockKind;
116}
117
118ProItem::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 ----------------
152ProVariable::ProVariable(const QString &name, ProBlock *parent)
153 : ProBlock(parent)
154{
155 setBlockKind(ProBlock::VariableKind);
156 m_variable = name;
157 m_variableKind = SetOperator;
158}
159
160void ProVariable::setVariableOperator(VariableOperator variableKind)
161{
162 m_variableKind = variableKind;
163}
164
165ProVariable::VariableOperator ProVariable::variableOperator() const
166{
167 return m_variableKind;
168}
169
170void ProVariable::setVariable(const QString &name)
171{
172 m_variable = name;
173}
174
175QString ProVariable::variable() const
176{
177 return m_variable;
178}
179
180ProItem::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 ----------------
190ProValue::ProValue(const QString &value, ProVariable *variable)
191{
192 m_variable = variable;
193 m_value = value;
194}
195
196void ProValue::setValue(const QString &value)
197{
198 m_value = value;
199}
200
201QString ProValue::value() const
202{
203 return m_value;
204}
205
206void ProValue::setVariable(ProVariable *variable)
207{
208 m_variable = variable;
209}
210
211ProVariable *ProValue::variable() const
212{
213 return m_variable;
214}
215
216ProItem::ProItemKind ProValue::kind() const
217{
218 return ProItem::ValueKind;
219}
220
221ProItem::ProItemReturn ProValue::Accept(AbstractProItemVisitor *visitor)
222{
223 visitor->visitProValue(this);
224 return ReturnTrue;
225}
226
227// --------------- ProFunction ----------------
228ProFunction::ProFunction(const QString &text)
229{
230 m_text = text;
231}
232
233void ProFunction::setText(const QString &text)
234{
235 m_text = text;
236}
237
238QString ProFunction::text() const
239{
240 return m_text;
241}
242
243ProItem::ProItemKind ProFunction::kind() const
244{
245 return ProItem::FunctionKind;
246}
247
248ProItem::ProItemReturn ProFunction::Accept(AbstractProItemVisitor *visitor)
249{
250 return visitor->visitProFunction(this);
251}
252
253// --------------- ProCondition ----------------
254ProCondition::ProCondition(const QString &text)
255{
256 m_text = text;
257}
258
259void ProCondition::setText(const QString &text)
260{
261 m_text = text;
262}
263
264QString ProCondition::text() const
265{
266 return m_text;
267}
268
269ProItem::ProItemKind ProCondition::kind() const
270{
271 return ProItem::ConditionKind;
272}
273
274ProItem::ProItemReturn ProCondition::Accept(AbstractProItemVisitor *visitor)
275{
276 visitor->visitProCondition(this);
277 return ReturnTrue;
278}
279
280// --------------- ProOperator ----------------
281ProOperator::ProOperator(OperatorKind operatorKind)
282{
283 m_operatorKind = operatorKind;
284}
285
286void ProOperator::setOperatorKind(OperatorKind operatorKind)
287{
288 m_operatorKind = operatorKind;
289}
290
291ProOperator::OperatorKind ProOperator::operatorKind() const
292{
293 return m_operatorKind;
294}
295
296ProItem::ProItemKind ProOperator::kind() const
297{
298 return ProItem::OperatorKind;
299}
300
301ProItem::ProItemReturn ProOperator::Accept(AbstractProItemVisitor *visitor)
302{
303 visitor->visitProOperator(this);
304 return ReturnTrue;
305}
306
307// --------------- ProFile ----------------
308ProFile::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
320ProFile::~ProFile()
321{
322}
323
324QString ProFile::displayFileName() const
325{
326 return m_displayFileName;
327}
328
329QString ProFile::fileName() const
330{
331 return m_fileName;
332}
333
334QString ProFile::directoryName() const
335{
336 return m_directoryName;
337}
338
339void ProFile::setModified(bool modified)
340{
341 m_modified = modified;
342}
343
344bool ProFile::isModified() const
345{
346 return m_modified;
347}
348
349ProItem::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
358QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.