summary refs log tree commit diff
path: root/src/timeline2/TimelineModel.cpp
blob: 592064ddafb82ba1d3e3ef33a66c0eea7c5ea583 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "TimelineModel.h"

#include "Utils.h"

QHash<int, QByteArray>
TimelineModel::roleNames() const
{
        return {
          {Type, "type"},
          {Body, "body"},
          {FormattedBody, "formattedBody"},
          {UserId, "userId"},
          {UserName, "userName"},
          {Timestamp, "timestamp"},
        };
}
int
TimelineModel::rowCount(const QModelIndex &parent) const
{
        Q_UNUSED(parent);
        return (int)this->eventOrder.size();
}

QVariant
TimelineModel::data(const QModelIndex &index, int role) const
{
        if (index.row() < 0 && index.row() >= (int)eventOrder.size())
                return QVariant();

        QString id = eventOrder[index.row()];

        switch (role) {
        case UserId:
                return QVariant(QString(""));
        default:
                return QVariant();
        }
}

QColor
TimelineModel::userColor(QString id, QColor background)
{
        if (!userColors.count(id))
                userColors.insert(
                  {id, QColor(utils::generateContrastingHexColor(id, background.name()))});
        return userColors.at(id);
}