@@ -1,42 +1,68 | |||
|
1 | 1 | #include "AmdaPlugin.h" |
|
2 | 2 | #include "AmdaParser.h" |
|
3 | #include "AmdaProvider.h" | |
|
3 | 4 | |
|
4 | 5 | #include <DataSource/DataSourceController.h> |
|
5 | 6 | #include <DataSource/DataSourceItem.h> |
|
7 | #include <DataSource/DataSourceItemAction.h> | |
|
6 | 8 | |
|
7 | 9 | #include <SqpApplication.h> |
|
8 | 10 | |
|
9 | 11 | Q_LOGGING_CATEGORY(LOG_AmdaPlugin, "AmdaPlugin") |
|
10 | 12 | |
|
11 | 13 | namespace { |
|
12 | 14 | |
|
13 | 15 | /// Name of the data source |
|
14 | 16 | const auto DATA_SOURCE_NAME = QStringLiteral("AMDA"); |
|
15 | 17 | |
|
16 | 18 | /// Path of the file used to generate the data source item for AMDA |
|
17 | 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 | 43 | } // namespace |
|
20 | 44 | |
|
21 | 45 | void AmdaPlugin::initialize() |
|
22 | 46 | { |
|
23 | 47 | if (auto app = sqpApp) { |
|
24 | 48 | // Registers to the data source controller |
|
25 | 49 | auto &dataSourceController = app->dataSourceController(); |
|
26 | 50 | auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME); |
|
27 | 51 | |
|
28 | 52 | // Sets data source tree |
|
29 | 53 | if (auto dataSourceItem = AmdaParser::readJson(JSON_FILE_PATH)) { |
|
54 | associateActions(*dataSourceItem, dataSourceUid); | |
|
55 | ||
|
30 | 56 | dataSourceController.setDataSourceItem(dataSourceUid, std::move(dataSourceItem)); |
|
31 | 57 | } |
|
32 | 58 | else { |
|
33 | 59 | qCCritical(LOG_AmdaPlugin()) << tr("No data source item could be generated for AMDA"); |
|
34 | 60 | } |
|
35 | 61 | |
|
36 | 62 | // Sets data provider |
|
37 | 63 | dataSourceController.setDataProvider(dataSourceUid, std::make_unique<AmdaProvider>()); |
|
38 | 64 | } |
|
39 | 65 | else { |
|
40 | 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