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

#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;
bool isHead() const;
bool isLast() const;
ChatMessage *previous = nullptr;
ChatMessage *next = nullptr;
private:
QString m_name;
QDateTime m_date;
QString m_message;
QString m_datestr;
QString m_hourstr;
};
class ChatModel : public QAbstractListModel
{
Q_OBJECT
public:
enum ChatModelRoles {
NameRole = Qt::UserRole + 1,
DateRole,
HourRole,
MessageRole,
isHeadRole,
isLastRole
};
ChatModel(QObject *parent = nullptr);
void appendMessage(ChatMessage *message);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QList<ChatMessage*> chats;
protected:
QHash<int, QByteArray> roleNames() const;
};
#endif