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