##// END OF EJS Templates
Removes hack that was downloading first component of a vector when vectors were not handled
Alexandre Leroux -
r567:1cffe83f175c
parent child
Show More
@@ -1,83 +1,74
1 1 #include "AmdaPlugin.h"
2 2 #include "AmdaDefs.h"
3 3 #include "AmdaParser.h"
4 4 #include "AmdaProvider.h"
5 5
6 6 #include <DataSource/DataSourceController.h>
7 7 #include <DataSource/DataSourceItem.h>
8 8 #include <DataSource/DataSourceItemAction.h>
9 9
10 10 #include <SqpApplication.h>
11 11
12 12 Q_LOGGING_CATEGORY(LOG_AmdaPlugin, "AmdaPlugin")
13 13
14 14 namespace {
15 15
16 16 /// Name of the data source
17 17 const auto DATA_SOURCE_NAME = QStringLiteral("AMDA");
18 18
19 19 /// Path of the file used to generate the data source item for AMDA
20 20 const auto JSON_FILE_PATH = QStringLiteral(":/samples/AmdaSampleV2.json");
21 21
22 22 void associateActions(DataSourceItem &item, const QUuid &dataSourceUid)
23 23 {
24 24 auto addLoadAction = [&item, dataSourceUid](const QString &label) {
25 25 item.addAction(
26 26 std::make_unique<DataSourceItemAction>(label, [dataSourceUid](DataSourceItem &item) {
27 27 if (auto app = sqpApp) {
28 28 app->dataSourceController().loadProductItem(dataSourceUid, item);
29 29 }
30 30 }));
31 31 };
32 32
33 33 const auto itemType = item.type();
34 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 35 addLoadAction(QObject::tr("Load %1 product").arg(item.name()));
45 36 }
46 37 else if (itemType == DataSourceItemType::COMPONENT) {
47 38 addLoadAction(QObject::tr("Load %1 component").arg(item.name()));
48 39 }
49 40
50 41 auto count = item.childCount();
51 42 for (auto i = 0; i < count; ++i) {
52 43 if (auto child = item.child(i)) {
53 44 associateActions(*child, dataSourceUid);
54 45 }
55 46 }
56 47 }
57 48
58 49 } // namespace
59 50
60 51 void AmdaPlugin::initialize()
61 52 {
62 53 if (auto app = sqpApp) {
63 54 // Registers to the data source controller
64 55 auto &dataSourceController = app->dataSourceController();
65 56 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
66 57
67 58 // Sets data source tree
68 59 if (auto dataSourceItem = AmdaParser::readJson(JSON_FILE_PATH)) {
69 60 associateActions(*dataSourceItem, dataSourceUid);
70 61
71 62 dataSourceController.setDataSourceItem(dataSourceUid, std::move(dataSourceItem));
72 63 }
73 64 else {
74 65 qCCritical(LOG_AmdaPlugin()) << tr("No data source item could be generated for AMDA");
75 66 }
76 67
77 68 // Sets data provider
78 69 dataSourceController.setDataProvider(dataSourceUid, std::make_unique<AmdaProvider>());
79 70 }
80 71 else {
81 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