##// END OF EJS Templates
Creates actions to load a product in the data source tree
Alexandre Leroux -
r381:86fdbf82f68d
parent child
Show More
@@ -1,8 +1,10
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
@@ -16,6 +18,28 const auto DATA_SOURCE_NAME = QStringLiteral("AMDA");
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()
@@ -27,6 +51,8 void AmdaPlugin::initialize()
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 {
General Comments 0
You need to be logged in to leave comments. Login now