forked from pbek/QOwnNotes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotesubfolderapi.cpp
More file actions
92 lines (73 loc) · 2.25 KB
/
notesubfolderapi.cpp
File metadata and controls
92 lines (73 loc) · 2.25 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
91
92
#include "notesubfolderapi.h"
#include <entities/note.h>
#include <QVector>
#include "noteapi.h"
NoteSubFolderApi *NoteSubFolderApi::fetch(int id) {
_noteSubFolder = NoteSubFolder::fetch(id);
if (_noteSubFolder.isFetched()) {
_id = _noteSubFolder.getId();
_name = _noteSubFolder.getName();
}
return this;
}
NoteSubFolderApi *NoteSubFolderApi::fromNoteSubFolder(const NoteSubFolder ¬eSubFolder) {
auto* noteSubFolderApi = new NoteSubFolderApi();
noteSubFolderApi->fetch(noteSubFolder.getId());
return noteSubFolderApi;
}
/**
* Returns all notes of the note subfolder
*/
QQmlListProperty<NoteApi> NoteSubFolderApi::notes() {
_notes.clear();
NoteSubFolder noteSubFolder = NoteSubFolder::fetch(_id);
QVector<Note> notes = Note::fetchAllByNoteSubFolderId(_id);
QVectorIterator<Note> itr(notes);
while (itr.hasNext()) {
Note note = itr.next();
auto* noteApi = new NoteApi();
noteApi->fetch(note.getId());
_notes.append(noteApi);
}
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
return {this, _notes};
#else
return {this, &_notes};
#endif
}
/**
* Fetches a note subfolder by its id
*
* @param id int the id of the note subfolder
* @return NoteSubFolderApi*
*/
NoteSubFolderApi *NoteSubFolderApi::fetchNoteSubFolderById(int id)
{
auto *noteSubFolder = new NoteSubFolderApi();
noteSubFolder->fetch(id);
return noteSubFolder;
}
/**
* Fetches note subfolders that are children of parentId
*
* @param parentId int the id of the parent note subfolder
* @return QList<QObject*>
*/
QList<QObject*> NoteSubFolderApi::fetchNoteSubFoldersByParentId(int parentId)
{
QList<QObject *> noteSubFolderApis;
const auto noteSubFolders = NoteSubFolder::fetchAllByParentId(parentId);
for (const auto ¬eSubFolder : noteSubFolders) {
noteSubFolderApis.append(NoteSubFolderApi::fromNoteSubFolder(noteSubFolder));
}
return noteSubFolderApis;
}
NoteSubFolderApi *NoteSubFolderApi::activeNoteSubFolder() {
return fetchNoteSubFolderById(NoteSubFolder::activeNoteSubFolderId());
}
QString NoteSubFolderApi::relativePath() {
return _noteSubFolder.relativePath();
}
QString NoteSubFolderApi::fullPath() {
return _noteSubFolder.fullPath();
}