Added settings wrapper for weather
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include "weatherwidget.h"
|
#include "weatherwidget.h"
|
||||||
#include "weathersettings.h"
|
#include "weathersettingswidget.h"
|
||||||
|
|
||||||
WeatherPlugin::WeatherPlugin(QObject *parent) :
|
WeatherPlugin::WeatherPlugin(QObject *parent) :
|
||||||
ZeiterfassungPlugin(parent)
|
ZeiterfassungPlugin(parent)
|
||||||
@@ -38,5 +38,5 @@ void WeatherPlugin::attachTo(MainWindow &mainWindow)
|
|||||||
|
|
||||||
SettingsWidget *WeatherPlugin::settingsWidget(ZeiterfassungSettings &settings, QWidget *parent) const
|
SettingsWidget *WeatherPlugin::settingsWidget(ZeiterfassungSettings &settings, QWidget *parent) const
|
||||||
{
|
{
|
||||||
return new WeatherSettings(settings, parent);
|
return new WeatherSettingsWidget(settings, parent);
|
||||||
}
|
}
|
||||||
|
@@ -18,10 +18,12 @@ DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSA
|
|||||||
|
|
||||||
HEADERS += weatherplugin.h \
|
HEADERS += weatherplugin.h \
|
||||||
weathersettings.h \
|
weathersettings.h \
|
||||||
|
weathersettingswidget.h \
|
||||||
weatherwidget.h
|
weatherwidget.h
|
||||||
|
|
||||||
SOURCES += weatherplugin.cpp \
|
SOURCES += weatherplugin.cpp \
|
||||||
weathersettings.cpp \
|
weathersettings.cpp \
|
||||||
|
weathersettingswidget.cpp \
|
||||||
weatherwidget.cpp
|
weatherwidget.cpp
|
||||||
|
|
||||||
FORMS +=
|
FORMS +=
|
||||||
|
@@ -1,31 +1,21 @@
|
|||||||
#include "weathersettings.h"
|
#include "weathersettings.h"
|
||||||
|
|
||||||
#include <QFormLayout>
|
#include "zeiterfassungsettings.h"
|
||||||
#include <QLineEdit>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
WeatherSettings::WeatherSettings(ZeiterfassungSettings &settings, QWidget *parent) :
|
WeatherSettings::WeatherSettings(ZeiterfassungSettings &settings) :
|
||||||
SettingsWidget(parent),
|
|
||||||
m_settings(settings)
|
m_settings(settings)
|
||||||
{
|
{
|
||||||
auto layout = new QFormLayout(this);
|
|
||||||
layout->setMargin(0);
|
|
||||||
|
|
||||||
m_lineEdit = new QLineEdit(this);
|
|
||||||
layout->addRow(tr("Weather API:"), m_lineEdit);
|
|
||||||
|
|
||||||
setLayout(layout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WeatherSettings::isValid(QString &message) const
|
QUrl WeatherSettings::url() const
|
||||||
{
|
{
|
||||||
Q_UNUSED(message)
|
return m_settings.value(QStringLiteral("WeatherPlugin/url"),
|
||||||
|
QUrl(QStringLiteral("http://api.openweathermap.org/data/2.5/weather?q=Graz,AT&units=metric&APPID=40f6c892c6162680c6c9235169dc9f83")))
|
||||||
qDebug() << "called";
|
.toUrl();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeatherSettings::apply()
|
void WeatherSettings::setUrl(const QUrl &url)
|
||||||
{
|
{
|
||||||
qDebug() << "called";
|
m_settings.setValue(QStringLiteral("WeatherPlugin/url"), url);
|
||||||
}
|
}
|
||||||
|
@@ -1,27 +1,20 @@
|
|||||||
#ifndef WEATHERSETTINGS_H
|
#ifndef WEATHERSETTINGS_H
|
||||||
#define WEATHERSETTINGS_H
|
#define WEATHERSETTINGS_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QUrl>
|
||||||
|
|
||||||
#include "settingswidget.h"
|
|
||||||
|
|
||||||
class ZeiterfassungSettings;
|
class ZeiterfassungSettings;
|
||||||
|
|
||||||
class WeatherSettings : public SettingsWidget
|
class WeatherSettings
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
explicit WeatherSettings(ZeiterfassungSettings &settings, QWidget *parent = Q_NULLPTR);
|
WeatherSettings(ZeiterfassungSettings &settings);
|
||||||
|
|
||||||
bool isValid(QString &message) const Q_DECL_OVERRIDE;
|
QUrl url() const;
|
||||||
|
void setUrl(const QUrl &url);
|
||||||
public Q_SLOTS:
|
|
||||||
void apply() Q_DECL_OVERRIDE;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ZeiterfassungSettings &m_settings;
|
ZeiterfassungSettings &m_settings;
|
||||||
|
|
||||||
QLineEdit *m_lineEdit;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WEATHERSETTINGS_H
|
#endif // WEATHERSETTINGS_H
|
||||||
|
31
plugins/weatherplugin/weathersettingswidget.cpp
Normal file
31
plugins/weatherplugin/weathersettingswidget.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include "weathersettingswidget.h"
|
||||||
|
|
||||||
|
#include <QFormLayout>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
WeatherSettingsWidget::WeatherSettingsWidget(ZeiterfassungSettings &settings, QWidget *parent) :
|
||||||
|
SettingsWidget(parent),
|
||||||
|
m_settings(settings)
|
||||||
|
{
|
||||||
|
auto layout = new QFormLayout(this);
|
||||||
|
layout->setMargin(0);
|
||||||
|
|
||||||
|
m_lineEdit = new QLineEdit(this);
|
||||||
|
layout->addRow(tr("Weather API:"), m_lineEdit);
|
||||||
|
|
||||||
|
setLayout(layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WeatherSettingsWidget::isValid(QString &message) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(message)
|
||||||
|
|
||||||
|
qDebug() << "called";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WeatherSettingsWidget::apply()
|
||||||
|
{
|
||||||
|
qDebug() << "called";
|
||||||
|
}
|
29
plugins/weatherplugin/weathersettingswidget.h
Normal file
29
plugins/weatherplugin/weathersettingswidget.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#ifndef WEATHERSETTINGS_H
|
||||||
|
#define WEATHERSETTINGS_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include "settingswidget.h"
|
||||||
|
|
||||||
|
class QLineEdit;
|
||||||
|
|
||||||
|
class ZeiterfassungSettings;
|
||||||
|
|
||||||
|
class WeatherSettingsWidget : public SettingsWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit WeatherSettingsWidget(ZeiterfassungSettings &settings, QWidget *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
bool isValid(QString &message) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void apply() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ZeiterfassungSettings &m_settings;
|
||||||
|
|
||||||
|
QLineEdit *m_lineEdit;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WEATHERSETTINGS_H
|
@@ -14,6 +14,8 @@
|
|||||||
#include "zeiterfassungsettings.h"
|
#include "zeiterfassungsettings.h"
|
||||||
#include "zeiterfassungapi.h"
|
#include "zeiterfassungapi.h"
|
||||||
|
|
||||||
|
#include "weathersettings.h"
|
||||||
|
|
||||||
WeatherWidget::WeatherWidget(MainWindow &mainWindow) :
|
WeatherWidget::WeatherWidget(MainWindow &mainWindow) :
|
||||||
QLabel(&mainWindow),
|
QLabel(&mainWindow),
|
||||||
m_mainWindow(mainWindow)
|
m_mainWindow(mainWindow)
|
||||||
@@ -30,10 +32,9 @@ void WeatherWidget::refresh()
|
|||||||
{
|
{
|
||||||
setText(tr("Loading..."));
|
setText(tr("Loading..."));
|
||||||
|
|
||||||
auto url = m_mainWindow.settings().value(QStringLiteral("WeatherPlugin/url"),
|
auto url = WeatherSettings(m_mainWindow.settings()).url();
|
||||||
QStringLiteral("http://api.openweathermap.org/data/2.5/weather?q=Graz,AT&units=metric&APPID=40f6c892c6162680c6c9235169dc9f83")).toString();
|
|
||||||
|
|
||||||
m_reply = std::unique_ptr<QNetworkReply>(m_mainWindow.erfassung().manager()->get(QNetworkRequest(QUrl(url))));
|
m_reply = std::unique_ptr<QNetworkReply>(m_mainWindow.erfassung().manager()->get(QNetworkRequest(url)));
|
||||||
connect(m_reply.get(), &QNetworkReply::finished, this, &WeatherWidget::finished);
|
connect(m_reply.get(), &QNetworkReply::finished, this, &WeatherWidget::finished);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user