2018-01-09 17:33:54 +08:00
|
|
|
#ifndef POST_H
|
|
|
|
|
#define POST_H
|
2016-05-12 14:08:58 +08:00
|
|
|
|
|
|
|
|
#include <QtCore/qglobal.h>
|
2018-02-17 23:44:39 +08:00
|
|
|
#include <QtCore/QDateTime>
|
2020-07-31 00:13:57 +08:00
|
|
|
#include <QtNut/table.h>
|
|
|
|
|
#include <QtNut/database.h>
|
|
|
|
|
#include <QtNut/databasemodel.h>
|
2016-05-12 14:08:58 +08:00
|
|
|
|
2017-02-01 18:01:21 +08:00
|
|
|
#ifdef NUT_NAMESPACE
|
|
|
|
|
using namespace NUT_NAMESPACE;
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-01-09 01:07:26 +08:00
|
|
|
class Comment;
|
2018-01-14 22:03:24 +08:00
|
|
|
class Score;
|
2016-05-12 14:08:58 +08:00
|
|
|
class Post : public Table
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
2021-01-27 22:50:31 +08:00
|
|
|
Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged)
|
|
|
|
|
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
|
|
|
|
|
Q_PROPERTY(QDateTime saveDate READ saveDate WRITE setSaveDate NOTIFY saveDateChanged)
|
|
|
|
|
Q_PROPERTY(QString body READ body WRITE setBody NOTIFY bodyChanged)
|
|
|
|
|
Q_PROPERTY(bool isPublic READ isPublic WRITE setPublic NOTIFY isPublicChanged)
|
|
|
|
|
|
2016-05-12 14:08:58 +08:00
|
|
|
NUT_PRIMARY_AUTO_INCREMENT(id)
|
2021-01-27 22:50:31 +08:00
|
|
|
NUT_FIELD(int, id)
|
2016-05-12 14:08:58 +08:00
|
|
|
|
|
|
|
|
NUT_NOT_NULL(title)
|
|
|
|
|
NUT_LEN(title, 50)
|
2021-01-27 22:50:31 +08:00
|
|
|
NUT_FIELD(QString, title)
|
2016-05-12 14:08:58 +08:00
|
|
|
|
2021-01-27 22:50:31 +08:00
|
|
|
NUT_FIELD(QDateTime, saveDate)
|
2016-05-21 16:09:03 +08:00
|
|
|
|
2021-01-27 22:50:31 +08:00
|
|
|
NUT_FIELD(QString, body)
|
|
|
|
|
NUT_FIELD(bool, isPublic)
|
2016-05-12 14:08:58 +08:00
|
|
|
|
|
|
|
|
NUT_DECLARE_CHILD_TABLE(Comment, comments)
|
2018-01-14 22:03:24 +08:00
|
|
|
NUT_DECLARE_CHILD_TABLE(Score, scores)
|
2016-05-12 14:08:58 +08:00
|
|
|
|
2021-01-27 22:50:31 +08:00
|
|
|
int m_id;
|
|
|
|
|
QString m_title;
|
|
|
|
|
QDateTime m_saveDate;
|
|
|
|
|
QString m_body;
|
|
|
|
|
bool m_isPublic;
|
|
|
|
|
|
2016-05-12 14:08:58 +08:00
|
|
|
public:
|
2019-02-08 17:26:26 +08:00
|
|
|
Q_INVOKABLE Post(QObject *parentTableSet = nullptr);
|
2016-05-12 14:08:58 +08:00
|
|
|
|
2021-01-27 22:50:31 +08:00
|
|
|
int id() const;
|
|
|
|
|
QString title() const;
|
|
|
|
|
QDateTime saveDate() const;
|
|
|
|
|
QString body() const;
|
|
|
|
|
bool isPublic() const;
|
|
|
|
|
|
2016-05-12 14:08:58 +08:00
|
|
|
signals:
|
2021-01-27 22:50:31 +08:00
|
|
|
void idChanged(int id);
|
|
|
|
|
void titleChanged(QString title);
|
|
|
|
|
void saveDateChanged(QDateTime saveDate);
|
|
|
|
|
void bodyChanged(QString body);
|
|
|
|
|
void isPublicChanged(bool isPublic);
|
2016-05-12 14:08:58 +08:00
|
|
|
|
|
|
|
|
public slots:
|
2021-01-27 22:50:31 +08:00
|
|
|
void setId(int id);
|
|
|
|
|
void setTitle(QString title);
|
|
|
|
|
void setSaveDate(QDateTime saveDate);
|
|
|
|
|
void setBody(QString body);
|
|
|
|
|
void setPublic(bool isPublic);
|
2016-05-12 14:08:58 +08:00
|
|
|
};
|
|
|
|
|
|
2018-01-09 00:59:16 +08:00
|
|
|
Q_DECLARE_METATYPE(Post*)
|
|
|
|
|
|
2018-01-09 17:33:54 +08:00
|
|
|
#endif // POST_H
|