forked from len0rd/rockbox
Theme Editor: Got a barely functional treeview in place
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26401 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
9843626b69
commit
9f2e1b1e1a
4 changed files with 54 additions and 21 deletions
|
|
@ -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)<param2|param3>";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<ParseTreeNode*>(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<ParseTreeNode*>
|
||||
(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<ParseTreeNode*>(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<ParseTreeNode*>(index.internalPointer())->
|
||||
data(index.column());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue