-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.cpp
More file actions
91 lines (72 loc) · 2.26 KB
/
tree.cpp
File metadata and controls
91 lines (72 loc) · 2.26 KB
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
#include "tree.h"
Tree::Tree()
{
// emit add(*this);
}
Tree::Tree(QString name, QDateTime updateDate, QDir path, QDir backupPath)
{
QString stringFile;
stringFile += name + "\n";
stringFile += updateDate.toString("yyyy/MM/dd hh:mm:ss") + "\n";
stringFile += path.path() + "\n";
if (backupPath.path() != "") stringFile += backupPath.path() + "\n";
else stringFile += "BE CAREFUL, NO BACKUP \n";
stringFile += "name,surname,query,parents,birthdate";
// We create the directory if needed
if (!path.exists(path.path() + "/"))
path.mkpath(path.path() + "/");
QFile file(path.path() + "/" + name + ".tree");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return;
QTextStream flux(&file);
flux.setCodec("UTF-8");
flux << stringFile << endl;
qDebug() << path.path() + "/" + name + ".tree" << endl;
if (backupPath.path() != "") {
// We create the directory if needed
if (!backupPath.exists(backupPath.path() + "/"))
backupPath.mkpath(backupPath.path() + "/");
qDebug() << backupPath.path() + "/" + name + ".tree" << endl;
QFile file(backupPath.path() + "/" + name + ".tree");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return;
QTextStream flux(&file);
flux.setCodec("UTF-8");
flux << stringFile << endl;
}
this->name = name;
this->updateDate = &updateDate;
this->path = path;
this->backupPath = backupPath;
persons = new QList<std::shared_ptr<Person>>();
// emit add(*this);
}
void Tree::newPerson(std::shared_ptr<Person> person)
{
*persons<<person;
}
QString Tree::Test_DiplayTree()
{
QString str_tmp="";
for (int i =0; i<persons->size();i++)
{
str_tmp += persons->at(i)->getName() + "\n";
}
return str_tmp;
}
QList<std::shared_ptr<Person>> Tree::getListPerson()
{
return *persons;
}
//void Tree::addPerson(Person person){
// persons<<person;
// // QString stringFile ="";
// // stringFile += person.name + "," + person.surname + ","
// // + person.query + "," + person.parents + "," + person.birthdate;
// // QFile file(path.path()+"/" + name + ".tree");
// // if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
// // return;
// // QTextStream flux(&file);
// // flux.setCodec("UTF-8");
// // flux << stringFile <<endl;
//}