/** * @RDE_HEADER@ * $Id$ * $HeadURL$ * $Author$ * Created by Philipp Last, NLSE, 2018-01-11 */ #include "evl_comment_model.h" #include #include #include #include namespace Evaluations { EvlCommentDataViewModel::EvlCommentDataViewModel(QObject *parent) : LtsAbstractTableModel( { tr("Id"), tr("Timestamp"), tr("Sender"), tr("Is personal"), tr("Comment"), tr("Hierarchy") }, parent) { } QVariant EvlCommentDataViewModel::data(const QModelIndex &index, int role) const { if (!indexIsValid(index)) return QVariant(); if (role == Qt::BackgroundRole) { const CommentTuple &row = m_vecData.at(index.row()); if (row.m_receiver.size()) return QColor(188, 210, 238); } if (role == Qt::DisplayRole) { const CommentTuple &row = m_vecData.at(index.row()); switch (index.column()) { case Id: return index.row() + 1; case Timestamp: return QDateTime::fromMSecsSinceEpoch(row.m_timestamp.currentMSecsSinceEpoch()); case Sender: return row.m_sender; case IsPersonal: return row.m_receiver.size() ? tr("Yes") : tr("No"); case Comment: return row.m_text; case Hierarchy: return row.m_hierarchy; default: break; } } return QVariant(); } void EvlCommentDataViewProxyModel::setSourceModel(QAbstractItemModel *sourceModel) { m_sourceModel = qobject_cast(sourceModel); LtsWidgets::LtsColumnFilterProxyModel::setSourceModel(sourceModel); } bool EvlCommentDataViewProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const { if (!m_sourceModel || source_left.column() != source_right.column() || !source_left.isValid() || !source_right.isValid()) return LtsWidgets::LtsColumnFilterProxyModel::lessThan(source_left, source_right); const auto &dataLeft = m_sourceModel->m_vecData.at(source_left.row()); const auto dataRight = m_sourceModel->m_vecData.at(source_right.row()); switch (source_left.column()) { case EvlCommentDataViewModel::Timestamp: return dataLeft.m_timestamp.currentMSecsSinceEpoch() < dataRight.m_timestamp.currentMSecsSinceEpoch(); case EvlCommentDataViewModel::Id: case EvlCommentDataViewModel::Sender: case EvlCommentDataViewModel::IsPersonal: case EvlCommentDataViewModel::Comment: case EvlCommentDataViewModel::Hierarchy: break; } return LtsWidgets::LtsColumnFilterProxyModel::lessThan(source_left, source_right); } }