forked from nerososft/Nider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.cpp
executable file
·257 lines (221 loc) · 8.96 KB
/
project.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#include "project.h"
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonValue>
Project::Project(QJsonObject projectOBJ)
{
this->projectOBJ = projectOBJ;
projectObjectToProjectEntity();
this->icon.InitFileIcon(":/icon/icons.png");
}
void Project::projectObjectToProjectEntity(){
//projectname
QString projectName = this->projectOBJ.find("projectname").value().toString();
//version
QString version = this->projectOBJ.find("version").value().toString();
//source
std::vector<Source> v_sources;
QJsonArray sources = this->projectOBJ.find("source").value().toArray();
foreach(QJsonValue source_v,sources){
QJsonObject source = source_v.toObject();
Source p_source;
//src
QString src = source.find("src").value().toString();
//mark
std::vector<Mark> v_mark;
QJsonArray marks = source.find("mark").value().toArray();
foreach(QJsonValue mark_v,marks){
QJsonObject mark = mark_v.toObject();
QString id = mark.find("id").value().toString();
QString level = mark.find("level").value().toString();
QString content = mark.find("content").value().toString();
QString row = mark.find("row").value().toString();
QString date = mark.find("date").value().toString();
QString author = mark.find("author").value().toString();
Mark markItem;
markItem.id = id;
markItem.content = content;
markItem.author = author;
markItem.row = row;
markItem.date = date;
markItem.level = level;
v_mark.push_back(markItem);
}
p_source.mark = v_mark;
p_source.src = src;
v_sources.push_back(p_source);
}
//header
std::vector<Source> v_headers;
QJsonArray headers = this->projectOBJ.find("header").value().toArray();
foreach(QJsonValue header_v, headers){
QJsonObject header = header_v.toObject();
Source p_header;
//src
QString src = header.find("src").value().toString();
//mark
std::vector<Mark> v_mark;
QJsonArray marks = header.find("mark").value().toArray();
foreach(QJsonValue mark_v,marks){
QJsonObject mark = mark_v.toObject();
QString id = mark.find("id").value().toString();
QString level = mark.find("level").value().toString();
QString content = mark.find("content").value().toString();
QString row = mark.find("row").value().toString();
QString date = mark.find("date").value().toString();
QString author = mark.find("author").value().toString();
Mark markItem;
markItem.id = id;
markItem.content = content;
markItem.author = author;
markItem.row = row;
markItem.date = date;
markItem.level = level;
v_mark.push_back(markItem);
}
p_header.mark = v_mark;
p_header.src = src;
v_headers.push_back(p_header);
}
//task
Task p_task;
QJsonObject task = this->projectOBJ.find("task").value().toObject();
//undo
QJsonArray undos = task.find("undo").value().toArray();
std::vector<TaskItem> v_undos;
foreach(QJsonValue undo_v,undos){
QJsonObject undo= undo_v.toObject();
QString id = undo.find("id").value().toString();
QString content = undo.find("content").value().toString();
QString level = undo.find("level").value().toString();
QString date = undo.find("date").value().toString();
QString author = undo.find("author").value().toString();
TaskItem taskItemUndo;
taskItemUndo.id = id;
taskItemUndo.content = content;
taskItemUndo.level = level;
taskItemUndo.date = date;
taskItemUndo.author = author;
v_undos.push_back(taskItemUndo);
}
//doing
QJsonArray doings = task.find("doing").value().toArray();
std::vector<TaskItem> v_doings;
foreach(QJsonValue doing_v,doings){
QJsonObject doing = doing_v.toObject();
QString id = doing.find("id").value().toString();
QString content = doing.find("content").value().toString();
QString level = doing.find("level").value().toString();
QString date = doing.find("date").value().toString();
QString author = doing.find("author").value().toString();
TaskItem taskItemDoing;
taskItemDoing.id = id;
taskItemDoing.content = content;
taskItemDoing.level = level;
taskItemDoing.date = date;
taskItemDoing.author = author;
v_doings.push_back(taskItemDoing);
}
//done
QJsonArray dones = task.find("done").value().toArray();
std::vector<TaskItem> v_dones;
foreach(QJsonValue done_v,dones){
QJsonObject done = done_v.toObject();
QString id = done.find("id").value().toString();
QString content = done.find("content").value().toString();
QString level = done.find("level").value().toString();
QString date = done.find("date").value().toString();
QString author = done.find("author").value().toString();
TaskItem taskItemDone;
taskItemDone.id = id;
taskItemDone.content = content;
taskItemDone.level = level;
taskItemDone.date = date;
taskItemDone.author = author;
v_dones.push_back(taskItemDone);
}
p_task.undo = v_undos;
p_task.doing = v_doings;
p_task.done = v_dones;
this->project.header = v_headers;
this->project.source = v_sources;
this->project.projectname = projectName;
this->project.version = version;
this->project.task = p_task;
}
QString Project::getProjectName(){
return this->project.projectname;
}
QString Project::getProjectVersion(){
return this->project.version;
}
QStandardItemModel* Project::getTaskUndo(){
QStandardItemModel* model = new QStandardItemModel();
foreach(TaskItem item,this->project.task.undo){
QStandardItem* itemProject = new QStandardItem(QIcon(":/icon/level_"+item.level+".png"),item.content);
model->appendRow(itemProject);
}
return model;
}
QStandardItemModel* Project::getTaskDoing(){
QStandardItemModel* model = new QStandardItemModel();
foreach(TaskItem item,this->project.task.doing){
QStandardItem* itemProject = new QStandardItem(QIcon(":/icon/level_"+item.level+".png"),item.content);
model->appendRow(itemProject);
}
return model;
}
QStandardItemModel* Project::getTaskDone(){
QStandardItemModel* model = new QStandardItemModel();
foreach(TaskItem item,this->project.task.done){
QStandardItem* itemProject = new QStandardItem(QIcon(":/icon/level_"+item.level+".png"),item.content);
model->appendRow(itemProject);
}
return model;
}
QStandardItem* Project::getSource(){
QStandardItem* source = new QStandardItem(QIcon(":/icon/open_file.png"),"Sources");
foreach(Source item,this->project.source){
QStandardItem* itemProject = new QStandardItem(this->icon.getIcon("cpp"),item.src);
source->appendRow(itemProject);
}
return source;
}
QStandardItem* Project::getHeaders(){
QStandardItem* header = new QStandardItem(QIcon(":/icon/open_file.png"),"Headers");
foreach(Source item,this->project.header){
QStandardItem* itemProject = new QStandardItem(this->icon.getIcon("cpp"),item.src);
header->appendRow(itemProject);
}
return header;
}
QStandardItemModel* Project::getProjectTree(){
QStandardItemModel* model = new QStandardItemModel();
model->appendRow(getSource());
model->appendRow(getHeaders());
return model;
}
QStandardItemModel* Project::getMark(QString src){
QStandardItemModel* mark = new QStandardItemModel();
foreach(Source item,this->project.source){
if(item.src==src){
foreach(Mark mark_item,item.mark){
QStandardItem* itemProject = new QStandardItem(QIcon(":/icon/mark_"+mark_item.level+".png"),mark_item.content);
mark->appendRow(itemProject);
}
}else{
continue;
}
}
foreach(Source item,this->project.header){
if(item.src==src){
foreach(Mark mark_item,item.mark){
QStandardItem* itemProject = new QStandardItem(QIcon(":/icon/mark_"+mark_item.level+".png"),mark_item.content);
mark->appendRow(itemProject);
}
}else{
continue;
}
}
return mark;
}