mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Add methods to read weather grid from file
This commit is contained in:
committed by
Klaus Basan
parent
9f1a51fb13
commit
4b888d87f5
@@ -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;
|
||||
|
||||
|
||||
@@ -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); }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -31,6 +31,11 @@ namespace BlackMisc
|
||||
//! Request weather grid
|
||||
virtual void requestWeatherGrid(const CWeatherGrid &weatherGrid,
|
||||
const CSlot<void(const CWeatherGrid &)> &callback) = 0;
|
||||
|
||||
//! Request weather grid from file
|
||||
virtual void requestWeatherGridFromFile(const QString &filePath,
|
||||
const BlackMisc::Weather::CWeatherGrid &weatherGrid,
|
||||
const BlackMisc::CSlot<void(const BlackMisc::Weather::CWeatherGrid &)> &callback) = 0;
|
||||
};
|
||||
|
||||
//! Delegating class which can be directly used to access an \sa IWeatherGridProvider instance
|
||||
@@ -40,7 +45,6 @@ namespace BlackMisc
|
||||
//! \copydoc IWeatherGridProvider::requestWeatherGrid
|
||||
virtual void requestWeatherGrid(const CWeatherGrid &weatherGrid,
|
||||
const CSlot<void(const CWeatherGrid &)> &callback);
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
CWeatherGridAware(IWeatherGridProvider *weatherGridProvider) : IProviderAware(weatherGridProvider) { Q_ASSERT(weatherGridProvider); }
|
||||
|
||||
@@ -90,6 +90,23 @@ namespace BlackWxPlugin
|
||||
}
|
||||
}
|
||||
|
||||
void CWeatherDataGfs::fetchWeatherDataFromFile(const QString &filePath, const CWeatherGrid &grid, const CLength &range)
|
||||
{
|
||||
m_grid = grid;
|
||||
m_maxRange = range;
|
||||
|
||||
QFile file(filePath);
|
||||
if (!file.exists() || !file.open(QIODevice::ReadOnly)) { return; }
|
||||
m_gribData = file.readAll();
|
||||
|
||||
Q_ASSERT_X(!m_parseGribFileWorker, Q_FUNC_INFO, "Worker already running");
|
||||
m_parseGribFileWorker = BlackMisc::CWorker::fromTask(this, "parseGribFile", [this]()
|
||||
{
|
||||
parseGfsFileImpl(m_gribData);
|
||||
});
|
||||
m_parseGribFileWorker->then(this, &CWeatherDataGfs::fetchingWeatherDataFinished);
|
||||
}
|
||||
|
||||
CWeatherGrid CWeatherDataGfs::getWeatherData() const
|
||||
{
|
||||
QReadLocker l(&m_lockData);
|
||||
|
||||
@@ -50,6 +50,11 @@ namespace BlackWxPlugin
|
||||
virtual void fetchWeatherData(const BlackMisc::Weather::CWeatherGrid &grid,
|
||||
const BlackMisc::PhysicalQuantities::CLength &range) override;
|
||||
|
||||
//! \copydoc BlackCore::IWeatherData::fetchWeatherDataFromFile
|
||||
virtual void fetchWeatherDataFromFile(const QString &filePath,
|
||||
const BlackMisc::Weather::CWeatherGrid &grid,
|
||||
const BlackMisc::PhysicalQuantities::CLength &range) override;
|
||||
|
||||
//! \copydoc BlackCore::IWeatherData::getWeatherData()
|
||||
virtual BlackMisc::Weather::CWeatherGrid getWeatherData() const override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user