##// 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 1 #ifndef SCIQLOP_MOCKPLUGIN_H
2 2 #define SCIQLOP_MOCKPLUGIN_H
3 3
4 4 #include <Plugin/IPlugin.h>
5 5
6 6 #include <QLoggingCategory>
7 7
8 8 #include <memory>
9 9
10 10 Q_DECLARE_LOGGING_CATEGORY(LOG_MockPlugin)
11 11
12 12 class DataSourceItem;
13 13
14 14 class MockPlugin : public QObject, public IPlugin {
15 15 Q_OBJECT
16 16 Q_INTERFACES(IPlugin)
17 17 Q_PLUGIN_METADATA(IID "sciqlop.plugin.IPlugin" FILE "mockplugin.json")
18 18 public:
19 19 /// @sa IPlugin::initialize()
20 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 23 #endif // SCIQLOP_MOCKPLUGIN_H
@@ -1,55 +1,67
1 #include <MockPlugin.h>
1 #include "MockPlugin.h"
2 #include "CosinusProvider.h"
2 3
3 4 #include <DataSource/DataSourceController.h>
4 5 #include <DataSource/DataSourceItem.h>
5 6
6 7 #include <SqpApplication.h>
7 8
8 9 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
9 10
10 11 namespace {
11 12
12 13 /// Name of the data source
13 14 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
14 15
15 } // namespace
16
17 void MockPlugin::initialize()
16 /// Creates the data provider relative to the plugin
17 std::unique_ptr<IDataProvider> createDataProvider() noexcept
18 18 {
19 if (auto app = sqpApp) {
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 }
19 return std::make_unique<CosinusProvider>();
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 25 // Magnetic field products
34 26 auto fgmProduct = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
35 27 QVector<QVariant>{QStringLiteral("FGM")});
36 28 auto scProduct = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
37 29 QVector<QVariant>{QStringLiteral("SC")});
38 30
39 31 auto magneticFieldFolder = std::make_unique<DataSourceItem>(
40 32 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")});
41 33 magneticFieldFolder->appendChild(std::move(fgmProduct));
42 34 magneticFieldFolder->appendChild(std::move(scProduct));
43 35
44 36 // Electric field products
45 37 auto electricFieldFolder = std::make_unique<DataSourceItem>(
46 38 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Electric field")});
47 39
48 40 // Root
49 41 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
50 42 QVector<QVariant>{DATA_SOURCE_NAME});
51 43 root->appendChild(std::move(magneticFieldFolder));
52 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