##// END OF EJS Templates
Sets the name of the plugin for products and components...
Alexandre Leroux -
r1036:9c3bb5e93c54
parent child
Show More
@@ -25,6 +25,8 class SCIQLOP_CORE_EXPORT DataSourceItem {
25 25 public:
26 26 /// Key associated with the name of the item
27 27 static const QString NAME_DATA_KEY;
28 /// Key associated with the plugin of the item
29 static const QString PLUGIN_DATA_KEY;
28 30
29 31 explicit DataSourceItem(DataSourceItemType type, const QString &name);
30 32 explicit DataSourceItem(DataSourceItemType type, QVariantHash data = {});
@@ -12,28 +12,6
12 12
13 13 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
14 14
15 namespace {
16
17 /**
18 * Builds the metadata of the variable that will be generated from the loading of an item
19 * @param dataSourceItem the data source item from which to generate the metadata
20 * @return the metadata of the variable
21 */
22 QVariantHash variableMetadata(const DataSourceItem &dataSourceItem)
23 {
24 // Variable metadata contains...
25
26 // ... all metadata of the item
27 auto result = dataSourceItem.data();
28
29 // ... and the name of the plugin, recovered from root item
30 result.insert(QStringLiteral("plugin"), dataSourceItem.rootItem().name());
31
32 return result;
33 }
34
35 } // namespace
36
37 15 class DataSourceController::DataSourceControllerPrivate {
38 16 public:
39 17 QMutex m_WorkingMutex;
@@ -131,8 +109,7 void DataSourceController::loadProductItem(const QUuid &dataSourceUid,
131 109 auto it = impl->m_DataProviders.find(dataSourceUid);
132 110 auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr;
133 111
134 emit variableCreationRequested(productItem.name(), variableMetadata(productItem),
135 dataProvider);
112 emit variableCreationRequested(productItem.name(), productItem.data(), dataProvider);
136 113 }
137 114 else {
138 115 qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product");
@@ -5,6 +5,7
5 5 #include <QVector>
6 6
7 7 const QString DataSourceItem::NAME_DATA_KEY = QStringLiteral("name");
8 const QString DataSourceItem::PLUGIN_DATA_KEY = QStringLiteral("plugin");
8 9
9 10 struct DataSourceItem::DataSourceItemPrivate {
10 11 explicit DataSourceItemPrivate(DataSourceItemType type, QVariantHash data)
@@ -31,11 +31,14 void associateActions(DataSourceItem &item, const QUuid &dataSourceUid)
31 31 };
32 32
33 33 const auto itemType = item.type();
34 if (itemType == DataSourceItemType::PRODUCT) {
35 addLoadAction(QObject::tr("Load %1 product").arg(item.name()));
36 }
37 else if (itemType == DataSourceItemType::COMPONENT) {
38 addLoadAction(QObject::tr("Load %1 component").arg(item.name()));
34 if (itemType == DataSourceItemType::PRODUCT || itemType == DataSourceItemType::COMPONENT) {
35 // Adds plugin name to item metadata
36 item.setData(DataSourceItem::PLUGIN_DATA_KEY, DATA_SOURCE_NAME);
37
38 // Adds load action
39 auto actionLabel = QObject::tr(
40 itemType == DataSourceItemType::PRODUCT ? "Load %1 product" : "Load %1 component");
41 addLoadAction(actionLabel.arg(item.name()));
39 42 }
40 43
41 44 auto count = item.childCount();
@@ -25,6 +25,10 std::unique_ptr<DataSourceItem> createProductItem(const QVariantHash &data,
25 25 const QUuid &dataSourceUid)
26 26 {
27 27 auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, data);
28
29 // Adds plugin name to product metadata
30 result->setData(DataSourceItem::PLUGIN_DATA_KEY, DATA_SOURCE_NAME);
31
28 32 auto productName = data.value(DataSourceItem::NAME_DATA_KEY).toString();
29 33
30 34 // Add action to load product from DataSourceController
General Comments 0
You need to be logged in to leave comments. Login now