This repository has been archived by the owner on Mar 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
znote.h
79 lines (67 loc) · 2.82 KB
/
znote.h
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
#ifndef ZNOTE_H
#define ZNOTE_H
#include <QTextDocumentFragment>
#include <QtCore>
#define AbstractMaxLength 200
class ZNote {
public:
enum Attachments {
Attach,
Detach
};
ZNote(const bool isAttached = true);
ZNote(const QDateTime& key);
ZNote(const QDateTime& create, const QDateTime& upd, const QString& html = "", const QString& abstract = "", const bool isAttached = true);
//ZNote(ZNote& other);
ZNote(const ZNote& other);
ZNote(const QJsonObject& obj);
inline bool operator<(const ZNote& x) const;
inline bool operator<=(const ZNote& x) const;
inline bool operator>(const ZNote& x) const;
/*inline bool operator<(const QDateTime& x);
inline bool operator>(const QDateTime& x);*/
inline QDateTime lastModified() const;
inline QString getHtml() const;
inline QString getAbstract() const;
inline bool isAttached() const;
inline QString getUpdateTime() const;
inline QString getCreateTime() const;
inline QDateTime getUpdateTimeRaw() const;
inline void setContent(const QTextDocumentFragment& doc);
inline void setHtml(const QString& _html);
inline void setAbstract(const QString& _abstract);
inline void commitChange();
inline void toggleAttach();
QJsonObject jsonObject() const;
static QString humanDateTime(const QDateTime& from);
friend QDebug operator<<(QDebug o, const ZNote& z);
private:
QDateTime createTime;
QDateTime updateTime;
QString html;
QString abstract;
bool attachment;
};
bool ZNote::operator<(const ZNote& x) const { return updateTime > x.updateTime; }
bool ZNote::operator<=(const ZNote& x) const { return updateTime >= x.updateTime; }
bool ZNote::operator>(const ZNote& x) const { return updateTime < x.updateTime; }
/*bool ZNote::operator<(const QDateTime& x) { return updateTime > x; }
bool ZNote::operator>(const QDateTime& x) { return updateTime < x; }*/
QDateTime ZNote::lastModified() const { return updateTime; }
QString ZNote::getHtml() const { return html; }
QString ZNote::getAbstract() const { return abstract; }
bool ZNote::isAttached() const { return attachment; }
QString ZNote::getUpdateTime() const { return humanDateTime(updateTime); }
QString ZNote::getCreateTime() const { return humanDateTime(createTime); }
QDateTime ZNote::getUpdateTimeRaw() const { return updateTime; }
void ZNote::setContent(const QTextDocumentFragment& doc)
{
html = doc.toHtml();
abstract = doc.toPlainText().left(AbstractMaxLength);
}
void ZNote::setHtml(const QString& _html) { html = _html; }
void ZNote::setAbstract(const QString& _abstract) { abstract = _abstract.left(AbstractMaxLength); }
void ZNote::commitChange() { updateTime = QDateTime::currentDateTime(); }
void ZNote::toggleAttach() { attachment = !attachment; }
Q_DECLARE_METATYPE(ZNote) //to enable storage in QVariant
#endif // ZNOTE_H