From 9f2e1b1e1a1dae857fe74728b91c5393d5f1c283 Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Sun, 30 May 2010 01:47:35 +0000 Subject: Theme Editor: Got a barely functional treeview in place git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26401 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/main.cpp | 24 +++++++++---------- utils/themeeditor/parsetreemodel.cpp | 45 ++++++++++++++++++++++++++++++++---- utils/themeeditor/parsetreemodel.h | 2 +- utils/themeeditor/parsetreenode.cpp | 4 +--- 4 files changed, 54 insertions(+), 21 deletions(-) (limited to 'utils/themeeditor') 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" int main(int argc, char* argv[]) { + QApplication app(argc, argv); char doc[] = "#Comment\n%Vd(U);Hey\n%?bl(test,3,5,2,1)"; + ParseTreeModel tree(doc); + + QTreeView view; + view.setModel(&tree); + view.show(); + + return app.exec(); + + /* struct skin_element* test = skin_parse(doc); - ParseTreeNode tree(test); + ParseTreeModel tree(doc); std::cout << "----" << std::endl; if(std::string(doc) == tree.genCode().toStdString()) std::cout << "Code in/out matches" << std::endl; @@ -50,17 +60,7 @@ int main(int argc, char* argv[]) skin_free_tree(test); + */ -/* - QApplication app(argc, argv); - - QTreeView tree; - ParseTreeModel model(doc); - tree.setModel(&model); - tree.show(); - - return app.exec(); -*/ - return 0; } 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() QModelIndex ParseTreeModel::index(int row, int column, const QModelIndex& parent) const { - return QModelIndex(); + if(!hasIndex(row, column, parent)) + return QModelIndex(); + + ParseTreeNode* foundParent; + + if(parent.isValid()) + foundParent = static_cast(parent.internalPointer()); + else + foundParent = root; + + if(row < foundParent->numChildren() && row >= 0) + return createIndex(row, column, foundParent->child(row)); + else + return QModelIndex(); } QModelIndex ParseTreeModel::parent(const QModelIndex &child) const { - return QModelIndex(); + if(!child.isValid()) + return QModelIndex(); + + ParseTreeNode* foundParent = static_cast + (child.internalPointer())->getParent(); + + if(foundParent == root) + return QModelIndex(); + + return createIndex(foundParent->getRow(), 0, foundParent); } int ParseTreeModel::rowCount(const QModelIndex &parent) const { - return 0; + if(!parent.isValid()) + return root->numChildren(); + + if(parent.column() > 0) + return 0; + + return static_cast(parent.internalPointer())->numChildren(); } int ParseTreeModel::columnCount(const QModelIndex &parent) const { - return 0; + return 3; } QVariant ParseTreeModel::data(const QModelIndex &index, int role) const { - return QVariant(); + if(!index.isValid()) + return QVariant(); + + if(role != Qt::DisplayRole) + return QVariant(); + + return static_cast(index.internalPointer())-> + data(index.column()); } 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 Q_OBJECT public: - /* Initializes a tree with a WPS document in a string */ + /* Initializes a tree with a skin document in a string */ ParseTreeModel(char* document, QObject* parent = 0); virtual ~ParseTreeModel(); 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 switch(element->type) { case LINE: - return QString(); - case SUBLINES: + case CONDITIONAL: return QString(); case NEWLINE: @@ -285,7 +284,6 @@ QVariant ParseTreeNode::data(int column) const case COMMENT: return QString(element->text); - case CONDITIONAL: case TAG: return QString(element->name); } -- cgit v1.2.3