matrixion/src/timeline2/TimelineModel.cpp

48 lines
1.1 KiB
C++
Raw Normal View History

2019-08-31 00:20:53 +03:00
#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);
}