-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNote.cpp
executable file
·198 lines (150 loc) · 4.83 KB
/
Note.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
#include "Note.h"
namespace NM {
//-----------------NOTE-------------------
Note::Note(const unsigned int i, const QString &te)
: id(i), title(te), loaded(false), modified(false)
{
//this->log();
}
void Note::log() const {}
//-----------------NARTICLE---------------
NArticle::NArticle(unsigned int i, const QString &te, const QString &txt)
: Note(i, te), text(txt)
{
log();
}
QString NArticle::toText () const {
QString str;
str = QString::number(id) + "\n";
str += "NArticle\n";
str += title + "\n\n";
str += text;
return str;
}
void NArticle::load() {
if (loaded == true)
return;
NotesManager& nm = NotesManager::getInstance();
QFile fd(nm.getWorkspace().path() + "/" + QString::number(id));
fd.open(QIODevice::ReadOnly);
fd.readLine(); //on passe l'id
fd.readLine(); //on passe le type
fd.readLine(); //on passe le titre
fd.readLine(); //on passe le saut de ligne
while (!fd.atEnd()) {
text += fd.readLine();
}
fd.close();
loaded = true;
}
void NArticle::log() const {
qDebug() << "Article : " << getId() << "\n";
//std::cout<< "Article :" << getId() << std::endl;
}
//-----------------Document----------------
Document::Document(unsigned int i, const QString &te)
: Note(i, te)
{
log();
}
void Document::addNote(Note *n) {
modified = true;
notes << n;
}
void Document::operator <<(Note *n) {
addNote(n);
}
void Document::removeNote(Note *n) {
modified = true;
while(notes.removeOne(n))
qDebug() << "note enlevee du document";
}
QString Document::toText () const {
QString str;
str = QString::number(id) + "\n"
+ "Document\n"
+ title + "\n\n";
QListIterator<Note*> i(notes);
while (i.hasNext()) {
str += QString::number(i.next()->getId(), 10) + "\n";
}
return str;
}
void Document::load() {
if (this->loaded) { return; }
loaded = true;
NotesManager& nm = NotesManager::getInstance();
qDebug() <<nm.getWorkspace().path() + "/" + QString::number(id);
QFile fd(nm.getWorkspace().path() + "/" + QString::number(id));
if(!fd.open(QIODevice::ReadOnly))
qDebug() << "échec lors de l'ouverture de fichier\n";
fd.readLine(); //on passe l'id
fd.readLine(); //on passe le type
fd.readLine(); //on passe le titre
fd.readLine(); //on passe le saut de ligne
unsigned int idNote;
qDebug() << "Attention chargememt des notes";
while (!fd.atEnd()) {
//----------récupérer le pointeur sur la bonne note
QString idS = fd.readLine();
idS.chop(1);
idNote = idS.toUInt();
qDebug() << "chargement de la note d'id : " << idNote << "\n";
notes<<nm.getNote(idNote);
}
fd.close();
}
void Document::log() const {
qDebug() << "Document" << getId() << "\n";
}
//-----------------NMedia----------------
NMedia::NMedia(unsigned int i, const QString & te, const QString & u, const QString & desc)
: Note (i, te), url(u), description(desc)
{
}
void NMedia::log() const {
qDebug() << "NMedia" << getId() << "\n";
}
void NMedia::load(){
NotesManager & nm = NotesManager::getInstance();
QFile fd(nm.getWorkspace().path() + "/" + QString::number(id));
fd.open(QIODevice::ReadOnly);
fd.readLine(); //on passe l'id
fd.readLine(); //on passe le type
fd.readLine(); //on passe le titre
fd.readLine(); //on passe le saut de ligne
url = fd.readLine();
url.chop(1);
while(!fd.atEnd()){
description += fd.readLine();
}
loaded = true;
}
//-----------------NAudio----------------
QString NAudio::toText() const{
QString str = QString::number(id) + "\n";
str += "NAudio\n";
str += title + "\n\n";
str += url + "\n";
str += description;
return str;
}
//-----------------NVideo----------------
QString NVideo::toText() const{
QString str = QString::number(id) + "\n";
str += "NVideo\n";
str += title + "\n\n";
str += url + "\n";
str += description + "\n";
return str;
}
//-----------------NImage----------------
QString NImage::toText() const{
QString str = QString::number(id) + "\n";
str += "NImage\n";
str += title + "\n\n";
str += url + "\n";
str += description + "\n";
return str;
}
}