summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-06-02 20:36:30 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-06-02 20:36:30 +0000
commite5a3ec2baf5bc57f93f5ea19fa9198e2a3e080db (patch)
tree68002e6e06420e7b6453cc00a8f049114b19a721 /utils
parent87174d83fdde79a70bc3daad20729df585b7bbff (diff)
downloadrockbox-e5a3ec2baf5bc57f93f5ea19fa9198e2a3e080db.tar.gz
rockbox-e5a3ec2baf5bc57f93f5ea19fa9198e2a3e080db.tar.bz2
rockbox-e5a3ec2baf5bc57f93f5ea19fa9198e2a3e080db.zip
Changed build subdirectory
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26492 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils')
-rw-r--r--utils/themeeditor/editorwindow.cpp10
-rw-r--r--utils/themeeditor/parsetreemodel.cpp39
-rw-r--r--utils/themeeditor/parsetreemodel.h2
-rw-r--r--utils/themeeditor/parsetreenode.cpp71
-rw-r--r--utils/themeeditor/parsetreenode.h9
-rw-r--r--utils/themeeditor/themeeditor.pro7
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) :
{
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 9faa9ea560..918903bb68 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 4c448ce558..76960937f1 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 99fdbd858d..3a20b1e003 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 12f1d364d9..7a0807bb0d 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 5b1ab34ca2..9bc78149d2 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 \