From 86fdbf82f68dfc4632f6e2824f7ff49e03cb01d1 2017-07-10 08:09:24 From: Alexandre Leroux Date: 2017-07-10 08:09:24 Subject: [PATCH] Creates actions to load a product in the data source tree --- diff --git a/plugins/amda/src/AmdaPlugin.cpp b/plugins/amda/src/AmdaPlugin.cpp index f208168..af18f76 100644 --- a/plugins/amda/src/AmdaPlugin.cpp +++ b/plugins/amda/src/AmdaPlugin.cpp @@ -1,8 +1,10 @@ #include "AmdaPlugin.h" #include "AmdaParser.h" +#include "AmdaProvider.h" #include #include +#include #include @@ -16,6 +18,28 @@ const auto DATA_SOURCE_NAME = QStringLiteral("AMDA"); /// Path of the file used to generate the data source item for AMDA const auto JSON_FILE_PATH = QStringLiteral(":/samples/AmdaSample.json"); +void associateActions(DataSourceItem &item, const QUuid &dataSourceUid) +{ + if (item.type() == DataSourceItemType::PRODUCT) { + auto itemName = item.name(); + + item.addAction(std::make_unique( + QObject::tr("Load %1 product").arg(itemName), + [itemName, dataSourceUid](DataSourceItem &item) { + if (auto app = sqpApp) { + app->dataSourceController().loadProductItem(dataSourceUid, item); + } + })); + } + + auto count = item.childCount(); + for (auto i = 0; i < count; ++i) { + if (auto child = item.child(i)) { + associateActions(*child, dataSourceUid); + } + } +} + } // namespace void AmdaPlugin::initialize() @@ -27,6 +51,8 @@ void AmdaPlugin::initialize() // Sets data source tree if (auto dataSourceItem = AmdaParser::readJson(JSON_FILE_PATH)) { + associateActions(*dataSourceItem, dataSourceUid); + dataSourceController.setDataSourceItem(dataSourceUid, std::move(dataSourceItem)); } else {