mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-28 20:13:40 +08:00
69
src/blackcore/pluginmanagerweatherdata.cpp
Normal file
69
src/blackcore/pluginmanagerweatherdata.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "pluginmanagerweatherdata.h"
|
||||
#include "weatherdata.h"
|
||||
#include <QStringBuilder>
|
||||
#include <QCoreApplication>
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
CPluginManagerWeatherData::CPluginManagerWeatherData(QObject *parent) : IPluginManager(parent)
|
||||
{
|
||||
}
|
||||
|
||||
IWeatherDataFactory *CPluginManagerWeatherData::getFactory(const QString &pluginId)
|
||||
{
|
||||
return getPluginById<IWeatherDataFactory>(pluginId);
|
||||
}
|
||||
|
||||
Weather::CWeatherDataPluginInfoList CPluginManagerWeatherData::getAvailableWeatherDataPlugins() const
|
||||
{
|
||||
BlackMisc::Weather::CWeatherDataPluginInfoList list;
|
||||
for (const auto &i : m_plugins.values())
|
||||
{
|
||||
list.push_back(i.info);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
void CPluginManagerWeatherData::collectPlugins()
|
||||
{
|
||||
IPluginManager::collectPlugins();
|
||||
|
||||
const CSequence<QJsonObject> &plugins = getPlugins();
|
||||
for (const QJsonObject &json : plugins)
|
||||
{
|
||||
QString iid = json["IID"].toString();
|
||||
if (iid == QStringLiteral("org.swift-project.blackcore.weatherdata"))
|
||||
{
|
||||
// PluginExtended() instead of {} to silence wrong warning for gcc < 5.X
|
||||
auto it = m_plugins.insert(pluginIdentifier(json), PluginExtended());
|
||||
it->info.convertFromJson(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BlackMisc::CSequence<QString> CPluginManagerWeatherData::acceptedIids() const
|
||||
{
|
||||
return
|
||||
{
|
||||
QStringLiteral("org.swift-project.blackcore.weatherdata")
|
||||
};
|
||||
}
|
||||
|
||||
QString CPluginManagerWeatherData::pluginDirectory() const
|
||||
{
|
||||
return qApp->applicationDirPath() % QStringLiteral("/plugins/weatherdata");
|
||||
}
|
||||
|
||||
}
|
||||
66
src/blackcore/pluginmanagerweatherdata.h
Normal file
66
src/blackcore/pluginmanagerweatherdata.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKCORE_PLUGINMANAGERWEATHERDATA_H
|
||||
#define BLACKCORE_PLUGINMANAGERWEATHERDATA_H
|
||||
|
||||
#include "blackcoreexport.h"
|
||||
#include "pluginmanager.h"
|
||||
#include "blackmisc/weather/weatherdataplugininfolist.h"
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
class IWeatherDataFactory;
|
||||
class IWeatherData;
|
||||
|
||||
/*!
|
||||
* Manages plugins of type WeatherData.
|
||||
*/
|
||||
class BLACKCORE_EXPORT CPluginManagerWeatherData :
|
||||
public BlackCore::IPluginManager
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Ctor
|
||||
CPluginManagerWeatherData(QObject *parent = nullptr);
|
||||
|
||||
//! Get weatherdata factory from the plugin
|
||||
IWeatherDataFactory *getFactory(const QString &pluginId);
|
||||
|
||||
//! Get all weather data plugins
|
||||
BlackMisc::Weather::CWeatherDataPluginInfoList getAvailableWeatherDataPlugins() const;
|
||||
|
||||
//! \copydoc BlackCore::IPluginManager::collectPlugins()
|
||||
virtual void collectPlugins() override;
|
||||
|
||||
protected:
|
||||
//! \copydoc BlackCore::IPluginManager::acceptedIids()
|
||||
virtual BlackMisc::CSequence<QString> acceptedIids() const override;
|
||||
|
||||
//! \copydoc BlackCore::IPluginManager::pluginDirectory()
|
||||
virtual QString pluginDirectory() const override;
|
||||
|
||||
private:
|
||||
//! Extended data for plugin
|
||||
struct PluginExtended
|
||||
{
|
||||
BlackMisc::Weather::CWeatherDataPluginInfo info;
|
||||
QHash<QString, BlackMisc::CVariant> storage; //!< Permanent plugin storage - data stored here will be kept even when plugin is unloaded
|
||||
};
|
||||
|
||||
QMap<QString, PluginExtended> m_plugins; //!< Id <-> extended data pairs
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
15
src/blackcore/weatherdata.cpp
Normal file
15
src/blackcore/weatherdata.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "weatherdata.h"
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
} // namespace
|
||||
67
src/blackcore/weatherdata.h
Normal file
67
src/blackcore/weatherdata.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKCORE_WEATHERDATA_H
|
||||
#define BLACKCORE_WEATHERDATA_H
|
||||
|
||||
#include "blackcoreexport.h"
|
||||
#include "blackmisc/geo/latitude.h"
|
||||
#include "blackmisc/geo/longitude.h"
|
||||
#include "blackmisc/weather/gridpoint.h"
|
||||
#include "blackmisc/weather/weathergrid.h"
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
/*!
|
||||
* Interface to weather data
|
||||
*/
|
||||
class BLACKCORE_EXPORT IWeatherData : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Destructor
|
||||
virtual ~IWeatherData() {}
|
||||
|
||||
//! Fetch new weather data
|
||||
virtual void fetchWeatherData(const BlackMisc::Geo::CLatitude &latitude, const BlackMisc::Geo::CLongitude &longitude, double maxDistance = -1) = 0;
|
||||
|
||||
//! Get fetched weather data
|
||||
virtual BlackMisc::Weather::CWeatherGrid getWeatherData() const = 0;
|
||||
|
||||
signals:
|
||||
//! Finished fetching data
|
||||
void fetchingFinished();
|
||||
|
||||
protected:
|
||||
//! Default constructor
|
||||
IWeatherData(QObject *parent = nullptr) : QObject(parent) {}
|
||||
};
|
||||
|
||||
/*!
|
||||
* Factory pattern class to create instances of IWeatherData
|
||||
*/
|
||||
class BLACKCORE_EXPORT IWeatherDataFactory
|
||||
{
|
||||
public:
|
||||
//! Virtual destructor
|
||||
virtual ~IWeatherDataFactory() {}
|
||||
|
||||
//! Create a new instance
|
||||
virtual IWeatherData *create(QObject *parent = nullptr) = 0;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_INTERFACE(BlackCore::IWeatherDataFactory, "org.swift-project.blackcore.weatherdata")
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user