You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

3 years ago
#ifndef CHATMODEL_H
#define CHATMODEL_H
#include <QAbstractListModel>
#include <QDateTime>
#include <QStringList>
class ChatMessage
{
public:
ChatMessage(const QString &name, const QDateTime &date, const QString &message);
QString name() const;
QDateTime date() const;
QString message() const;
QString datestr() const;
QString hourstr() const;
3 years ago
bool isHead() const;
bool isLast() const;
ChatMessage *previous = nullptr;
ChatMessage *next = nullptr;
3 years ago
private:
QString m_name;
QDateTime m_date;
QString m_message;
QString m_datestr;
QString m_hourstr;
};
class ChatModel : public QAbstractListModel
{
Q_OBJECT
public:
3 years ago
enum ChatModelRoles {
3 years ago
NameRole = Qt::UserRole + 1,
DateRole,
HourRole,
3 years ago
MessageRole,
isHeadRole,
isLastRole
3 years ago
};
ChatModel(QObject *parent = nullptr);
3 years ago
void appendMessage(ChatMessage *message);
3 years ago
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
3 years ago
QList<ChatMessage*> chats;
3 years ago
protected:
QHash<int, QByteArray> roleNames() const;
};
#endif