Commit 37043891 authored by Volker Krause's avatar Volker Krause

Replace single temperature with a temperature range

parent 659fec71
......@@ -57,13 +57,16 @@ private slots:
QVERIFY(updateSpy.wait());
fc = mgr.forecast(46.1, 7.78, now).value<WeatherForecast>();
qDebug() << fc.dateTime() << fc.temperature() << fc.symbolType() << fc.symbolIconName();
qDebug() << fc.dateTime() << fc.minimumTemperature() << fc.maximumTemperature() << fc.symbolType() << fc.symbolIconName();
QVERIFY(fc.isValid());
QVERIFY(fc.dateTime().isValid());
QVERIFY(fc.dateTime() <= now);
QVERIFY(fc.symbolType() != WeatherForecast::Unknown);
QVERIFY(fc.temperature() > -50);
QVERIFY(fc.temperature() < 50);
QVERIFY(fc.minimumTemperature() > -50);
QVERIFY(fc.minimumTemperature() < 50);
QVERIFY(fc.maximumTemperature() > -50);
QVERIFY(fc.maximumTemperature() < 50);
QVERIFY(fc.maximumTemperature() >= fc.minimumTemperature());
}
};
......
......@@ -51,7 +51,9 @@ Kirigami.AbstractCard {
contentItem: ColumnLayout {
Layout.fillWidth: true
QQC2.Label {
text: qsTr("Temperature: %1 °C").arg(weatherForecast.temperature)
text: qsTr("Temperature: %1 °C / %2 °C")
.arg(weatherForecast.minimumTemperature)
.arg(weatherForecast.maximumTemperature)
color: Kirigami.Theme.textColor
Layout.fillWidth: true
}
......
......@@ -19,10 +19,13 @@
#include <QDateTime>
#include <limits>
class WeatherForecastPrivate : public QSharedData {
public:
QDateTime m_dt;
float m_temp = -300;
float m_minTemp = std::numeric_limits<float>::max();
float m_maxTemp = std::numeric_limits<float>::min();
WeatherForecast::SymbolType m_symbol = WeatherForecast::Unknown;
};
......@@ -51,15 +54,26 @@ void WeatherForecast::setDateTime(const QDateTime &dt)
d->m_dt = dt;
}
float WeatherForecast::temperature() const
float WeatherForecast::minimumTemperature() const
{
return d->m_minTemp;
}
void WeatherForecast::setMinimumTemperature(float t)
{
d.detach();
d->m_minTemp = t;
}
float WeatherForecast::maximumTemperature() const
{
return d->m_temp;
return d->m_maxTemp;
}
void WeatherForecast::setTemperature(float t)
void WeatherForecast::setMaximumTemperature(float t)
{
d.detach();
d->m_temp = t;
d->m_maxTemp = t;
}
WeatherForecast::SymbolType WeatherForecast::symbolType() const
......@@ -102,9 +116,9 @@ QString WeatherForecast::symbolIconName() const
void WeatherForecast::merge(WeatherForecast &other)
{
d.detach();
if (d->m_temp < -273.15) {
d->m_temp = other.temperature();
}
d->m_minTemp = std::min(other.minimumTemperature(), d->m_minTemp);
d->m_maxTemp = std::max(other.maximumTemperature(), d->m_maxTemp);
if (d->m_symbol == Unknown) {
d->m_symbol = other.symbolType();
}
......
......@@ -32,7 +32,8 @@ class WeatherForecast
{
Q_GADGET
Q_PROPERTY(bool valid READ isValid CONSTANT)
Q_PROPERTY(float temperature READ temperature CONSTANT)
Q_PROPERTY(float minimumTemperature READ minimumTemperature CONSTANT)
Q_PROPERTY(float maximumTemperature READ maximumTemperature CONSTANT)
Q_PROPERTY(QString symbolIconName READ symbolIconName CONSTANT)
public:
......@@ -71,9 +72,10 @@ public:
QDateTime dateTime() const;
void setDateTime(const QDateTime &dt);
// TODO is this enough or do we need min/max ranges?
float temperature() const;
void setTemperature(float t);
float minimumTemperature() const;
void setMinimumTemperature(float t);
float maximumTemperature() const;
void setMaximumTemperature(float t);
SymbolType symbolType() const;
void setSymbolType(SymbolType type);
......
......@@ -342,7 +342,13 @@ WeatherForecast WeatherForecastManager::parseForecastElement(QXmlStreamReader &r
switch (reader.tokenType()) {
case QXmlStreamReader::StartElement:
if (reader.name() == QLatin1String("temperature")) {
fc.setTemperature(reader.attributes().value(QLatin1String("value")).toFloat());
const auto t = reader.attributes().value(QLatin1String("value")).toFloat();
fc.setMinimumTemperature(t);
fc.setMaximumTemperature(t);
} else if (reader.name() == QLatin1String("minTemperature")) {
fc.setMinimumTemperature(reader.attributes().value(QLatin1String("value")).toFloat());
} else if (reader.name() == QLatin1String("maxTemperature")) {
fc.setMaximumTemperature(reader.attributes().value(QLatin1String("value")).toFloat());
} else if (reader.name() == QLatin1String("symbol")) {
auto symId = reader.attributes().value(QLatin1String("number")).toInt();
if (symId > 100) {
......
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