Warning, file /network/ruqola/src/core/model/servererrorinfohistorymodel.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 "servererrorinfohistorymodel.h" 0008 #include <KLocalizedString> 0009 0010 ServerErrorInfoHistoryModel::ServerErrorInfoHistoryModel(QObject *parent) 0011 : QAbstractListModel{parent} 0012 { 0013 } 0014 0015 ServerErrorInfoHistoryModel::~ServerErrorInfoHistoryModel() = default; 0016 0017 int ServerErrorInfoHistoryModel::rowCount(const QModelIndex &parent) const 0018 { 0019 Q_UNUSED(parent) 0020 return mServerErrorInfo.count(); 0021 } 0022 0023 QVariant ServerErrorInfoHistoryModel::data(const QModelIndex &index, int role) const 0024 { 0025 if (index.row() < 0 || index.row() >= mServerErrorInfo.count()) { 0026 return {}; 0027 } 0028 const auto info = mServerErrorInfo.at(index.row()); 0029 switch (role) { 0030 case Qt::DisplayRole: 0031 case AccountName: 0032 return info.accountName(); 0033 case MessageStr: 0034 return info.message(); 0035 case Identifier: 0036 return info.identifier(); 0037 case DateTime: 0038 return info.dateTime(); 0039 case DateTimeStr: 0040 return info.dateTimeStr(); 0041 } 0042 return {}; 0043 } 0044 0045 void ServerErrorInfoHistoryModel::clear() 0046 { 0047 if (!mServerErrorInfo.isEmpty()) { 0048 beginResetModel(); 0049 mServerErrorInfo.clear(); 0050 endResetModel(); 0051 } 0052 } 0053 0054 void ServerErrorInfoHistoryModel::insertServerErrorInfos(const QVector<ServerErrorInfo> &infos) 0055 { 0056 clear(); 0057 if (!infos.isEmpty()) { 0058 beginInsertRows(QModelIndex(), 0, infos.count() - 1); 0059 mServerErrorInfo = infos; 0060 endInsertRows(); 0061 } 0062 } 0063 0064 void ServerErrorInfoHistoryModel::addServerErrorInfo(const ServerErrorInfo &info) 0065 { 0066 const int numberOfElement = mServerErrorInfo.count(); 0067 mServerErrorInfo.append(info); 0068 beginInsertRows(QModelIndex(), numberOfElement, mServerErrorInfo.count() - 1); 0069 endInsertRows(); 0070 } 0071 0072 #include "moc_servererrorinfohistorymodel.cpp"