summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--utils/themeeditor/main.cpp11
-rw-r--r--utils/themeeditor/parsetreemodel.cpp101
-rw-r--r--utils/themeeditor/parsetreemodel.h59
-rw-r--r--utils/themeeditor/parsetreenode.cpp56
-rw-r--r--utils/themeeditor/parsetreenode.h35
-rw-r--r--utils/themeeditor/themeeditor.pro8
6 files changed, 267 insertions, 3 deletions
diff --git a/utils/themeeditor/main.cpp b/utils/themeeditor/main.cpp
index 45ea662944..b43b419143 100644
--- a/utils/themeeditor/main.cpp
+++ b/utils/themeeditor/main.cpp
@@ -32,9 +32,10 @@ namespace wps
#include <cstdio>
#include <QtGui/QApplication>
-#include <QFileSystemModel>
#include <QTreeView>
+#include "parsetreemodel.h"
+
int main(int argc, char* argv[])
{
@@ -46,6 +47,14 @@ int main(int argc, char* argv[])
wps::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
new file mode 100644
index 0000000000..cf6af14a5e
--- /dev/null
+++ b/utils/themeeditor/parsetreemodel.cpp
@@ -0,0 +1,101 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2010 Robert Bieber
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+
+#include "parsetreemodel.h"
+#include <QObject>
+
+ParseTreeModel::ParseTreeModel(char* wps, QObject* parent):
+ QAbstractItemModel(parent)
+{
+ this->wps = skin_parse(wps);
+ skin_debug_tree(this->wps);
+ this->root = new ParseTreeNode(this->wps, 0, true);
+}
+
+
+ParseTreeModel::~ParseTreeModel()
+{
+ delete root;
+}
+
+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();
+}
+
+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);
+}
+
+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();
+}
+
+int ParseTreeModel::columnCount(const QModelIndex &parent) const
+{
+ return 2;
+}
+
+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());
+}
diff --git a/utils/themeeditor/parsetreemodel.h b/utils/themeeditor/parsetreemodel.h
new file mode 100644
index 0000000000..78484eb5f4
--- /dev/null
+++ b/utils/themeeditor/parsetreemodel.h
@@ -0,0 +1,59 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2010 Robert Bieber
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+extern "C"
+{
+#include "skin_parser.h"
+#include "skin_debug.h"
+}
+
+#ifndef PARSETREEMODEL_H
+#define PARSETREEMODEL_H
+
+#include <QAbstractItemModel>
+#include <QList>
+
+#include "parsetreenode.h"
+
+class ParseTreeModel : public QAbstractItemModel
+{
+
+ Q_OBJECT
+
+public:
+ /* Initializes a tree with a WPS document in a string */
+ ParseTreeModel(char* wps, QObject* parent = 0);
+ virtual ~ParseTreeModel();
+
+ 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;
+ struct skin_element* wps;
+};
+
+
+
+#endif // PARSETREEMODEL_H
diff --git a/utils/themeeditor/parsetreenode.cpp b/utils/themeeditor/parsetreenode.cpp
new file mode 100644
index 0000000000..97cb559906
--- /dev/null
+++ b/utils/themeeditor/parsetreenode.cpp
@@ -0,0 +1,56 @@
+#include "parsetreenode.h"
+
+ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent,
+ bool stop):
+ parentLink(parent), element(data)
+{
+
+ if(stop)
+ return;
+ for(int i = 0; i < 5; i++)
+ appendChild(new ParseTreeNode(data, this, true));
+}
+
+ParseTreeNode::~ParseTreeNode()
+{
+ qDeleteAll(children);
+}
+
+void ParseTreeNode::appendChild(ParseTreeNode* child)
+{
+ children.append(child);
+}
+
+ParseTreeNode* ParseTreeNode::child(int row)
+{
+ return children[row];
+}
+
+int ParseTreeNode::childCount() const
+{
+ return children.count();
+}
+
+int ParseTreeNode::columnCount() const
+{
+ return 2;
+}
+
+QVariant ParseTreeNode::data(int column) const
+{
+ if(column == 0)
+ return element->type;
+ else
+ return element->line;
+}
+int ParseTreeNode::row() const
+{
+ if(parentLink)
+ return parentLink->children.indexOf(const_cast<ParseTreeNode*>(this));
+ return 0;
+}
+
+ParseTreeNode* ParseTreeNode::parent()
+{
+ return parentLink;
+}
diff --git a/utils/themeeditor/parsetreenode.h b/utils/themeeditor/parsetreenode.h
new file mode 100644
index 0000000000..bc091b9aa4
--- /dev/null
+++ b/utils/themeeditor/parsetreenode.h
@@ -0,0 +1,35 @@
+#ifndef PARSETREENODE_H
+#define PARSETREENODE_H
+
+extern "C"
+{
+#include "skin_parser.h"
+}
+
+#include <QString>
+#include <QVariant>
+#include <QList>
+
+class ParseTreeNode
+{
+public:
+ ParseTreeNode(struct skin_element* data, ParseTreeNode* parent, bool stop = false);
+ virtual ~ParseTreeNode();
+
+ void appendChild(ParseTreeNode* child);
+
+ ParseTreeNode* child(int row);
+ int childCount() const;
+ int columnCount() const;
+ QVariant data(int column) const;
+ int row() const;
+ ParseTreeNode* parent();
+
+private:
+ ParseTreeNode* parentLink;
+ QList<ParseTreeNode*> children;
+ struct skin_element* element;
+
+};
+
+#endif // PARSETREENODE_H
diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro
index ad6b41858e..b1c7688130 100644
--- a/utils/themeeditor/themeeditor.pro
+++ b/utils/themeeditor/themeeditor.pro
@@ -2,10 +2,14 @@ HEADERS += tag_table.h \
symbols.h \
skin_parser.h \
skin_scan.h \
- skin_debug.h
+ skin_debug.h \
+ parsetreemodel.h \
+ parsetreenode.h
SOURCES += tag_table.c \
skin_parser.c \
skin_scan.c \
skin_debug.c \
- main.cpp
+ main.cpp \
+ parsetreemodel.cpp \
+ parsetreenode.cpp
OTHER_FILES += README