Implemented changed signals in WeatherSettings #76

This commit is contained in:
Daniel Brunner
2018-03-24 15:18:38 +01:00
parent 937425a4a5
commit 099a4593c9
4 changed files with 18 additions and 12 deletions

View File

@@ -31,9 +31,6 @@ bool LunchMealSettingsWidget::isValid(QString &message) const
void LunchMealSettingsWidget::apply()
{
if(m_settings.url() != m_lineEditUrl->text())
m_settings.setUrl(m_lineEditUrl->text());
if(m_settings.dateFormat() != m_lineEditDateFormat->text())
m_settings.setDateFormat(m_lineEditDateFormat->text());
m_settings.setUrl(m_lineEditUrl->text());
m_settings.setDateFormat(m_lineEditDateFormat->text());
}

View File

@@ -2,6 +2,9 @@
#include "zeiterfassungsettings.h"
const QString WeatherSettings::m_url("WeatherPlugin/url");
const QUrl WeatherSettings::m_defaultUrl(QStringLiteral("http://api.openweathermap.org/data/2.5/weather?q=Graz,AT&units=metric&APPID=40f6c892c6162680c6c9235169dc9f83"));
WeatherSettings::WeatherSettings(ZeiterfassungSettings &settings) :
m_settings(settings)
{
@@ -10,12 +13,14 @@ WeatherSettings::WeatherSettings(ZeiterfassungSettings &settings) :
QUrl WeatherSettings::url() const
{
return m_settings.value(QStringLiteral("WeatherPlugin/url"),
QUrl(QStringLiteral("http://api.openweathermap.org/data/2.5/weather?q=Graz,AT&units=metric&APPID=40f6c892c6162680c6c9235169dc9f83")))
.toUrl();
return m_settings.value(m_url, m_defaultUrl).toUrl();
}
void WeatherSettings::setUrl(const QUrl &url)
{
m_settings.setValue(QStringLiteral("WeatherPlugin/url"), url);
if(this->url() != url)
{
m_settings.setValue(m_url, url);
Q_EMIT urlChanged(url);
}
}

View File

@@ -13,8 +13,14 @@ public:
QUrl url() const;
void setUrl(const QUrl &url);
Q_SIGNALS:
void urlChanged(const QUrl &url);
private:
ZeiterfassungSettings &m_settings;
static const QString m_url;
static const QUrl m_defaultUrl;
};
#endif // WEATHERSETTINGS_H

View File

@@ -28,7 +28,5 @@ bool WeatherSettingsWidget::isValid(QString &message) const
void WeatherSettingsWidget::apply()
{
auto url = QUrl::fromUserInput(m_lineEdit->text());
if(m_settings.url() != url)
m_settings.setUrl(url);
m_settings.setUrl(QUrl::fromUserInput(m_lineEdit->text()));
}