diff options
Diffstat (limited to 'utils/themeeditor/projectmodel.cpp')
-rw-r--r-- | utils/themeeditor/projectmodel.cpp | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/utils/themeeditor/projectmodel.cpp b/utils/themeeditor/projectmodel.cpp new file mode 100644 index 0000000000..8a26aa3263 --- /dev/null +++ b/utils/themeeditor/projectmodel.cpp | |||
@@ -0,0 +1,114 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Robert Bieber | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | |||
23 | #include "projectmodel.h" | ||
24 | |||
25 | ProjectModel::ProjectModel(QObject *parent) : | ||
26 | QAbstractItemModel(parent) | ||
27 | { | ||
28 | |||
29 | } | ||
30 | |||
31 | ProjectModel::~ProjectModel() | ||
32 | { | ||
33 | if(root) | ||
34 | delete root; | ||
35 | } | ||
36 | |||
37 | QModelIndex ProjectModel::index(int row, int column, | ||
38 | const QModelIndex& parent) const | ||
39 | { | ||
40 | |||
41 | if(!hasIndex(row, column, parent)) | ||
42 | return QModelIndex(); | ||
43 | |||
44 | ProjectNode* foundParent = root; | ||
45 | if(parent.isValid()) | ||
46 | foundParent = static_cast<ProjectNode*>(parent.internalPointer()); | ||
47 | |||
48 | if(row < foundParent->numChildren() && row >= 0) | ||
49 | return createIndex(row, column, foundParent->child(row)); | ||
50 | else | ||
51 | return QModelIndex(); | ||
52 | } | ||
53 | |||
54 | QModelIndex ProjectModel::parent(const QModelIndex &child) const | ||
55 | { | ||
56 | if(!child.isValid()) | ||
57 | return QModelIndex(); | ||
58 | |||
59 | ProjectNode* foundParent = static_cast<ProjectNode*> | ||
60 | (child.internalPointer())->parent(); | ||
61 | |||
62 | if(foundParent == root) | ||
63 | return QModelIndex(); | ||
64 | |||
65 | return createIndex(foundParent->row(), 0, foundParent); | ||
66 | } | ||
67 | |||
68 | int ProjectModel::rowCount(const QModelIndex &parent) const | ||
69 | { | ||
70 | if(!root) | ||
71 | return 0; | ||
72 | |||
73 | if(!parent.isValid()) | ||
74 | return root->numChildren(); | ||
75 | |||
76 | if(parent.column() != 0) | ||
77 | return 0; | ||
78 | |||
79 | return static_cast<ProjectNode*>(parent.internalPointer())->numChildren(); | ||
80 | } | ||
81 | |||
82 | int ProjectModel::columnCount(const QModelIndex &parent) const | ||
83 | { | ||
84 | return numColumns; | ||
85 | } | ||
86 | |||
87 | QVariant ProjectModel::data(const QModelIndex &index, int role) const | ||
88 | { | ||
89 | if(!index.isValid()) | ||
90 | return QVariant(); | ||
91 | |||
92 | if(role != Qt::DisplayRole) | ||
93 | return QVariant(); | ||
94 | |||
95 | return static_cast<ProjectNode*> | ||
96 | (index.internalPointer())->data(index.column()); | ||
97 | } | ||
98 | |||
99 | QVariant ProjectModel::headerData(int col, Qt::Orientation orientation, | ||
100 | int role) const | ||
101 | { | ||
102 | return QVariant(); | ||
103 | } | ||
104 | |||
105 | Qt::ItemFlags ProjectModel::flags(const QModelIndex &index) const | ||
106 | { | ||
107 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable; | ||
108 | } | ||
109 | |||
110 | bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, | ||
111 | int role) | ||
112 | { | ||
113 | return true; | ||
114 | } | ||