##// END OF EJS Templates
Merge branch 'feature/DataProvider' into develop
Alexandre Leroux -
r123:517990a8462b merge
parent child
Show More
@@ -0,0 +1,56
1 #ifndef SCIQLOP_ARRAYDATA_H
2 #define SCIQLOP_ARRAYDATA_H
3
4 #include <QVector>
5
6 /**
7 * @brief The ArrayData class represents a dataset for a data series.
8 *
9 * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim
10 * template-parameter.
11 *
12 * @tparam Dim the dimension of the ArrayData (one or two)
13 * @sa IDataSeries
14 */
15 template <int Dim>
16 class ArrayData {
17 public:
18 /**
19 * Ctor for a unidimensional ArrayData
20 * @param nbColumns the number of values the ArrayData will hold
21 */
22 template <int D = Dim, typename = std::enable_if_t<D == 1> >
23 explicit ArrayData(int nbColumns) : m_Data{1, QVector<double>{}}
24 {
25 m_Data[0].resize(nbColumns);
26 }
27
28 /**
29 * Sets a data at a specified index. The index has to be valid to be effective
30 * @param index the index to which the data will be set
31 * @param data the data to set
32 * @remarks this method is only available for a unidimensional ArrayData
33 */
34 template <int D = Dim, typename = std::enable_if_t<D == 1> >
35 void setData(int index, double data) noexcept
36 {
37 if (index >= 0 && index < m_Data.at(0).size()) {
38 m_Data[0].replace(index, data);
39 }
40 }
41
42 /**
43 * @return the data as a vector
44 * @remarks this method is only available for a unidimensional ArrayData
45 */
46 template <int D = Dim, typename = std::enable_if_t<D == 1> >
47 QVector<double> data() const noexcept
48 {
49 return m_Data.at(0);
50 }
51
52 private:
53 QVector<QVector<double> > m_Data;
54 };
55
56 #endif // SCIQLOP_ARRAYDATA_H
@@ -0,0 +1,16
1 #ifndef SCIQLOP_DATAPROVIDERPARAMETERS_H
2 #define SCIQLOP_DATAPROVIDERPARAMETERS_H
3
4 /**
5 * @brief The DataProviderParameters struct holds the information needed to retrieve data from a
6 * data provider
7 * @sa IDataProvider
8 */
9 struct DataProviderParameters {
10 /// Start time
11 double m_TStart;
12 /// End time
13 double m_TEnd;
14 };
15
16 #endif // SCIQLOP_DATAPROVIDERPARAMETERS_H
@@ -0,0 +1,50
1 #ifndef SCIQLOP_DATASERIES_H
2 #define SCIQLOP_DATASERIES_H
3
4 #include <Data/ArrayData.h>
5 #include <Data/IDataSeries.h>
6
7 #include <memory>
8
9 /**
10 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
11 *
12 * It proposes to set a dimension for the values ​​data
13 *
14 * @tparam Dim The dimension of the values data
15 *
16 */
17 template <int Dim>
18 class DataSeries : public IDataSeries {
19 public:
20 /// @sa IDataSeries::xAxisData()
21 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
22
23 /// @sa IDataSeries::xAxisUnit()
24 QString xAxisUnit() const override { return m_XAxisUnit; }
25
26 /// @return the values dataset
27 std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
28
29 /// @sa IDataSeries::valuesUnit()
30 QString valuesUnit() const override { return m_ValuesUnit; }
31
32 protected:
33 /// Protected ctor (DataSeries is abstract)
34 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const QString &xAxisUnit,
35 std::shared_ptr<ArrayData<Dim> > valuesData, const QString &valuesUnit)
36 : m_XAxisData{xAxisData},
37 m_XAxisUnit{xAxisUnit},
38 m_ValuesData{valuesData},
39 m_ValuesUnit{valuesUnit}
40 {
41 }
42
43 private:
44 std::shared_ptr<ArrayData<1> > m_XAxisData;
45 QString m_XAxisUnit;
46 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
47 QString m_ValuesUnit;
48 };
49
50 #endif // SCIQLOP_DATASERIES_H
@@ -0,0 +1,25
1 #ifndef SCIQLOP_IDATAPROVIDER_H
2 #define SCIQLOP_IDATAPROVIDER_H
3
4 #include <memory>
5
6 class DataProviderParameters;
7 class IDataSeries;
8
9 /**
10 * @brief The IDataProvider interface aims to declare a data provider.
11 *
12 * A data provider is an entity that generates data and returns it according to various parameters
13 * (time interval, product to retrieve the data, etc.)
14 *
15 * @sa IDataSeries
16 */
17 class IDataProvider {
18 public:
19 virtual ~IDataProvider() noexcept = default;
20
21 virtual std::unique_ptr<IDataSeries>
22 retrieveData(const DataProviderParameters &parameters) const = 0;
23 };
24
25 #endif // SCIQLOP_IDATAPROVIDER_H
@@ -0,0 +1,37
1 #ifndef SCIQLOP_IDATASERIES_H
2 #define SCIQLOP_IDATASERIES_H
3
4 #include <QString>
5
6 #include <memory>
7
8 template <int Dim>
9 class ArrayData;
10
11 /**
12 * @brief The IDataSeries aims to declare a data series.
13 *
14 * A data series is an entity that contains at least :
15 * - one dataset representing the x-axis
16 * - one dataset representing the values
17 *
18 * Each dataset is represented by an ArrayData, and is associated with a unit.
19 *
20 * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the
21 * IDataSeries. The x-axis dataset is always unidimensional.
22 *
23 * @sa ArrayData
24 */
25 class IDataSeries {
26 public:
27 virtual ~IDataSeries() noexcept = default;
28
29 /// Returns the x-axis dataset
30 virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0;
31
32 virtual QString xAxisUnit() const = 0;
33
34 virtual QString valuesUnit() const = 0;
35 };
36
37 #endif // SCIQLOP_IDATASERIES_H
@@ -0,0 +1,28
1 #ifndef SCIQLOP_SCALARSERIES_H
2 #define SCIQLOP_SCALARSERIES_H
3
4 #include <Data/DataSeries.h>
5
6 /**
7 * @brief The ScalarSeries class is the implementation for a data series representing a scalar.
8 */
9 class ScalarSeries : public DataSeries<1> {
10 public:
11 /**
12 * Ctor
13 * @param size the number of data the series will hold
14 * @param xAxisUnit x-axis unit
15 * @param valuesUnit values unit
16 */
17 explicit ScalarSeries(int size, const QString &xAxisUnit, const QString &valuesUnit);
18
19 /**
20 * Sets data for a specific index. The index has to be valid to be effective
21 * @param index the index to which the data will be set
22 * @param x the x-axis data
23 * @param value the value data
24 */
25 void setData(int index, double x, double value) noexcept;
26 };
27
28 #endif // SCIQLOP_SCALARSERIES_H
@@ -0,0 +1,13
1 #include <Data/ScalarSeries.h>
2
3 ScalarSeries::ScalarSeries(int size, const QString &xAxisUnit, const QString &valuesUnit)
4 : DataSeries{std::make_shared<ArrayData<1> >(size), xAxisUnit,
5 std::make_shared<ArrayData<1> >(size), valuesUnit}
6 {
7 }
8
9 void ScalarSeries::setData(int index, double x, double value) noexcept
10 {
11 xAxisData()->setData(index, x);
12 valuesData()->setData(index, value);
13 }
@@ -0,0 +1,16
1 #ifndef SCIQLOP_COSINUSPROVIDER_H
2 #define SCIQLOP_COSINUSPROVIDER_H
3
4 #include <Data/IDataProvider.h>
5
6 /**
7 * @brief The CosinusProvider class is an example of how a data provider can generate data
8 */
9 class CosinusProvider : public IDataProvider {
10 public:
11 /// @sa IDataProvider::retrieveData()
12 std::unique_ptr<IDataSeries>
13 retrieveData(const DataProviderParameters &parameters) const override;
14 };
15
16 #endif // SCIQLOP_COSINUSPROVIDER_H
@@ -0,0 +1,28
1 #include "CosinusProvider.h"
2
3 #include <Data/DataProviderParameters.h>
4 #include <Data/ScalarSeries.h>
5
6 std::unique_ptr<IDataSeries>
7 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
8 {
9 // Gets the timerange from the parameters
10 auto start = parameters.m_TStart;
11 auto end = parameters.m_TEnd;
12
13 // We assure that timerange is valid
14 if (end < start) {
15 std::swap(start, end);
16 }
17
18 // Generates scalar series containing cosinus values (one value per second)
19 auto scalarSeries
20 = std::make_unique<ScalarSeries>(end - start, QStringLiteral("t"), QStringLiteral(""));
21
22 for (auto time = start; time < end; ++time) {
23 auto dataIndex = time - start;
24 scalarSeries->setData(dataIndex, time, std::cos(time));
25 }
26
27 return scalarSeries;
28 }
@@ -1,61 +1,73
1 #ifndef SCIQLOP_DATASOURCECONTROLLER_H
1 #ifndef SCIQLOP_DATASOURCECONTROLLER_H
2 #define SCIQLOP_DATASOURCECONTROLLER_H
2 #define SCIQLOP_DATASOURCECONTROLLER_H
3
3
4 #include <QLoggingCategory>
4 #include <QLoggingCategory>
5 #include <QObject>
5 #include <QObject>
6 #include <QUuid>
6 #include <QUuid>
7
7
8 #include <Common/spimpl.h>
8 #include <Common/spimpl.h>
9
9
10 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController)
10 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController)
11
11
12 class DataSourceItem;
12 class DataSourceItem;
13 class IDataProvider;
13
14
14 /**
15 /**
15 * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This
16 * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This
16 * is the intermediate class that SciQlop has to use in the way to connect a data source. Please
17 * is the intermediate class that SciQlop has to use in the way to connect a data source. Please
17 * first use register method to initialize a plugin specified by its metadata name (JSON plugin
18 * first use register method to initialize a plugin specified by its metadata name (JSON plugin
18 * source) then others specifics method will be able to access it. You can load a data source driver
19 * source) then others specifics method will be able to access it. You can load a data source driver
19 * plugin then create a data source.
20 * plugin then create a data source.
20 */
21 */
21 class DataSourceController : public QObject {
22 class DataSourceController : public QObject {
22 Q_OBJECT
23 Q_OBJECT
23 public:
24 public:
24 explicit DataSourceController(QObject *parent = 0);
25 explicit DataSourceController(QObject *parent = 0);
25 virtual ~DataSourceController();
26 virtual ~DataSourceController();
26
27
27 /**
28 /**
28 * Registers a data source. The method delivers a unique id that can be used afterwards to
29 * Registers a data source. The method delivers a unique id that can be used afterwards to
29 * access to the data source properties (structure, connection parameters, data provider, etc.)
30 * access to the data source properties (structure, connection parameters, data provider, etc.)
30 * @param dataSourceName the name of the data source
31 * @param dataSourceName the name of the data source
31 * @return the unique id with which the data source has been registered
32 * @return the unique id with which the data source has been registered
32 */
33 */
33 QUuid registerDataSource(const QString &dataSourceName) noexcept;
34 QUuid registerDataSource(const QString &dataSourceName) noexcept;
34
35
35 /**
36 /**
36 * Sets the structure of a data source. The controller takes ownership of the structure.
37 * Sets the structure of a data source. The controller takes ownership of the structure.
37 * @param dataSourceUid the unique id with which the data source has been registered into the
38 * @param dataSourceUid the unique id with which the data source has been registered into the
38 * controller. If it is invalid, the method has no effect.
39 * controller. If it is invalid, the method has no effect.
39 * @param dataSourceItem the structure of the data source
40 * @param dataSourceItem the structure of the data source
40 * @sa registerDataSource()
41 * @sa registerDataSource()
41 */
42 */
42 void setDataSourceItem(const QUuid &dataSourceUid,
43 void setDataSourceItem(const QUuid &dataSourceUid,
43 std::unique_ptr<DataSourceItem> dataSourceItem) noexcept;
44 std::unique_ptr<DataSourceItem> dataSourceItem) noexcept;
44
45
46 /**
47 * Sets the data provider used to retrieve data from of a data source. The controller takes
48 * ownership of the provider.
49 * @param dataSourceUid the unique id with which the data source has been registered into the
50 * controller. If it is invalid, the method has no effect.
51 * @param dataProvider the provider of the data source
52 * @sa registerDataSource()
53 */
54 void setDataProvider(const QUuid &dataSourceUid,
55 std::unique_ptr<IDataProvider> dataProvider) noexcept;
56
45 public slots:
57 public slots:
46 /// Manage init/end of the controller
58 /// Manage init/end of the controller
47 void initialize();
59 void initialize();
48 void finalize();
60 void finalize();
49
61
50 signals:
62 signals:
51 /// Signal emitted when a structure has been set for a data source
63 /// Signal emitted when a structure has been set for a data source
52 void dataSourceItemSet(DataSourceItem *dataSourceItem);
64 void dataSourceItemSet(DataSourceItem *dataSourceItem);
53
65
54 private:
66 private:
55 void waitForFinish();
67 void waitForFinish();
56
68
57 class DataSourceControllerPrivate;
69 class DataSourceControllerPrivate;
58 spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl;
70 spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl;
59 };
71 };
60
72
61 #endif // SCIQLOP_DATASOURCECONTROLLER_H
73 #endif // SCIQLOP_DATASOURCECONTROLLER_H
@@ -1,78 +1,95
1 #include <DataSource/DataSourceController.h>
1 #include <DataSource/DataSourceController.h>
2 #include <DataSource/DataSourceItem.h>
2 #include <DataSource/DataSourceItem.h>
3
3
4 #include <Data/IDataProvider.h>
5
4 #include <QMutex>
6 #include <QMutex>
5 #include <QThread>
7 #include <QThread>
6
8
7 #include <QDir>
9 #include <QDir>
8 #include <QStandardPaths>
10 #include <QStandardPaths>
9
11
10 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
12 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
11
13
12 class DataSourceController::DataSourceControllerPrivate {
14 class DataSourceController::DataSourceControllerPrivate {
13 public:
15 public:
14 QMutex m_WorkingMutex;
16 QMutex m_WorkingMutex;
15 /// Data sources registered
17 /// Data sources registered
16 QHash<QUuid, QString> m_DataSources;
18 QHash<QUuid, QString> m_DataSources;
17 /// Data sources structures
19 /// Data sources structures
18 std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
20 std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
21 /// Data providers registered
22 std::map<QUuid, std::unique_ptr<IDataProvider> > m_DataProviders;
19 };
23 };
20
24
21 DataSourceController::DataSourceController(QObject *parent)
25 DataSourceController::DataSourceController(QObject *parent)
22 : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
26 : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
23 {
27 {
24 qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction")
28 qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction")
25 << QThread::currentThread();
29 << QThread::currentThread();
26 }
30 }
27
31
28 DataSourceController::~DataSourceController()
32 DataSourceController::~DataSourceController()
29 {
33 {
30 qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction")
34 qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction")
31 << QThread::currentThread();
35 << QThread::currentThread();
32 this->waitForFinish();
36 this->waitForFinish();
33 }
37 }
34
38
35 QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept
39 QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept
36 {
40 {
37 auto dataSourceUid = QUuid::createUuid();
41 auto dataSourceUid = QUuid::createUuid();
38 impl->m_DataSources.insert(dataSourceUid, dataSourceName);
42 impl->m_DataSources.insert(dataSourceUid, dataSourceName);
39
43
40 return dataSourceUid;
44 return dataSourceUid;
41 }
45 }
42
46
43 void DataSourceController::setDataSourceItem(
47 void DataSourceController::setDataSourceItem(
44 const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
48 const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
45 {
49 {
46 if (impl->m_DataSources.contains(dataSourceUid)) {
50 if (impl->m_DataSources.contains(dataSourceUid)) {
47 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
51 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
48
52
49 // Retrieves the data source item to emit the signal with it
53 // Retrieves the data source item to emit the signal with it
50 auto it = impl->m_DataSourceItems.find(dataSourceUid);
54 auto it = impl->m_DataSourceItems.find(dataSourceUid);
51 if (it != impl->m_DataSourceItems.end()) {
55 if (it != impl->m_DataSourceItems.end()) {
52 emit dataSourceItemSet(it->second.get());
56 emit dataSourceItemSet(it->second.get());
53 }
57 }
54 }
58 }
55 else {
59 else {
56 qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
60 qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
57 "data source has been registered with the uid")
61 "data source has been registered with the uid")
58 .arg(dataSourceUid.toString());
62 .arg(dataSourceUid.toString());
59 }
63 }
60 }
64 }
61
65
66 void DataSourceController::setDataProvider(const QUuid &dataSourceUid,
67 std::unique_ptr<IDataProvider> dataProvider) noexcept
68 {
69 if (impl->m_DataSources.contains(dataSourceUid)) {
70 impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider)));
71 }
72 else {
73 qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data "
74 "source has been registered with the uid")
75 .arg(dataSourceUid.toString());
76 }
77 }
78
62 void DataSourceController::initialize()
79 void DataSourceController::initialize()
63 {
80 {
64 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init")
81 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init")
65 << QThread::currentThread();
82 << QThread::currentThread();
66 impl->m_WorkingMutex.lock();
83 impl->m_WorkingMutex.lock();
67 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
84 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
68 }
85 }
69
86
70 void DataSourceController::finalize()
87 void DataSourceController::finalize()
71 {
88 {
72 impl->m_WorkingMutex.unlock();
89 impl->m_WorkingMutex.unlock();
73 }
90 }
74
91
75 void DataSourceController::waitForFinish()
92 void DataSourceController::waitForFinish()
76 {
93 {
77 QMutexLocker locker{&impl->m_WorkingMutex};
94 QMutexLocker locker{&impl->m_WorkingMutex};
78 }
95 }
@@ -1,6 +1,10
1 # On ignore toutes les règles vera++ pour le fichier spimpl
1 # On ignore toutes les règles vera++ pour le fichier spimpl
2 Common/spimpl\.h:\d+:.*
2 Common/spimpl\.h:\d+:.*
3
3
4 # Ignore false positive relative to two class definitions in a same file
4 # Ignore false positive relative to two class definitions in a same file
5 DataSourceItem\.h:\d+:.*IPSIS_S01.*
5 DataSourceItem\.h:\d+:.*IPSIS_S01.*
6
6
7 # Ignore false positive relative to a template class
8 ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (D)
9 ArrayData\.h:\d+:.*IPSIS_S06.*found: (D)
10 ArrayData\.h:\d+:.*IPSIS_S06.*found: (Dim)
@@ -1,27 +1,23
1 #ifndef SCIQLOP_MOCKPLUGIN_H
1 #ifndef SCIQLOP_MOCKPLUGIN_H
2 #define SCIQLOP_MOCKPLUGIN_H
2 #define SCIQLOP_MOCKPLUGIN_H
3
3
4 #include <Plugin/IPlugin.h>
4 #include <Plugin/IPlugin.h>
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7
7
8 #include <memory>
8 #include <memory>
9
9
10 Q_DECLARE_LOGGING_CATEGORY(LOG_MockPlugin)
10 Q_DECLARE_LOGGING_CATEGORY(LOG_MockPlugin)
11
11
12 class DataSourceItem;
12 class DataSourceItem;
13
13
14 class MockPlugin : public QObject, public IPlugin {
14 class MockPlugin : public QObject, public IPlugin {
15 Q_OBJECT
15 Q_OBJECT
16 Q_INTERFACES(IPlugin)
16 Q_INTERFACES(IPlugin)
17 Q_PLUGIN_METADATA(IID "sciqlop.plugin.IPlugin" FILE "mockplugin.json")
17 Q_PLUGIN_METADATA(IID "sciqlop.plugin.IPlugin" FILE "mockplugin.json")
18 public:
18 public:
19 /// @sa IPlugin::initialize()
19 /// @sa IPlugin::initialize()
20 void initialize() override;
20 void initialize() override;
21
22 private:
23 /// Creates the data source item relative to the plugin
24 std::unique_ptr<DataSourceItem> createDataSourceItem() const noexcept;
25 };
21 };
26
22
27 #endif // SCIQLOP_MOCKPLUGIN_H
23 #endif // SCIQLOP_MOCKPLUGIN_H
@@ -1,55 +1,67
1 #include <MockPlugin.h>
1 #include "MockPlugin.h"
2 #include "CosinusProvider.h"
2
3
3 #include <DataSource/DataSourceController.h>
4 #include <DataSource/DataSourceController.h>
4 #include <DataSource/DataSourceItem.h>
5 #include <DataSource/DataSourceItem.h>
5
6
6 #include <SqpApplication.h>
7 #include <SqpApplication.h>
7
8
8 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
9 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
9
10
10 namespace {
11 namespace {
11
12
12 /// Name of the data source
13 /// Name of the data source
13 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
14 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
14
15
15 } // namespace
16 /// Creates the data provider relative to the plugin
16
17 std::unique_ptr<IDataProvider> createDataProvider() noexcept
17 void MockPlugin::initialize()
18 {
18 {
19 if (auto app = sqpApp) {
19 return std::make_unique<CosinusProvider>();
20 // Registers to the data source controller
21 auto &dataSourceController = app->dataSourceController();
22 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
23
24 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem());
25 }
26 else {
27 qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application");
28 }
29 }
20 }
30
21
31 std::unique_ptr<DataSourceItem> MockPlugin::createDataSourceItem() const noexcept
22 /// Creates the data source item relative to the plugin
23 std::unique_ptr<DataSourceItem> createDataSourceItem() noexcept
32 {
24 {
33 // Magnetic field products
25 // Magnetic field products
34 auto fgmProduct = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
26 auto fgmProduct = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
35 QVector<QVariant>{QStringLiteral("FGM")});
27 QVector<QVariant>{QStringLiteral("FGM")});
36 auto scProduct = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
28 auto scProduct = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
37 QVector<QVariant>{QStringLiteral("SC")});
29 QVector<QVariant>{QStringLiteral("SC")});
38
30
39 auto magneticFieldFolder = std::make_unique<DataSourceItem>(
31 auto magneticFieldFolder = std::make_unique<DataSourceItem>(
40 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")});
32 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")});
41 magneticFieldFolder->appendChild(std::move(fgmProduct));
33 magneticFieldFolder->appendChild(std::move(fgmProduct));
42 magneticFieldFolder->appendChild(std::move(scProduct));
34 magneticFieldFolder->appendChild(std::move(scProduct));
43
35
44 // Electric field products
36 // Electric field products
45 auto electricFieldFolder = std::make_unique<DataSourceItem>(
37 auto electricFieldFolder = std::make_unique<DataSourceItem>(
46 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Electric field")});
38 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Electric field")});
47
39
48 // Root
40 // Root
49 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
41 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
50 QVector<QVariant>{DATA_SOURCE_NAME});
42 QVector<QVariant>{DATA_SOURCE_NAME});
51 root->appendChild(std::move(magneticFieldFolder));
43 root->appendChild(std::move(magneticFieldFolder));
52 root->appendChild(std::move(electricFieldFolder));
44 root->appendChild(std::move(electricFieldFolder));
53
45
54 return std::move(root);
46 return root;
47 }
48
49 } // namespace
50
51 void MockPlugin::initialize()
52 {
53 if (auto app = sqpApp) {
54 // Registers to the data source controller
55 auto &dataSourceController = app->dataSourceController();
56 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
57
58 // Sets data source tree
59 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem());
60
61 // Sets data provider
62 dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
63 }
64 else {
65 qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application");
66 }
55 }
67 }
General Comments 0
You need to be logged in to leave comments. Login now