diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-08-05 00:43:33 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-08-05 00:43:33 +0000 |
commit | 054a85fdca651844f969f44755b8531ab2e962d7 (patch) | |
tree | d424970a137d4bbdd57102961a46653e67589820 /utils/themeeditor/models | |
parent | 467451878726a3755eb3b2b472a3b33299cb9245 (diff) | |
download | rockbox-054a85fdca651844f969f44755b8531ab2e962d7.tar.gz rockbox-054a85fdca651844f969f44755b8531ab2e962d7.zip |
Theme Editor: Added code generate/undo functionality to SkinViewer
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27704 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor/models')
-rw-r--r-- | utils/themeeditor/models/parsetreemodel.cpp | 18 | ||||
-rw-r--r-- | utils/themeeditor/models/parsetreemodel.h | 4 | ||||
-rw-r--r-- | utils/themeeditor/models/parsetreenode.cpp | 35 | ||||
-rw-r--r-- | utils/themeeditor/models/parsetreenode.h | 10 |
4 files changed, 48 insertions, 19 deletions
diff --git a/utils/themeeditor/models/parsetreemodel.cpp b/utils/themeeditor/models/parsetreemodel.cpp index a7f04ffbf2..01d60c8775 100644 --- a/utils/themeeditor/models/parsetreemodel.cpp +++ b/utils/themeeditor/models/parsetreemodel.cpp @@ -40,7 +40,7 @@ ParseTreeModel::ParseTreeModel(const char* document, QObject* parent): this->tree = skin_parse(document); if(tree) - this->root = new ParseTreeNode(tree); + this->root = new ParseTreeNode(tree, this); else this->root = 0; @@ -77,7 +77,7 @@ QString ParseTreeModel::changeTree(const char *document) return error; } - ParseTreeNode* temp = new ParseTreeNode(test); + ParseTreeNode* temp = new ParseTreeNode(test, this); if(root) { @@ -364,3 +364,17 @@ QGraphicsScene* ParseTreeModel::render(ProjectModel* project, return scene; } + +void ParseTreeModel::paramChanged(ParseTreeNode *param) +{ + QModelIndex index = indexFromPointer(param); + emit dataChanged(index, index); +} + +QModelIndex ParseTreeModel::indexFromPointer(ParseTreeNode *p) +{ + /* Recursively finding an index for an arbitrary pointer within the tree */ + if(!p->getParent()) + return QModelIndex(); + return index(p->getRow(), 0, indexFromPointer(p->getParent())); +} diff --git a/utils/themeeditor/models/parsetreemodel.h b/utils/themeeditor/models/parsetreemodel.h index ec0a420a84..3c20a8ed3a 100644 --- a/utils/themeeditor/models/parsetreemodel.h +++ b/utils/themeeditor/models/parsetreemodel.h @@ -53,6 +53,8 @@ public: QString genCode(); /* Changes the parse tree to a new document */ QString changeTree(const char* document); + + /* Model implementation stuff */ QModelIndex index(int row, int column, const QModelIndex& parent) const; QModelIndex parent(const QModelIndex &child) const; int rowCount(const QModelIndex &parent) const; @@ -74,6 +76,8 @@ public: return fallback; } + void paramChanged(ParseTreeNode* param); + QModelIndex indexFromPointer(ParseTreeNode* p); private: ParseTreeNode* root; diff --git a/utils/themeeditor/models/parsetreenode.cpp b/utils/themeeditor/models/parsetreenode.cpp index 8d1fcc7d1a..1dedd4a689 100644 --- a/utils/themeeditor/models/parsetreenode.cpp +++ b/utils/themeeditor/models/parsetreenode.cpp @@ -36,19 +36,21 @@ int ParseTreeNode::openConditionals = 0; bool ParseTreeNode::breakFlag = false; /* Root element constructor */ -ParseTreeNode::ParseTreeNode(struct skin_element* data) - : parent(0), element(0), param(0), children() +ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeModel* model) + : parent(0), element(0), param(0), children(), model(model) { while(data) { - children.append(new ParseTreeNode(data, this)); + children.append(new ParseTreeNode(data, this, model)); data = data->next; } } /* Normal element constructor */ -ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent) - : parent(parent), element(data), param(0), children() +ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent, + ParseTreeModel* model) + : parent(parent), element(data), param(0), + children(), model(model) { switch(element->type) { @@ -58,29 +60,30 @@ ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent) { if(element->params[i].type == skin_tag_parameter::CODE) children.append(new ParseTreeNode(element->params[i].data.code, - this)); + this, model)); else - children.append(new ParseTreeNode(&element->params[i], this)); + children.append(new ParseTreeNode(&element->params[i], this, + model)); } break; case CONDITIONAL: for(int i = 0; i < element->params_count; i++) - children.append(new ParseTreeNode(&data->params[i], this)); + children.append(new ParseTreeNode(&data->params[i], this, model)); for(int i = 0; i < element->children_count; i++) - children.append(new ParseTreeNode(data->children[i], this)); + children.append(new ParseTreeNode(data->children[i], this, model)); break; case LINE_ALTERNATOR: for(int i = 0; i < element->children_count; i++) { - children.append(new ParseTreeNode(data->children[i], this)); + children.append(new ParseTreeNode(data->children[i], this, model)); } break; case VIEWPORT: for(int i = 0; i < element->params_count; i++) - children.append(new ParseTreeNode(&data->params[i], this)); + children.append(new ParseTreeNode(&data->params[i], this, model)); /* Deliberate fall-through here */ case LINE: @@ -89,7 +92,7 @@ case VIEWPORT: for(struct skin_element* current = data->children[i]; current; current = current->next) { - children.append(new ParseTreeNode(current, this)); + children.append(new ParseTreeNode(current, this, model)); } } break; @@ -100,8 +103,10 @@ case VIEWPORT: } /* Parameter constructor */ -ParseTreeNode::ParseTreeNode(skin_tag_parameter *data, ParseTreeNode *parent) - : parent(parent), element(0), param(data), children() +ParseTreeNode::ParseTreeNode(skin_tag_parameter *data, ParseTreeNode *parent, + ParseTreeModel *model) + : parent(parent), element(0), param(data), + children(), model(model) { } @@ -1085,5 +1090,7 @@ void ParseTreeNode::modParam(QVariant value, int index) param->data.number = value.toInt(); } + model->paramChanged(this); + } } diff --git a/utils/themeeditor/models/parsetreenode.h b/utils/themeeditor/models/parsetreenode.h index 39f0dbdfcd..106907799e 100644 --- a/utils/themeeditor/models/parsetreenode.h +++ b/utils/themeeditor/models/parsetreenode.h @@ -34,9 +34,11 @@ class ParseTreeNode { public: - ParseTreeNode(struct skin_element* data); - ParseTreeNode(struct skin_element* data, ParseTreeNode* parent); - ParseTreeNode(struct skin_tag_parameter* data, ParseTreeNode* parent); + ParseTreeNode(struct skin_element* data, ParseTreeModel* model); + ParseTreeNode(struct skin_element* data, ParseTreeNode* parent, + ParseTreeModel* model); + ParseTreeNode(struct skin_tag_parameter* data, ParseTreeNode* parent, + ParseTreeModel* model); virtual ~ParseTreeNode(); QString genCode() const; @@ -84,6 +86,8 @@ private: static bool breakFlag; QGraphicsItem* rendered; + ParseTreeModel* model; + }; #endif // PARSETREENODE_H |