summaryrefslogtreecommitdiff
path: root/utils/themeeditor/projectmodel.cpp
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-06-14 06:20:07 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-06-14 06:20:07 +0000
commit046832c821276cb07b86519ab3c0dae4ff68173d (patch)
tree39c3177daf1ecfb4bbce17387a1726486e0aab3f /utils/themeeditor/projectmodel.cpp
parent4b0c1cf23bdd3c54296b05ce52f8fec3f29c408e (diff)
downloadrockbox-046832c821276cb07b86519ab3c0dae4ff68173d.tar.gz
rockbox-046832c821276cb07b86519ab3c0dae4ff68173d.zip
Theme Editor: Stripped out the sub-classes for ProjectModel and turned ProjectModel into a list model, also replaced the project tree view with a list view
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26839 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor/projectmodel.cpp')
-rw-r--r--utils/themeeditor/projectmodel.cpp161
1 files changed, 47 insertions, 114 deletions
diff --git a/utils/themeeditor/projectmodel.cpp b/utils/themeeditor/projectmodel.cpp
index da810d4906..925be81950 100644
--- a/utils/themeeditor/projectmodel.cpp
+++ b/utils/themeeditor/projectmodel.cpp
@@ -21,124 +21,18 @@
21 21
22 22
23#include "projectmodel.h" 23#include "projectmodel.h"
24#include "projectfiles.h"
25#include "projectsettings.h"
26#include "editorwindow.h" 24#include "editorwindow.h"
27 25
28#include <QFile> 26#include <QFile>
29#include <QTextStream> 27#include <QTextStream>
30#include <QHash> 28#include <QMap>
31#include <QDir> 29#include <QDir>
32 30
33ProjectModel::ProjectModel(QString config, EditorWindow* mainWindow, 31ProjectModel::ProjectModel(QString config, EditorWindow* mainWindow,
34 QObject *parent) 32 QObject *parent)
35 : QAbstractItemModel(parent), 33 : QAbstractListModel(parent),
36 mainWindow(mainWindow) 34 mainWindow(mainWindow)
37{ 35{
38 root = new ProjectRoot(config, this);
39}
40
41ProjectModel::~ProjectModel()
42{
43 if(root)
44 delete root;
45}
46
47QModelIndex ProjectModel::index(int row, int column,
48 const QModelIndex& parent) const
49{
50
51 if(!hasIndex(row, column, parent))
52 return QModelIndex();
53
54 ProjectNode* foundParent = root;
55 if(parent.isValid())
56 foundParent = static_cast<ProjectNode*>(parent.internalPointer());
57
58 if(row < foundParent->numChildren() && row >= 0)
59 return createIndex(row, column, foundParent->child(row));
60 else
61 return QModelIndex();
62}
63
64QModelIndex ProjectModel::parent(const QModelIndex &child) const
65{
66 if(!child.isValid())
67 return QModelIndex();
68
69 ProjectNode* foundParent = static_cast<ProjectNode*>
70 (child.internalPointer())->parent();
71
72 if(foundParent == root)
73 return QModelIndex();
74
75 return createIndex(foundParent->row(), 0, foundParent);
76}
77
78int ProjectModel::rowCount(const QModelIndex &parent) const
79{
80 if(!root)
81 return 0;
82
83 if(!parent.isValid())
84 return root->numChildren();
85
86 if(parent.column() != 0)
87 return 0;
88
89 return static_cast<ProjectNode*>(parent.internalPointer())->numChildren();
90}
91
92int ProjectModel::columnCount(const QModelIndex &parent) const
93{
94 return numColumns;
95}
96
97QVariant ProjectModel::data(const QModelIndex &index, int role) const
98{
99 if(!index.isValid())
100 return QVariant();
101
102 if(role != Qt::DisplayRole)
103 return QVariant();
104
105 return static_cast<ProjectNode*>
106 (index.internalPointer())->data(index.column());
107}
108
109QVariant ProjectModel::headerData(int col, Qt::Orientation orientation,
110 int role) const
111{
112 return QVariant();
113}
114
115Qt::ItemFlags ProjectModel::flags(const QModelIndex &index) const
116{
117 return static_cast<ProjectNode*>
118 (index.internalPointer())->flags(index.column());
119}
120
121bool ProjectModel::setData(const QModelIndex &index, const QVariant &value,
122 int role)
123{
124 return true;
125}
126
127void ProjectModel::loadFile(QString file)
128{
129 mainWindow->loadTabFromFile(file);
130}
131
132void ProjectModel::activated(const QModelIndex &index)
133{
134 static_cast<ProjectNode*>(index.internalPointer())->activated();
135}
136
137/* Constructor and destructor for the root class */
138ProjectRoot::ProjectRoot(QString config, ProjectModel* model)
139{
140 this->model = model;
141
142 /* Reading the config file */ 36 /* Reading the config file */
143 QFile cfg(config); 37 QFile cfg(config);
144 cfg.open(QFile::ReadOnly | QFile::Text); 38 cfg.open(QFile::ReadOnly | QFile::Text);
@@ -172,14 +66,53 @@ ProjectRoot::ProjectRoot(QString config, ProjectModel* model)
172 66
173 cfg.close(); 67 cfg.close();
174 68
175 /* Showing the files */ 69 /* Adding the files, starting with the .cfg */
176 children.append(new ProjectFiles(settings, model, this)); 70 config.replace(base.canonicalPath() + "/", "");
177 children.append(new ProjectSettings(settings, model, this)); 71 files.append(config);
72
73 QList<QString> keys;
74 keys.append("wps");
75 keys.append("rwps");
76 keys.append("sbs");
77 keys.append("rsbs");
78 keys.append("fms");
79 keys.append("rfms");
80
81 for(int i = 0; i < keys.count(); i++)
82 {
83 QString file = settings.value(keys[i], "");
84 if(file != "" && file != "-")
85 {
86 file.replace("/.rockbox/", "");
87 files.append(file);
88 }
89 }
178 90
91
92}
93
94ProjectModel::~ProjectModel()
95{
179} 96}
180 97
181ProjectRoot::~ProjectRoot() 98int ProjectModel::rowCount(const QModelIndex& parent) const
99{
100 return files.count();
101}
102
103QVariant ProjectModel::data(const QModelIndex &index, int role) const
104{
105 if(!index.isValid())
106 return QVariant();
107
108 if(role != Qt::DisplayRole)
109 return QVariant();
110
111 return files[index.row()];
112}
113
114void ProjectModel::activated(const QModelIndex &index)
182{ 115{
183 for(int i = 0; i < children.count(); i++) 116 mainWindow->loadTabFromFile(settings.value("themebase", "")
184 delete children[i]; 117 + "/" + files[index.row()]);
185} 118}