summaryrefslogtreecommitdiffstats
path: root/utils/themeeditor/parsetreemodel.cpp
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/themeeditor/parsetreemodel.cpp
parent253cfbcd47adfe3d7ccbd6f1646b1486397682df (diff)
downloadrockbox-5943f4c5e239475a32ac2b341a6df8189c8f1768.tar.gz
rockbox-5943f4c5e239475a32ac2b341a6df8189c8f1768.tar.bz2
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/themeeditor/parsetreemodel.cpp')
-rw-r--r--utils/themeeditor/parsetreemodel.cpp100
1 files changed, 98 insertions, 2 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 @@
#include "parsetreemodel.h"
+#include "symbols.h"
+
+#include <cstdlib>
+
#include <QObject>
ParseTreeModel::ParseTreeModel(char* document, QObject* parent):
@@ -82,7 +86,7 @@ int ParseTreeModel::rowCount(const QModelIndex &parent) const
if(!parent.isValid())
return root->numChildren();
- if(parent.column() > 0)
+ if(parent.column() != typeColumn)
return 0;
return static_cast<ParseTreeNode*>(parent.internalPointer())->numChildren();
@@ -90,8 +94,9 @@ int ParseTreeModel::rowCount(const QModelIndex &parent) const
int ParseTreeModel::columnCount(const QModelIndex &parent) const
{
- return 3;
+ return numColumns;
}
+
QVariant ParseTreeModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
@@ -103,3 +108,94 @@ QVariant ParseTreeModel::data(const QModelIndex &index, int role) const
return static_cast<ParseTreeNode*>(index.internalPointer())->
data(index.column());
}
+
+QVariant ParseTreeModel::headerData(int col, Qt::Orientation orientation,
+ int role) const
+{
+ if(orientation != Qt::Horizontal)
+ return QVariant();
+
+ if(col >= numColumns)
+ return QVariant();
+
+ if(role != Qt::DisplayRole)
+ return QVariant();
+
+ switch(col)
+ {
+ case typeColumn:
+ return QObject::tr("Type");
+
+ case lineColumn:
+ return QObject::tr("Line");
+
+ case valueColumn:
+ return QObject::tr("Value");
+ }
+
+ return QVariant();
+}
+
+Qt::ItemFlags ParseTreeModel::flags(const QModelIndex &index) const
+{
+ Qt::ItemFlags retval = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+
+ ParseTreeNode* element = static_cast<ParseTreeNode*>
+ (index.internalPointer());
+ if(element->isParam() && index.column() == valueColumn)
+ retval |= Qt::ItemIsEditable;
+
+ return retval;
+}
+
+bool ParseTreeModel::setData(const QModelIndex &index, const QVariant &value,
+ int role)
+{
+ if(role != Qt::EditRole)
+ return false;
+
+ if(index.column() != valueColumn)
+ return false;
+
+ ParseTreeNode* element = static_cast<ParseTreeNode*>
+ (index.internalPointer());
+
+ if(!element->isParam())
+ return false;
+
+ struct skin_tag_parameter* param = element->getParam();
+
+ /* Now that we've established that we do, in fact, have a parameter, we'll
+ * set it to its new value if an acceptable one has been entered
+ */
+ if(value.toString().trimmed() == QString(QChar(DEFAULTSYM)))
+ {
+ if(islower(param->type_code))
+ param->type = skin_tag_parameter::DEFAULT;
+ else
+ return false;
+ }
+ else if(tolower(param->type_code) == 's' || tolower(param->type_code) == 'f')
+ {
+ if(param->type == skin_tag_parameter::STRING)
+ free(param->data.text);
+
+ param->type = skin_tag_parameter::STRING;
+ param->data.text = strdup(value.toString().trimmed().toAscii());
+ }
+ else if(tolower(param->type_code) == 'i')
+ {
+ if(!value.canConvert(QVariant::Int))
+ return false;
+
+ param->type = skin_tag_parameter::NUMERIC;
+ param->data.numeric = value.toInt();
+ }
+ else
+ {
+ return false;
+ }
+
+ emit dataChanged(index, index);
+ return true;
+}