##// END OF EJS Templates
Updates the MockPlugin::initialize() to create a cosinus provider and register it to the data source controller
Alexandre Leroux -
r129:e98a7f43fb7b
parent child
Show More
@@ -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