-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinote.cpp
More file actions
161 lines (129 loc) · 2.88 KB
/
Copy pathinote.cpp
File metadata and controls
161 lines (129 loc) · 2.88 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "inote.h"
#include <QSqlQuery>
#include <boost/regex.hpp>
using namespace boost;
INote::INote()
{
}
INote::~INote()
{
}
QDateTime INote::getUpdateTime() const
{
return updateTime;
}
void INote::setUpdateTime(const QDateTime &value)
{
updateTime = value;
}
void INote::updateFromContent()
{
// title
regex ptitle("^#([^#]+?)$");
string cs = content.toStdString();
smatch match;
if(regex_search(cs,match,ptitle)){
title = QString::fromStdString(match[1]);
}else
{
title = "untitled";
}
// describe
}
QDateTime INote::getCreateTime() const
{
return createTime;
}
void INote::setCreateTime(const QDateTime &value)
{
createTime = value;
}
int INote::getId() const
{
return id;
}
void INote::setId(int value)
{
id = value;
}
QString INote::getTags() const
{
return tags;
}
void INote::setTags(const QString &value)
{
tags = value;
}
QString INote::getContent() const
{
return content;
}
void INote::setContent(const QString &value)
{
content = value;
}
QString INote::getDescribe() const
{
return describe;
}
void INote::setDescribe(const QString &value)
{
describe = value;
}
QString INote::getTitle() const
{
return title;
}
void INote::setTitle(const QString &value)
{
title = value;
}
bool INote::dbInsert()
{
QSqlQuery query;
query.prepare("INSERT INTO tbl_note (content, tags) VALUES (:content, :tags)");
query.bindValue(":content", this->content);
query.bindValue(":tags", this->tags);
bool result = query.exec();
return result;
}
bool INote::dbUpdate()
{
QSqlQuery query;
query.prepare("UPDATE tbl_note SET content=:content,tags=:tags, \
title=:title,describe=:describe,\
updatetime=datetime(CURRENT_TIMESTAMP,'localtime') where id=:id");
query.bindValue(":content", this->content);
query.bindValue(":tags", this->tags);
query.bindValue(":title", this->title);
query.bindValue(":describe", this->describe);
query.bindValue(":id",this->id);
bool result = query.exec();
return result;
}
bool INote::dbDelete()
{
QSqlQuery query;
query.prepare("DELETE FROM tbl_note where id=:id");
query.bindValue(":id",this->id);
return query.exec();
}
QList<INote>* INote::queryAllNote()
{
QList<INote> *list = new QList<INote>;
QSqlQuery query;
query.exec("SELECT * FROM tbl_note ORDER BY updatetime DESC");
while(query.next())
{
INote *item = new INote;
item->setId(query.value(0).toInt());
item->setTitle(query.value(1).toString());
item->setDescribe(query.value(2).toString());
item->setContent(query.value(3).toString());
item->setTags(query.value(4).toString());
item->setUpdateTime(query.value(5).toDateTime());
item->setCreateTime(query.value(6).toDateTime());
list->append(*item);
}
return list;
}