@@ -54,6 +54,12 public: | |||||
54 | void setDataProvider(const QUuid &dataSourceUid, |
|
54 | void setDataProvider(const QUuid &dataSourceUid, | |
55 | std::unique_ptr<IDataProvider> dataProvider) noexcept; |
|
55 | std::unique_ptr<IDataProvider> dataProvider) noexcept; | |
56 |
|
56 | |||
|
57 | /** | |||
|
58 | * Loads an item (product) as a variable in SciQlop | |||
|
59 | * @param productItem the item to load | |||
|
60 | */ | |||
|
61 | void loadProductItem(const DataSourceItem &productItem) noexcept; | |||
|
62 | ||||
57 | public slots: |
|
63 | public slots: | |
58 | /// Manage init/end of the controller |
|
64 | /// Manage init/end of the controller | |
59 | void initialize(); |
|
65 | void initialize(); |
@@ -55,6 +55,8 public: | |||||
55 | */ |
|
55 | */ | |
56 | QVariant data(int dataIndex) const noexcept; |
|
56 | QVariant data(int dataIndex) const noexcept; | |
57 |
|
57 | |||
|
58 | QString name() const noexcept; | |||
|
59 | ||||
58 | /** |
|
60 | /** | |
59 | * Get the item's parent |
|
61 | * Get the item's parent | |
60 | * @return a pointer to the parent if it exists, nullptr if the item is a root |
|
62 | * @return a pointer to the parent if it exists, nullptr if the item is a root |
@@ -76,6 +76,11 void DataSourceController::setDataProvider(const QUuid &dataSourceUid, | |||||
76 | } |
|
76 | } | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
|
79 | void DataSourceController::loadProductItem(const DataSourceItem &productItem) noexcept | |||
|
80 | { | |||
|
81 | /// @todo ALX | |||
|
82 | } | |||
|
83 | ||||
79 | void DataSourceController::initialize() |
|
84 | void DataSourceController::initialize() | |
80 | { |
|
85 | { | |
81 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init") |
|
86 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init") |
@@ -3,6 +3,13 | |||||
3 |
|
3 | |||
4 | #include <QVector> |
|
4 | #include <QVector> | |
5 |
|
5 | |||
|
6 | namespace { | |||
|
7 | ||||
|
8 | /// Index of the 'name' value in the item | |||
|
9 | const auto NAME_INDEX = 0; | |||
|
10 | ||||
|
11 | } // namespace | |||
|
12 | ||||
6 | struct DataSourceItem::DataSourceItemPrivate { |
|
13 | struct DataSourceItem::DataSourceItemPrivate { | |
7 | explicit DataSourceItemPrivate(DataSourceItemType type, QVector<QVariant> data) |
|
14 | explicit DataSourceItemPrivate(DataSourceItemType type, QVector<QVariant> data) | |
8 | : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{} |
|
15 | : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{} | |
@@ -63,6 +70,11 QVariant DataSourceItem::data(int dataIndex) const noexcept | |||||
63 | return impl->m_Data.value(dataIndex); |
|
70 | return impl->m_Data.value(dataIndex); | |
64 | } |
|
71 | } | |
65 |
|
72 | |||
|
73 | QString DataSourceItem::name() const noexcept | |||
|
74 | { | |||
|
75 | return data(NAME_INDEX).toString(); | |||
|
76 | } | |||
|
77 | ||||
66 | DataSourceItem *DataSourceItem::parentItem() const noexcept |
|
78 | DataSourceItem *DataSourceItem::parentItem() const noexcept | |
67 | { |
|
79 | { | |
68 | return impl->m_Parent; |
|
80 | return impl->m_Parent; |
@@ -3,6 +3,7 | |||||
3 |
|
3 | |||
4 | #include <DataSource/DataSourceController.h> |
|
4 | #include <DataSource/DataSourceController.h> | |
5 | #include <DataSource/DataSourceItem.h> |
|
5 | #include <DataSource/DataSourceItem.h> | |
|
6 | #include <DataSource/DataSourceItemAction.h> | |||
6 |
|
7 | |||
7 | #include <SqpApplication.h> |
|
8 | #include <SqpApplication.h> | |
8 |
|
9 | |||
@@ -19,19 +20,30 std::unique_ptr<IDataProvider> createDataProvider() noexcept | |||||
19 | return std::make_unique<CosinusProvider>(); |
|
20 | return std::make_unique<CosinusProvider>(); | |
20 | } |
|
21 | } | |
21 |
|
22 | |||
|
23 | std::unique_ptr<DataSourceItem> createProductItem(const QString &productName) | |||
|
24 | { | |||
|
25 | auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, | |||
|
26 | QVector<QVariant>{productName}); | |||
|
27 | ||||
|
28 | // Add action to load product from DataSourceController | |||
|
29 | result->addAction(std::make_unique<DataSourceItemAction>( | |||
|
30 | QObject::tr("Load %1 product").arg(productName), [productName](DataSourceItem &item) { | |||
|
31 | if (auto app = sqpApp) { | |||
|
32 | app->dataSourceController().loadProductItem(item); | |||
|
33 | } | |||
|
34 | })); | |||
|
35 | ||||
|
36 | return result; | |||
|
37 | } | |||
|
38 | ||||
22 | /// Creates the data source item relative to the plugin |
|
39 | /// Creates the data source item relative to the plugin | |
23 | std::unique_ptr<DataSourceItem> createDataSourceItem() noexcept |
|
40 | std::unique_ptr<DataSourceItem> createDataSourceItem() noexcept | |
24 | { |
|
41 | { | |
25 | // Magnetic field products |
|
42 | // Magnetic field products | |
26 | auto fgmProduct = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, |
|
|||
27 | QVector<QVariant>{QStringLiteral("FGM")}); |
|
|||
28 | auto scProduct = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, |
|
|||
29 | QVector<QVariant>{QStringLiteral("SC")}); |
|
|||
30 |
|
||||
31 | auto magneticFieldFolder = std::make_unique<DataSourceItem>( |
|
43 | auto magneticFieldFolder = std::make_unique<DataSourceItem>( | |
32 | DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")}); |
|
44 | DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")}); | |
33 |
magneticFieldFolder->appendChild( |
|
45 | magneticFieldFolder->appendChild(createProductItem(QStringLiteral("FGM"))); | |
34 |
magneticFieldFolder->appendChild( |
|
46 | magneticFieldFolder->appendChild(createProductItem(QStringLiteral("SC"))); | |
35 |
|
47 | |||
36 | // Electric field products |
|
48 | // Electric field products | |
37 | auto electricFieldFolder = std::make_unique<DataSourceItem>( |
|
49 | auto electricFieldFolder = std::make_unique<DataSourceItem>( |
General Comments 0
You need to be logged in to leave comments.
Login now