##// END OF EJS Templates
Adds action in the mock plugin to load products
Alexandre Leroux -
r146:f61d116e8daa
parent child
Show More
@@ -1,73 +1,79
1 #ifndef SCIQLOP_DATASOURCECONTROLLER_H
1 #ifndef SCIQLOP_DATASOURCECONTROLLER_H
2 #define SCIQLOP_DATASOURCECONTROLLER_H
2 #define SCIQLOP_DATASOURCECONTROLLER_H
3
3
4 #include <QLoggingCategory>
4 #include <QLoggingCategory>
5 #include <QObject>
5 #include <QObject>
6 #include <QUuid>
6 #include <QUuid>
7
7
8 #include <Common/spimpl.h>
8 #include <Common/spimpl.h>
9
9
10 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController)
10 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController)
11
11
12 class DataSourceItem;
12 class DataSourceItem;
13 class IDataProvider;
13 class IDataProvider;
14
14
15 /**
15 /**
16 * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This
16 * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This
17 * is the intermediate class that SciQlop has to use in the way to connect a data source. Please
17 * is the intermediate class that SciQlop has to use in the way to connect a data source. Please
18 * first use register method to initialize a plugin specified by its metadata name (JSON plugin
18 * first use register method to initialize a plugin specified by its metadata name (JSON plugin
19 * source) then others specifics method will be able to access it. You can load a data source driver
19 * source) then others specifics method will be able to access it. You can load a data source driver
20 * plugin then create a data source.
20 * plugin then create a data source.
21 */
21 */
22 class DataSourceController : public QObject {
22 class DataSourceController : public QObject {
23 Q_OBJECT
23 Q_OBJECT
24 public:
24 public:
25 explicit DataSourceController(QObject *parent = 0);
25 explicit DataSourceController(QObject *parent = 0);
26 virtual ~DataSourceController();
26 virtual ~DataSourceController();
27
27
28 /**
28 /**
29 * Registers a data source. The method delivers a unique id that can be used afterwards to
29 * Registers a data source. The method delivers a unique id that can be used afterwards to
30 * access to the data source properties (structure, connection parameters, data provider, etc.)
30 * access to the data source properties (structure, connection parameters, data provider, etc.)
31 * @param dataSourceName the name of the data source
31 * @param dataSourceName the name of the data source
32 * @return the unique id with which the data source has been registered
32 * @return the unique id with which the data source has been registered
33 */
33 */
34 QUuid registerDataSource(const QString &dataSourceName) noexcept;
34 QUuid registerDataSource(const QString &dataSourceName) noexcept;
35
35
36 /**
36 /**
37 * Sets the structure of a data source. The controller takes ownership of the structure.
37 * Sets the structure of a data source. The controller takes ownership of the structure.
38 * @param dataSourceUid the unique id with which the data source has been registered into the
38 * @param dataSourceUid the unique id with which the data source has been registered into the
39 * controller. If it is invalid, the method has no effect.
39 * controller. If it is invalid, the method has no effect.
40 * @param dataSourceItem the structure of the data source
40 * @param dataSourceItem the structure of the data source
41 * @sa registerDataSource()
41 * @sa registerDataSource()
42 */
42 */
43 void setDataSourceItem(const QUuid &dataSourceUid,
43 void setDataSourceItem(const QUuid &dataSourceUid,
44 std::unique_ptr<DataSourceItem> dataSourceItem) noexcept;
44 std::unique_ptr<DataSourceItem> dataSourceItem) noexcept;
45
45
46 /**
46 /**
47 * Sets the data provider used to retrieve data from of a data source. The controller takes
47 * Sets the data provider used to retrieve data from of a data source. The controller takes
48 * ownership of the provider.
48 * ownership of the provider.
49 * @param dataSourceUid the unique id with which the data source has been registered into the
49 * @param dataSourceUid the unique id with which the data source has been registered into the
50 * controller. If it is invalid, the method has no effect.
50 * controller. If it is invalid, the method has no effect.
51 * @param dataProvider the provider of the data source
51 * @param dataProvider the provider of the data source
52 * @sa registerDataSource()
52 * @sa registerDataSource()
53 */
53 */
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();
60 void finalize();
66 void finalize();
61
67
62 signals:
68 signals:
63 /// Signal emitted when a structure has been set for a data source
69 /// Signal emitted when a structure has been set for a data source
64 void dataSourceItemSet(DataSourceItem *dataSourceItem);
70 void dataSourceItemSet(DataSourceItem *dataSourceItem);
65
71
66 private:
72 private:
67 void waitForFinish();
73 void waitForFinish();
68
74
69 class DataSourceControllerPrivate;
75 class DataSourceControllerPrivate;
70 spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl;
76 spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl;
71 };
77 };
72
78
73 #endif // SCIQLOP_DATASOURCECONTROLLER_H
79 #endif // SCIQLOP_DATASOURCECONTROLLER_H
@@ -1,71 +1,73
1 #ifndef SCIQLOP_DATASOURCEITEM_H
1 #ifndef SCIQLOP_DATASOURCEITEM_H
2 #define SCIQLOP_DATASOURCEITEM_H
2 #define SCIQLOP_DATASOURCEITEM_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5
5
6 #include <QVariant>
6 #include <QVariant>
7 #include <QVector>
7 #include <QVector>
8
8
9 class DataSourceItemAction;
9 class DataSourceItemAction;
10
10
11 /**
11 /**
12 * Possible types of an item
12 * Possible types of an item
13 */
13 */
14 enum class DataSourceItemType { NODE, PRODUCT };
14 enum class DataSourceItemType { NODE, PRODUCT };
15
15
16 /**
16 /**
17 * @brief The DataSourceItem class aims to represent a structure element of a data source.
17 * @brief The DataSourceItem class aims to represent a structure element of a data source.
18 * A data source has a tree structure that is made up of a main DataSourceItem object (root)
18 * A data source has a tree structure that is made up of a main DataSourceItem object (root)
19 * containing other DataSourceItem objects (children).
19 * containing other DataSourceItem objects (children).
20 * For each DataSourceItem can be associated a set of data representing it.
20 * For each DataSourceItem can be associated a set of data representing it.
21 */
21 */
22 class DataSourceItem {
22 class DataSourceItem {
23 public:
23 public:
24 explicit DataSourceItem(DataSourceItemType type, QVector<QVariant> data = {});
24 explicit DataSourceItem(DataSourceItemType type, QVector<QVariant> data = {});
25
25
26 /// @return the actions of the item as a vector
26 /// @return the actions of the item as a vector
27 QVector<DataSourceItemAction *> actions() const noexcept;
27 QVector<DataSourceItemAction *> actions() const noexcept;
28
28
29 /**
29 /**
30 * Adds an action to the item. The item takes ownership of the action, and the action is
30 * Adds an action to the item. The item takes ownership of the action, and the action is
31 * automatically associated to the item
31 * automatically associated to the item
32 * @param action the action to add
32 * @param action the action to add
33 */
33 */
34 void addAction(std::unique_ptr<DataSourceItemAction> action) noexcept;
34 void addAction(std::unique_ptr<DataSourceItemAction> action) noexcept;
35
35
36 /**
36 /**
37 * Adds a child to the item. The item takes ownership of the child.
37 * Adds a child to the item. The item takes ownership of the child.
38 * @param child the child to add
38 * @param child the child to add
39 */
39 */
40 void appendChild(std::unique_ptr<DataSourceItem> child) noexcept;
40 void appendChild(std::unique_ptr<DataSourceItem> child) noexcept;
41
41
42 /**
42 /**
43 * Returns the item's child associated to an index
43 * Returns the item's child associated to an index
44 * @param childIndex the index to search
44 * @param childIndex the index to search
45 * @return a pointer to the child if index is valid, nullptr otherwise
45 * @return a pointer to the child if index is valid, nullptr otherwise
46 */
46 */
47 DataSourceItem *child(int childIndex) const noexcept;
47 DataSourceItem *child(int childIndex) const noexcept;
48
48
49 int childCount() const noexcept;
49 int childCount() const noexcept;
50
50
51 /**
51 /**
52 * Get the data associated to an index
52 * Get the data associated to an index
53 * @param dataIndex the index to search
53 * @param dataIndex the index to search
54 * @return the data found if index is valid, default QVariant otherwise
54 * @return the data found if index is valid, default QVariant otherwise
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
61 */
63 */
62 DataSourceItem *parentItem() const noexcept;
64 DataSourceItem *parentItem() const noexcept;
63
65
64 DataSourceItemType type() const noexcept;
66 DataSourceItemType type() const noexcept;
65
67
66 private:
68 private:
67 class DataSourceItemPrivate;
69 class DataSourceItemPrivate;
68 spimpl::unique_impl_ptr<DataSourceItemPrivate> impl;
70 spimpl::unique_impl_ptr<DataSourceItemPrivate> impl;
69 };
71 };
70
72
71 #endif // SCIQLOP_DATASOURCEITEMMODEL_H
73 #endif // SCIQLOP_DATASOURCEITEMMODEL_H
@@ -1,95 +1,100
1 #include <DataSource/DataSourceController.h>
1 #include <DataSource/DataSourceController.h>
2 #include <DataSource/DataSourceItem.h>
2 #include <DataSource/DataSourceItem.h>
3
3
4 #include <Data/IDataProvider.h>
4 #include <Data/IDataProvider.h>
5
5
6 #include <QMutex>
6 #include <QMutex>
7 #include <QThread>
7 #include <QThread>
8
8
9 #include <QDir>
9 #include <QDir>
10 #include <QStandardPaths>
10 #include <QStandardPaths>
11
11
12 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
12 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
13
13
14 class DataSourceController::DataSourceControllerPrivate {
14 class DataSourceController::DataSourceControllerPrivate {
15 public:
15 public:
16 QMutex m_WorkingMutex;
16 QMutex m_WorkingMutex;
17 /// Data sources registered
17 /// Data sources registered
18 QHash<QUuid, QString> m_DataSources;
18 QHash<QUuid, QString> m_DataSources;
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 std::map<QUuid, std::unique_ptr<IDataProvider> > m_DataProviders;
23 };
23 };
24
24
25 DataSourceController::DataSourceController(QObject *parent)
25 DataSourceController::DataSourceController(QObject *parent)
26 : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
26 : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
27 {
27 {
28 qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction")
28 qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction")
29 << QThread::currentThread();
29 << QThread::currentThread();
30 }
30 }
31
31
32 DataSourceController::~DataSourceController()
32 DataSourceController::~DataSourceController()
33 {
33 {
34 qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction")
34 qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction")
35 << QThread::currentThread();
35 << QThread::currentThread();
36 this->waitForFinish();
36 this->waitForFinish();
37 }
37 }
38
38
39 QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept
39 QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept
40 {
40 {
41 auto dataSourceUid = QUuid::createUuid();
41 auto dataSourceUid = QUuid::createUuid();
42 impl->m_DataSources.insert(dataSourceUid, dataSourceName);
42 impl->m_DataSources.insert(dataSourceUid, dataSourceName);
43
43
44 return dataSourceUid;
44 return dataSourceUid;
45 }
45 }
46
46
47 void DataSourceController::setDataSourceItem(
47 void DataSourceController::setDataSourceItem(
48 const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
48 const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
49 {
49 {
50 if (impl->m_DataSources.contains(dataSourceUid)) {
50 if (impl->m_DataSources.contains(dataSourceUid)) {
51 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
51 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
52
52
53 // Retrieves the data source item to emit the signal with it
53 // Retrieves the data source item to emit the signal with it
54 auto it = impl->m_DataSourceItems.find(dataSourceUid);
54 auto it = impl->m_DataSourceItems.find(dataSourceUid);
55 if (it != impl->m_DataSourceItems.end()) {
55 if (it != impl->m_DataSourceItems.end()) {
56 emit dataSourceItemSet(it->second.get());
56 emit dataSourceItemSet(it->second.get());
57 }
57 }
58 }
58 }
59 else {
59 else {
60 qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
60 qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
61 "data source has been registered with the uid")
61 "data source has been registered with the uid")
62 .arg(dataSourceUid.toString());
62 .arg(dataSourceUid.toString());
63 }
63 }
64 }
64 }
65
65
66 void DataSourceController::setDataProvider(const QUuid &dataSourceUid,
66 void DataSourceController::setDataProvider(const QUuid &dataSourceUid,
67 std::unique_ptr<IDataProvider> dataProvider) noexcept
67 std::unique_ptr<IDataProvider> dataProvider) noexcept
68 {
68 {
69 if (impl->m_DataSources.contains(dataSourceUid)) {
69 if (impl->m_DataSources.contains(dataSourceUid)) {
70 impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider)));
70 impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider)));
71 }
71 }
72 else {
72 else {
73 qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data "
73 qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data "
74 "source has been registered with the uid")
74 "source has been registered with the uid")
75 .arg(dataSourceUid.toString());
75 .arg(dataSourceUid.toString());
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")
82 << QThread::currentThread();
87 << QThread::currentThread();
83 impl->m_WorkingMutex.lock();
88 impl->m_WorkingMutex.lock();
84 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
89 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
85 }
90 }
86
91
87 void DataSourceController::finalize()
92 void DataSourceController::finalize()
88 {
93 {
89 impl->m_WorkingMutex.unlock();
94 impl->m_WorkingMutex.unlock();
90 }
95 }
91
96
92 void DataSourceController::waitForFinish()
97 void DataSourceController::waitForFinish()
93 {
98 {
94 QMutexLocker locker{&impl->m_WorkingMutex};
99 QMutexLocker locker{&impl->m_WorkingMutex};
95 }
100 }
@@ -1,74 +1,86
1 #include <DataSource/DataSourceItem.h>
1 #include <DataSource/DataSourceItem.h>
2 #include <DataSource/DataSourceItemAction.h>
2 #include <DataSource/DataSourceItemAction.h>
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{}
9 {
16 {
10 }
17 }
11
18
12 DataSourceItem *m_Parent;
19 DataSourceItem *m_Parent;
13 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
20 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
14 DataSourceItemType m_Type;
21 DataSourceItemType m_Type;
15 QVector<QVariant> m_Data;
22 QVector<QVariant> m_Data;
16 std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions;
23 std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions;
17 };
24 };
18
25
19 DataSourceItem::DataSourceItem(DataSourceItemType type, QVector<QVariant> data)
26 DataSourceItem::DataSourceItem(DataSourceItemType type, QVector<QVariant> data)
20 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
27 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
21 {
28 {
22 }
29 }
23
30
24 QVector<DataSourceItemAction *> DataSourceItem::actions() const noexcept
31 QVector<DataSourceItemAction *> DataSourceItem::actions() const noexcept
25 {
32 {
26 QVector<DataSourceItemAction *> result{};
33 QVector<DataSourceItemAction *> result{};
27
34
28 std::transform(std::cbegin(impl->m_Actions), std::cend(impl->m_Actions),
35 std::transform(std::cbegin(impl->m_Actions), std::cend(impl->m_Actions),
29 std::back_inserter(result), [](const auto &action) { return action.get(); });
36 std::back_inserter(result), [](const auto &action) { return action.get(); });
30
37
31 return result;
38 return result;
32 }
39 }
33
40
34 void DataSourceItem::addAction(std::unique_ptr<DataSourceItemAction> action) noexcept
41 void DataSourceItem::addAction(std::unique_ptr<DataSourceItemAction> action) noexcept
35 {
42 {
36 action->setDataSourceItem(this);
43 action->setDataSourceItem(this);
37 impl->m_Actions.push_back(std::move(action));
44 impl->m_Actions.push_back(std::move(action));
38 }
45 }
39
46
40 void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept
47 void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept
41 {
48 {
42 child->impl->m_Parent = this;
49 child->impl->m_Parent = this;
43 impl->m_Children.push_back(std::move(child));
50 impl->m_Children.push_back(std::move(child));
44 }
51 }
45
52
46 DataSourceItem *DataSourceItem::child(int childIndex) const noexcept
53 DataSourceItem *DataSourceItem::child(int childIndex) const noexcept
47 {
54 {
48 if (childIndex < 0 || childIndex >= childCount()) {
55 if (childIndex < 0 || childIndex >= childCount()) {
49 return nullptr;
56 return nullptr;
50 }
57 }
51 else {
58 else {
52 return impl->m_Children.at(childIndex).get();
59 return impl->m_Children.at(childIndex).get();
53 }
60 }
54 }
61 }
55
62
56 int DataSourceItem::childCount() const noexcept
63 int DataSourceItem::childCount() const noexcept
57 {
64 {
58 return impl->m_Children.size();
65 return impl->m_Children.size();
59 }
66 }
60
67
61 QVariant DataSourceItem::data(int dataIndex) const noexcept
68 QVariant DataSourceItem::data(int dataIndex) const noexcept
62 {
69 {
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;
69 }
81 }
70
82
71 DataSourceItemType DataSourceItem::type() const noexcept
83 DataSourceItemType DataSourceItem::type() const noexcept
72 {
84 {
73 return impl->m_Type;
85 return impl->m_Type;
74 }
86 }
@@ -1,67 +1,79
1 #include "MockPlugin.h"
1 #include "MockPlugin.h"
2 #include "CosinusProvider.h"
2 #include "CosinusProvider.h"
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
9 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
10 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
10
11
11 namespace {
12 namespace {
12
13
13 /// Name of the data source
14 /// Name of the data source
14 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
15 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
15
16
16 /// Creates the data provider relative to the plugin
17 /// Creates the data provider relative to the plugin
17 std::unique_ptr<IDataProvider> createDataProvider() noexcept
18 std::unique_ptr<IDataProvider> createDataProvider() noexcept
18 {
19 {
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(std::move(fgmProduct));
45 magneticFieldFolder->appendChild(createProductItem(QStringLiteral("FGM")));
34 magneticFieldFolder->appendChild(std::move(scProduct));
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>(
38 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Electric field")});
50 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Electric field")});
39
51
40 // Root
52 // Root
41 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
53 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
42 QVector<QVariant>{DATA_SOURCE_NAME});
54 QVector<QVariant>{DATA_SOURCE_NAME});
43 root->appendChild(std::move(magneticFieldFolder));
55 root->appendChild(std::move(magneticFieldFolder));
44 root->appendChild(std::move(electricFieldFolder));
56 root->appendChild(std::move(electricFieldFolder));
45
57
46 return root;
58 return root;
47 }
59 }
48
60
49 } // namespace
61 } // namespace
50
62
51 void MockPlugin::initialize()
63 void MockPlugin::initialize()
52 {
64 {
53 if (auto app = sqpApp) {
65 if (auto app = sqpApp) {
54 // Registers to the data source controller
66 // Registers to the data source controller
55 auto &dataSourceController = app->dataSourceController();
67 auto &dataSourceController = app->dataSourceController();
56 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
68 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
57
69
58 // Sets data source tree
70 // Sets data source tree
59 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem());
71 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem());
60
72
61 // Sets data provider
73 // Sets data provider
62 dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
74 dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
63 }
75 }
64 else {
76 else {
65 qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application");
77 qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application");
66 }
78 }
67 }
79 }
General Comments 0
You need to be logged in to leave comments. Login now