##// END OF EJS Templates
Generates vectors (5)...
Alexandre Leroux -
r788:5e7d2f907fac
parent child
Show More
@@ -1,91 +1,109
1 #include "MockPlugin.h"
1 #include "MockPlugin.h"
2 #include "CosinusProvider.h"
2 #include "CosinusProvider.h"
3 #include "MockDefs.h"
3 #include "MockDefs.h"
4
4
5 #include <DataSource/DataSourceController.h>
5 #include <DataSource/DataSourceController.h>
6 #include <DataSource/DataSourceItem.h>
6 #include <DataSource/DataSourceItem.h>
7 #include <DataSource/DataSourceItemAction.h>
7 #include <DataSource/DataSourceItemAction.h>
8
8
9 #include <SqpApplication.h>
9 #include <SqpApplication.h>
10
10
11 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
11 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
12
12
13 namespace {
13 namespace {
14
14
15 /// Name of the data source
15 /// Name of the data source
16 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
16 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
17
17
18 /// Creates the data provider relative to the plugin
18 /// Creates the data provider relative to the plugin
19 std::unique_ptr<IDataProvider> createDataProvider() noexcept
19 std::unique_ptr<IDataProvider> createDataProvider() noexcept
20 {
20 {
21 return std::make_unique<CosinusProvider>();
21 return std::make_unique<CosinusProvider>();
22 }
22 }
23
23
24 std::unique_ptr<DataSourceItem> createProductItem(const QVariantHash &data,
24 std::unique_ptr<DataSourceItem> createProductItem(const QVariantHash &data,
25 const QUuid &dataSourceUid)
25 const QUuid &dataSourceUid)
26 {
26 {
27 auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, data);
27 auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, data);
28 auto productName = data.value(DataSourceItem::NAME_DATA_KEY).toString();
28 auto productName = data.value(DataSourceItem::NAME_DATA_KEY).toString();
29
29
30 // Add action to load product from DataSourceController
30 // Add action to load product from DataSourceController
31 result->addAction(std::make_unique<DataSourceItemAction>(
31 result->addAction(std::make_unique<DataSourceItemAction>(
32 QObject::tr("Load %1 product").arg(productName),
32 QObject::tr("Load %1 product").arg(productName),
33 [productName, dataSourceUid](DataSourceItem &item) {
33 [productName, dataSourceUid](DataSourceItem &item) {
34 if (auto app = sqpApp) {
34 if (auto app = sqpApp) {
35 app->dataSourceController().loadProductItem(dataSourceUid, item);
35 app->dataSourceController().loadProductItem(dataSourceUid, item);
36 }
36 }
37 }));
37 }));
38
38
39 return result;
39 return result;
40 }
40 }
41
41
42 /// Creates the data source item relative to the plugin
42 /// Creates the data source item relative to the plugin
43 std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept
43 std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept
44 {
44 {
45 // Magnetic field products
45 // Magnetic field products
46 auto magneticFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
46 auto magneticFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
47 QStringLiteral("Magnetic field"));
47 QStringLiteral("Magnetic field"));
48 magneticFieldFolder->appendChild(
48 magneticFieldFolder->appendChild(
49 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 10 Hz")},
49 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 10 Hz")},
50 {COSINUS_TYPE_KEY, "scalar"},
50 {COSINUS_FREQUENCY_KEY, 10.}},
51 {COSINUS_FREQUENCY_KEY, 10.}},
51 dataSourceUid));
52 dataSourceUid));
52 magneticFieldFolder->appendChild(
53 magneticFieldFolder->appendChild(
53 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 60 Hz")},
54 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 60 Hz")},
55 {COSINUS_TYPE_KEY, "scalar"},
54 {COSINUS_FREQUENCY_KEY, 60.}},
56 {COSINUS_FREQUENCY_KEY, 60.}},
55 dataSourceUid));
57 dataSourceUid));
56 magneticFieldFolder->appendChild(
58 magneticFieldFolder->appendChild(
57 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 100 Hz")},
59 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 100 Hz")},
60 {COSINUS_TYPE_KEY, "scalar"},
61 {COSINUS_FREQUENCY_KEY, 100.}},
62 dataSourceUid));
63 magneticFieldFolder->appendChild(
64 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 10 Hz")},
65 {COSINUS_TYPE_KEY, "vector"},
66 {COSINUS_FREQUENCY_KEY, 10.}},
67 dataSourceUid));
68 magneticFieldFolder->appendChild(
69 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 60 Hz")},
70 {COSINUS_TYPE_KEY, "vector"},
71 {COSINUS_FREQUENCY_KEY, 60.}},
72 dataSourceUid));
73 magneticFieldFolder->appendChild(
74 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 100 Hz")},
75 {COSINUS_TYPE_KEY, "vector"},
58 {COSINUS_FREQUENCY_KEY, 100.}},
76 {COSINUS_FREQUENCY_KEY, 100.}},
59 dataSourceUid));
77 dataSourceUid));
60
78
61 // Electric field products
79 // Electric field products
62 auto electricFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
80 auto electricFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
63 QStringLiteral("Electric field"));
81 QStringLiteral("Electric field"));
64
82
65 // Root
83 // Root
66 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, DATA_SOURCE_NAME);
84 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, DATA_SOURCE_NAME);
67 root->appendChild(std::move(magneticFieldFolder));
85 root->appendChild(std::move(magneticFieldFolder));
68 root->appendChild(std::move(electricFieldFolder));
86 root->appendChild(std::move(electricFieldFolder));
69
87
70 return root;
88 return root;
71 }
89 }
72
90
73 } // namespace
91 } // namespace
74
92
75 void MockPlugin::initialize()
93 void MockPlugin::initialize()
76 {
94 {
77 if (auto app = sqpApp) {
95 if (auto app = sqpApp) {
78 // Registers to the data source controller
96 // Registers to the data source controller
79 auto &dataSourceController = app->dataSourceController();
97 auto &dataSourceController = app->dataSourceController();
80 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
98 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
81
99
82 // Sets data source tree
100 // Sets data source tree
83 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem(dataSourceUid));
101 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem(dataSourceUid));
84
102
85 // Sets data provider
103 // Sets data provider
86 dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
104 dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
87 }
105 }
88 else {
106 else {
89 qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application");
107 qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application");
90 }
108 }
91 }
109 }
General Comments 0
You need to be logged in to leave comments. Login now