on xenial help sign in
expose the UTC offset (in hours) from the timezone model
commit65f91df98760125d4db18197b20cf0f86957d85b authorLukáš Tinkl <lukas.tinkl@canonical.com> dateWed 23 Dec 2015, 15:24 (11 years ago) parent0cd476b
2 files changed+8−1
plugins/Wizard/timezonemodel.cpp+5 plugins/Wizard/timezonemodel.h+3−1
plugins/Wizard/timezonemodel.cpp+5
@@ -34,6 +34,7 @@ TimeZoneLocationModel::TimeZoneLocationModel(QObject *parent):
3434 m_roleNames[TimeZoneRole] = "timeZone";
3535 m_roleNames[CityRole] = "city";
3636 m_roleNames[CountryRole] = "country";
37+ m_roleNames[OffsetRole] = "offset";
3738
3839 QObject::connect(m_workerThread,
3940 &TimeZonePopulateWorker::resultReady,
@@ -98,6 +99,10 @@ QVariant TimeZoneLocationModel::data(const QModelIndex &index, int role) const
9899 return tz.country;
99100 case CityRole:
100101 return tz.city;
102+ case OffsetRole: {
103+ QTimeZone tmp(tz.timezone.toLatin1());
104+ return static_cast<double>(tmp.standardTimeOffset(QDateTime::currentDateTime())) / 3600;
105+ }
101106 default:
102107 qWarning() << Q_FUNC_INFO << "Unknown role";
103108 return QVariant();
plugins/Wizard/timezonemodel.h+3−1
@@ -36,7 +36,8 @@ public:
3636 TimeZoneRole = Qt::UserRole + 1,
3737 CityRole,
3838 CountryRole,
39− SimpleRole
39+ SimpleRole,
40+ OffsetRole
4041 };
4142
4243 struct TzLocation {
@@ -45,6 +46,7 @@ public:
4546 QString timezone;
4647 QString state;
4748 QString full_country;
49+ double offset;
4850 };
4951
5052 int rowCount(const QModelIndex &parent = QModelIndex()) const override;