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 ****************************************************************************/
27 #include "parsetreenode.h"
29 /* Root element constructor */
30 ParseTreeNode::ParseTreeNode(struct skin_element
* data
)
31 : parent(0), element(0), param(0), children()
35 children
.append(new ParseTreeNode(data
, this));
40 /* Normal element constructor */
41 ParseTreeNode::ParseTreeNode(struct skin_element
* data
, ParseTreeNode
* parent
)
42 : parent(parent
), element(data
), param(0), children()
48 for(int i
= 0; i
< element
->params_count
; i
++)
50 if(element
->params
[i
].type
== skin_tag_parameter::CODE
)
51 children
.append(new ParseTreeNode(element
->params
[i
].data
.code
,
54 children
.append(new ParseTreeNode(&element
->params
[i
], this));
58 /* CONDITIONAL and SUBLINES fall through to the same code */
61 for(int i
= 0; i
< element
->children_count
; i
++)
63 children
.append(new ParseTreeNode(data
->children
[i
], this));
68 for(struct skin_element
* current
= data
->children
[0]; current
;
69 current
= current
->next
)
71 children
.append(new ParseTreeNode(current
, this));
80 /* Parameter constructor */
81 ParseTreeNode::ParseTreeNode(skin_tag_parameter
*data
, ParseTreeNode
*parent
)
82 : parent(parent
), element(0), param(data
), children()
87 QString
ParseTreeNode::genCode() const
96 for(int i
= 0; i
< children
.count(); i
++)
99 Adding a % in case of tag, because the tag rendering code
100 doesn't insert its own
102 if(children
[i
]->element
->type
== TAG
)
103 buffer
.append(TAGSYM
);
104 buffer
.append(children
[i
]->genCode());
109 for(int i
= 0; i
< children
.count(); i
++)
111 buffer
.append(children
[i
]->genCode());
112 if(i
!= children
.count() - 1)
113 buffer
.append(MULTILINESYM
);
118 /* Inserts a %?, the tag renderer doesn't deal with the TAGSYM */
119 buffer
.append(TAGSYM
);
120 buffer
.append(CONDITIONSYM
);
121 buffer
.append(children
[0]->genCode());
123 /* Inserting the sublines */
124 buffer
.append(ENUMLISTOPENSYM
);
125 for(int i
= 1; i
< children
.count(); i
++)
127 buffer
.append(children
[i
]->genCode());
128 if(i
!= children
.count() - 1)
129 buffer
.append(ENUMLISTSEPERATESYM
);
131 buffer
.append(ENUMLISTCLOSESYM
);
135 /* When generating code, we DO NOT insert the leading TAGSYM, leave
136 * the calling functions to handle that
138 buffer
.append(element
->name
);
140 if(element
->params_count
> 0)
142 /* Rendering parameters if there are any */
143 buffer
.append(ARGLISTOPENSYM
);
144 for(int i
= 0; i
< children
.count(); i
++)
146 buffer
.append(children
[i
]->genCode());
147 if(i
!= children
.count() - 1)
148 buffer
.append(ARGLISTSEPERATESYM
);
150 buffer
.append(ARGLISTCLOSESYM
);
159 buffer
.append(element
->text
);
163 buffer
.append(COMMENTSYM
);
164 buffer
.append(element
->text
);
172 case skin_tag_parameter::STRING
:
173 buffer
.append(param
->data
.text
);
176 case skin_tag_parameter::NUMERIC
:
177 buffer
.append(QString::number(param
->data
.numeric
, 10));
180 case skin_tag_parameter::DEFAULT
:
181 buffer
.append(DEFAULTSYM
);
184 case skin_tag_parameter::CODE
:
185 buffer
.append(QObject::tr("This doesn't belong here"));
192 for(int i
= 0; i
< children
.count(); i
++)
193 buffer
.append(children
[i
]->genCode());
199 ParseTreeNode
* ParseTreeNode::child(int row
)
201 if(row
< 0 || row
>= children
.count())
204 return children
[row
];
207 int ParseTreeNode::numChildren() const
209 return children
.count();
213 QVariant
ParseTreeNode::data(int column
) const
217 /* Column 0 is the element type */
221 switch(element
->type
)
224 return QObject::tr("Logical Line");
227 return QObject::tr("Alternator");
230 return QObject::tr("Comment");
233 return QObject::tr("Conditional Tag");
236 return QObject::tr("Tag");
239 return QObject::tr("Newline");
242 return QObject::tr("Plaintext");
249 case skin_tag_parameter::STRING
:
250 return QObject::tr("String");
252 case skin_tag_parameter::NUMERIC
:
253 return QObject::tr("Number");
255 case skin_tag_parameter::DEFAULT
:
256 return QObject::tr("Default Argument");
258 case skin_tag_parameter::CODE
:
259 return QObject::tr("This doesn't belong here");
264 return QObject::tr("Root");
269 /* Column 1 is the value */
273 switch(element
->type
)
282 return QObject::tr("\\n");
286 return QString(element
->text
);
290 return QString(element
->name
);
297 case skin_tag_parameter::DEFAULT
:
298 return QObject::tr("-");
300 case skin_tag_parameter::STRING
:
301 return QString(param
->data
.text
);
303 case skin_tag_parameter::NUMERIC
:
304 return QString::number(param
->data
.numeric
, 10);
306 case skin_tag_parameter::CODE
:
307 return QObject::tr("Seriously, something's wrong here");
316 /* Column 2 is the line number */
319 return QString::number(element
->line
, 10);
329 int ParseTreeNode::getRow() const
334 return parent
->children
.indexOf(const_cast<ParseTreeNode
*>(this));
337 ParseTreeNode
* ParseTreeNode::getParent() const
342 ParseTreeNode::~ParseTreeNode()
344 for(int i
= 0; i
< children
.count(); i
++)