-
Notifications
You must be signed in to change notification settings - Fork 1
/
datemodel.h
62 lines (54 loc) · 1.42 KB
/
datemodel.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
#ifndef DATEMODEL_H
#define DATEMODEL_H
#include <QAbstractListModel>
#include<QString>
class Date{
public:
Date(const QString &title,const QString &author,const QString& dynasty,const QString &content,const QString &image);
QString title()const
{
return m_title;
}
QString author()const
{
return m_author;
}
QString dynasty()const{
return m_dynasty;
}
QString content()const{
return m_content;
}
QString image()const {
return m_image;
}
private:
QString m_title;
QString m_author;
QString m_dynasty;
QString m_content;
QString m_image;
};
class dateModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit dateModel(QObject *parent = nullptr);
enum DataRoles{
TITLE_ROLER=Qt::UserRole +1,
AUTHOR_ROLER,
DYNASTY_ROLER,
CONTENT_ROLER,
IMAGE_ROLER
};
// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
void insert(int index,const Date &date);
void append(const QString &title,const QString &author,const QString &dysty,const QString &content,const QString &image);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
protected: // interface QAbstractListModel
virtual QHash<int, QByteArray> roleNames() const;
private:
QList<Date>m_datas;
};
#endif // DATEMODEL_H