1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Robert Bieber
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
25 #include "tag_table.h"
28 #include "parsetreenode.h"
30 /* Root element constructor */
31 ParseTreeNode::ParseTreeNode(struct skin_element
* data
)
32 : parent(0), element(0), param(0), children()
36 children
.append(new ParseTreeNode(data
, this));
41 /* Normal element constructor */
42 ParseTreeNode::ParseTreeNode(struct skin_element
* data
, ParseTreeNode
* parent
)
43 : parent(parent
), element(data
), param(0), children()
49 for(int i
= 0; i
< element
->params_count
; i
++)
51 if(element
->params
[i
].type
== skin_tag_parameter::CODE
)
52 children
.append(new ParseTreeNode(element
->params
[i
].data
.code
,
55 children
.append(new ParseTreeNode(&element
->params
[i
], this));
59 /* CONDITIONAL and SUBLINES fall through to the same code */
62 for(int i
= 0; i
< element
->children_count
; i
++)
64 children
.append(new ParseTreeNode(data
->children
[i
], this));
70 for(struct skin_element
* current
= data
->children
[0]; current
;
71 current
= current
->next
)
73 children
.append(new ParseTreeNode(current
, this));
82 /* Parameter constructor */
83 ParseTreeNode::ParseTreeNode(skin_tag_parameter
*data
, ParseTreeNode
*parent
)
84 : parent(parent
), element(0), param(data
), children()
89 QString
ParseTreeNode::genCode() const
99 buffer
.append(children
[0]->genCode());
102 for(int i
= 0; i
< children
.count(); i
++)
105 Adding a % in case of tag, because the tag rendering code
106 doesn't insert its own
108 if(children
[i
]->element
->type
== TAG
)
109 buffer
.append(TAGSYM
);
110 buffer
.append(children
[i
]->genCode());
115 for(int i
= 0; i
< children
.count(); i
++)
117 buffer
.append(children
[i
]->genCode());
118 if(i
!= children
.count() - 1)
119 buffer
.append(MULTILINESYM
);
124 /* Inserts a %?, the tag renderer doesn't deal with the TAGSYM */
125 buffer
.append(TAGSYM
);
126 buffer
.append(CONDITIONSYM
);
127 buffer
.append(children
[0]->genCode());
129 /* Inserting the sublines */
130 buffer
.append(ENUMLISTOPENSYM
);
131 for(int i
= 1; i
< children
.count(); i
++)
133 buffer
.append(children
[i
]->genCode());
134 if(i
!= children
.count() - 1)
135 buffer
.append(ENUMLISTSEPERATESYM
);
137 buffer
.append(ENUMLISTCLOSESYM
);
141 /* When generating code, we DO NOT insert the leading TAGSYM, leave
142 * the calling functions to handle that
144 buffer
.append(element
->tag
->name
);
146 if(element
->params_count
> 0)
148 /* Rendering parameters if there are any */
149 buffer
.append(ARGLISTOPENSYM
);
150 for(int i
= 0; i
< children
.count(); i
++)
152 buffer
.append(children
[i
]->genCode());
153 if(i
!= children
.count() - 1)
154 buffer
.append(ARGLISTSEPERATESYM
);
156 buffer
.append(ARGLISTCLOSESYM
);
165 buffer
.append(element
->text
);
169 buffer
.append(COMMENTSYM
);
170 buffer
.append(element
->text
);
178 case skin_tag_parameter::STRING
:
179 buffer
.append(param
->data
.text
);
182 case skin_tag_parameter::NUMERIC
:
183 buffer
.append(QString::number(param
->data
.numeric
, 10));
186 case skin_tag_parameter::DEFAULT
:
187 buffer
.append(DEFAULTSYM
);
190 case skin_tag_parameter::CODE
:
191 buffer
.append(QObject::tr("This doesn't belong here"));
198 for(int i
= 0; i
< children
.count(); i
++)
199 buffer
.append(children
[i
]->genCode());
205 ParseTreeNode
* ParseTreeNode::child(int row
)
207 if(row
< 0 || row
>= children
.count())
210 return children
[row
];
213 int ParseTreeNode::numChildren() const
215 return children
.count();
219 QVariant
ParseTreeNode::data(int column
) const
223 /* Column 0 is the element type */
227 switch(element
->type
)
230 return QObject::tr("Viewport");
233 return QObject::tr("Logical Line");
236 return QObject::tr("Alternator");
239 return QObject::tr("Comment");
242 return QObject::tr("Conditional Tag");
245 return QObject::tr("Tag");
248 return QObject::tr("Newline");
251 return QObject::tr("Plaintext");
258 case skin_tag_parameter::STRING
:
259 return QObject::tr("String");
261 case skin_tag_parameter::NUMERIC
:
262 return QObject::tr("Number");
264 case skin_tag_parameter::DEFAULT
:
265 return QObject::tr("Default Argument");
267 case skin_tag_parameter::CODE
:
268 return QObject::tr("This doesn't belong here");
273 return QObject::tr("Root");
278 /* Column 1 is the value */
282 switch(element
->type
)
291 return QObject::tr("\\n");
295 return QString(element
->text
);
298 return QString(element
->tag
->name
);
305 case skin_tag_parameter::DEFAULT
:
306 return QObject::tr("-");
308 case skin_tag_parameter::STRING
:
309 return QString(param
->data
.text
);
311 case skin_tag_parameter::NUMERIC
:
312 return QString::number(param
->data
.numeric
, 10);
314 case skin_tag_parameter::CODE
:
315 return QObject::tr("Seriously, something's wrong here");
324 /* Column 2 is the line number */
327 return QString::number(element
->line
, 10);
337 int ParseTreeNode::getRow() const
342 return parent
->children
.indexOf(const_cast<ParseTreeNode
*>(this));
345 ParseTreeNode
* ParseTreeNode::getParent() const
350 ParseTreeNode::~ParseTreeNode()
352 for(int i
= 0; i
< children
.count(); i
++)