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