-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTrash.cpp
88 lines (69 loc) · 1.56 KB
/
Trash.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
#include "Trash.h"
#include "mainwindow.h"
Trash* Trash::instance = 0;
Trash::Trash()
{
}
void Trash::releaseInstance(){
if(instance)
delete instance;
instance = 0;
}
void Trash::recycle(Note *n)
{
DeletedNote * dn = new DeletedNote(n);
// store all
dn->setWasInDocuments(n->getInDocuments());
// remove all relationships between notes and docs.
for(QSet<Document*>::ConstIterator it = n->beginInDoc(); it!=n->endInDoc(); ++it){
(*it)->removeNote(n, false);
}
n->resetInDocuments();
n->setDeleted(true);
deletedNotes.insert(dn);
MainWindow::getInstance()->updateSideBar();
}
void Trash::restore(DeletedNote *n)
{
for(docSetIt it = n->begin(); it!=n->end(); ++it){
if((*it))
(*it)->addNote(n->getNote());
}
n->getNote()->setInDocuments(n->getWasInDocuments());
n->getNote()->setDeleted(false);
MainWindow::getInstance()->updateSideBar();
deletedNotes.remove(n);
}
void Trash::remove(DeletedNote *n)
{
QFile::remove(n->getNote()->getFilePath());
deletedNotes.remove(n);
delete n;
}
Trash *Trash::getInstance()
{
if(!instance)
instance = new Trash;
return instance;
}
DeletedNote::DeletedNote(Note *note):n(note)
{}
DeletedNote::~DeletedNote()
{
}
Note *DeletedNote::getNote() const
{
return n;
}
void DeletedNote::setNote(Note *value)
{
n = value;
}
QSet<Document *> DeletedNote::getWasInDocuments() const
{
return wasInDocuments;
}
void DeletedNote::setWasInDocuments(const QSet<Document *> &value)
{
wasInDocuments = value;
}