##// END OF EJS Templates
Creates actions to load a product in the data source tree
Alexandre Leroux -
r381:86fdbf82f68d
parent child
Show More
@@ -1,42 +1,68
1 #include "AmdaPlugin.h"
1 #include "AmdaPlugin.h"
2 #include "AmdaParser.h"
2 #include "AmdaParser.h"
3 #include "AmdaProvider.h"
3
4
4 #include <DataSource/DataSourceController.h>
5 #include <DataSource/DataSourceController.h>
5 #include <DataSource/DataSourceItem.h>
6 #include <DataSource/DataSourceItem.h>
7 #include <DataSource/DataSourceItemAction.h>
6
8
7 #include <SqpApplication.h>
9 #include <SqpApplication.h>
8
10
9 Q_LOGGING_CATEGORY(LOG_AmdaPlugin, "AmdaPlugin")
11 Q_LOGGING_CATEGORY(LOG_AmdaPlugin, "AmdaPlugin")
10
12
11 namespace {
13 namespace {
12
14
13 /// Name of the data source
15 /// Name of the data source
14 const auto DATA_SOURCE_NAME = QStringLiteral("AMDA");
16 const auto DATA_SOURCE_NAME = QStringLiteral("AMDA");
15
17
16 /// Path of the file used to generate the data source item for AMDA
18 /// Path of the file used to generate the data source item for AMDA
17 const auto JSON_FILE_PATH = QStringLiteral(":/samples/AmdaSample.json");
19 const auto JSON_FILE_PATH = QStringLiteral(":/samples/AmdaSample.json");
18
20
21 void associateActions(DataSourceItem &item, const QUuid &dataSourceUid)
22 {
23 if (item.type() == DataSourceItemType::PRODUCT) {
24 auto itemName = item.name();
25
26 item.addAction(std::make_unique<DataSourceItemAction>(
27 QObject::tr("Load %1 product").arg(itemName),
28 [itemName, dataSourceUid](DataSourceItem &item) {
29 if (auto app = sqpApp) {
30 app->dataSourceController().loadProductItem(dataSourceUid, item);
31 }
32 }));
33 }
34
35 auto count = item.childCount();
36 for (auto i = 0; i < count; ++i) {
37 if (auto child = item.child(i)) {
38 associateActions(*child, dataSourceUid);
39 }
40 }
41 }
42
19 } // namespace
43 } // namespace
20
44
21 void AmdaPlugin::initialize()
45 void AmdaPlugin::initialize()
22 {
46 {
23 if (auto app = sqpApp) {
47 if (auto app = sqpApp) {
24 // Registers to the data source controller
48 // Registers to the data source controller
25 auto &dataSourceController = app->dataSourceController();
49 auto &dataSourceController = app->dataSourceController();
26 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
50 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
27
51
28 // Sets data source tree
52 // Sets data source tree
29 if (auto dataSourceItem = AmdaParser::readJson(JSON_FILE_PATH)) {
53 if (auto dataSourceItem = AmdaParser::readJson(JSON_FILE_PATH)) {
54 associateActions(*dataSourceItem, dataSourceUid);
55
30 dataSourceController.setDataSourceItem(dataSourceUid, std::move(dataSourceItem));
56 dataSourceController.setDataSourceItem(dataSourceUid, std::move(dataSourceItem));
31 }
57 }
32 else {
58 else {
33 qCCritical(LOG_AmdaPlugin()) << tr("No data source item could be generated for AMDA");
59 qCCritical(LOG_AmdaPlugin()) << tr("No data source item could be generated for AMDA");
34 }
60 }
35
61
36 // Sets data provider
62 // Sets data provider
37 dataSourceController.setDataProvider(dataSourceUid, std::make_unique<AmdaProvider>());
63 dataSourceController.setDataProvider(dataSourceUid, std::make_unique<AmdaProvider>());
38 }
64 }
39 else {
65 else {
40 qCWarning(LOG_AmdaPlugin()) << tr("Can't access to SciQlop application");
66 qCWarning(LOG_AmdaPlugin()) << tr("Can't access to SciQlop application");
41 }
67 }
42 }
68 }
General Comments 0
You need to be logged in to leave comments. Login now