diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/themeeditor/editorwindow.cpp | 10 | ||||
-rw-r--r-- | utils/themeeditor/parsetreemodel.cpp | 39 | ||||
-rw-r--r-- | utils/themeeditor/parsetreemodel.h | 2 | ||||
-rw-r--r-- | utils/themeeditor/parsetreenode.cpp | 71 | ||||
-rw-r--r-- | utils/themeeditor/parsetreenode.h | 9 | ||||
-rw-r--r-- | utils/themeeditor/themeeditor.pro | 7 |
6 files changed, 130 insertions, 8 deletions
diff --git a/utils/themeeditor/editorwindow.cpp b/utils/themeeditor/editorwindow.cpp index 42ca22cec2..feaac6fe47 100644 --- a/utils/themeeditor/editorwindow.cpp +++ b/utils/themeeditor/editorwindow.cpp | |||
@@ -30,7 +30,9 @@ EditorWindow::EditorWindow(QWidget *parent) : | |||
30 | { | 30 | { |
31 | ui->setupUi(this); | 31 | ui->setupUi(this); |
32 | 32 | ||
33 | tree = 0; | 33 | /* Establishing the parse tree */ |
34 | tree = new ParseTreeModel(ui->code->document()->toPlainText().toAscii()); | ||
35 | ui->parseTree->setModel(tree); | ||
34 | 36 | ||
35 | /* Connecting the buttons */ | 37 | /* Connecting the buttons */ |
36 | QObject::connect(ui->code, SIGNAL(cursorPositionChanged()), | 38 | QObject::connect(ui->code, SIGNAL(cursorPositionChanged()), |
@@ -41,11 +43,7 @@ EditorWindow::EditorWindow(QWidget *parent) : | |||
41 | 43 | ||
42 | void EditorWindow::updateTree() | 44 | void EditorWindow::updateTree() |
43 | { | 45 | { |
44 | if(tree) | 46 | tree->changeTree(ui->code->document()->toPlainText().toAscii()); |
45 | delete tree; | ||
46 | |||
47 | tree = new ParseTreeModel(ui->code->document()->toPlainText().toAscii()); | ||
48 | ui->parseTree->setModel(tree); | ||
49 | ui->parseTree->expandAll(); | 47 | ui->parseTree->expandAll(); |
50 | } | 48 | } |
51 | 49 | ||
diff --git a/utils/themeeditor/parsetreemodel.cpp b/utils/themeeditor/parsetreemodel.cpp index 9faa9ea560..918903bb68 100644 --- a/utils/themeeditor/parsetreemodel.cpp +++ b/utils/themeeditor/parsetreemodel.cpp | |||
@@ -31,7 +31,11 @@ ParseTreeModel::ParseTreeModel(const char* document, QObject* parent): | |||
31 | QAbstractItemModel(parent) | 31 | QAbstractItemModel(parent) |
32 | { | 32 | { |
33 | this->tree = skin_parse(document); | 33 | this->tree = skin_parse(document); |
34 | this->root = new ParseTreeNode(tree); | 34 | |
35 | if(tree) | ||
36 | this->root = new ParseTreeNode(tree); | ||
37 | else | ||
38 | this->root = 0; | ||
35 | } | 39 | } |
36 | 40 | ||
37 | 41 | ||
@@ -48,6 +52,36 @@ QString ParseTreeModel::genCode() | |||
48 | return root->genCode(); | 52 | return root->genCode(); |
49 | } | 53 | } |
50 | 54 | ||
55 | bool ParseTreeModel::changeTree(const char *document) | ||
56 | { | ||
57 | struct skin_element* test = skin_parse(document); | ||
58 | |||
59 | if(!test) | ||
60 | return false; | ||
61 | |||
62 | ParseTreeNode* temp = new ParseTreeNode(test); | ||
63 | if(root && temp->genHash() == root->genHash()) | ||
64 | { | ||
65 | delete temp; | ||
66 | return true; | ||
67 | } | ||
68 | |||
69 | if(root) | ||
70 | { | ||
71 | emit beginRemoveRows(QModelIndex(), 0, root->numChildren() - 1); | ||
72 | delete root; | ||
73 | emit endRemoveRows(); | ||
74 | } | ||
75 | |||
76 | root = temp; | ||
77 | |||
78 | emit beginInsertRows(QModelIndex(), 0, temp->numChildren() - 1); | ||
79 | emit endInsertRows(); | ||
80 | |||
81 | return true; | ||
82 | |||
83 | } | ||
84 | |||
51 | QModelIndex ParseTreeModel::index(int row, int column, | 85 | QModelIndex ParseTreeModel::index(int row, int column, |
52 | const QModelIndex& parent) const | 86 | const QModelIndex& parent) const |
53 | { | 87 | { |
@@ -83,6 +117,9 @@ QModelIndex ParseTreeModel::parent(const QModelIndex &child) const | |||
83 | 117 | ||
84 | int ParseTreeModel::rowCount(const QModelIndex &parent) const | 118 | int ParseTreeModel::rowCount(const QModelIndex &parent) const |
85 | { | 119 | { |
120 | if(!root) | ||
121 | return 0; | ||
122 | |||
86 | if(!parent.isValid()) | 123 | if(!parent.isValid()) |
87 | return root->numChildren(); | 124 | return root->numChildren(); |
88 | 125 | ||
diff --git a/utils/themeeditor/parsetreemodel.h b/utils/themeeditor/parsetreemodel.h index 4c448ce558..76960937f1 100644 --- a/utils/themeeditor/parsetreemodel.h +++ b/utils/themeeditor/parsetreemodel.h | |||
@@ -47,6 +47,8 @@ public: | |||
47 | virtual ~ParseTreeModel(); | 47 | virtual ~ParseTreeModel(); |
48 | 48 | ||
49 | QString genCode(); | 49 | QString genCode(); |
50 | /* Changes the parse tree to a new document */ | ||
51 | bool changeTree(const char* document); | ||
50 | 52 | ||
51 | QModelIndex index(int row, int column, const QModelIndex& parent) const; | 53 | QModelIndex index(int row, int column, const QModelIndex& parent) const; |
52 | QModelIndex parent(const QModelIndex &child) const; | 54 | QModelIndex parent(const QModelIndex &child) const; |
diff --git a/utils/themeeditor/parsetreenode.cpp b/utils/themeeditor/parsetreenode.cpp index 99fdbd858d..3a20b1e003 100644 --- a/utils/themeeditor/parsetreenode.cpp +++ b/utils/themeeditor/parsetreenode.cpp | |||
@@ -224,6 +224,75 @@ QString ParseTreeNode::genCode() const | |||
224 | return buffer; | 224 | return buffer; |
225 | } | 225 | } |
226 | 226 | ||
227 | /* A more or less random hashing algorithm */ | ||
228 | int ParseTreeNode::genHash() const | ||
229 | { | ||
230 | int hash = 0; | ||
231 | |||
232 | if(element) | ||
233 | { | ||
234 | hash += element->type; | ||
235 | switch(element->type) | ||
236 | { | ||
237 | case VIEWPORT: | ||
238 | case LINE: | ||
239 | case SUBLINES: | ||
240 | case CONDITIONAL: | ||
241 | hash += element->children_count; | ||
242 | break; | ||
243 | |||
244 | case TAG: | ||
245 | for(unsigned int i = 0; i < strlen(element->tag->name); i++) | ||
246 | hash += element->tag->name[i]; | ||
247 | break; | ||
248 | |||
249 | case COMMENT: | ||
250 | case TEXT: | ||
251 | for(unsigned int i = 0; i < strlen(element->text); i++) | ||
252 | { | ||
253 | if(i % 2) | ||
254 | hash += element->text[i] % element->type; | ||
255 | else | ||
256 | hash += element->text[i] % element->type * 2; | ||
257 | } | ||
258 | break; | ||
259 | } | ||
260 | |||
261 | } | ||
262 | |||
263 | if(param) | ||
264 | { | ||
265 | hash += param->type; | ||
266 | switch(param->type) | ||
267 | { | ||
268 | case skin_tag_parameter::DEFAULT: | ||
269 | case skin_tag_parameter::CODE: | ||
270 | break; | ||
271 | |||
272 | case skin_tag_parameter::NUMERIC: | ||
273 | hash += param->data.numeric * (param->data.numeric / 4); | ||
274 | break; | ||
275 | |||
276 | case skin_tag_parameter::STRING: | ||
277 | for(unsigned int i = 0; i < strlen(param->data.text); i++) | ||
278 | { | ||
279 | if(i % 2) | ||
280 | hash += param->data.text[i] * 2; | ||
281 | else | ||
282 | hash += param->data.text[i]; | ||
283 | } | ||
284 | break; | ||
285 | } | ||
286 | } | ||
287 | |||
288 | for(int i = 0; i < children.count(); i++) | ||
289 | { | ||
290 | hash += children[i]->genHash(); | ||
291 | } | ||
292 | |||
293 | return hash; | ||
294 | } | ||
295 | |||
227 | ParseTreeNode* ParseTreeNode::child(int row) | 296 | ParseTreeNode* ParseTreeNode::child(int row) |
228 | { | 297 | { |
229 | if(row < 0 || row >= children.count()) | 298 | if(row < 0 || row >= children.count()) |
@@ -234,7 +303,7 @@ ParseTreeNode* ParseTreeNode::child(int row) | |||
234 | 303 | ||
235 | int ParseTreeNode::numChildren() const | 304 | int ParseTreeNode::numChildren() const |
236 | { | 305 | { |
237 | return children.count(); | 306 | return children.count(); |
238 | } | 307 | } |
239 | 308 | ||
240 | 309 | ||
diff --git a/utils/themeeditor/parsetreenode.h b/utils/themeeditor/parsetreenode.h index 12f1d364d9..7a0807bb0d 100644 --- a/utils/themeeditor/parsetreenode.h +++ b/utils/themeeditor/parsetreenode.h | |||
@@ -37,6 +37,8 @@ public: | |||
37 | virtual ~ParseTreeNode(); | 37 | virtual ~ParseTreeNode(); |
38 | 38 | ||
39 | QString genCode() const; | 39 | QString genCode() const; |
40 | int genHash() const; | ||
41 | |||
40 | bool isParam() const{ if(param) return true; else return false; } | 42 | bool isParam() const{ if(param) return true; else return false; } |
41 | struct skin_tag_parameter* getParam(){ return param;} | 43 | struct skin_tag_parameter* getParam(){ return param;} |
42 | struct skin_element* getElement(){return element;} | 44 | struct skin_element* getElement(){return element;} |
@@ -46,6 +48,13 @@ public: | |||
46 | QVariant data(int column) const; | 48 | QVariant data(int column) const; |
47 | int getRow() const; | 49 | int getRow() const; |
48 | ParseTreeNode* getParent() const; | 50 | ParseTreeNode* getParent() const; |
51 | ParseTreeNode* getChild(int row) const | ||
52 | { | ||
53 | if(row < children.count()) | ||
54 | return children[row]; | ||
55 | else | ||
56 | return 0; | ||
57 | } | ||
49 | 58 | ||
50 | private: | 59 | private: |
51 | ParseTreeNode* parent; | 60 | ParseTreeNode* parent; |
diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index 5b1ab34ca2..9bc78149d2 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro | |||
@@ -1,3 +1,10 @@ | |||
1 | # build in a separate folder. | ||
2 | MYBUILDDIR = $$OUT_PWD/build/ | ||
3 | OBJECTS_DIR = $$MYBUILDDIR/o | ||
4 | UI_DIR = $$MYBUILDDIR/ui | ||
5 | MOC_DIR = $$MYBUILDDIR/moc | ||
6 | RCC_DIR = $$MYBUILDDIR/rcc | ||
7 | |||
1 | HEADERS += tag_table.h \ | 8 | HEADERS += tag_table.h \ |
2 | symbols.h \ | 9 | symbols.h \ |
3 | skin_parser.h \ | 10 | skin_parser.h \ |