File indexing completed on 2025-01-26 05:07:37
0001 /* 0002 SPDX-FileCopyrightText: 2014 Kai Uwe Broulik <kde@privat.broulik.de> 0003 SPDX-FileCopyrightText: 2014 Martin Klapetek <mklapetek@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <QAbstractListModel> 0011 #include <QSortFilterProxyModel> 0012 0013 #include "timezonedata.h" 0014 0015 class TimezonesI18n; 0016 0017 class TimeZoneFilterProxy : public QSortFilterProxyModel 0018 { 0019 Q_OBJECT 0020 Q_PROPERTY(QString filterString WRITE setFilterString MEMBER m_filterString NOTIFY filterStringChanged) 0021 Q_PROPERTY(bool onlyShowChecked WRITE setOnlyShowChecked MEMBER m_onlyShowChecked NOTIFY onlyShowCheckedChanged) 0022 0023 public: 0024 explicit TimeZoneFilterProxy(QObject *parent = nullptr); 0025 bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; 0026 0027 void setFilterString(const QString &filterString); 0028 void setOnlyShowChecked(const bool show); 0029 0030 Q_SIGNALS: 0031 void filterStringChanged(); 0032 void onlyShowCheckedChanged(); 0033 0034 private: 0035 QString m_filterString; 0036 bool m_onlyShowChecked = false; 0037 QStringMatcher m_stringMatcher; 0038 }; 0039 0040 //============================================================================= 0041 0042 class TimeZoneModel : public QAbstractListModel 0043 { 0044 Q_OBJECT 0045 Q_PROPERTY(QStringList selectedTimeZones WRITE setSelectedTimeZones MEMBER m_selectedTimeZones NOTIFY selectedTimeZonesChanged) 0046 0047 public: 0048 explicit TimeZoneModel(QObject *parent = nullptr); 0049 ~TimeZoneModel() override; 0050 0051 enum Roles { 0052 TimeZoneIdRole = Qt::UserRole + 1, 0053 RegionRole, 0054 CityRole, 0055 CommentRole, 0056 CheckedRole, 0057 IsLocalTimeZoneRole, 0058 }; 0059 0060 int rowCount(const QModelIndex &parent) const override; 0061 QVariant data(const QModelIndex &index, int role) const override; 0062 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 0063 0064 void update(); 0065 void setSelectedTimeZones(const QStringList &selectedTimeZones); 0066 0067 Q_INVOKABLE void selectLocalTimeZone(); 0068 Q_INVOKABLE QString localTimeZoneCity(); 0069 0070 public Q_SLOTS: 0071 void slotUpdate(); 0072 0073 Q_SIGNALS: 0074 void selectedTimeZonesChanged(); 0075 0076 protected: 0077 QHash<int, QByteArray> roleNames() const override; 0078 0079 private: 0080 void sortTimeZones(); 0081 0082 QList<TimeZoneData> m_data; 0083 QHash<QString, int> m_offsetData; // used for sorting 0084 QStringList m_selectedTimeZones; 0085 TimezonesI18n *m_timezonesI18n; 0086 };