2 * Copyright (C) 2015 Canonical Ltd.
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 * Author: Lukáš Tinkl <lukas.tinkl@canonical.com>
22#include "timezonemodel.h"
25TimeZoneModel::TimeZoneModel(QObject *parent)
26 : QAbstractListModel(parent)
31QString TimeZoneModel::selectedZoneId() const
33 return m_selectedZoneId;
36void TimeZoneModel::setSelectedZoneId(const QString &selectedZoneId)
38 if (m_selectedZoneId == selectedZoneId)
41 m_selectedZoneId = selectedZoneId;
42 Q_EMIT selectedZoneIdChanged(selectedZoneId);
45int TimeZoneModel::rowCount(const QModelIndex &parent) const
48 return m_zoneIds.count();
51QVariant TimeZoneModel::data(const QModelIndex &index, int role) const
53 if (index.isValid()) {
54 const QByteArray tzid = m_zoneIds.at(index.row());
58 qWarning() << Q_FUNC_INFO << "Invalid timezone" << tzid;
64 return QString(tz.id()); // to let QML compare it effortlessly with a QString
66 return tz.abbreviation(QDateTime::currentDateTime());
68 return QLocale::countryToString(tz.country());
70 const QString cityName = QString::fromUtf8(tzid.split('/').last().replace("_", " "));
76 return QDateTime::currentDateTime().toTimeZone(tz).toString("h:mm");
78 qWarning() << Q_FUNC_INFO << "Unsupported data role" << role;
86QHash<int, QByteArray> TimeZoneModel::roleNames() const
88 return {{IdRole, "id"}, {Abbreviation, "abbreviation"}, {Country, "country"}, {City, "city"}, {Comment, "comment"}, {Time, "time"}};
91void TimeZoneModel::init()
94 m_zoneIds = QTimeZone::availableTimeZoneIds();
99TimeZoneFilterModel::TimeZoneFilterModel(QObject *parent)
100 : QSortFilterProxyModel(parent)
102 setDynamicSortFilter(false);
103 setSortLocaleAware(true);
104 setSortRole(TimeZoneModel::City);
105 m_stringMatcher.setCaseSensitivity(Qt::CaseInsensitive);
109bool TimeZoneFilterModel::filterAcceptsRow(int row, const QModelIndex &parentIndex) const
111 if (!sourceModel() || m_filter.isEmpty()) {
115 const QString city = sourceModel()->index(row, 0, parentIndex).data(TimeZoneModel::City).toString();
116 const QString country = sourceModel()->index(row, 0, parentIndex).data(TimeZoneModel::Country).toString();
118 if (m_stringMatcher.indexIn(city) != -1 || m_stringMatcher.indexIn(country) != -1) {
125QString TimeZoneFilterModel::filter() const
130void TimeZoneFilterModel::setFilter(const QString &filter)
133 m_stringMatcher.setPattern(m_filter);
134 Q_EMIT filterChanged();
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list