diff options
Diffstat (limited to 'utils/themeeditor/parsetreemodel.cpp')
-rw-r--r-- | utils/themeeditor/parsetreemodel.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/utils/themeeditor/parsetreemodel.cpp b/utils/themeeditor/parsetreemodel.cpp index 9faa9ea560..918903bb68 100644 --- a/utils/themeeditor/parsetreemodel.cpp +++ b/utils/themeeditor/parsetreemodel.cpp | |||
@@ -31,7 +31,11 @@ ParseTreeModel::ParseTreeModel(const char* document, QObject* parent): | |||
31 | QAbstractItemModel(parent) | 31 | QAbstractItemModel(parent) |
32 | { | 32 | { |
33 | this->tree = skin_parse(document); | 33 | this->tree = skin_parse(document); |
34 | this->root = new ParseTreeNode(tree); | 34 | |
35 | if(tree) | ||
36 | this->root = new ParseTreeNode(tree); | ||
37 | else | ||
38 | this->root = 0; | ||
35 | } | 39 | } |
36 | 40 | ||
37 | 41 | ||
@@ -48,6 +52,36 @@ QString ParseTreeModel::genCode() | |||
48 | return root->genCode(); | 52 | return root->genCode(); |
49 | } | 53 | } |
50 | 54 | ||
55 | bool ParseTreeModel::changeTree(const char *document) | ||
56 | { | ||
57 | struct skin_element* test = skin_parse(document); | ||
58 | |||
59 | if(!test) | ||
60 | return false; | ||
61 | |||
62 | ParseTreeNode* temp = new ParseTreeNode(test); | ||
63 | if(root && temp->genHash() == root->genHash()) | ||
64 | { | ||
65 | delete temp; | ||
66 | return true; | ||
67 | } | ||
68 | |||
69 | if(root) | ||
70 | { | ||
71 | emit beginRemoveRows(QModelIndex(), 0, root->numChildren() - 1); | ||
72 | delete root; | ||
73 | emit endRemoveRows(); | ||
74 | } | ||
75 | |||
76 | root = temp; | ||
77 | |||
78 | emit beginInsertRows(QModelIndex(), 0, temp->numChildren() - 1); | ||
79 | emit endInsertRows(); | ||
80 | |||
81 | return true; | ||
82 | |||
83 | } | ||
84 | |||
51 | QModelIndex ParseTreeModel::index(int row, int column, | 85 | QModelIndex ParseTreeModel::index(int row, int column, |
52 | const QModelIndex& parent) const | 86 | const QModelIndex& parent) const |
53 | { | 87 | { |
@@ -83,6 +117,9 @@ QModelIndex ParseTreeModel::parent(const QModelIndex &child) const | |||
83 | 117 | ||
84 | int ParseTreeModel::rowCount(const QModelIndex &parent) const | 118 | int ParseTreeModel::rowCount(const QModelIndex &parent) const |
85 | { | 119 | { |
120 | if(!root) | ||
121 | return 0; | ||
122 | |||
86 | if(!parent.isValid()) | 123 | if(!parent.isValid()) |
87 | return root->numChildren(); | 124 | return root->numChildren(); |
88 | 125 | ||