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)
downloadrockbox-5943f4c5e239475a32ac2b341a6df8189c8f1768.tar.gz
rockbox-5943f4c5e239475a32ac2b341a6df8189c8f1768.zip
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 @@
21 21
22 22
23#include "parsetreemodel.h" 23#include "parsetreemodel.h"
24#include "symbols.h"
25
26#include <cstdlib>
27
24#include <QObject> 28#include <QObject>
25 29
26ParseTreeModel::ParseTreeModel(char* document, QObject* parent): 30ParseTreeModel::ParseTreeModel(char* document, QObject* parent):
@@ -82,7 +86,7 @@ int ParseTreeModel::rowCount(const QModelIndex &parent) const
82 if(!parent.isValid()) 86 if(!parent.isValid())
83 return root->numChildren(); 87 return root->numChildren();
84 88
85 if(parent.column() > 0) 89 if(parent.column() != typeColumn)
86 return 0; 90 return 0;
87 91
88 return static_cast<ParseTreeNode*>(parent.internalPointer())->numChildren(); 92 return static_cast<ParseTreeNode*>(parent.internalPointer())->numChildren();
@@ -90,8 +94,9 @@ int ParseTreeModel::rowCount(const QModelIndex &parent) const
90 94
91int ParseTreeModel::columnCount(const QModelIndex &parent) const 95int ParseTreeModel::columnCount(const QModelIndex &parent) const
92{ 96{
93 return 3; 97 return numColumns;
94} 98}
99
95QVariant ParseTreeModel::data(const QModelIndex &index, int role) const 100QVariant ParseTreeModel::data(const QModelIndex &index, int role) const
96{ 101{
97 if(!index.isValid()) 102 if(!index.isValid())
@@ -103,3 +108,94 @@ QVariant ParseTreeModel::data(const QModelIndex &index, int role) const
103 return static_cast<ParseTreeNode*>(index.internalPointer())-> 108 return static_cast<ParseTreeNode*>(index.internalPointer())->
104 data(index.column()); 109 data(index.column());
105} 110}
111
112QVariant ParseTreeModel::headerData(int col, Qt::Orientation orientation,
113 int role) const
114{
115 if(orientation != Qt::Horizontal)
116 return QVariant();
117
118 if(col >= numColumns)
119 return QVariant();
120
121 if(role != Qt::DisplayRole)
122 return QVariant();
123
124 switch(col)
125 {
126 case typeColumn:
127 return QObject::tr("Type");
128
129 case lineColumn:
130 return QObject::tr("Line");
131
132 case valueColumn:
133 return QObject::tr("Value");
134 }
135
136 return QVariant();
137}
138
139Qt::ItemFlags ParseTreeModel::flags(const QModelIndex &index) const
140{
141 Qt::ItemFlags retval = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
142
143 ParseTreeNode* element = static_cast<ParseTreeNode*>
144 (index.internalPointer());
145 if(element->isParam() && index.column() == valueColumn)
146 retval |= Qt::ItemIsEditable;
147
148 return retval;
149}
150
151bool ParseTreeModel::setData(const QModelIndex &index, const QVariant &value,
152 int role)
153{
154 if(role != Qt::EditRole)
155 return false;
156
157 if(index.column() != valueColumn)
158 return false;
159
160 ParseTreeNode* element = static_cast<ParseTreeNode*>
161 (index.internalPointer());
162
163 if(!element->isParam())
164 return false;
165
166 struct skin_tag_parameter* param = element->getParam();
167
168 /* Now that we've established that we do, in fact, have a parameter, we'll
169 * set it to its new value if an acceptable one has been entered
170 */
171 if(value.toString().trimmed() == QString(QChar(DEFAULTSYM)))
172 {
173 if(islower(param->type_code))
174 param->type = skin_tag_parameter::DEFAULT;
175 else
176 return false;
177 }
178 else if(tolower(param->type_code) == 's' || tolower(param->type_code) == 'f')
179 {
180 if(param->type == skin_tag_parameter::STRING)
181 free(param->data.text);
182
183 param->type = skin_tag_parameter::STRING;
184 param->data.text = strdup(value.toString().trimmed().toAscii());
185 }
186 else if(tolower(param->type_code) == 'i')
187 {
188 if(!value.canConvert(QVariant::Int))
189 return false;
190
191 param->type = skin_tag_parameter::NUMERIC;
192 param->data.numeric = value.toInt();
193 }
194 else
195 {
196 return false;
197 }
198
199 emit dataChanged(index, index);
200 return true;
201}
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
36 Q_OBJECT 36 Q_OBJECT
37 37
38public: 38public:
39 /* Constants */
40 static const int numColumns = 3;
41 static const int typeColumn = 0;
42 static const int lineColumn = 1;
43 static const int valueColumn = 2;
44
39 /* Initializes a tree with a skin document in a string */ 45 /* Initializes a tree with a skin document in a string */
40 ParseTreeModel(char* document, QObject* parent = 0); 46 ParseTreeModel(char* document, QObject* parent = 0);
41 virtual ~ParseTreeModel(); 47 virtual ~ParseTreeModel();
@@ -47,6 +53,9 @@ public:
47 int rowCount(const QModelIndex &parent) const; 53 int rowCount(const QModelIndex &parent) const;
48 int columnCount(const QModelIndex &parent) const; 54 int columnCount(const QModelIndex &parent) const;
49 QVariant data(const QModelIndex &index, int role) const; 55 QVariant data(const QModelIndex &index, int role) const;
56 QVariant headerData(int col, Qt::Orientation orientation, int role) const;
57 Qt::ItemFlags flags(const QModelIndex &index) const;
58 bool setData(const QModelIndex &index, const QVariant &value, int role);
50 59
51private: 60private:
52 ParseTreeNode* root; 61 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"
26} 26}
27 27
28#include "parsetreenode.h" 28#include "parsetreenode.h"
29#include "parsetreemodel.h"
29 30
30/* Root element constructor */ 31/* Root element constructor */
31ParseTreeNode::ParseTreeNode(struct skin_element* data) 32ParseTreeNode::ParseTreeNode(struct skin_element* data)
@@ -223,8 +224,7 @@ QVariant ParseTreeNode::data(int column) const
223{ 224{
224 switch(column) 225 switch(column)
225 { 226 {
226 /* Column 0 is the element type */ 227 case ParseTreeModel::typeColumn:
227 case 0:
228 if(element) 228 if(element)
229 { 229 {
230 switch(element->type) 230 switch(element->type)
@@ -278,8 +278,7 @@ QVariant ParseTreeNode::data(int column) const
278 278
279 break; 279 break;
280 280
281 /* Column 1 is the value */ 281 case ParseTreeModel::valueColumn:
282 case 1:
283 if(element) 282 if(element)
284 { 283 {
285 switch(element->type) 284 switch(element->type)
@@ -324,8 +323,7 @@ QVariant ParseTreeNode::data(int column) const
324 } 323 }
325 break; 324 break;
326 325
327 /* Column 2 is the line number */ 326 case ParseTreeModel::lineColumn:
328 case 2:
329 if(element) 327 if(element)
330 return QString::number(element->line, 10); 328 return QString::number(element->line, 10);
331 else 329 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:
37 virtual ~ParseTreeNode(); 37 virtual ~ParseTreeNode();
38 38
39 QString genCode() const; 39 QString genCode() const;
40 bool isParam() const{ if(param) return true; else return false; }
41 struct skin_tag_parameter* getParam(){ return param;}
42 struct skin_element* getElement(){return element;}
40 43
41 ParseTreeNode* child(int row); 44 ParseTreeNode* child(int row);
42 int numChildren() const; 45 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)
481 if(*cursor == COMMENTSYM) 481 if(*cursor == COMMENTSYM)
482 skip_comment(&cursor); 482 skip_comment(&cursor);
483 483
484 /* Storing the type code */
485 element->params[i].type_code = *tag_args;
486
484 /* Checking a nullable argument for null */ 487 /* Checking a nullable argument for null */
485 if(*cursor == DEFAULTSYM) 488 if(*cursor == DEFAULTSYM)
486 { 489 {
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
85 char* text; 85 char* text;
86 struct skin_element* code; 86 struct skin_element* code;
87 } data; 87 } data;
88
89 char type_code;
88 90
89}; 91};
90 92