3#include <QAbstractListModel>
5#include <QSortFilterProxyModel>
13class Thread :
public QAbstractListModel {
29 explicit Thread(QObject *parent =
nullptr);
34 const QModelIndex &parent = QModelIndex())
const override;
39 [[nodiscard]] QVariant
data(
const QModelIndex &index,
40 int role = Qt::DisplayRole)
const override;
43 [[nodiscard]] QHash<int, QByteArray>
roleNames()
const override;
49 Q_INVOKABLE
void addMessage(
const QString &text,
bool is_user,
50 const QVector<QVariant> &context = {},
51 const bool in_progress =
false);
55 [[nodiscard]]
inline const QList<Message *> &
messages()
const {
63 [[nodiscard]]
inline const QDateTime &
createdAt()
const {
71 QList<Message *> m_Messages;
72 QDateTime m_CreatedAt;
The Thread class provides a model for the chat interface.
Definition thread.h:13
void removeLatestMessage()
Removes the latest message from the model.
Definition thread.cpp:61
Thread(QObject *parent=nullptr)
Constructs a new Thread object.
Definition thread.cpp:10
const QDateTime & createdAt() const
Returns the creation time of the chat thread.
Definition thread.h:63
MessageRoles
The data roles for the model.
Definition thread.h:20
@ ContextRole
Definition thread.h:23
@ TextRole
Definition thread.h:21
@ FinishedRole
Definition thread.h:24
@ IsUserRole
Definition thread.h:22
Q_INVOKABLE void addMessage(const QString &text, bool is_user, const QVector< QVariant > &context={}, const bool in_progress=false)
Adds a new message to the model.
Definition thread.cpp:46
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns the data stored under the given role for the item referred to by the index.
Definition thread.cpp:19
QDateTime createdAt
Definition thread.h:16
const QList< Message * > & messages() const
Returns the list of messages.
Definition thread.h:55
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under the given parent.
Definition thread.cpp:14
void clearMessages()
Clears the list of messages.
Definition thread.cpp:54
QHash< int, QByteArray > roleNames() const override
Returns the role names for the model.
Definition thread.cpp:37
QList< Message * > messages
Definition thread.h:15
Definition backend.cpp:11