@@ -1,83 +1,74 | |||||
1 | #include "AmdaPlugin.h" |
|
1 | #include "AmdaPlugin.h" | |
2 | #include "AmdaDefs.h" |
|
2 | #include "AmdaDefs.h" | |
3 | #include "AmdaParser.h" |
|
3 | #include "AmdaParser.h" | |
4 | #include "AmdaProvider.h" |
|
4 | #include "AmdaProvider.h" | |
5 |
|
5 | |||
6 | #include <DataSource/DataSourceController.h> |
|
6 | #include <DataSource/DataSourceController.h> | |
7 | #include <DataSource/DataSourceItem.h> |
|
7 | #include <DataSource/DataSourceItem.h> | |
8 | #include <DataSource/DataSourceItemAction.h> |
|
8 | #include <DataSource/DataSourceItemAction.h> | |
9 |
|
9 | |||
10 | #include <SqpApplication.h> |
|
10 | #include <SqpApplication.h> | |
11 |
|
11 | |||
12 | Q_LOGGING_CATEGORY(LOG_AmdaPlugin, "AmdaPlugin") |
|
12 | Q_LOGGING_CATEGORY(LOG_AmdaPlugin, "AmdaPlugin") | |
13 |
|
13 | |||
14 | namespace { |
|
14 | namespace { | |
15 |
|
15 | |||
16 | /// Name of the data source |
|
16 | /// Name of the data source | |
17 | const auto DATA_SOURCE_NAME = QStringLiteral("AMDA"); |
|
17 | const auto DATA_SOURCE_NAME = QStringLiteral("AMDA"); | |
18 |
|
18 | |||
19 | /// Path of the file used to generate the data source item for AMDA |
|
19 | /// Path of the file used to generate the data source item for AMDA | |
20 | const auto JSON_FILE_PATH = QStringLiteral(":/samples/AmdaSampleV2.json"); |
|
20 | const auto JSON_FILE_PATH = QStringLiteral(":/samples/AmdaSampleV2.json"); | |
21 |
|
21 | |||
22 | void associateActions(DataSourceItem &item, const QUuid &dataSourceUid) |
|
22 | void associateActions(DataSourceItem &item, const QUuid &dataSourceUid) | |
23 | { |
|
23 | { | |
24 | auto addLoadAction = [&item, dataSourceUid](const QString &label) { |
|
24 | auto addLoadAction = [&item, dataSourceUid](const QString &label) { | |
25 | item.addAction( |
|
25 | item.addAction( | |
26 | std::make_unique<DataSourceItemAction>(label, [dataSourceUid](DataSourceItem &item) { |
|
26 | std::make_unique<DataSourceItemAction>(label, [dataSourceUid](DataSourceItem &item) { | |
27 | if (auto app = sqpApp) { |
|
27 | if (auto app = sqpApp) { | |
28 | app->dataSourceController().loadProductItem(dataSourceUid, item); |
|
28 | app->dataSourceController().loadProductItem(dataSourceUid, item); | |
29 | } |
|
29 | } | |
30 | })); |
|
30 | })); | |
31 | }; |
|
31 | }; | |
32 |
|
32 | |||
33 | const auto itemType = item.type(); |
|
33 | const auto itemType = item.type(); | |
34 | if (itemType == DataSourceItemType::PRODUCT) { |
|
34 | if (itemType == DataSourceItemType::PRODUCT) { | |
35 | /// @todo : As for the moment we do not manage the loading of vectors, in the case of a |
|
|||
36 | /// parameter, we update the identifier of download of the data: |
|
|||
37 | /// - if the parameter has no component, the identifier remains the same |
|
|||
38 | /// - if the parameter has at least one component, the identifier is that of the first |
|
|||
39 | /// component (for example, "imf" becomes "imf (0)") |
|
|||
40 | if (item.childCount() != 0) { |
|
|||
41 | item.setData(AMDA_XML_ID_KEY, item.child(0)->data(AMDA_XML_ID_KEY)); |
|
|||
42 | } |
|
|||
43 |
|
||||
44 | addLoadAction(QObject::tr("Load %1 product").arg(item.name())); |
|
35 | addLoadAction(QObject::tr("Load %1 product").arg(item.name())); | |
45 | } |
|
36 | } | |
46 | else if (itemType == DataSourceItemType::COMPONENT) { |
|
37 | else if (itemType == DataSourceItemType::COMPONENT) { | |
47 | addLoadAction(QObject::tr("Load %1 component").arg(item.name())); |
|
38 | addLoadAction(QObject::tr("Load %1 component").arg(item.name())); | |
48 | } |
|
39 | } | |
49 |
|
40 | |||
50 | auto count = item.childCount(); |
|
41 | auto count = item.childCount(); | |
51 | for (auto i = 0; i < count; ++i) { |
|
42 | for (auto i = 0; i < count; ++i) { | |
52 | if (auto child = item.child(i)) { |
|
43 | if (auto child = item.child(i)) { | |
53 | associateActions(*child, dataSourceUid); |
|
44 | associateActions(*child, dataSourceUid); | |
54 | } |
|
45 | } | |
55 | } |
|
46 | } | |
56 | } |
|
47 | } | |
57 |
|
48 | |||
58 | } // namespace |
|
49 | } // namespace | |
59 |
|
50 | |||
60 | void AmdaPlugin::initialize() |
|
51 | void AmdaPlugin::initialize() | |
61 | { |
|
52 | { | |
62 | if (auto app = sqpApp) { |
|
53 | if (auto app = sqpApp) { | |
63 | // Registers to the data source controller |
|
54 | // Registers to the data source controller | |
64 | auto &dataSourceController = app->dataSourceController(); |
|
55 | auto &dataSourceController = app->dataSourceController(); | |
65 | auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME); |
|
56 | auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME); | |
66 |
|
57 | |||
67 | // Sets data source tree |
|
58 | // Sets data source tree | |
68 | if (auto dataSourceItem = AmdaParser::readJson(JSON_FILE_PATH)) { |
|
59 | if (auto dataSourceItem = AmdaParser::readJson(JSON_FILE_PATH)) { | |
69 | associateActions(*dataSourceItem, dataSourceUid); |
|
60 | associateActions(*dataSourceItem, dataSourceUid); | |
70 |
|
61 | |||
71 | dataSourceController.setDataSourceItem(dataSourceUid, std::move(dataSourceItem)); |
|
62 | dataSourceController.setDataSourceItem(dataSourceUid, std::move(dataSourceItem)); | |
72 | } |
|
63 | } | |
73 | else { |
|
64 | else { | |
74 | qCCritical(LOG_AmdaPlugin()) << tr("No data source item could be generated for AMDA"); |
|
65 | qCCritical(LOG_AmdaPlugin()) << tr("No data source item could be generated for AMDA"); | |
75 | } |
|
66 | } | |
76 |
|
67 | |||
77 | // Sets data provider |
|
68 | // Sets data provider | |
78 | dataSourceController.setDataProvider(dataSourceUid, std::make_unique<AmdaProvider>()); |
|
69 | dataSourceController.setDataProvider(dataSourceUid, std::make_unique<AmdaProvider>()); | |
79 | } |
|
70 | } | |
80 | else { |
|
71 | else { | |
81 | qCWarning(LOG_AmdaPlugin()) << tr("Can't access to SciQlop application"); |
|
72 | qCWarning(LOG_AmdaPlugin()) << tr("Can't access to SciQlop application"); | |
82 | } |
|
73 | } | |
83 | } |
|
74 | } |
General Comments 0
You need to be logged in to leave comments.
Login now