From 4f3a3edcd1d8da09b2ecd85f770d714bcd04a5b0 2017-07-13 08:18:09 From: Alexandre Leroux Date: 2017-07-13 08:18:09 Subject: [PATCH] Amda provider update (3) Creates actions to load components --- diff --git a/core/src/DataSource/DataSourceController.cpp b/core/src/DataSource/DataSourceController.cpp index 12243c1..f41d211 100644 --- a/core/src/DataSource/DataSourceController.cpp +++ b/core/src/DataSource/DataSourceController.cpp @@ -88,7 +88,8 @@ void DataSourceController::setDataProvider(const QUuid &dataSourceUid, void DataSourceController::loadProductItem(const QUuid &dataSourceUid, const DataSourceItem &productItem) noexcept { - if (productItem.type() == DataSourceItemType::PRODUCT) { + if (productItem.type() == DataSourceItemType::PRODUCT + || productItem.type() == DataSourceItemType::COMPONENT) { /// Retrieves the data provider of the data source (if any) auto it = impl->m_DataProviders.find(dataSourceUid); auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr; diff --git a/plugins/amda/src/AmdaPlugin.cpp b/plugins/amda/src/AmdaPlugin.cpp index af18f76..1fd9955 100644 --- a/plugins/amda/src/AmdaPlugin.cpp +++ b/plugins/amda/src/AmdaPlugin.cpp @@ -20,16 +20,21 @@ 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) { + auto addLoadAction = [&item, dataSourceUid](const QString &label) { + item.addAction( + std::make_unique(label, [dataSourceUid](DataSourceItem &item) { if (auto app = sqpApp) { app->dataSourceController().loadProductItem(dataSourceUid, item); } })); + }; + + const auto itemType = item.type(); + if (itemType == DataSourceItemType::PRODUCT) { + addLoadAction(QObject::tr("Load %1 product").arg(item.name())); + } + else if (itemType == DataSourceItemType::COMPONENT) { + addLoadAction(QObject::tr("Load %1 component").arg(item.name())); } auto count = item.childCount();