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 ****************************************************************************/
23 #include "tag_table.h"
25 #include "parsetreenode.h"
26 #include "parsetreemodel.h"
28 /* Root element constructor */
29 ParseTreeNode::ParseTreeNode(struct skin_element
* data
)
30 : parent(0), element(0), param(0), children()
34 children
.append(new ParseTreeNode(data
, this));
39 /* Normal element constructor */
40 ParseTreeNode::ParseTreeNode(struct skin_element
* data
, ParseTreeNode
* parent
)
41 : parent(parent
), element(data
), param(0), children()
47 for(int i
= 0; i
< element
->params_count
; i
++)
49 if(element
->params
[i
].type
== skin_tag_parameter::CODE
)
50 children
.append(new ParseTreeNode(element
->params
[i
].data
.code
,
53 children
.append(new ParseTreeNode(&element
->params
[i
], this));
57 /* CONDITIONAL and SUBLINES fall through to the same code */
60 for(int i
= 0; i
< element
->children_count
; i
++)
62 children
.append(new ParseTreeNode(data
->children
[i
], this));
68 for(int i
= 0; i
< data
->children_count
; i
++)
70 for(struct skin_element
* current
= data
->children
[i
]; current
;
71 current
= current
->next
)
73 children
.append(new ParseTreeNode(current
, this));
83 /* Parameter constructor */
84 ParseTreeNode::ParseTreeNode(skin_tag_parameter
*data
, ParseTreeNode
*parent
)
85 : parent(parent
), element(0), param(data
), children()
90 QString
ParseTreeNode::genCode() const
101 for(int i
= 0; i
< children
.count(); i
++)
104 Adding a % in case of tag, because the tag rendering code
105 doesn't insert its own
107 if(children
[i
]->element
->type
== TAG
)
108 buffer
.append(TAGSYM
);
109 buffer
.append(children
[i
]->genCode());
110 if(element
->type
== LINE
|| i
== 0)
116 for(int i
= 0; i
< children
.count(); i
++)
118 buffer
.append(children
[i
]->genCode());
119 if(i
!= children
.count() - 1)
120 buffer
.append(MULTILINESYM
);
126 /* Inserts a %?, the tag renderer doesn't deal with the TAGSYM */
127 buffer
.append(TAGSYM
);
128 buffer
.append(CONDITIONSYM
);
129 buffer
.append(children
[0]->genCode());
131 /* Inserting the sublines */
132 buffer
.append(ENUMLISTOPENSYM
);
133 for(int i
= 1; i
< children
.count(); i
++)
135 buffer
.append(children
[i
]->genCode());
136 if(i
!= children
.count() - 1)
137 buffer
.append(ENUMLISTSEPERATESYM
);
139 buffer
.append(ENUMLISTCLOSESYM
);
143 /* When generating code, we DO NOT insert the leading TAGSYM, leave
144 * the calling functions to handle that
146 buffer
.append(element
->tag
->name
);
148 if(element
->params_count
> 0)
150 /* Rendering parameters if there are any */
151 buffer
.append(ARGLISTOPENSYM
);
152 for(int i
= 0; i
< children
.count(); i
++)
154 buffer
.append(children
[i
]->genCode());
155 if(i
!= children
.count() - 1)
156 buffer
.append(ARGLISTSEPERATESYM
);
158 buffer
.append(ARGLISTCLOSESYM
);
163 for(char* cursor
= element
->text
; *cursor
; cursor
++)
165 if(find_escape_character(*cursor
))
166 buffer
.append(TAGSYM
);
167 buffer
.append(*cursor
);
172 buffer
.append(COMMENTSYM
);
173 buffer
.append(element
->text
);
182 case skin_tag_parameter::STRING
:
183 for(char* cursor
= param
->data
.text
; *cursor
; cursor
++)
185 if(find_escape_character(*cursor
))
186 buffer
.append(TAGSYM
);
187 buffer
.append(*cursor
);
191 case skin_tag_parameter::NUMERIC
:
192 buffer
.append(QString::number(param
->data
.numeric
, 10));
195 case skin_tag_parameter::DEFAULT
:
196 buffer
.append(DEFAULTSYM
);
199 case skin_tag_parameter::CODE
:
200 buffer
.append(QObject::tr("This doesn't belong here"));
207 for(int i
= 0; i
< children
.count(); i
++)
208 buffer
.append(children
[i
]->genCode());
214 ParseTreeNode
* ParseTreeNode::child(int row
)
216 if(row
< 0 || row
>= children
.count())
219 return children
[row
];
222 int ParseTreeNode::numChildren() const
224 return children
.count();
228 QVariant
ParseTreeNode::data(int column
) const
232 case ParseTreeModel::typeColumn
:
235 switch(element
->type
)
238 return QObject::tr("Viewport");
241 return QObject::tr("Logical Line");
244 return QObject::tr("Alternator");
247 return QObject::tr("Comment");
250 return QObject::tr("Conditional Tag");
253 return QObject::tr("Tag");
256 return QObject::tr("Plaintext");
263 case skin_tag_parameter::STRING
:
264 return QObject::tr("String");
266 case skin_tag_parameter::NUMERIC
:
267 return QObject::tr("Number");
269 case skin_tag_parameter::DEFAULT
:
270 return QObject::tr("Default Argument");
272 case skin_tag_parameter::CODE
:
273 return QObject::tr("This doesn't belong here");
278 return QObject::tr("Root");
283 case ParseTreeModel::valueColumn
:
286 switch(element
->type
)
296 return QString(element
->text
);
299 return QString(element
->tag
->name
);
306 case skin_tag_parameter::DEFAULT
:
307 return QObject::tr("-");
309 case skin_tag_parameter::STRING
:
310 return QString(param
->data
.text
);
312 case skin_tag_parameter::NUMERIC
:
313 return QString::number(param
->data
.numeric
, 10);
315 case skin_tag_parameter::CODE
:
316 return QObject::tr("Seriously, something's wrong here");
325 case ParseTreeModel::lineColumn
:
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
++)