From 9db5a96cd8d5ff4af988ba2d468f52841f288373 Mon Sep 17 00:00:00 2001 From: bieber Date: Wed, 2 Jun 2010 20:36:30 +0000 Subject: [PATCH] Changed build subdirectory git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26492 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/editorwindow.cpp | 10 ++--- utils/themeeditor/parsetreemodel.cpp | 39 +++++++++++++++++++- utils/themeeditor/parsetreemodel.h | 2 + utils/themeeditor/parsetreenode.cpp | 71 +++++++++++++++++++++++++++++++++++- utils/themeeditor/parsetreenode.h | 9 +++++ 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 42ca22cec..feaac6fe4 100644 --- a/utils/themeeditor/editorwindow.cpp +++ b/utils/themeeditor/editorwindow.cpp @@ -30,7 +30,9 @@ EditorWindow::EditorWindow(QWidget *parent) : { ui->setupUi(this); - tree = 0; + /* Establishing the parse tree */ + tree = new ParseTreeModel(ui->code->document()->toPlainText().toAscii()); + ui->parseTree->setModel(tree); /* Connecting the buttons */ QObject::connect(ui->code, SIGNAL(cursorPositionChanged()), @@ -41,11 +43,7 @@ EditorWindow::EditorWindow(QWidget *parent) : void EditorWindow::updateTree() { - if(tree) - delete tree; - - tree = new ParseTreeModel(ui->code->document()->toPlainText().toAscii()); - ui->parseTree->setModel(tree); + tree->changeTree(ui->code->document()->toPlainText().toAscii()); ui->parseTree->expandAll(); } diff --git a/utils/themeeditor/parsetreemodel.cpp b/utils/themeeditor/parsetreemodel.cpp index 9faa9ea56..918903bb6 100644 --- a/utils/themeeditor/parsetreemodel.cpp +++ b/utils/themeeditor/parsetreemodel.cpp @@ -31,7 +31,11 @@ ParseTreeModel::ParseTreeModel(const char* document, QObject* parent): QAbstractItemModel(parent) { this->tree = skin_parse(document); - this->root = new ParseTreeNode(tree); + + if(tree) + this->root = new ParseTreeNode(tree); + else + this->root = 0; } @@ -48,6 +52,36 @@ QString ParseTreeModel::genCode() return root->genCode(); } +bool ParseTreeModel::changeTree(const char *document) +{ + struct skin_element* test = skin_parse(document); + + if(!test) + return false; + + ParseTreeNode* temp = new ParseTreeNode(test); + if(root && temp->genHash() == root->genHash()) + { + delete temp; + return true; + } + + if(root) + { + emit beginRemoveRows(QModelIndex(), 0, root->numChildren() - 1); + delete root; + emit endRemoveRows(); + } + + root = temp; + + emit beginInsertRows(QModelIndex(), 0, temp->numChildren() - 1); + emit endInsertRows(); + + return true; + +} + QModelIndex ParseTreeModel::index(int row, int column, const QModelIndex& parent) const { @@ -83,6 +117,9 @@ QModelIndex ParseTreeModel::parent(const QModelIndex &child) const int ParseTreeModel::rowCount(const QModelIndex &parent) const { + if(!root) + return 0; + if(!parent.isValid()) return root->numChildren(); diff --git a/utils/themeeditor/parsetreemodel.h b/utils/themeeditor/parsetreemodel.h index 4c448ce55..76960937f 100644 --- a/utils/themeeditor/parsetreemodel.h +++ b/utils/themeeditor/parsetreemodel.h @@ -47,6 +47,8 @@ public: virtual ~ParseTreeModel(); QString genCode(); + /* Changes the parse tree to a new document */ + bool changeTree(const char* document); QModelIndex index(int row, int column, const QModelIndex& parent) const; QModelIndex parent(const QModelIndex &child) const; diff --git a/utils/themeeditor/parsetreenode.cpp b/utils/themeeditor/parsetreenode.cpp index 99fdbd858..3a20b1e00 100644 --- a/utils/themeeditor/parsetreenode.cpp +++ b/utils/themeeditor/parsetreenode.cpp @@ -224,6 +224,75 @@ QString ParseTreeNode::genCode() const return buffer; } +/* A more or less random hashing algorithm */ +int ParseTreeNode::genHash() const +{ + int hash = 0; + + if(element) + { + hash += element->type; + switch(element->type) + { + case VIEWPORT: + case LINE: + case SUBLINES: + case CONDITIONAL: + hash += element->children_count; + break; + + case TAG: + for(unsigned int i = 0; i < strlen(element->tag->name); i++) + hash += element->tag->name[i]; + break; + + case COMMENT: + case TEXT: + for(unsigned int i = 0; i < strlen(element->text); i++) + { + if(i % 2) + hash += element->text[i] % element->type; + else + hash += element->text[i] % element->type * 2; + } + break; + } + + } + + if(param) + { + hash += param->type; + switch(param->type) + { + case skin_tag_parameter::DEFAULT: + case skin_tag_parameter::CODE: + break; + + case skin_tag_parameter::NUMERIC: + hash += param->data.numeric * (param->data.numeric / 4); + break; + + case skin_tag_parameter::STRING: + for(unsigned int i = 0; i < strlen(param->data.text); i++) + { + if(i % 2) + hash += param->data.text[i] * 2; + else + hash += param->data.text[i]; + } + break; + } + } + + for(int i = 0; i < children.count(); i++) + { + hash += children[i]->genHash(); + } + + return hash; +} + ParseTreeNode* ParseTreeNode::child(int row) { if(row < 0 || row >= children.count()) @@ -234,7 +303,7 @@ ParseTreeNode* ParseTreeNode::child(int row) int ParseTreeNode::numChildren() const { - return children.count(); + return children.count(); } diff --git a/utils/themeeditor/parsetreenode.h b/utils/themeeditor/parsetreenode.h index 12f1d364d..7a0807bb0 100644 --- a/utils/themeeditor/parsetreenode.h +++ b/utils/themeeditor/parsetreenode.h @@ -37,6 +37,8 @@ public: virtual ~ParseTreeNode(); QString genCode() const; + int genHash() const; + bool isParam() const{ if(param) return true; else return false; } struct skin_tag_parameter* getParam(){ return param;} struct skin_element* getElement(){return element;} @@ -46,6 +48,13 @@ public: QVariant data(int column) const; int getRow() const; ParseTreeNode* getParent() const; + ParseTreeNode* getChild(int row) const + { + if(row < children.count()) + return children[row]; + else + return 0; + } private: ParseTreeNode* parent; diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index 5b1ab34ca..9bc78149d 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro @@ -1,3 +1,10 @@ +# build in a separate folder. +MYBUILDDIR = $$OUT_PWD/build/ +OBJECTS_DIR = $$MYBUILDDIR/o +UI_DIR = $$MYBUILDDIR/ui +MOC_DIR = $$MYBUILDDIR/moc +RCC_DIR = $$MYBUILDDIR/rcc + HEADERS += tag_table.h \ symbols.h \ skin_parser.h \ -- 2.11.4.GIT