##// END OF EJS Templates
Updates DataSourceController::loadProductItem() method...
Alexandre Leroux -
r167:31990a7209fc
parent child
Show More
@@ -56,9 +56,11 public:
56
56
57 /**
57 /**
58 * Loads an item (product) as a variable in SciQlop
58 * Loads an item (product) as a variable in SciQlop
59 * @param dataSourceUid the unique id of the data source containing the item. It is used to get
60 * the data provider associated to the data source, and pass it to for the variable creation
59 * @param productItem the item to load
61 * @param productItem the item to load
60 */
62 */
61 void loadProductItem(const DataSourceItem &productItem) noexcept;
63 void loadProductItem(const QUuid &dataSourceUid, const DataSourceItem &productItem) noexcept;
62
64
63 public slots:
65 public slots:
64 /// Manage init/end of the controller
66 /// Manage init/end of the controller
@@ -19,7 +19,9 public:
19 /// Data sources structures
19 /// Data sources structures
20 std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
20 std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
21 /// Data providers registered
21 /// Data providers registered
22 std::map<QUuid, std::unique_ptr<IDataProvider> > m_DataProviders;
22 /// @remarks Data providers are stored as shared_ptr as they can be sent to a variable and
23 /// continue to live without necessarily the data source controller
24 std::map<QUuid, std::shared_ptr<IDataProvider> > m_DataProviders;
23 };
25 };
24
26
25 DataSourceController::DataSourceController(QObject *parent)
27 DataSourceController::DataSourceController(QObject *parent)
@@ -48,6 +50,7 void DataSourceController::setDataSourceItem(
48 const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
50 const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
49 {
51 {
50 if (impl->m_DataSources.contains(dataSourceUid)) {
52 if (impl->m_DataSources.contains(dataSourceUid)) {
53 // The data provider is implicitly converted to a shared_ptr
51 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
54 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
52
55
53 // Retrieves the data source item to emit the signal with it
56 // Retrieves the data source item to emit the signal with it
@@ -76,7 +79,8 void DataSourceController::setDataProvider(const QUuid &dataSourceUid,
76 }
79 }
77 }
80 }
78
81
79 void DataSourceController::loadProductItem(const DataSourceItem &productItem) noexcept
82 void DataSourceController::loadProductItem(const QUuid &dataSourceUid,
83 const DataSourceItem &productItem) noexcept
80 {
84 {
81 /// @todo ALX
85 /// @todo ALX
82 }
86 }
@@ -20,16 +20,18 std::unique_ptr<IDataProvider> createDataProvider() noexcept
20 return std::make_unique<CosinusProvider>();
20 return std::make_unique<CosinusProvider>();
21 }
21 }
22
22
23 std::unique_ptr<DataSourceItem> createProductItem(const QString &productName)
23 std::unique_ptr<DataSourceItem> createProductItem(const QString &productName,
24 const QUuid &dataSourceUid)
24 {
25 {
25 auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
26 auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
26 QVector<QVariant>{productName});
27 QVector<QVariant>{productName});
27
28
28 // Add action to load product from DataSourceController
29 // Add action to load product from DataSourceController
29 result->addAction(std::make_unique<DataSourceItemAction>(
30 result->addAction(std::make_unique<DataSourceItemAction>(
30 QObject::tr("Load %1 product").arg(productName), [productName](DataSourceItem &item) {
31 QObject::tr("Load %1 product").arg(productName),
32 [productName, dataSourceUid](DataSourceItem &item) {
31 if (auto app = sqpApp) {
33 if (auto app = sqpApp) {
32 app->dataSourceController().loadProductItem(item);
34 app->dataSourceController().loadProductItem(dataSourceUid, item);
33 }
35 }
34 }));
36 }));
35
37
@@ -37,13 +39,13 std::unique_ptr<DataSourceItem> createProductItem(const QString &productName)
37 }
39 }
38
40
39 /// Creates the data source item relative to the plugin
41 /// Creates the data source item relative to the plugin
40 std::unique_ptr<DataSourceItem> createDataSourceItem() noexcept
42 std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept
41 {
43 {
42 // Magnetic field products
44 // Magnetic field products
43 auto magneticFieldFolder = std::make_unique<DataSourceItem>(
45 auto magneticFieldFolder = std::make_unique<DataSourceItem>(
44 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")});
46 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")});
45 magneticFieldFolder->appendChild(createProductItem(QStringLiteral("FGM")));
47 magneticFieldFolder->appendChild(createProductItem(QStringLiteral("FGM"), dataSourceUid));
46 magneticFieldFolder->appendChild(createProductItem(QStringLiteral("SC")));
48 magneticFieldFolder->appendChild(createProductItem(QStringLiteral("SC"), dataSourceUid));
47
49
48 // Electric field products
50 // Electric field products
49 auto electricFieldFolder = std::make_unique<DataSourceItem>(
51 auto electricFieldFolder = std::make_unique<DataSourceItem>(
@@ -68,7 +70,7 void MockPlugin::initialize()
68 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
70 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
69
71
70 // Sets data source tree
72 // Sets data source tree
71 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem());
73 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem(dataSourceUid));
72
74
73 // Sets data provider
75 // Sets data provider
74 dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
76 dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
General Comments 0
You need to be logged in to leave comments. Login now