on xenial help sign in
reuse the timezone model provided by System Settings

disambiguate the displayed TZ caption

commit53b0e4f7a6f6666c899aaa2fb750b75a3e2ea2d3 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateWed 7 Oct 2015, 19:18 (11 years ago) parent8c6349f
5 files changed+33−19
plugins/Utils/timezoneFormatter.cpp+10 plugins/Utils/timezoneFormatter.h+1 qml/Wizard/Pages/50-timezone.qml+18−18 tests/mocks/Utils/CMakeLists.txt+1−1 tests/mocks/Utils/plugin.cpp+3
plugins/Utils/timezoneFormatter.cpp+10
@@ -33,3 +33,13 @@ QString TimezoneFormatter::currentTimeInTimezone(const QVariant &tzId) const
3333 }
3434 return QString();
3535}
36+
37+QString TimezoneFormatter::currentTimeInTimezoneWithAbbrev(const QVariant &tzId) const
38+{
39+ QTimeZone tz(tzId.toByteArray());
40+ if (tz.isValid()) {
41+ const QDateTime now = QDateTime::currentDateTime().toTimeZone(tz);
42+ return QStringLiteral("%1 %2").arg(now.time().toString("h:mm")).arg(tz.abbreviation(now));
43+ }
44+ return QString();
45+}
plugins/Utils/timezoneFormatter.h+1
@@ -27,6 +27,7 @@ public:
2727 ~TimezoneFormatter() = default;
2828
2929 Q_INVOKABLE QString currentTimeInTimezone(const QVariant &tzId) const;
30+ Q_INVOKABLE QString currentTimeInTimezoneWithAbbrev(const QVariant &tzId) const;
3031};
3132
3233#endif
qml/Wizard/Pages/50-timezone.qml+18−18
@@ -18,6 +18,7 @@ import QtQuick 2.3
1818import Ubuntu.Components 1.2
1919import Wizard 0.1
2020import Ubuntu.SystemSettings.TimeDate 1.0
21+import Utils 0.1 as Utils
2122import ".." as LocalComponents
2223
2324LocalComponents.Page {
@@ -27,21 +28,11 @@ LocalComponents.Page {
2728 title: i18n.tr("Time Zone")
2829 forwardButtonSourceComponent: forwardButton
2930
30− property alias selectedTimeZone: tzModel.selectedZoneId
31+ property string selectedTimeZone: ""
3132
3233 UbuntuTimeDatePanel {
3334 id: timeDatePanel
34− }
35−
36− TimeZoneModel {
37− id: tzModel
38− }
39−
40− TimeZoneFilterModel {
41− id: tzFilterModel
42− sourceModel: tzModel
4335 filter: searchField.text
44− country: root.countryCode
4536 }
4637
4738 Component.onCompleted: {
@@ -61,28 +52,34 @@ LocalComponents.Page {
6152 id: tz
6253 objectName: "tz"
6354 highlightColor: backgroundColor
64− readonly property bool currentTz: !!id ? selectedTimeZone === id : false
55+ readonly property bool currentTz: ListView.view.currentIndex === index
6556
6657 Column {
6758 anchors.verticalCenter: parent.verticalCenter
6859 anchors.left: parent.left
6960 anchors.leftMargin: leftMargin
61+ anchors.right: image.left
62+ anchors.rightMargin: rightMargin
7063 Label {
7164 id: cityLabel
72− text: !!city ? city : ""
65+ text: displayName
7366 font.weight: tz.currentTz ? Font.Normal : Font.Light
7467 fontSize: "medium"
7568 color: textColor
69+ elide: Text.ElideMiddle
70+ maximumLineCount: 1
71+ width: parent.width
7672 }
7773 Label {
7874 id: timeLabel
79− text: !!time ? time + " " + abbreviation : ""
75+ text: Utils.TimezoneFormatter.currentTimeInTimezoneWithAbbrev(timeZone)
8076 font.weight: tz.currentTz ? Font.Normal : Font.Light
8177 fontSize: "small"
8278 color: textColor
8379 }
8480 }
8581 Image {
82+ id: image
8683 anchors {
8784 right: parent.right
8885 verticalCenter: parent.verticalCenter
@@ -96,9 +93,10 @@ LocalComponents.Page {
9693 }
9794
9895 onClicked: {
99− selectedTimeZone = id
100− print("Selected tz: " + selectedTimeZone)
101− print("Clicked country", countryCode)
96+ print("Clicked index", index)
97+ ListView.view.currentIndex = index
98+ selectedTimeZone = timeZone
99+ print("Clicked country", country)
102100 }
103101 }
104102 }
@@ -121,7 +119,9 @@ LocalComponents.Page {
121119 inputMethodHints: Qt.ImhNoPredictiveText
122120 onTextChanged: {
123121 // reset when switching between filter modes (text/country)
122+ print("Filter:", text)
124123 selectedTimeZone = ""
124+ tzList.currentIndex = -1
125125 }
126126 }
127127
@@ -139,7 +139,7 @@ LocalComponents.Page {
139139 }
140140
141141 height: column.height - searchField.height - column.spacing - topMargin
142− model: tzFilterModel
142+ model: timeDatePanel.timeZoneModel
143143 delegate: tzComponent
144144 }
145145 }
tests/mocks/Utils/CMakeLists.txt+1−1
@@ -20,10 +20,10 @@ set(QMLPLUGIN_SRC
2020 ${CMAKE_SOURCE_DIR}/plugins/Utils/windowscreenshotprovider.cpp
2121 ${CMAKE_SOURCE_DIR}/plugins/Utils/easingcurve.cpp
2222 ${CMAKE_SOURCE_DIR}/plugins/Utils/inputwatcher.cpp
23+ ${CMAKE_SOURCE_DIR}/plugins/Utils/timezoneFormatter.cpp
2324 constants.cpp
2425 plugin.cpp
2526 windowstatestorage.cpp
26− plugin.cpp
2727 )
2828
2929add_library(FakeUtils-qml SHARED
tests/mocks/Utils/plugin.cpp+3
@@ -45,6 +45,7 @@
4545#include <windowkeysfilter.h>
4646#include <windowscreenshotprovider.h>
4747#include <easingcurve.h>
48+#include <timezoneFormatter.h>
4849
4950static QObject *createWindowStateStorage(QQmlEngine *engine, QJSEngine *scriptEngine)
5051{
@@ -75,6 +76,8 @@ void FakeUtilsPlugin::registerTypes(const char *uri)
7576 qmlRegisterSingletonType<WindowStateStorage>(uri, 0, 1, "WindowStateStorage", createWindowStateStorage);
7677 qmlRegisterType<InputWatcher>(uri, 0, 1, "InputWatcher");
7778 qmlRegisterSingletonType<Constants>(uri, 0, 1, "Constants", createConstants);
79+ qmlRegisterSingletonType<TimezoneFormatter>(uri, 0, 1, "TimezoneFormatter",
80+ [](QQmlEngine*, QJSEngine*) -> QObject* { return new TimezoneFormatter; });
7881 qmlRegisterType<ActiveFocusLogger>(uri, 0, 1, "ActiveFocusLogger");
7982}
8083