forked from len0rd/rockbox
Theme Editor: Enabled editing tag parameters from a treeview
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26452 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
253cfbcd47
commit
5943f4c5e2
6 changed files with 119 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,12 @@ class ParseTreeModel : public QAbstractItemModel
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/* Constants */
|
||||
static const int numColumns = 3;
|
||||
static const int typeColumn = 0;
|
||||
static const int lineColumn = 1;
|
||||
static const int valueColumn = 2;
|
||||
|
||||
/* Initializes a tree with a skin document in a string */
|
||||
ParseTreeModel(char* document, QObject* parent = 0);
|
||||
virtual ~ParseTreeModel();
|
||||
|
@ -47,6 +53,9 @@ public:
|
|||
int rowCount(const QModelIndex &parent) const;
|
||||
int columnCount(const QModelIndex &parent) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
QVariant headerData(int col, Qt::Orientation orientation, int role) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
||||
|
||||
private:
|
||||
ParseTreeNode* root;
|
||||
|
|
|
@ -26,6 +26,7 @@ extern "C"
|
|||
}
|
||||
|
||||
#include "parsetreenode.h"
|
||||
#include "parsetreemodel.h"
|
||||
|
||||
/* Root element constructor */
|
||||
ParseTreeNode::ParseTreeNode(struct skin_element* data)
|
||||
|
@ -223,8 +224,7 @@ QVariant ParseTreeNode::data(int column) const
|
|||
{
|
||||
switch(column)
|
||||
{
|
||||
/* Column 0 is the element type */
|
||||
case 0:
|
||||
case ParseTreeModel::typeColumn:
|
||||
if(element)
|
||||
{
|
||||
switch(element->type)
|
||||
|
@ -278,8 +278,7 @@ QVariant ParseTreeNode::data(int column) const
|
|||
|
||||
break;
|
||||
|
||||
/* Column 1 is the value */
|
||||
case 1:
|
||||
case ParseTreeModel::valueColumn:
|
||||
if(element)
|
||||
{
|
||||
switch(element->type)
|
||||
|
@ -324,8 +323,7 @@ QVariant ParseTreeNode::data(int column) const
|
|||
}
|
||||
break;
|
||||
|
||||
/* Column 2 is the line number */
|
||||
case 2:
|
||||
case ParseTreeModel::lineColumn:
|
||||
if(element)
|
||||
return QString::number(element->line, 10);
|
||||
else
|
||||
|
|
|
@ -37,6 +37,9 @@ public:
|
|||
virtual ~ParseTreeNode();
|
||||
|
||||
QString genCode() const;
|
||||
bool isParam() const{ if(param) return true; else return false; }
|
||||
struct skin_tag_parameter* getParam(){ return param;}
|
||||
struct skin_element* getElement(){return element;}
|
||||
|
||||
ParseTreeNode* child(int row);
|
||||
int numChildren() const;
|
||||
|
|
|
@ -481,6 +481,9 @@ int skin_parse_tag(struct skin_element* element, char** document)
|
|||
if(*cursor == COMMENTSYM)
|
||||
skip_comment(&cursor);
|
||||
|
||||
/* Storing the type code */
|
||||
element->params[i].type_code = *tag_args;
|
||||
|
||||
/* Checking a nullable argument for null */
|
||||
if(*cursor == DEFAULTSYM)
|
||||
{
|
||||
|
|
|
@ -86,6 +86,8 @@ struct skin_tag_parameter
|
|||
struct skin_element* code;
|
||||
} data;
|
||||
|
||||
char type_code;
|
||||
|
||||
};
|
||||
|
||||
/* Defines an element of a SKIN file */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue