summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-05-30 01:47:35 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-05-30 01:47:35 +0000
commit9f2e1b1e1a1dae857fe74728b91c5393d5f1c283 (patch)
treebfb60801f71d8660766ae45f9bb9d81a51b5b3ef /utils
parent9843626b6941f63b964c3352e996032247115aad (diff)
downloadrockbox-9f2e1b1e1a1dae857fe74728b91c5393d5f1c283.tar.gz
rockbox-9f2e1b1e1a1dae857fe74728b91c5393d5f1c283.zip
Theme Editor: Got a barely functional treeview in place
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26401 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils')
-rw-r--r--utils/themeeditor/main.cpp24
-rw-r--r--utils/themeeditor/parsetreemodel.cpp45
-rw-r--r--utils/themeeditor/parsetreemodel.h2
-rw-r--r--utils/themeeditor/parsetreenode.cpp4
4 files changed, 54 insertions, 21 deletions
diff --git a/utils/themeeditor/main.cpp b/utils/themeeditor/main.cpp
index 27ce2da23f..f876b1906e 100644
--- a/utils/themeeditor/main.cpp
+++ b/utils/themeeditor/main.cpp
@@ -36,12 +36,22 @@ extern "C"
36 36
37int main(int argc, char* argv[]) 37int main(int argc, char* argv[])
38{ 38{
39 QApplication app(argc, argv);
39 40
40 char doc[] = "#Comment\n%Vd(U);Hey\n%?bl(test,3,5,2,1)<param2|param3>"; 41 char doc[] = "#Comment\n%Vd(U);Hey\n%?bl(test,3,5,2,1)<param2|param3>";
41 42
43 ParseTreeModel tree(doc);
44
45 QTreeView view;
46 view.setModel(&tree);
47 view.show();
48
49 return app.exec();
50
51 /*
42 struct skin_element* test = skin_parse(doc); 52 struct skin_element* test = skin_parse(doc);
43 53
44 ParseTreeNode tree(test); 54 ParseTreeModel tree(doc);
45 std::cout << "----" << std::endl; 55 std::cout << "----" << std::endl;
46 if(std::string(doc) == tree.genCode().toStdString()) 56 if(std::string(doc) == tree.genCode().toStdString())
47 std::cout << "Code in/out matches" << std::endl; 57 std::cout << "Code in/out matches" << std::endl;
@@ -50,17 +60,7 @@ int main(int argc, char* argv[])
50 60
51 61
52 skin_free_tree(test); 62 skin_free_tree(test);
63 */
53 64
54/*
55 QApplication app(argc, argv);
56
57 QTreeView tree;
58 ParseTreeModel model(doc);
59 tree.setModel(&model);
60 tree.show();
61
62 return app.exec();
63*/
64 return 0;
65} 65}
66 66
diff --git a/utils/themeeditor/parsetreemodel.cpp b/utils/themeeditor/parsetreemodel.cpp
index 4c46320bb3..08f10615ef 100644
--- a/utils/themeeditor/parsetreemodel.cpp
+++ b/utils/themeeditor/parsetreemodel.cpp
@@ -47,24 +47,59 @@ QString ParseTreeModel::genCode()
47QModelIndex ParseTreeModel::index(int row, int column, 47QModelIndex ParseTreeModel::index(int row, int column,
48 const QModelIndex& parent) const 48 const QModelIndex& parent) const
49{ 49{
50 return QModelIndex(); 50 if(!hasIndex(row, column, parent))
51 return QModelIndex();
52
53 ParseTreeNode* foundParent;
54
55 if(parent.isValid())
56 foundParent = static_cast<ParseTreeNode*>(parent.internalPointer());
57 else
58 foundParent = root;
59
60 if(row < foundParent->numChildren() && row >= 0)
61 return createIndex(row, column, foundParent->child(row));
62 else
63 return QModelIndex();
51} 64}
52 65
53QModelIndex ParseTreeModel::parent(const QModelIndex &child) const 66QModelIndex ParseTreeModel::parent(const QModelIndex &child) const
54{ 67{
55 return QModelIndex(); 68 if(!child.isValid())
69 return QModelIndex();
70
71 ParseTreeNode* foundParent = static_cast<ParseTreeNode*>
72 (child.internalPointer())->getParent();
73
74 if(foundParent == root)
75 return QModelIndex();
76
77 return createIndex(foundParent->getRow(), 0, foundParent);
56} 78}
57 79
58int ParseTreeModel::rowCount(const QModelIndex &parent) const 80int ParseTreeModel::rowCount(const QModelIndex &parent) const
59{ 81{
60 return 0; 82 if(!parent.isValid())
83 return root->numChildren();
84
85 if(parent.column() > 0)
86 return 0;
87
88 return static_cast<ParseTreeNode*>(parent.internalPointer())->numChildren();
61} 89}
62 90
63int ParseTreeModel::columnCount(const QModelIndex &parent) const 91int ParseTreeModel::columnCount(const QModelIndex &parent) const
64{ 92{
65 return 0; 93 return 3;
66} 94}
67QVariant ParseTreeModel::data(const QModelIndex &index, int role) const 95QVariant ParseTreeModel::data(const QModelIndex &index, int role) const
68{ 96{
69 return QVariant(); 97 if(!index.isValid())
98 return QVariant();
99
100 if(role != Qt::DisplayRole)
101 return QVariant();
102
103 return static_cast<ParseTreeNode*>(index.internalPointer())->
104 data(index.column());
70} 105}
diff --git a/utils/themeeditor/parsetreemodel.h b/utils/themeeditor/parsetreemodel.h
index 4abf623672..eedfe3f6bb 100644
--- a/utils/themeeditor/parsetreemodel.h
+++ b/utils/themeeditor/parsetreemodel.h
@@ -39,7 +39,7 @@ class ParseTreeModel : public QAbstractItemModel
39 Q_OBJECT 39 Q_OBJECT
40 40
41public: 41public:
42 /* Initializes a tree with a WPS document in a string */ 42 /* Initializes a tree with a skin document in a string */
43 ParseTreeModel(char* document, QObject* parent = 0); 43 ParseTreeModel(char* document, QObject* parent = 0);
44 virtual ~ParseTreeModel(); 44 virtual ~ParseTreeModel();
45 45
diff --git a/utils/themeeditor/parsetreenode.cpp b/utils/themeeditor/parsetreenode.cpp
index 60a18b8dbc..caafff5f43 100644
--- a/utils/themeeditor/parsetreenode.cpp
+++ b/utils/themeeditor/parsetreenode.cpp
@@ -273,9 +273,8 @@ QVariant ParseTreeNode::data(int column) const
273 switch(element->type) 273 switch(element->type)
274 { 274 {
275 case LINE: 275 case LINE:
276 return QString();
277
278 case SUBLINES: 276 case SUBLINES:
277 case CONDITIONAL:
279 return QString(); 278 return QString();
280 279
281 case NEWLINE: 280 case NEWLINE:
@@ -285,7 +284,6 @@ QVariant ParseTreeNode::data(int column) const
285 case COMMENT: 284 case COMMENT:
286 return QString(element->text); 285 return QString(element->text);
287 286
288 case CONDITIONAL:
289 case TAG: 287 case TAG:
290 return QString(element->name); 288 return QString(element->name);
291 } 289 }