From 84b4281cc26fcc0aa8fa3b2693ee212e7c4e7e7e Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Thu, 16 Oct 2014 16:01:48 +0200 Subject: Add the wind direction for accessibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I6de63d01c21aabd8e00c750c987300ecf610a758 Reviewed-by: Jan Arve Sæther Reviewed-by: Caroline Chao --- qml/js/utils.js | 7 ++++++- qml/models/WeatherModel.qml | 1 + qml/pages/OneDayZoomItem.qml | 2 +- src/daymodel.cpp | 8 +++++++- src/daymodel.h | 8 +++++--- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/qml/js/utils.js b/qml/js/utils.js index 9333062..9426cff 100644 --- a/qml/js/utils.js +++ b/qml/js/utils.js @@ -163,7 +163,7 @@ function updateDayModel(dayModel, item) { var windIconUrl = getWindSymbolUrl(item.windSpeed, item.windDirectionDeg) var weatherUrl = extractSymbolUrl(item.symbolcode) - dayModel.addRow(weatherUrl, item.from, item.to, item.temperature, item.windSpeed, windIconUrl, item.rain, item.period) + dayModel.addRow(weatherUrl, item.from, item.to, item.temperature, item.windSpeed, item.windDirectionName, windIconUrl, item.rain, item.period) } function getItemDate(item) @@ -254,6 +254,11 @@ function getWindSpeed(index, dayModel) return isMetricSystem() ? speed_ms : Math.round(speed_ms * 223.694)/100 // convert to mph } +function getWindDirectionName(index, dayModel) +{ + return dayModel.getDayDetails(index, "windDirectionName") +} + function getWindUrl(index, dayModel) { var url = dayModel.getDayDetails(index, "windUrl") diff --git a/qml/models/WeatherModel.qml b/qml/models/WeatherModel.qml index 920c494..131f36e 100644 --- a/qml/models/WeatherModel.qml +++ b/qml/models/WeatherModel.qml @@ -101,6 +101,7 @@ Item { XmlRole { name: "period"; query: "@period/string()" } XmlRole { name: "symbolcode"; query: "symbol/@var/string()" } XmlRole { name: "windType"; query: "windSpeed/@name/string()" } + XmlRole { name: "windDirectionName"; query: "windDirection/@name/string()" } XmlRole { name: "windDirectionDeg"; query: "windDirection/@deg/string()" } XmlRole { name: "windSpeed"; query: "windSpeed/@mps/string()" } XmlRole { name: "temperature"; query: "temperature/@value/string()" } diff --git a/qml/pages/OneDayZoomItem.qml b/qml/pages/OneDayZoomItem.qml index 0a03725..fa8e4ec 100644 --- a/qml/pages/OneDayZoomItem.qml +++ b/qml/pages/OneDayZoomItem.qml @@ -176,7 +176,7 @@ GridLayout { text : qsTr("Wind: ") + Utils.getWindSpeed(root.sliderValue, root.model) Layout.alignment: Qt.AlignLeft | Qt.AlignBaseline pixelSize: 30 - Accessible.name: text + " " + windUnit.text + Accessible.name: text + " " + windUnit.text + " " + Utils.getWindDirectionName(root.sliderValue, root.model) } TouchLabel { //: The wind speed unit, meters per second or miles per hour diff --git a/src/daymodel.cpp b/src/daymodel.cpp index 3473fa1..82aa022 100644 --- a/src/daymodel.cpp +++ b/src/daymodel.cpp @@ -66,6 +66,8 @@ QVariant DayModel::data(const QModelIndex &index, int role) const return m_data.at(index.row()).windSpeed; if (role == WindUrlRole) return m_data.at(index.row()).windUrl; + if (role == WindDirectionNameRole) + return m_data.at(index.row()).windDirectionName; if (role == RainRole) return m_data.at(index.row()).rain; return QVariant(); @@ -80,6 +82,7 @@ QHash DayModel::roleNames() const rn[TemperatureRole] = "temperature"; rn[WindSpeedRole] = "windSpeed"; rn[WindUrlRole] = "windUrl"; + rn[WindDirectionNameRole] = "windDirectionName"; rn[RainRole] = "rain"; return rn; } @@ -91,7 +94,7 @@ void DayModel::clear() m_data.clear(); } -void DayModel::addRow(QString weatherUrl, QString from, QString to, QString temperature, QString windSpeed, QString windUrl, QString rain) { +void DayModel::addRow(QString weatherUrl, QString from, QString to, QString temperature, QString windSpeed, QString windDirectionName, QString windUrl, QString rain) { QStringList m_images; DayModelStructure temp; temp.from = from; @@ -103,6 +106,7 @@ void DayModel::addRow(QString weatherUrl, QString from, QString to, QString temp temp.temperature = temperature; temp.windSpeed = windSpeed; temp.windUrl = windUrl; + temp.windDirectionName = windDirectionName; m_images.append(windUrl); temp.rain = rain; m_data.append(temp); @@ -147,6 +151,8 @@ QString DayModel::getDayDetails(int index, QString prop) const return temp.temperature; if (prop == "windSpeed") return temp.windSpeed; + if (prop == "windDirectionName") + return temp.windDirectionName; if (prop == "windUrl") return temp.windUrl; if (prop == "rain") diff --git a/src/daymodel.h b/src/daymodel.h index 2edeeb3..13291b9 100644 --- a/src/daymodel.h +++ b/src/daymodel.h @@ -66,6 +66,7 @@ public: QString to; QString temperature; QString windSpeed; + QString windDirectionName; QString windUrl; QString rain; }; @@ -76,8 +77,9 @@ public: ToRole = Qt::UserRole + 3, TemperatureRole = Qt::UserRole + 4, WindSpeedRole = Qt::UserRole + 5, - WindUrlRole = Qt::UserRole + 6, - RainRole = Qt::UserRole + 7 + WindDirectionNameRole = Qt::UserRole + 6, + WindUrlRole = Qt::UserRole + 7, + RainRole = Qt::UserRole + 8 }; DayModel(); @@ -93,7 +95,7 @@ public: QVariant data(const QModelIndex &index, int role) const; QHash roleNames() const; - Q_INVOKABLE void addRow(QString weatherUrl, QString from, QString to, QString temperature, QString windSpeed, QString windUrl, QString rain); + Q_INVOKABLE void addRow(QString weatherUrl, QString from, QString to, QString temperature, QString windSpeed, QString windDirectionName, QString windUrl, QString rain); Q_INVOKABLE QString getDayDetails(int index, QString prop) const; Q_INVOKABLE int periodCount() const { return m_data.count(); } -- cgit v1.2.3