on xenial help sign in
initially, filter the list of timezones by the user-selected country
commit3fff389cfdf370d6847819c704ee74e6c4e662d3 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateMon 20 Jul 2015, 20:40 (11 years ago) parenta3651e8
4 files changed+32−6
plugins/Wizard/LocalePlugin.cpp+1−1 plugins/Wizard/timezonemodel.cpp+24−5 plugins/Wizard/timezonemodel.h+6 qml/Wizard/Pages/50-timezone.qml+1
plugins/Wizard/LocalePlugin.cpp+1−1
@@ -341,7 +341,7 @@ QString LocaleAttached::qlocToCountryCode(QLocale::Country c)
341341{
342342 const QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, c);
343343 if (!locales.isEmpty()) {
344− return locales.first().name().split('_').at(1);
344+ return locales.first().name().section('_', 1, 1);
345345 }
346346
347347 return QString();
plugins/Wizard/timezonemodel.cpp+24−5
@@ -117,15 +117,20 @@ TimeZoneFilterModel::TimeZoneFilterModel(QObject *parent)
117117
118118bool TimeZoneFilterModel::filterAcceptsRow(int row, const QModelIndex &parentIndex) const
119119{
120− if (!sourceModel() || m_filter.isEmpty()) {
120+ if (!sourceModel()) {
121121 return true;
122122 }
123123
124− 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();
124+ if (!m_filter.isEmpty()) { // filtering by freeform text input, cf setFilter(QString)
125+ const QString city = sourceModel()->index(row, 0, parentIndex).data(TimeZoneModel::City).toString();
126+ const QString country = sourceModel()->index(row, 0, parentIndex).data(TimeZoneModel::Country).toString();
126127
127− if (m_stringMatcher.indexIn(city) != -1 || m_stringMatcher.indexIn(country) != -1) {
128− return true;
128+ if (m_stringMatcher.indexIn(city) != -1 || m_stringMatcher.indexIn(country) != -1) {
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;
129134 }
130135
131136 return false;
@@ -143,3 +148,17 @@ void TimeZoneFilterModel::setFilter(const QString &filter)
143148 Q_EMIT filterChanged();
144149 invalidate();
145150}
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
2424{
2525 Q_OBJECT
2626 Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
27+ Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY countryChanged)
2728
2829public:
2930 explicit TimeZoneFilterModel(QObject *parent = 0);
@@ -33,12 +34,17 @@ public:
3334 QString filter() const;
3435 void setFilter(const QString &filter);
3536
37+ QString country() const;
38+ void setCountry(const QString &country);
39+
3640Q_SIGNALS:
3741 void filterChanged();
42+ void countryChanged(const QString &country);
3843
3944private:
4045 QString m_filter;
4146 QStringMatcher m_stringMatcher;
47+ QString m_country;
4248};
4349
4450class TimeZoneModel: public QAbstractListModel
qml/Wizard/Pages/50-timezone.qml+1
@@ -36,6 +36,7 @@ LocalComponents.Page {
3636 id: tzFilterModel
3737 sourceModel: tzModel
3838 filter: searchField.text
39+ country: root.country
3940 }
4041
4142 Component.onCompleted: {