summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-06-01 19:55:20 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-06-01 19:55:20 +0000
commit5943f4c5e239475a32ac2b341a6df8189c8f1768 (patch)
treee010d5f5a600d06d947cffa8087d42274269caf3 /utils
parent253cfbcd47adfe3d7ccbd6f1646b1486397682df (diff)
Theme Editor: Enabled editing tag parameters from a treeview
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26452 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils')
-rw-r--r--utils/themeeditor/parsetreemodel.cpp100
-rw-r--r--utils/themeeditor/parsetreemodel.h9
-rw-r--r--utils/themeeditor/parsetreenode.cpp10
-rw-r--r--utils/themeeditor/parsetreenode.h3
-rw-r--r--utils/themeeditor/skin_parser.c3
-rw-r--r--utils/themeeditor/skin_parser.h2
6 files changed, 119 insertions, 8 deletions
diff --git a/utils/themeeditor/parsetreemodel.cpp b/utils/themeeditor/parsetreemodel.cpp
index 08f10615ef..a0e3abb03b 100644
--- a/utils/themeeditor/parsetreemodel.cpp
+++ b/utils/themeeditor/parsetreemodel.cpp
@@ -21,6 +21,10 @@
#include "parsetreemodel.h"
+#include "symbols.h"
+
+#include <cstdlib>
+
#include <QObject>
ParseTreeModel::ParseTreeModel(char* document, QObject* parent):
@@ -82,7 +86,7 @@ int ParseTreeModel::rowCount(const QModelIndex &parent) const
if(!parent.isValid())
return root->numChildren();
- if(parent.column() > 0)
+ if(parent.column() != typeColumn)
return 0;
return static_cast<ParseTreeNode*>(parent.internalPointer())->numChildren();
@@ -90,8 +94,9 @@ int ParseTreeModel::rowCount(const QModelIndex &parent) const
int ParseTreeModel::columnCount(const QModelIndex &parent) const
{
- return 3;
+ return numColumns;
}
+
QVariant ParseTreeModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
@@ -103,3 +108,94 @@ QVariant ParseTreeModel::data(const QModelIndex &index, int role) const
return static_cast<ParseTreeNode*>(index.internalPointer())->
data(index.column());
}
+
+QVariant ParseTreeModel::headerData(int col, Qt::Orientation orientation,
+ int role) const
+{
+ if(orientation != Qt::Horizontal)
+ return QVariant();
+
+ if(col >= numColumns)
+ return QVariant();
+
+ if(role != Qt::DisplayRole)
+ return QVariant();
+
+ switch(col)
+ {
+ case typeColumn:
+ return QObject::tr("Type");
+
+ case lineColumn:
+ return QObject::tr("Line");
+
+ case valueColumn:
+ return QObject::tr("Value");
+ }
+
+ return QVariant();
+}
+
+Qt::ItemFlags ParseTreeModel::flags(const QModelIndex &index) const
+{
+ Qt::ItemFlags retval = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+
+ ParseTreeNode* element = static_cast<ParseTreeNode*>
+ (index.internalPointer());
+ if(element->isParam() && index.column() == valueColumn)
+ retval |= Qt::ItemIsEditable;
+
+ return retval;
+}
+
+bool ParseTreeModel::setData(const QModelIndex &index, const QVariant &value,
+ int role)
+{
+ if(role != Qt::EditRole)
+ return false;
+
+ if(index.column() != valueColumn)
+ return false;
+
+ ParseTreeNode* element = static_cast<ParseTreeNode*>
+ (index.internalPointer());
+
+ if(!element->isParam())
+ return false;
+
+ struct skin_tag_parameter* param = element->getParam();
+
+ /* Now that we've established that we do, in fact, have a parameter, we'll
+ * set it to its new value if an acceptable one has been entered
+ */
+ if(value.toString().trimmed() == QString(QChar(DEFAULTSYM)))
+ {
+ if(islower(param->type_code))
+ param->type = skin_tag_parameter::DEFAULT;
+ else
+ return false;
+ }
+ else if(tolower(param->type_code) == 's' || tolower(param->type_code) == 'f')
+ {
+ if(param->type == skin_tag_parameter::STRING)
+ free(param->data.text);
+
+ param->type = skin_tag_parameter::STRING;
+ param->data.text = strdup(value.toString().trimmed().toAscii());
+ }
+ else if(tolower(param->type_code) == 'i')
+ {
+ if(!value.canConvert(QVariant::Int))
+ return false;
+
+ param->type = skin_tag_parameter::NUMERIC;
+ param->data.numeric = value.toInt();
+ }
+ else
+ {
+ return false;
+ }
+
+ emit dataChanged(index, index);
+ return true;
+}
diff --git a/utils/themeeditor/parsetreemodel.h b/utils/themeeditor/parsetreemodel.h
index 2d19452546..6d1f153d25 100644
--- a/utils/themeeditor/parsetreemodel.h
+++ b/utils/themeeditor/parsetreemodel.h
@@ -36,6 +36,12 @@ class ParseTreeModel : public QAbstractItemModel
Q_OBJECT
public:
+ /* Constants */
+ static const int numColumns = 3;
+ static const int typeColumn = 0;
+ static const int lineColumn = 1;
+ static const int valueColumn = 2;
+
/* Initializes a tree with a skin document in a string */
ParseTreeModel(char* document, QObject* parent = 0);
virtual ~ParseTreeModel();
@@ -47,6 +53,9 @@ public:
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
+ QVariant headerData(int col, Qt::Orientation orientation, int role) const;
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+ bool setData(const QModelIndex &index, const QVariant &value, int role);
private:
ParseTreeNode* root;
diff --git a/utils/themeeditor/parsetreenode.cpp b/utils/themeeditor/parsetreenode.cpp
index 3f8936a54c..98b4187a9e 100644
--- a/utils/themeeditor/parsetreenode.cpp
+++ b/utils/themeeditor/parsetreenode.cpp
@@ -26,6 +26,7 @@ extern "C"
}
#include "parsetreenode.h"
+#include "parsetreemodel.h"
/* Root element constructor */
ParseTreeNode::ParseTreeNode(struct skin_element* data)
@@ -223,8 +224,7 @@ QVariant ParseTreeNode::data(int column) const
{
switch(column)
{
- /* Column 0 is the element type */
- case 0:
+ case ParseTreeModel::typeColumn:
if(element)
{
switch(element->type)
@@ -278,8 +278,7 @@ QVariant ParseTreeNode::data(int column) const
break;
- /* Column 1 is the value */
- case 1:
+ case ParseTreeModel::valueColumn:
if(element)
{
switch(element->type)
@@ -324,8 +323,7 @@ QVariant ParseTreeNode::data(int column) const
}
break;
- /* Column 2 is the line number */
- case 2:
+ case ParseTreeModel::lineColumn:
if(element)
return QString::number(element->line, 10);
else
diff --git a/utils/themeeditor/parsetreenode.h b/utils/themeeditor/parsetreenode.h
index 49f89c19db..b07024f90e 100644
--- a/utils/themeeditor/parsetreenode.h
+++ b/utils/themeeditor/parsetreenode.h
@@ -37,6 +37,9 @@ public:
virtual ~ParseTreeNode();
QString genCode() const;
+ bool isParam() const{ if(param) return true; else return false; }
+ struct skin_tag_parameter* getParam(){ return param;}
+ struct skin_element* getElement(){return element;}
ParseTreeNode* child(int row);
int numChildren() const;
diff --git a/utils/themeeditor/skin_parser.c b/utils/themeeditor/skin_parser.c
index 9fd9001790..d118e9b97b 100644
--- a/utils/themeeditor/skin_parser.c
+++ b/utils/themeeditor/skin_parser.c
@@ -481,6 +481,9 @@ int skin_parse_tag(struct skin_element* element, char** document)
if(*cursor == COMMENTSYM)
skip_comment(&cursor);
+ /* Storing the type code */
+ element->params[i].type_code = *tag_args;
+
/* Checking a nullable argument for null */
if(*cursor == DEFAULTSYM)
{
diff --git a/utils/themeeditor/skin_parser.h b/utils/themeeditor/skin_parser.h
index 27d39cd5cc..cd50b996c0 100644
--- a/utils/themeeditor/skin_parser.h
+++ b/utils/themeeditor/skin_parser.h
@@ -85,6 +85,8 @@ struct skin_tag_parameter
char* text;
struct skin_element* code;
} data;
+
+ char type_code;
};