Add methods to read weather grid from file

This commit is contained in:
Roland Winklmeier
2018-09-08 14:18:30 +02:00
committed by Klaus Basan
parent 9f1a51fb13
commit 4b888d87f5
6 changed files with 58 additions and 4 deletions

View File

@@ -34,6 +34,11 @@ namespace BlackCore
virtual void fetchWeatherData(const BlackMisc::Weather::CWeatherGrid &grid,
const BlackMisc::PhysicalQuantities::CLength &range) = 0;
//! Fetch new weather around grid from file
virtual void fetchWeatherDataFromFile(const QString &filePath,
const BlackMisc::Weather::CWeatherGrid &grid,
const BlackMisc::PhysicalQuantities::CLength &range) = 0;
//! Get fetched weather data
virtual BlackMisc::Weather::CWeatherGrid getWeatherData() const = 0;

View File

@@ -41,7 +41,7 @@ namespace BlackCore
void CWeatherManager::requestWeatherGrid(const CWeatherGrid &weatherGrid, const CIdentifier &identifier)
{
WeatherRequest request { identifier, weatherGrid, {} };
WeatherRequest request { {}, identifier, weatherGrid, {} };
m_pendingRequests.append(request);
// Serialize the requests, since plugins can handle only one at a time
if (m_pendingRequests.size() == 1) { fetchNextWeatherData(); }
@@ -56,7 +56,23 @@ namespace BlackCore
return;
}
WeatherRequest weatherRequest { CIdentifier::null(), weatherGrid, callback };
WeatherRequest weatherRequest { {}, CIdentifier::null(), weatherGrid, callback };
m_pendingRequests.append(weatherRequest);
// Serialize the requests, since plugins can handle only one at a time
if (m_pendingRequests.size() == 1) { fetchNextWeatherData(); }
}
void CWeatherManager::requestWeatherGridFromFile(const QString &filePath, const CWeatherGrid &weatherGrid,
const CSlot<void(const CWeatherGrid &)> &callback)
{
if (m_isWeatherClear)
{
callback(CWeatherGrid::getClearWeatherGrid());
return;
}
WeatherRequest weatherRequest { filePath, CIdentifier::null(), weatherGrid, callback };
m_pendingRequests.append(weatherRequest);
// Serialize the requests, since plugins can handle only one at a time
@@ -102,7 +118,8 @@ namespace BlackCore
for (IWeatherData *plugin : as_const(m_weatherDataPlugins))
{
plugin->fetchWeatherData(weatherRequest.weatherGrid, maxDistance);
if (weatherRequest.filePath.isEmpty()) { plugin->fetchWeatherData(weatherRequest.weatherGrid, maxDistance); }
else { plugin->fetchWeatherDataFromFile(weatherRequest.filePath, weatherRequest.weatherGrid, maxDistance); }
}
}

View File

@@ -53,6 +53,11 @@ namespace BlackCore
virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid,
const BlackMisc::CSlot<void(const BlackMisc::Weather::CWeatherGrid &)> &callback) override;
//! \copydoc BlackMisc::Weather::IWeatherGridProvider::requestWeatherGrid
virtual void requestWeatherGridFromFile(const QString &filePath,
const BlackMisc::Weather::CWeatherGrid &weatherGrid,
const BlackMisc::CSlot<void(const BlackMisc::Weather::CWeatherGrid &)> &callback) override;
signals:
//! The weather grid, requested from identified, is available
@@ -61,6 +66,7 @@ namespace BlackCore
private:
struct WeatherRequest
{
QString filePath;
BlackMisc::CIdentifier identifier;
BlackMisc::Weather::CWeatherGrid weatherGrid;
BlackMisc::CSlot<void(const BlackMisc::Weather::CWeatherGrid &)> callback;