/** * @RDE_HEADER@ * List of topics of selected thp * $Id: tpm_exported_scripts_model.h 53111 2021-03-22 08:21:29Z wille_m $ * $HeadURL: svn://slssvn/TDS/branches/product/iterations/21_03_salted_caramel/Lts/Plugins/TakeHomePackageManager/tpm_exported_scripts_model.h $ * $Author: wille_m $ * * Created by Mike Wille, SLTE, 2024-02-09 */ #include "tpm_topics_model.h" #include #include #include #include namespace TakeHomePackageManager { TopicsModel::TopicsModel(QObject *parent) : LtsWidgets::LtsAbstractTableModel( { tr("id"), tr("Channel"), tr("Filter"), tr("Description"), tr("Type"), tr("Start [mm:ss]"), tr("Duration [mm:ss]")}, parent) , m_logger(getLogger("TopicsModel")) {} void TopicsModel::addTopic(const Topic &topic) { insertRow(topic); } QVariant TopicsModel::data(const QModelIndex &index, int role) const { if (!indexIsValid(index)) return QVariant(); if (role == Qt::UserRole) { const auto &topic = m_vecData[index.row()]; return topic.id; } if (role != Qt::DisplayRole) { return {}; } auto channelName = [](const int channel) { switch (channel) { case 1: return tr("Audio"); case 2: return tr("Replay"); case 3: return tr("Screen 1"); case 4: return tr("Screen 2"); default: { assert(false); return L("UNKNOWN"); } } }; const auto &topic = m_vecData[index.row()]; switch (index.column()) { case ColId: return topic.id; case ColChannel: return channelName(topic.channel); case ColFilter: return (topic.filterSet ? QString::number(topic.filter) : L(" - ")); case ColDescription: return (topic.description.isEmpty() ? L(" - ") : topic.description); case ColType: return TopicEditorBase::topicTypeTranslation((TopicEditorBase::TopicType)topic.type); case ColStart: return QTime(0, 0).addSecs(topic.start).toString(L("mm:ss")); case ColDuration: return QTime(0, 0).addSecs(topic.duration).toString(L("mm:ss")); } return {}; } } // namespace TakeHomePackageManager