on xenial help sign in
initially, filter the list of timezones by the user-selected country
3fff389Lukáš Tinkl
plugins/Wizard/LocalePlugin.cpp+1−1
@@ -341,7 +341,7 @@ QString LocaleAttached::qlocToCountryCode(QLocale::Country c)
341{
341{
342 const QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, c);
342 const QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, c);
343 if (!locales.isEmpty()) {
343 if (!locales.isEmpty()) {
344− return locales.first().name().split('_').at(1);
344+ return locales.first().name().section('_', 1, 1);
345 }
345 }
346
346
347 return QString();
347 return QString();
plugins/Wizard/timezonemodel.cpp+24−5
@@ -117,15 +117,20 @@ TimeZoneFilterModel::TimeZoneFilterModel(QObject *parent)
117
117
118bool TimeZoneFilterModel::filterAcceptsRow(int row, const QModelIndex &parentIndex) const
118bool TimeZoneFilterModel::filterAcceptsRow(int row, const QModelIndex &parentIndex) const
119{
119{
120− if (!sourceModel() || m_filter.isEmpty()) {
120+ if (!sourceModel()) {
121 return true;
121 return true;
122 }
122 }
123
123
124+ if (!m_filter.isEmpty()) { // filtering by freeform text input, cf setFilter(QString)
124− const QString city = sourceModel()->index(row, 0, parentIndex).data(TimeZoneModel::City).toString();
125+ const QString city = sourceModel()->index(row, 0, parentIndex).data(TimeZoneModel::City).toString();
125− const QString country = sourceModel()->index(row, 0, parentIndex).data(TimeZoneModel::Country).toString();
126+ const QString country = sourceModel()->index(row, 0, parentIndex).data(TimeZoneModel::Country).toString();
126
127
127− if (m_stringMatcher.indexIn(city) != -1 || m_stringMatcher.indexIn(country) != -1) {
128+ if (m_stringMatcher.indexIn(city) != -1 || m_stringMatcher.indexIn(country) != -1) {
128− return true;
129+ return true;
130+ }
131+ } else if (!m_country.isEmpty()) { // filter by country code
132+ const QString countryCode = sourceModel()->index(row, 0, parentIndex).data(TimeZoneModel::CountryCode).toString();
133+ return m_country.compare(countryCode, Qt::CaseInsensitive) == 0;
129 }
134 }
130
135
131 return false;
136 return false;
@@ -143,3 +148,17 @@ void TimeZoneFilterModel::setFilter(const QString &filter)
143 Q_EMIT filterChanged();
148 Q_EMIT filterChanged();
144 invalidate();
149 invalidate();
145}
150}
151+
152+QString TimeZoneFilterModel::country() const
153+{
154+ return m_country;
155+}
156+
157+void TimeZoneFilterModel::setCountry(const QString &country)
158+{
159+ if (m_country == country)
160+ return;
161+
162+ m_country = country;
163+ Q_EMIT countryChanged(country);
164+}
plugins/Wizard/timezonemodel.h+6
@@ -24,6 +24,7 @@ class TimeZoneFilterModel: public QSortFilterProxyModel
24{
24{
25 Q_OBJECT
25 Q_OBJECT
26 Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
26 Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
27+ Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY countryChanged)
27
28
28public:
29public:
29 explicit TimeZoneFilterModel(QObject *parent = 0);
30 explicit TimeZoneFilterModel(QObject *parent = 0);
@@ -33,12 +34,17 @@ public:
33 QString filter() const;
34 QString filter() const;
34 void setFilter(const QString &filter);
35 void setFilter(const QString &filter);
35
36
37+ QString country() const;
38+ void setCountry(const QString &country);
39+
36Q_SIGNALS:
40Q_SIGNALS:
37 void filterChanged();
41 void filterChanged();
42+ void countryChanged(const QString &country);
38
43
39private:
44private:
40 QString m_filter;
45 QString m_filter;
41 QStringMatcher m_stringMatcher;
46 QStringMatcher m_stringMatcher;
47+ QString m_country;
42};
48};
43
49
44class TimeZoneModel: public QAbstractListModel
50class TimeZoneModel: public QAbstractListModel
qml/Wizard/Pages/50-timezone.qml+1
@@ -36,6 +36,7 @@ LocalComponents.Page {
36 id: tzFilterModel
36 id: tzFilterModel
37 sourceModel: tzModel
37 sourceModel: tzModel
38 filter: searchField.text
38 filter: searchField.text
39+ country: root.country
39 }
40 }
40
41
41 Component.onCompleted: {
42 Component.onCompleted: {