From 28292e3af7348f65f310ee51d8f83ab17eae3923 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sat, 26 Mar 2016 21:19:33 +0100 Subject: [PATCH] Use CWeatherManager in sampleweatherdata refs #612 --- samples/weatherdata/weatherdataprinter.cpp | 33 ++++------------------ samples/weatherdata/weatherdataprinter.h | 7 ++--- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/samples/weatherdata/weatherdataprinter.cpp b/samples/weatherdata/weatherdataprinter.cpp index be949de22..38da977df 100644 --- a/samples/weatherdata/weatherdataprinter.cpp +++ b/samples/weatherdata/weatherdataprinter.cpp @@ -13,42 +13,21 @@ using namespace BlackCore; CWeatherDataPrinter::CWeatherDataPrinter(QObject *parent) : QObject(parent) -{ - m_plugins.collectPlugins(); +{ } - if (m_plugins.getAvailableWeatherDataPlugins().isEmpty()) - { - CLogMessage(this).warning("No weather data plugin found!"); - } - - CWeatherDataPluginInfo info = m_plugins.getAvailableWeatherDataPlugins().front(); - m_weatherDataFactory.reset(m_plugins.getPluginById(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) +void CWeatherDataPrinter::fetchAndPrintWetherData(const CCoordinateGeodetic &position) { QTextStream qtout(stdout); 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); qtout << "... finished." << endl; - CWeatherGrid weatherGrid = m_weatherData->getWeatherData(); for (const CGridPoint &gridPoint : weatherGrid) { qtout << "Latitude:" << gridPoint.getPosition().latitude().toQString() << endl; diff --git a/samples/weatherdata/weatherdataprinter.h b/samples/weatherdata/weatherdataprinter.h index 3cf17ea17..5ecd3b1e1 100644 --- a/samples/weatherdata/weatherdataprinter.h +++ b/samples/weatherdata/weatherdataprinter.h @@ -15,6 +15,7 @@ #include "blackcore/pluginmanagerweatherdata.h" #include "blackcore/weatherdata.h" +#include "blackcore/weathermanager.h" #include "blackmisc/geo/latitude.h" #include "blackmisc/geo/longitude.h" #include @@ -36,12 +37,10 @@ public slots: private slots: //! Print weather data to stdout - void ps_printWeatherData(); + void ps_printWeatherData(const BlackMisc::Weather::CWeatherGrid &weatherGrid); private: - BlackCore::CPluginManagerWeatherData m_plugins; - QScopedPointer m_weatherDataFactory; - BlackCore::IWeatherData *m_weatherData = nullptr; + BlackCore::CWeatherManager m_weatherManger { this }; }; #endif // guard