Commit 081c6a66 authored by Volker Krause's avatar Volker Krause
Browse files

Warn about severe weather conditions

parent 0825fb38
Pipeline #130826 passed with stage
in 1 minute and 26 seconds
......@@ -60,6 +60,7 @@ private Q_SLOTS:
QCOMPARE((*it).precipitation(), 0.0f);
QCOMPARE((*it).symbolType(), WeatherForecast::Clear);
QCOMPARE((*it).windSpeed(), 1.6f);
QCOMPARE((*it).isSevere(), false);
}
void testWeatherSymbol()
......
......@@ -22,7 +22,7 @@ Kirigami.AbstractCard {
id: headerBackground
Kirigami.Theme.colorSet: Kirigami.Theme.Complementary
Kirigami.Theme.inherit: false
color: Kirigami.Theme.backgroundColor
color: weatherForecast.isSevere ? Kirigami.Theme.negativeBackgroundColor : Kirigami.Theme.backgroundColor
radius: Kirigami.Units.smallSpacing
implicitWidth: icon.implicitWidth + Kirigami.Units.largeSpacing * 2
Layout.minimumHeight: implicitWidth
......
......@@ -27,6 +27,7 @@ Kirigami.Page {
Kirigami.AbstractListItem {
readonly property var fc: model.weatherForecast
highlighted: false
backgroundColor: fc.isSevere ? Kirigami.Theme.negativeBackgroundColor : "transparent"
Row {
spacing: Kirigami.Units.largeSpacing
Kirigami.Icon {
......
......@@ -213,3 +213,30 @@ void WeatherForecast::setTile(WeatherTile tile)
d.detach();
d->m_tile = tile;
}
bool WeatherForecast::isSevere() const
{
// heat: https://en.wikipedia.org/wiki/Heat_index
// TODO to do this properly we need the humidity value as well
if (d->m_maxTemp > 35.0) {
return true;
}
// cold
if (d->m_minTemp < -20.0) {
return true;
}
// precipitation: https://de.wikipedia.org/wiki/Unwetter
if ((d->m_precipitation / d->m_range) > 25.0 || (d->m_precipitation > 35.0 && d->m_range >= 6)) {
return true;
}
// wind: https://en.wikipedia.org/wiki/Beaufort_scale
if (d->m_windSpeed > 17.5) {
return true;
}
return false;
}
......@@ -28,6 +28,7 @@ class WeatherForecast
Q_PROPERTY(float windSpeed READ windSpeed CONSTANT)
Q_PROPERTY(QString symbolIconName READ symbolIconName CONSTANT)
Q_PROPERTY(int range READ range CONSTANT)
Q_PROPERTY(bool isSevere READ isSevere STORED false)
public:
enum SymbolFlag : uint16_t {
......@@ -86,6 +87,10 @@ public:
// internal for weighting different forecast elements
int range() const;
void setRange(int hours);
/** Severe weather conditions. */
bool isSevere() const;
// internal for computing the day/night icons
WeatherTile tile() const;
void setTile(WeatherTile tile);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment