Spectral/src/messageeventmodel.h

71 lines
1.7 KiB
C
Raw Normal View History

2018-03-05 11:12:13 +00:00
#ifndef MESSAGEEVENTMODEL_H
#define MESSAGEEVENTMODEL_H
#include "spectralroom.h"
#include "room.h"
2018-03-06 11:01:11 +00:00
#include <QtCore/QAbstractListModel>
2018-07-09 02:45:26 +00:00
class MessageEventModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(SpectralRoom* room READ getRoom WRITE setRoom NOTIFY roomChanged)
2018-07-09 02:45:26 +00:00
public:
enum EventRoles {
EventTypeRole = Qt::UserRole + 1,
2018-09-17 03:58:02 +00:00
MessageRole,
AboveEventTypeRole,
2018-07-09 02:45:26 +00:00
EventIdRole,
TimeRole,
AboveTimeRole,
2018-07-09 02:45:26 +00:00
SectionRole,
AboveSectionRole,
AuthorRole,
AboveAuthorRole,
ContentRole,
ContentTypeRole,
HighlightRole,
ReadMarkerRole,
SpecialMarksRole,
LongOperationRole,
2018-08-05 16:53:22 +00:00
AnnotationRole,
2018-09-13 05:05:51 +00:00
UserMarkerRole,
2018-07-09 02:45:26 +00:00
// For debugging
EventResolvedTypeRole,
};
explicit MessageEventModel(QObject* parent = nullptr);
~MessageEventModel();
SpectralRoom* getRoom() { return m_currentRoom; }
void setRoom(SpectralRoom* room);
2018-07-09 02:45:26 +00:00
2018-08-05 16:53:22 +00:00
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
2018-08-06 12:13:51 +00:00
QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const override;
2018-09-13 05:05:51 +00:00
QHash<int, QByteArray> roleNames() const override;
2018-07-09 02:45:26 +00:00
private slots:
int refreshEvent(const QString& eventId);
2018-08-05 16:53:22 +00:00
void refreshRow(int row);
2018-07-09 02:45:26 +00:00
private:
SpectralRoom* m_currentRoom = nullptr;
2018-07-09 02:45:26 +00:00
QString lastReadEventId;
2018-08-05 16:53:22 +00:00
int rowBelowInserted = -1;
bool movingEvent = 0;
2018-07-09 02:45:26 +00:00
2018-08-05 16:53:22 +00:00
int timelineBaseIndex() const;
QDateTime makeMessageTimestamp(
const QMatrixClient::Room::rev_iter_t& baseIt) const;
2018-08-05 16:53:22 +00:00
QString renderDate(QDateTime timestamp) const;
2018-08-06 12:13:51 +00:00
2018-08-05 16:53:22 +00:00
void refreshEventRoles(int row, const QVector<int>& roles = {});
int refreshEventRoles(const QString& eventId, const QVector<int>& roles = {});
2018-07-09 02:45:26 +00:00
signals:
void roomChanged();
2018-03-05 11:12:13 +00:00
};
2018-07-09 02:45:26 +00:00
#endif // MESSAGEEVENTMODEL_H