File indexing completed on 2024-03-24 17:01:23
0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0002 // SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org> 0003 0004 #include "reproducibilitymodel.h" 0005 0006 #include <QMetaEnum> 0007 0008 #include <KLocalizedString> 0009 0010 QList<ReportInterface::Reproducible> ReproducibilityModel::reproducibilities() 0011 { 0012 QList<ReportInterface::Reproducible> list; 0013 auto roleEnum = QMetaEnum::fromType<ReportInterface::Reproducible>(); 0014 for (int i = 0; i < roleEnum.keyCount(); ++i) { 0015 const int value = roleEnum.value(i); 0016 Q_ASSERT(value != -1); 0017 list.append(static_cast<ReportInterface::Reproducible>(value)); 0018 } 0019 return list; 0020 } 0021 0022 int ReproducibilityModel::rowCount(const QModelIndex &parent) const 0023 { 0024 Q_UNUSED(parent) 0025 return m_list.size(); 0026 } 0027 0028 QVariant ReproducibilityModel::data(const QModelIndex &index, int intRole) const 0029 { 0030 if (!index.isValid()) { 0031 return {}; 0032 } 0033 0034 switch (static_cast<Role>(intRole)) { 0035 case Role::String: 0036 switch (m_list.at(index.row())) { 0037 case ReportInterface::ReproducibleUnsure: 0038 return i18nc("@item:inlistbox user didn't tried to repeat the crash situation", "I did not try again"); 0039 case ReportInterface::ReproducibleNever: 0040 return i18nc("@item:inlistbox the crash cannot be reproduce. reproduciblity->never", "Never"); 0041 case ReportInterface::ReproducibleSometimes: 0042 return i18nc("@item:inlistbox the bug can be reproduced sometimes", "Sometimes"); 0043 case ReportInterface::ReproducibleEverytime: 0044 return i18nc("@item:inlistbox the bug can be reproduced every time", "Every time"); 0045 } 0046 return {}; 0047 case Role::Integer: 0048 return m_list.at(index.row()); 0049 } 0050 0051 return {}; 0052 } 0053 0054 QHash<int, QByteArray> ReproducibilityModel::roleNames() const 0055 { 0056 static QHash<int, QByteArray> roles; 0057 if (!roles.isEmpty()) { 0058 return roles; 0059 } 0060 0061 const QMetaEnum roleEnum = QMetaEnum::fromType<Role>(); 0062 for (int i = 0; i < roleEnum.keyCount(); ++i) { 0063 const int value = roleEnum.value(i); 0064 Q_ASSERT(value != -1); 0065 roles[static_cast<int>(value)] = QByteArray("ROLE_") + roleEnum.valueToKey(value); 0066 } 0067 return roles; 0068 }