Use CWeatherManager in sampleweatherdata

refs #612
This commit is contained in:
Roland Winklmeier
2016-03-26 21:19:33 +01:00
parent 82fc267b22
commit 28292e3af7
2 changed files with 9 additions and 31 deletions

View File

@@ -13,42 +13,21 @@ using namespace BlackCore;
CWeatherDataPrinter::CWeatherDataPrinter(QObject *parent) : QObject(parent) CWeatherDataPrinter::CWeatherDataPrinter(QObject *parent) : QObject(parent)
{ { }
m_plugins.collectPlugins();
if (m_plugins.getAvailableWeatherDataPlugins().isEmpty()) void CWeatherDataPrinter::fetchAndPrintWetherData(const CCoordinateGeodetic &position)
{
CLogMessage(this).warning("No weather data plugin found!");
}
CWeatherDataPluginInfo info = m_plugins.getAvailableWeatherDataPlugins().front();
m_weatherDataFactory.reset(m_plugins.getPluginById<IWeatherDataFactory>(info.getIdentifier()));
if (!m_weatherDataFactory)
{
CLogMessage(this).error("Failed to create IWeatherDataFactory.");
}
m_weatherData = m_weatherDataFactory->create(this);
if (!m_weatherData)
{
CLogMessage(this).error("Failed to create IWeatherData instance.");
}
connect(m_weatherData, &IWeatherData::fetchingFinished, this, &CWeatherDataPrinter::ps_printWeatherData);
}
void CWeatherDataPrinter::fetchAndPrintWetherData(const CLatitude &lat, const CLongitude &lon)
{ {
QTextStream qtout(stdout); QTextStream qtout(stdout);
qtout << "Fetching weather data. This may take a while..." << endl; qtout << "Fetching weather data. This may take a while..." << endl;
m_weatherData->fetchWeatherData(lat, lon, 0.001);
CWeatherGrid weatherGrid { { "", position } };
m_weatherManger.requestWeatherGrid(weatherGrid, { this, &CWeatherDataPrinter::ps_printWeatherData });
} }
void CWeatherDataPrinter::ps_printWeatherData() void CWeatherDataPrinter::ps_printWeatherData(const BlackMisc::Weather::CWeatherGrid &weatherGrid)
{ {
QTextStream qtout(stdout); QTextStream qtout(stdout);
qtout << "... finished." << endl; qtout << "... finished." << endl;
CWeatherGrid weatherGrid = m_weatherData->getWeatherData();
for (const CGridPoint &gridPoint : weatherGrid) for (const CGridPoint &gridPoint : weatherGrid)
{ {
qtout << "Latitude:" << gridPoint.getPosition().latitude().toQString() << endl; qtout << "Latitude:" << gridPoint.getPosition().latitude().toQString() << endl;

View File

@@ -15,6 +15,7 @@
#include "blackcore/pluginmanagerweatherdata.h" #include "blackcore/pluginmanagerweatherdata.h"
#include "blackcore/weatherdata.h" #include "blackcore/weatherdata.h"
#include "blackcore/weathermanager.h"
#include "blackmisc/geo/latitude.h" #include "blackmisc/geo/latitude.h"
#include "blackmisc/geo/longitude.h" #include "blackmisc/geo/longitude.h"
#include <QObject> #include <QObject>
@@ -36,12 +37,10 @@ public slots:
private slots: private slots:
//! Print weather data to stdout //! Print weather data to stdout
void ps_printWeatherData(); void ps_printWeatherData(const BlackMisc::Weather::CWeatherGrid &weatherGrid);
private: private:
BlackCore::CPluginManagerWeatherData m_plugins; BlackCore::CWeatherManager m_weatherManger { this };
QScopedPointer<BlackCore::IWeatherDataFactory> m_weatherDataFactory;
BlackCore::IWeatherData *m_weatherData = nullptr;
}; };
#endif // guard #endif // guard