forked from pbek/QOwnNotes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtagapi.cpp
More file actions
74 lines (58 loc) · 1.52 KB
/
tagapi.cpp
File metadata and controls
74 lines (58 loc) · 1.52 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
#include "tagapi.h"
#include <utility>
TagApi* TagApi::fetch(int Id) {
Tag tag = Tag::fetch(Id);
if (tag.isFetched()) {
this->_id = tag.getId();
_name = tag.getName();
_parentId = tag.getParentId();
_priority = tag.getPriority();
}
return this;
}
TagApi* TagApi::fetchByName(const QString& Name, int ParentId) {
Tag tag = Tag::fetchByName(Name, ParentId);
if (tag.isFetched()) {
this->_id = tag.getId();
this->_name = tag.getName();
this->_parentId = tag.getParentId();
this->_priority = tag.getPriority();
}
return this;
}
QStringList TagApi::getParentTagNames() {
Tag tag = Tag::fetch(this->_id);
return tag.getParentTagNames();
}
TagApi* TagApi::fromTag(const Tag& tag) {
auto* tagApi = new TagApi();
tagApi->fetch(tag.getId());
return tagApi;
}
void TagApi::copy(const Tag &tag)
{
this->_id = tag.getId();
_name = tag.getName();
_parentId = tag.getParentId();
_priority = tag.getPriority();
}
/**
* Returns all linked notes
*/
QQmlListProperty<NoteApi> TagApi::notes() {
_notes.clear();
Tag tag = Tag::fetch(_id);
QVector<Note> notes = tag.fetchAllLinkedNotes();
QVectorIterator<Note> itr(notes);
while (itr.hasNext()) {
Note note = itr.next();
auto* noteApi = new NoteApi();
noteApi->copy(note);
_notes.append(noteApi);
}
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
return {this, _notes};
#else
return {this, &_notes};
#endif
}