Warning, file /network/ruqola/src/core/model/moderationreportinfomodel.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "moderationreportinfomodel.h" 0008 #include <KLocalizedString> 0009 0010 ModerationReportInfoModel::ModerationReportInfoModel(QObject *parent) 0011 : QAbstractListModel{parent} 0012 { 0013 } 0014 0015 ModerationReportInfoModel::~ModerationReportInfoModel() = default; 0016 0017 int ModerationReportInfoModel::rowCount(const QModelIndex &parent) const 0018 { 0019 Q_UNUSED(parent) 0020 return mModerationReportInfos.count(); 0021 } 0022 0023 QVariant ModerationReportInfoModel::data(const QModelIndex &index, int role) const 0024 { 0025 if (index.row() < 0 || index.row() >= mModerationReportInfos.count()) { 0026 return {}; 0027 } 0028 const auto info = mModerationReportInfos.at(index.row()); 0029 switch (role) { 0030 case Qt::DisplayRole: 0031 case Message: 0032 return info.description(); 0033 case ReportIdentifier: 0034 return info.reportIdentifier(); 0035 case ReportUserName: 0036 return info.userName(); 0037 case DateTime: 0038 return info.timeStampDateTimeStr(); 0039 } 0040 return {}; 0041 } 0042 0043 void ModerationReportInfoModel::clear() 0044 { 0045 if (rowCount() != 0) { 0046 beginResetModel(); 0047 mModerationReportInfos.clear(); 0048 endResetModel(); 0049 } 0050 } 0051 0052 void ModerationReportInfoModel::addModerationReportInfos(const ModerationReportInfos &moderationReportInfos) 0053 { 0054 clear(); 0055 if (!moderationReportInfos.isEmpty()) { 0056 beginInsertRows(QModelIndex(), 0, moderationReportInfos.count() - 1); 0057 mModerationReportInfos = moderationReportInfos; 0058 endInsertRows(); 0059 } 0060 } 0061 0062 #include "moc_moderationreportinfomodel.cpp"