File indexing completed on 2024-12-01 07:42:52
0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com> 0002 // SPDX-License-Identifier: GPL-3.0-or-later 0003 0004 #include "polltimemodel.h" 0005 0006 #include <KLocalizedString> 0007 0008 PollTimeModel::PollTimeModel(QObject *parent) 0009 : QAbstractListModel(parent) 0010 { 0011 using namespace std::chrono_literals; 0012 0013 m_times = { 0014 {i18nc("@item:inlistbox Poll expire times", "5 minutes"), std::chrono::seconds{5min}.count()}, 0015 {i18nc("@item:inlistbox Poll expire times", "30 minutes"), std::chrono::seconds{30min}.count()}, 0016 {i18nc("@item:inlistbox Poll expire times", "1 hour"), std::chrono::seconds{1h}.count()}, 0017 {i18nc("@item:inlistbox Poll expire times", "6 hours"), std::chrono::seconds{6h}.count()}, 0018 {i18nc("@item:inlistbox Poll expire times", "12 hours"), std::chrono::seconds{12h}.count()}, 0019 {i18nc("@item:inlistbox Poll expire times", "1 day"), std::chrono::seconds{24h}.count()}, 0020 {i18nc("@item:inlistbox Poll expire times", "3 days"), std::chrono::seconds{72h}.count()}, 0021 {i18nc("@item:inlistbox Poll expire times", "7 days"), std::chrono::seconds{168h}.count()}, 0022 }; 0023 } 0024 0025 QVariant PollTimeModel::data(const QModelIndex &index, int role) const 0026 { 0027 if (!index.isValid()) 0028 return {}; 0029 0030 if (index.row() < 0 || index.row() >= m_times.size()) 0031 return {}; 0032 0033 switch (role) { 0034 case CustomRoles::TextRole: 0035 return m_times[index.row()].name; 0036 case CustomRoles::TimeRole: 0037 return m_times[index.row()].time; 0038 default: 0039 return {}; 0040 } 0041 } 0042 0043 int PollTimeModel::rowCount(const QModelIndex &parent) const 0044 { 0045 Q_UNUSED(parent); 0046 return m_times.count(); 0047 } 0048 0049 QHash<int, QByteArray> PollTimeModel::roleNames() const 0050 { 0051 return { 0052 {CustomRoles::TextRole, "text"}, 0053 {CustomRoles::TimeRole, "time"}, 0054 }; 0055 } 0056 0057 int PollTimeModel::getTime(const int index) 0058 { 0059 return m_times[index].time; 0060 } 0061 0062 #include "moc_polltimemodel.cpp"