Nut/tests/auto/common/post.h

80 lines
1.8 KiB
C
Raw Normal View History

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>
#include <QSharedPointer>
2016-05-12 14:08:58 +08:00
2017-02-01 18:01:21 +08:00
#ifdef NUT_NAMESPACE
using namespace NUT_NAMESPACE;
#endif
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
Q_MOC_INCLUDE("comment.h")
Q_MOC_INCLUDE("score.h")
#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
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)
NUT_FIELD(int, id)
2016-05-12 14:08:58 +08:00
NUT_NOT_NULL(title)
NUT_LEN(title, 50)
NUT_FIELD(QString, title)
2016-05-12 14:08:58 +08:00
NUT_FIELD(QDateTime, saveDate)
2016-05-21 16:09:03 +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
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
int id() const;
QString title() const;
QDateTime saveDate() const;
QString body() const;
bool isPublic() const;
2021-03-14 16:42:04 +08:00
Q_SIGNALS:
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
2021-03-14 16:42:04 +08:00
public Q_SLOTS:
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