-
Notifications
You must be signed in to change notification settings - Fork 2
/
Note.cpp
138 lines (114 loc) · 2.51 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
#include "Note.h"
#include "Document.h"
/***
* Note
*/
const QString & Note::getTitle() const {
return title;
}
const QString & Note::getFilePath() const {
return filePath;
}
void Note::setFilePath(const QString &p) {
filePath = p;
modified=true;
}
void Note::setTitle(const QString &t) {
title = t;
modified = true;
}
void Note::setModified(bool b) {
modified = b;
modified = true;
}
bool Note::isModified() const {
return modified;
}
void Note::setDeleted(bool b) {
deleted = b;
modified = true;
}
bool Note::isDeleted() const {
return deleted;
}
Editor *Note::createAndAttachEditor()
{
editor = this->createEditor();
return editor;
}
bool Note::isDocument() const
{
return type == document;
}
nListIt Note::begin() const
{
if(isDocument())
return dynamic_cast<const Document*>(this)->begin();
else
return 0;
}
nListIt Note::end() const
{
if(isDocument())
return dynamic_cast<const Document*>(this)->end();
else
return 0;
}
/**
* @brief Note::Note used to create new Note, modified = true
* @param path
*/
Note::Note(const QString& path)
:title("New Note"), filePath(path), modified(true), deleted(false){}
/**
* @brief Note::Note used to create from existing Note, modified=false
* @param path
* @param ti
*/
Note::Note(const QString& path, const QString& ti)
:title(ti), filePath(path), modified(false), deleted(false){}
Note::~Note()
{
qDebug()<<"Destruction of "<<this->getTitle();
for(QSet<Document*>::const_iterator it = inDocuments.begin(); it!=inDocuments.end(); ++it){
(*it)->removeNote(this);
}
}
bool Note::operator ==(const Note &other)
{
return this->getFilePath()==other.getFilePath();
}
Editor *Note::getEditor() const
{
return editor;
}
void Note::setEditor(Editor *value)
{
editor = value;
}
void Note::addToDocument(Document *doc)
{
inDocuments << doc;
qDebug()<<"Note: "<<this->getTitle()<<" Added to: "<<doc->getTitle();
qDebug()<<"==========";
for(QSet<Document*>::const_iterator it = inDocuments.begin(); it!=inDocuments.end(); ++it){
qDebug()<<this->title<<" included in: "<<doc->getTitle();
}
qDebug()<<"==========";
}
void Note::removeFromDocument(Document *doc)
{
inDocuments.remove(doc);
}
bool Note::belongs(Document *doc)
{
return inDocuments.contains(doc);
}
QSet<Document *> Note::getInDocuments() const
{
return inDocuments;
}
void Note::setInDocuments(const QSet<Document *> &value)
{
inDocuments = value;
}