##// END OF EJS Templates
Create mock plugin
Alexandre Leroux -
r96:be11fc26511e
parent child
Show More
@@ -0,0 +1,27
1 #ifndef SCIQLOP_MOCKPLUGIN_H
2 #define SCIQLOP_MOCKPLUGIN_H
3
4 #include <Plugin/IPlugin.h>
5
6 #include <QLoggingCategory>
7
8 #include <memory>
9
10 Q_DECLARE_LOGGING_CATEGORY(LOG_MockPlugin)
11
12 class DataSourceItem;
13
14 class MockPlugin : public QObject, public IPlugin {
15 Q_OBJECT
16 Q_INTERFACES(IPlugin)
17 Q_PLUGIN_METADATA(IID "sciqlop.plugin.IPlugin" FILE "mockplugin.json")
18 public:
19 /// @sa IPlugin::initialize()
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 };
26
27 #endif // SCIQLOP_MOCKPLUGIN_H
@@ -0,0 +1,3
1 {
2 "name" : "MockPlugin"
3 }
@@ -0,0 +1,55
1 #include <MockPlugin.h>
2
3 #include <DataSource/DataSourceController.h>
4 #include <DataSource/DataSourceItem.h>
5
6 #include <SqpApplication.h>
7
8 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
9
10 namespace {
11
12 /// Name of the data source
13 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
14
15 } // namespace
16
17 void MockPlugin::initialize()
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 }
29 }
30
31 std::unique_ptr<DataSourceItem> MockPlugin::createDataSourceItem() const noexcept
32 {
33 // Magnetic field products
34 auto fgmProduct = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
35 QVector<QVariant>{QStringLiteral("FGM")});
36 auto scProduct = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
37 QVector<QVariant>{QStringLiteral("SC")});
38
39 auto magneticFieldFolder = std::make_unique<DataSourceItem>(
40 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")});
41 magneticFieldFolder->appendChild(std::move(fgmProduct));
42 magneticFieldFolder->appendChild(std::move(scProduct));
43
44 // Electric field products
45 auto electricFieldFolder = std::make_unique<DataSourceItem>(
46 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Electric field")});
47
48 // Root
49 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
50 QVector<QVariant>{DATA_SOURCE_NAME});
51 root->appendChild(std::move(magneticFieldFolder));
52 root->appendChild(std::move(electricFieldFolder));
53
54 return std::move(root);
55 }
General Comments 6
Under Review
author

Pull request updated. Auto status change to "Under Review"

Changed commits:
  * 1 added
  * 0 removed

Changed files:
  * M app/src/MainWindow.cpp
Approved
author

Status change > Approved

You need to be logged in to leave comments. Login now