From 9c3bb5e93c54352da55cc8a581819aed8099648c 2017-11-28 13:37:13 From: Alexandre Leroux Date: 2017-11-28 13:37:13 Subject: [PATCH] Sets the name of the plugin for products and components Since there is only one common root in the data source widget, it is no longer possible to retrieve on the fly the name of the plugin in which a component or product is located. This name is therefore attached to their creation. --- diff --git a/core/include/DataSource/DataSourceItem.h b/core/include/DataSource/DataSourceItem.h index 3d0666c..9b82471 100644 --- a/core/include/DataSource/DataSourceItem.h +++ b/core/include/DataSource/DataSourceItem.h @@ -25,6 +25,8 @@ class SCIQLOP_CORE_EXPORT DataSourceItem { public: /// Key associated with the name of the item static const QString NAME_DATA_KEY; + /// Key associated with the plugin of the item + static const QString PLUGIN_DATA_KEY; explicit DataSourceItem(DataSourceItemType type, const QString &name); explicit DataSourceItem(DataSourceItemType type, QVariantHash data = {}); diff --git a/core/src/DataSource/DataSourceController.cpp b/core/src/DataSource/DataSourceController.cpp index 81adfb3..a7bc3d2 100644 --- a/core/src/DataSource/DataSourceController.cpp +++ b/core/src/DataSource/DataSourceController.cpp @@ -12,28 +12,6 @@ Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController") -namespace { - -/** - * Builds the metadata of the variable that will be generated from the loading of an item - * @param dataSourceItem the data source item from which to generate the metadata - * @return the metadata of the variable - */ -QVariantHash variableMetadata(const DataSourceItem &dataSourceItem) -{ - // Variable metadata contains... - - // ... all metadata of the item - auto result = dataSourceItem.data(); - - // ... and the name of the plugin, recovered from root item - result.insert(QStringLiteral("plugin"), dataSourceItem.rootItem().name()); - - return result; -} - -} // namespace - class DataSourceController::DataSourceControllerPrivate { public: QMutex m_WorkingMutex; @@ -131,8 +109,7 @@ void DataSourceController::loadProductItem(const QUuid &dataSourceUid, auto it = impl->m_DataProviders.find(dataSourceUid); auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr; - emit variableCreationRequested(productItem.name(), variableMetadata(productItem), - dataProvider); + emit variableCreationRequested(productItem.name(), productItem.data(), dataProvider); } else { qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product"); diff --git a/core/src/DataSource/DataSourceItem.cpp b/core/src/DataSource/DataSourceItem.cpp index 208835c..919946c 100644 --- a/core/src/DataSource/DataSourceItem.cpp +++ b/core/src/DataSource/DataSourceItem.cpp @@ -5,6 +5,7 @@ #include const QString DataSourceItem::NAME_DATA_KEY = QStringLiteral("name"); +const QString DataSourceItem::PLUGIN_DATA_KEY = QStringLiteral("plugin"); struct DataSourceItem::DataSourceItemPrivate { explicit DataSourceItemPrivate(DataSourceItemType type, QVariantHash data) diff --git a/plugins/amda/src/AmdaPlugin.cpp b/plugins/amda/src/AmdaPlugin.cpp index 5ce9064..0a033a9 100644 --- a/plugins/amda/src/AmdaPlugin.cpp +++ b/plugins/amda/src/AmdaPlugin.cpp @@ -31,11 +31,14 @@ void associateActions(DataSourceItem &item, const QUuid &dataSourceUid) }; 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())); + if (itemType == DataSourceItemType::PRODUCT || itemType == DataSourceItemType::COMPONENT) { + // Adds plugin name to item metadata + item.setData(DataSourceItem::PLUGIN_DATA_KEY, DATA_SOURCE_NAME); + + // Adds load action + auto actionLabel = QObject::tr( + itemType == DataSourceItemType::PRODUCT ? "Load %1 product" : "Load %1 component"); + addLoadAction(actionLabel.arg(item.name())); } auto count = item.childCount(); diff --git a/plugins/mockplugin/src/MockPlugin.cpp b/plugins/mockplugin/src/MockPlugin.cpp index 734200b..1cbf77b 100644 --- a/plugins/mockplugin/src/MockPlugin.cpp +++ b/plugins/mockplugin/src/MockPlugin.cpp @@ -25,6 +25,10 @@ std::unique_ptr createProductItem(const QVariantHash &data, const QUuid &dataSourceUid) { auto result = std::make_unique(DataSourceItemType::PRODUCT, data); + + // Adds plugin name to product metadata + result->setData(DataSourceItem::PLUGIN_DATA_KEY, DATA_SOURCE_NAME); + auto productName = data.value(DataSourceItem::NAME_DATA_KEY).toString(); // Add action to load product from DataSourceController