Changed build subdirectory

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26492 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Bieber 2010-06-02 20:36:30 +00:00
parent 87174d83fd
commit e5a3ec2baf
6 changed files with 130 additions and 8 deletions

View file

@ -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();
}

View file

@ -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();

View file

@ -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;

View file

@ -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();
}

View file

@ -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;

View file

@ -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 \