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