Spectral/matrix/messageeventmodel.h

55 lines
1.7 KiB
C
Raw Normal View History

2018-03-05 11:12:13 +00:00
#ifndef MESSAGEEVENTMODEL_H
#define MESSAGEEVENTMODEL_H
#include <QtCore/QAbstractListModel>
2018-03-06 11:01:11 +00:00
#include "matriqueroom.h"
2018-03-05 11:12:13 +00:00
class MessageEventModel: public QAbstractListModel
{
2018-03-06 11:11:39 +00:00
Q_OBJECT
// The below property is marked constant because it only changes
// when the whole model is reset (so anything that depends on the model
// has to be re-calculated anyway).
// XXX: A better way would be to make [Room::]Timeline a list model
// itself, leaving only representation of the model to a client.
Q_PROPERTY(MatriqueRoom* room MEMBER m_currentRoom CONSTANT)
2018-03-05 11:12:13 +00:00
public:
2018-03-06 11:01:11 +00:00
enum EventRoles {
EventTypeRole = Qt::UserRole + 1,
EventIdRole,
TimeRole,
SectionRole,
AboveSectionRole,
AuthorRole,
ContentRole,
ContentTypeRole,
HighlightRole,
ReadMarkerRole,
SpecialMarksRole,
LongOperationRole,
};
2018-03-05 11:12:13 +00:00
explicit MessageEventModel(QObject* parent = nullptr);
2018-03-06 11:01:11 +00:00
void changeRoom(MatriqueRoom* room);
2018-03-05 11:12:13 +00:00
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
private slots:
void refreshEvent(const QString& eventId);
private:
2018-03-06 11:01:11 +00:00
MatriqueRoom* m_currentRoom;
2018-03-05 11:12:13 +00:00
QString lastReadEventId;
2018-03-06 11:01:11 +00:00
QDateTime makeMessageTimestamp(MatriqueRoom::rev_iter_t baseIt) const;
QString makeDateString(MatriqueRoom::rev_iter_t baseIt) const;
2018-03-05 11:12:13 +00:00
void refreshEventRoles(const QString& eventId, const QVector<int> roles);
};
#endif // MESSAGEEVENTMODEL_H