Commit 97ccd4dc authored by Volker Krause's avatar Volker Krause

Add precipitation data

parent 6930a129
......@@ -67,6 +67,7 @@ private slots:
QVERIFY(fc.maximumTemperature() > -50);
QVERIFY(fc.maximumTemperature() < 50);
QVERIFY(fc.maximumTemperature() >= fc.minimumTemperature());
QVERIFY(fc.precipitation() >= 0.0f);
}
};
......
......@@ -26,6 +26,7 @@ public:
QDateTime m_dt;
float m_minTemp = std::numeric_limits<float>::max();
float m_maxTemp = std::numeric_limits<float>::min();
float m_precipitation = 0.0f;
WeatherForecast::SymbolType m_symbol = WeatherForecast::Unknown;
};
......@@ -113,11 +114,23 @@ QString WeatherForecast::symbolIconName() const
return {};
}
void WeatherForecast::merge(WeatherForecast &other)
float WeatherForecast::precipitation() const
{
return d->m_precipitation;
}
void WeatherForecast::setPrecipitation(float precipitation)
{
d.detach();
d->m_precipitation = std::max(precipitation, 0.0f);
}
void WeatherForecast::merge(const WeatherForecast &other)
{
d.detach();
d->m_minTemp = std::min(other.minimumTemperature(), d->m_minTemp);
d->m_maxTemp = std::max(other.maximumTemperature(), d->m_maxTemp);
d->m_precipitation = std::max(other.precipitation(), d->m_precipitation);
if (d->m_symbol == Unknown) {
d->m_symbol = other.symbolType();
......
......@@ -34,6 +34,7 @@ class WeatherForecast
Q_PROPERTY(bool valid READ isValid CONSTANT)
Q_PROPERTY(float minimumTemperature READ minimumTemperature CONSTANT)
Q_PROPERTY(float maximumTemperature READ maximumTemperature CONSTANT)
Q_PROPERTY(float precipitation READ precipitation CONSTANT)
Q_PROPERTY(QString symbolIconName READ symbolIconName CONSTANT)
public:
......@@ -72,19 +73,23 @@ public:
QDateTime dateTime() const;
void setDateTime(const QDateTime &dt);
/** Temperature range. */
float minimumTemperature() const;
void setMinimumTemperature(float t);
float maximumTemperature() const;
void setMaximumTemperature(float t);
/** Precipitation in mm/m². */
float precipitation() const;
void setPrecipitation(float precipitation);
/** Weather symbol. */
SymbolType symbolType() const;
void setSymbolType(SymbolType type);
QString symbolIconName() const;
// TODO precipitation probability
/** Merge with @p other. */
void merge(WeatherForecast &other);
void merge(const WeatherForecast &other);
private:
QExplicitlySharedDataPointer<WeatherForecastPrivate> d;
......
......@@ -364,6 +364,8 @@ WeatherForecast WeatherForecastManager::parseForecastElement(QXmlStreamReader &r
if (it != std::end(symbol_map) && (*it).id == symId) {
fc.setSymbolType((*it).type);
}
} else if (reader.name() == QLatin1String("precipitation")) {
fc.setPrecipitation(reader.attributes().value(QLatin1String("value")).toFloat());
}
break;
case QXmlStreamReader::EndElement:
......
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