summaryrefslogtreecommitdiffstats
path: root/utils/themeeditor
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-05-30 01:20:05 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-05-30 01:20:05 +0000
commit9843626b6941f63b964c3352e996032247115aad (patch)
tree157a0a54d14c403e859fe44c76ecb1fdb6f98bfb /utils/themeeditor
parentcc07d688668d6e8ec3c6bb66fe2e36462ef6c8b7 (diff)
downloadrockbox-9843626b6941f63b964c3352e996032247115aad.tar.gz
rockbox-9843626b6941f63b964c3352e996032247115aad.tar.bz2
rockbox-9843626b6941f63b964c3352e996032247115aad.zip
Themeditor: Got the ParseTreeNode class in good shape, preparing to start on ParseTreeModel
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26400 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor')
-rw-r--r--utils/themeeditor/parsetreemodel.cpp65
-rw-r--r--utils/themeeditor/parsetreemodel.h4
-rw-r--r--utils/themeeditor/parsetreenode.cpp160
-rw-r--r--utils/themeeditor/parsetreenode.h3
4 files changed, 170 insertions, 62 deletions
diff --git a/utils/themeeditor/parsetreemodel.cpp b/utils/themeeditor/parsetreemodel.cpp
index c99f166c41..4c46320bb3 100644
--- a/utils/themeeditor/parsetreemodel.cpp
+++ b/utils/themeeditor/parsetreemodel.cpp
@@ -23,85 +23,48 @@
#include "parsetreemodel.h"
#include <QObject>
-ParseTreeModel::ParseTreeModel(char* wps, QObject* parent):
+ParseTreeModel::ParseTreeModel(char* document, QObject* parent):
QAbstractItemModel(parent)
{
- this->tree = skin_parse(wps);
- this->root = new ParseTreeNode(tree, 0);
+ this->tree = skin_parse(document);
+ this->root = new ParseTreeNode(tree);
}
ParseTreeModel::~ParseTreeModel()
{
- delete root;
+ if(root)
+ delete root;
+ if(tree)
+ skin_free_tree(tree);
}
-QString genCode()
+QString ParseTreeModel::genCode()
{
- return QString();
+ return root->genCode();
}
-/*
QModelIndex ParseTreeModel::index(int row, int column,
const QModelIndex& parent) const
{
- if(!hasIndex(row, column, parent))
- return QModelIndex();
-
- ParseTreeNode* parentLookup;
-
- if(!parent.isValid())
- parentLookup = root;
- else
- parentLookup = static_cast<ParseTreeNode*>(parent.internalPointer());
-
- ParseTreeNode* childLookup = parentLookup->child(row);
- if(childLookup)
- return createIndex(row, column, childLookup);
- else
- return QModelIndex();
+ return QModelIndex();
}
QModelIndex ParseTreeModel::parent(const QModelIndex &child) const
{
- if(!child.isValid())
- return QModelIndex();
-
- ParseTreeNode* childLookup = static_cast<ParseTreeNode*>
- (child.internalPointer());
- ParseTreeNode* parentLookup = childLookup->parent();
-
- if(parentLookup == root)
- return QModelIndex();
-
- return createIndex(parentLookup->row(), 0, parentLookup);
+ return QModelIndex();
}
int ParseTreeModel::rowCount(const QModelIndex &parent) const
{
- ParseTreeNode* parentLookup;
- if(parent.column() > 0)
- return 0;
-
- if(!parent.isValid())
- parentLookup = root;
- else
- parentLookup = static_cast<ParseTreeNode*>(parent.internalPointer());
-
- return parentLookup->childCount();
+ return 0;
}
int ParseTreeModel::columnCount(const QModelIndex &parent) const
{
- return 2;
+ return 0;
}
-
QVariant ParseTreeModel::data(const QModelIndex &index, int role) const
{
- if(!index.isValid() || role != Qt::DisplayRole)
- return QVariant();
-
- ParseTreeNode* item = static_cast<ParseTreeNode*>(index.internalPointer());
- return item->data(index.column());
+ return QVariant();
}
-*/
diff --git a/utils/themeeditor/parsetreemodel.h b/utils/themeeditor/parsetreemodel.h
index 64365ed038..4abf623672 100644
--- a/utils/themeeditor/parsetreemodel.h
+++ b/utils/themeeditor/parsetreemodel.h
@@ -40,18 +40,16 @@ class ParseTreeModel : public QAbstractItemModel
public:
/* Initializes a tree with a WPS document in a string */
- ParseTreeModel(char* wps, QObject* parent = 0);
+ ParseTreeModel(char* document, QObject* parent = 0);
virtual ~ParseTreeModel();
QString genCode();
- /*
QModelIndex index(int row, int column, const QModelIndex& parent) const;
QModelIndex parent(const QModelIndex &child) const;
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
- */
private:
ParseTreeNode* root;
diff --git a/utils/themeeditor/parsetreenode.cpp b/utils/themeeditor/parsetreenode.cpp
index ccfac615be..60a18b8dbc 100644
--- a/utils/themeeditor/parsetreenode.cpp
+++ b/utils/themeeditor/parsetreenode.cpp
@@ -181,6 +181,10 @@ QString ParseTreeNode::genCode() const
buffer.append(DEFAULTSYM);
break;
+ case skin_tag_parameter::CODE:
+ buffer.append(QObject::tr("This doesn't belong here"));
+ break;
+
}
}
else
@@ -191,10 +195,152 @@ QString ParseTreeNode::genCode() const
return buffer;
}
-/*
-ParseTreeNode* child(int row);
-int numChildren() const;
-QVariant data(int column) const;
-int getRow() const;
-ParseTreeNode* getParent();
-*/
+
+ParseTreeNode* ParseTreeNode::child(int row)
+{
+ if(row < 0 || row >= children.count())
+ return 0;
+
+ return children[row];
+}
+
+int ParseTreeNode::numChildren() const
+{
+ return children.count();
+}
+
+
+QVariant ParseTreeNode::data(int column) const
+{
+ switch(column)
+ {
+ /* Column 0 is the element type */
+ case 0:
+ if(element)
+ {
+ switch(element->type)
+ {
+ case LINE:
+ return QObject::tr("Logical Line");
+
+ case SUBLINES:
+ return QObject::tr("Alternator");
+
+ case COMMENT:
+ return QObject::tr("Comment");
+
+ case CONDITIONAL:
+ return QObject::tr("Conditional Tag");
+
+ case TAG:
+ return QObject::tr("Tag");
+
+ case NEWLINE:
+ return QObject::tr("Newline");
+
+ case TEXT:
+ return QObject::tr("Plaintext");
+ }
+ }
+ else if(param)
+ {
+ switch(param->type)
+ {
+ case skin_tag_parameter::STRING:
+ return QObject::tr("String");
+
+ case skin_tag_parameter::NUMERIC:
+ return QObject::tr("Number");
+
+ case skin_tag_parameter::DEFAULT:
+ return QObject::tr("Default Argument");
+
+ case skin_tag_parameter::CODE:
+ return QObject::tr("This doesn't belong here");
+ }
+ }
+ else
+ {
+ return QObject::tr("Root");
+ }
+
+ break;
+
+ /* Column 1 is the value */
+ case 1:
+ if(element)
+ {
+ switch(element->type)
+ {
+ case LINE:
+ return QString();
+
+ case SUBLINES:
+ return QString();
+
+ case NEWLINE:
+ return QObject::tr("\\n");
+
+ case TEXT:
+ case COMMENT:
+ return QString(element->text);
+
+ case CONDITIONAL:
+ case TAG:
+ return QString(element->name);
+ }
+ }
+ else if(param)
+ {
+ switch(param->type)
+ {
+ case skin_tag_parameter::DEFAULT:
+ return QObject::tr("-");
+
+ case skin_tag_parameter::STRING:
+ return QString(param->data.text);
+
+ case skin_tag_parameter::NUMERIC:
+ return QString::number(param->data.numeric, 10);
+
+ case skin_tag_parameter::CODE:
+ return QObject::tr("Seriously, something's wrong here");
+ }
+ }
+ else
+ {
+ return QString();
+ }
+ break;
+
+ /* Column 2 is the line number */
+ case 2:
+ if(element)
+ return QString::number(element->line, 10);
+ else
+ return QString();
+ break;
+ }
+
+ return QVariant();
+}
+
+
+int ParseTreeNode::getRow() const
+{
+ if(!parent)
+ return -1;
+
+ return parent->children.indexOf(const_cast<ParseTreeNode*>(this));
+}
+
+ParseTreeNode* ParseTreeNode::getParent() const
+{
+ return parent;
+}
+
+ParseTreeNode::~ParseTreeNode()
+{
+ for(int i = 0; i < children.count(); i++)
+ delete children[i];
+}
diff --git a/utils/themeeditor/parsetreenode.h b/utils/themeeditor/parsetreenode.h
index 4d8c4ebc14..822924ace2 100644
--- a/utils/themeeditor/parsetreenode.h
+++ b/utils/themeeditor/parsetreenode.h
@@ -37,6 +37,7 @@ public:
ParseTreeNode(struct skin_element* data);
ParseTreeNode(struct skin_element* data, ParseTreeNode* parent);
ParseTreeNode(struct skin_tag_parameter* data, ParseTreeNode* parent);
+ virtual ~ParseTreeNode();
QString genCode() const;
@@ -44,7 +45,7 @@ public:
int numChildren() const;
QVariant data(int column) const;
int getRow() const;
- ParseTreeNode* getParent();
+ ParseTreeNode* getParent() const;
private:
ParseTreeNode* parent;