@@ -54,6 +54,12 public: | |||
|
54 | 54 | void setDataProvider(const QUuid &dataSourceUid, |
|
55 | 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 | 63 | public slots: |
|
58 | 64 | /// Manage init/end of the controller |
|
59 | 65 | void initialize(); |
@@ -55,6 +55,8 public: | |||
|
55 | 55 | */ |
|
56 | 56 | QVariant data(int dataIndex) const noexcept; |
|
57 | 57 | |
|
58 | QString name() const noexcept; | |
|
59 | ||
|
58 | 60 | /** |
|
59 | 61 | * Get the item's parent |
|
60 | 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 | 84 | void DataSourceController::initialize() |
|
80 | 85 | { |
|
81 | 86 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init") |
@@ -3,6 +3,13 | |||
|
3 | 3 | |
|
4 | 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 | 13 | struct DataSourceItem::DataSourceItemPrivate { |
|
7 | 14 | explicit DataSourceItemPrivate(DataSourceItemType type, QVector<QVariant> data) |
|
8 | 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 | 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 | 78 | DataSourceItem *DataSourceItem::parentItem() const noexcept |
|
67 | 79 | { |
|
68 | 80 | return impl->m_Parent; |
@@ -3,6 +3,7 | |||
|
3 | 3 | |
|
4 | 4 | #include <DataSource/DataSourceController.h> |
|
5 | 5 | #include <DataSource/DataSourceItem.h> |
|
6 | #include <DataSource/DataSourceItemAction.h> | |
|
6 | 7 | |
|
7 | 8 | #include <SqpApplication.h> |
|
8 | 9 | |
@@ -19,19 +20,30 std::unique_ptr<IDataProvider> createDataProvider() noexcept | |||
|
19 | 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 | 39 | /// Creates the data source item relative to the plugin |
|
23 | 40 | std::unique_ptr<DataSourceItem> createDataSourceItem() noexcept |
|
24 | 41 | { |
|
25 | 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 | 43 | auto magneticFieldFolder = std::make_unique<DataSourceItem>( |
|
32 | 44 | DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")}); |
|
33 |
magneticFieldFolder->appendChild( |
|
|
34 |
magneticFieldFolder->appendChild( |
|
|
45 | magneticFieldFolder->appendChild(createProductItem(QStringLiteral("FGM"))); | |
|
46 | magneticFieldFolder->appendChild(createProductItem(QStringLiteral("SC"))); | |
|
35 | 47 | |
|
36 | 48 | // Electric field products |
|
37 | 49 | auto electricFieldFolder = std::make_unique<DataSourceItem>( |
General Comments 0
You need to be logged in to leave comments.
Login now