timezonemodel.h 3.56 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/***************************************************************************
 *   Copyright (C) 2014 Kai Uwe Broulik <kde@privat.broulik.de>            *
 *   Copyright (C) 2014  Martin Klapetek <mklapetek@kde.org>               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 ***************************************************************************/

#ifndef TIMEZONEMODEL_H
#define TIMEZONEMODEL_H

#include <QAbstractListModel>
25
#include <QSortFilterProxyModel>
26
27
28

#include "timezonedata.h"

29
30
class TimezonesI18n;

31
32
33
34
class TimeZoneFilterProxy : public QSortFilterProxyModel
{
    Q_OBJECT
    Q_PROPERTY(QString filterString WRITE setFilterString MEMBER m_filterString NOTIFY filterStringChanged)
35
    Q_PROPERTY(bool onlyShowChecked WRITE setOnlyShowChecked MEMBER m_onlyShowChecked NOTIFY onlyShowCheckedChanged)
36
37

public:
Laurent Montel's avatar
Laurent Montel committed
38
    explicit TimeZoneFilterProxy(QObject *parent = nullptr);
39
    bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
40
41

    void setFilterString(const QString &filterString);
42
    void setOnlyShowChecked(const bool show);
43
44
45

Q_SIGNALS:
    void filterStringChanged();
46
    void onlyShowCheckedChanged();
47
48
49

private:
    QString m_filterString;
50
    bool m_onlyShowChecked = false;
51
52
53
54
55
    QStringMatcher m_stringMatcher;
};

//=============================================================================

56
57
58
59
60
61
class TimeZoneModel : public QAbstractListModel
{
    Q_OBJECT
    Q_PROPERTY(QStringList selectedTimeZones WRITE setSelectedTimeZones MEMBER m_selectedTimeZones NOTIFY selectedTimeZonesChanged)

public:
Laurent Montel's avatar
Laurent Montel committed
62
    explicit TimeZoneModel(QObject *parent = nullptr);
63
    ~TimeZoneModel() override;
64
65
66
67
68
69

    enum Roles {
        TimeZoneIdRole = Qt::UserRole + 1,
        RegionRole,
        CityRole,
        CommentRole,
70
        CheckedRole,
Nicolas Fella's avatar
Nicolas Fella committed
71
        IsLocalTimeZoneRole,
72
73
    };

74
75
76
    int rowCount(const QModelIndex &parent) const override;
    QVariant data(const QModelIndex &index, int role) const override;
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
77
78
79
80
81
82
83
84
85
86

    void update();
    void setSelectedTimeZones(const QStringList &selectedTimeZones);

    Q_INVOKABLE void selectLocalTimeZone();

Q_SIGNALS:
    void selectedTimeZonesChanged();

protected:
87
    QHash<int, QByteArray> roleNames() const override;
88
89

private:
90
91
    void sortTimeZones();

92
    QList<TimeZoneData> m_data;
93
    QHash<QString, int> m_offsetData; // used for sorting
94
    QStringList m_selectedTimeZones;
95
    TimezonesI18n *m_timezonesI18n;
96
97
98
};

#endif // TIMEZONEMODEL_H